Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
2.5 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: cfilename.cpp
  4. //
  5. // Module: CMSETUP.LIB
  6. //
  7. // Synopsis: Implementation of the CFileNameParts Class
  8. //
  9. // Copyright (c) 1998-1999 Microsoft Corporation
  10. //
  11. // Author: quintinb Created Header 08/19/99
  12. //
  13. //+----------------------------------------------------------------------------
  14. #include "cfilename.h"
  15. CFileNameParts::CFileNameParts(LPCTSTR szFullPath)
  16. {
  17. if (NULL == szFullPath)
  18. {
  19. CMASSERTMSG(FALSE, TEXT("NULL Input to CFileNameParts"));
  20. return;
  21. }
  22. MYDBGASSERT(MAX_PATH >= lstrlen(szFullPath));
  23. ZeroMemory(m_szFullPath, sizeof(m_szFullPath));
  24. ZeroMemory(m_Drive, sizeof(m_Drive));
  25. ZeroMemory(m_Dir, sizeof(m_Dir));
  26. ZeroMemory(m_FileName, sizeof(m_FileName));
  27. ZeroMemory(m_Extension, sizeof(m_Extension));
  28. TCHAR* pszStart = m_szFullPath;
  29. const TCHAR* pszCurrentSource = szFullPath;
  30. TCHAR* pszLastSlash = NULL;
  31. TCHAR* pszColon = NULL;
  32. TCHAR* pszLastDot = NULL;
  33. TCHAR* pszCurrentDest = m_szFullPath;
  34. //
  35. // Copy szFullPath to m_szFullPath
  36. //
  37. lstrcpy(m_szFullPath, szFullPath);
  38. while ((TEXT('\0') != *pszCurrentSource) && (MAX_PATH >= (pszCurrentSource - szFullPath)))
  39. {
  40. switch(*pszCurrentSource)
  41. {
  42. case TEXT(':'):
  43. //
  44. // Found a colon, take the drive letter.
  45. //
  46. if ((NULL == pszColon) && (pszCurrentDest != m_szFullPath) &&
  47. (m_szFullPath == CharPrev(m_szFullPath, pszCurrentDest)))
  48. {
  49. pszColon = pszCurrentDest;
  50. lstrcpyn(m_Drive, pszStart, (size_t)((pszCurrentDest - pszStart) + 2));
  51. pszStart = CharNext(pszColon);
  52. }
  53. else
  54. {
  55. CMASSERTMSG(FALSE, TEXT("CFileNameParts -- Error, we only allow one colon in a path."));
  56. return;
  57. }
  58. break;
  59. case TEXT('\\'):
  60. case TEXT('/'):
  61. pszLastSlash = pszCurrentDest;
  62. break;
  63. case TEXT('.'):
  64. pszLastDot = pszCurrentDest;
  65. break;
  66. }
  67. pszCurrentSource = CharNext(pszCurrentSource);
  68. pszCurrentDest = CharNext(pszCurrentDest);
  69. }
  70. if (pszLastSlash)
  71. {
  72. lstrcpyn(m_Dir, pszStart, (size_t)((pszLastSlash - pszStart) + 2));
  73. pszStart = CharNext(pszLastSlash) ;
  74. }
  75. if (pszLastDot && (pszLastDot > pszLastSlash))
  76. {
  77. lstrcpyn(m_FileName, pszStart, (size_t)((pszLastDot - pszStart) + 1));
  78. lstrcpyn(m_Extension, pszLastDot, _MAX_EXT+1);
  79. }
  80. else
  81. {
  82. //
  83. // No extension
  84. //
  85. lstrcpyn(m_FileName, pszStart, _MAX_FNAME+1);
  86. }
  87. }