Source code of Windows XP (NT5)
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.

226 lines
4.1 KiB

  1. #ifndef _INC_DSKQUOTA_PATHSTR_H
  2. #define _INC_DSKQUOTA_PATHSTR_H
  3. #ifndef _INC_DSKQUOTA_UTILS_H
  4. # include "utils.h"
  5. #endif
  6. #ifndef _INC_SHLWAPI
  7. # include <shlwapi.h>
  8. #endif
  9. #ifndef _INC_DSKQUOTA_STRCLASS_H
  10. # include "strclass.h"
  11. #endif
  12. class CPath : public CString
  13. {
  14. public:
  15. CPath(void) { }
  16. explicit CPath(LPCTSTR pszRoot, LPCTSTR pszDir = NULL, LPCTSTR pszFile = NULL, LPCTSTR pszExt = NULL);
  17. CPath(const CPath& rhs);
  18. CPath& operator = (const CPath& rhs);
  19. CPath& operator = (LPCTSTR rhs);
  20. ~CPath(void) { }
  21. //
  22. // Component replacement.
  23. //
  24. void SetRoot(LPCTSTR pszRoot);
  25. void SetPath(LPCTSTR pszPath);
  26. void SetDirectory(LPCTSTR pszDir);
  27. void SetFileSpec(LPCTSTR pszFileSpec);
  28. void SetExtension(LPCTSTR pszExt);
  29. //
  30. // Component query
  31. //
  32. bool GetRoot(CPath *pOut) const;
  33. bool GetPath(CPath *pOut) const;
  34. bool GetDirectory(CPath *pOut) const;
  35. bool GetFileSpec(CPath *pOut) const;
  36. bool GetExtension(CPath *pOut) const;
  37. //
  38. // Component removal
  39. //
  40. void RemoveRoot(void);
  41. void RemovePath(void);
  42. void RemoveFileSpec(void);
  43. void RemoveExtension(void);
  44. void StripToRoot(void);
  45. bool Append(LPCTSTR psz);
  46. //
  47. // DOS drive letter support.
  48. //
  49. bool BuildRoot(int iDrive);
  50. int GetDriveNumber(void) const;
  51. //
  52. // Type identification.
  53. //
  54. bool IsDirectory(void) const;
  55. bool IsFileSpec(void) const;
  56. bool IsPrefix(LPCTSTR pszPrefix) const;
  57. bool IsRelative(void) const;
  58. bool IsRoot(void) const;
  59. bool IsSameRoot(LPCTSTR pszPath) const;
  60. bool IsUNC(void) const;
  61. bool IsUNCServer(void) const;
  62. bool IsUNCServerShare(void) const;
  63. bool IsURL(void) const;
  64. //
  65. // Miscellaneous formatting.
  66. //
  67. bool MakePretty(void);
  68. void QuoteSpaces(void);
  69. void UnquoteSpaces(void);
  70. void RemoveBlanks(void);
  71. void AddBackslash(void);
  72. void RemoveBackslash(void);
  73. bool Canonicalize(void);
  74. bool Compact(HDC hdc, int cxPixels);
  75. bool CommonPrefix(LPCTSTR pszPath1, LPCTSTR pszPath2);
  76. bool Exists(void) const;
  77. private:
  78. template <class T>
  79. T MAX(const T& a, const T& b)
  80. { return a > b ? a : b; }
  81. };
  82. class CPathIter
  83. {
  84. public:
  85. CPathIter(const CPath& path);
  86. ~CPathIter(void) { }
  87. bool Next(CPath *pOut);
  88. void Reset(void);
  89. private:
  90. CPath m_path;
  91. LPTSTR m_pszCurrent;
  92. };
  93. inline bool
  94. CPath::Exists(
  95. void
  96. ) const
  97. {
  98. return boolify(::PathFileExists((LPCTSTR)*this));
  99. }
  100. inline bool
  101. CPath::IsDirectory(
  102. void
  103. ) const
  104. {
  105. return boolify(::PathIsDirectory((LPCTSTR)*this));
  106. }
  107. inline bool
  108. CPath::IsFileSpec(
  109. void
  110. ) const
  111. {
  112. return boolify(::PathIsFileSpec((LPCTSTR)*this));
  113. }
  114. inline bool
  115. CPath::IsPrefix(
  116. LPCTSTR pszPrefix
  117. ) const
  118. {
  119. return boolify(::PathIsPrefix(pszPrefix, (LPCTSTR)*this));
  120. }
  121. inline bool
  122. CPath::IsRelative(
  123. void
  124. ) const
  125. {
  126. return boolify(::PathIsRelative((LPCTSTR)*this));
  127. }
  128. inline bool
  129. CPath::IsRoot(
  130. void
  131. ) const
  132. {
  133. return boolify(::PathIsRoot((LPCTSTR)*this));
  134. }
  135. inline bool
  136. CPath::IsSameRoot(
  137. LPCTSTR pszPath
  138. ) const
  139. {
  140. return boolify(::PathIsSameRoot(pszPath, (LPCTSTR)*this));
  141. }
  142. inline bool
  143. CPath::IsUNC(
  144. void
  145. ) const
  146. {
  147. return boolify(::PathIsUNC((LPCTSTR)*this));
  148. }
  149. inline bool
  150. CPath::IsUNCServer(
  151. void
  152. ) const
  153. {
  154. return boolify(::PathIsUNCServer((LPCTSTR)*this));
  155. }
  156. inline bool
  157. CPath::IsUNCServerShare(
  158. void
  159. ) const
  160. {
  161. return boolify(::PathIsUNCServerShare((LPCTSTR)*this));
  162. }
  163. inline bool
  164. CPath::IsURL(
  165. void
  166. ) const
  167. {
  168. return boolify(::PathIsURL((LPCTSTR)*this));
  169. }
  170. inline bool
  171. CPath::MakePretty(
  172. void
  173. )
  174. {
  175. return boolify(::PathMakePretty((LPTSTR)*this));
  176. }
  177. inline int
  178. CPath::GetDriveNumber(
  179. void
  180. ) const
  181. {
  182. return ::PathGetDriveNumber(*this);
  183. }
  184. #endif // _INC_DSKQUOTA_PATHSTR_H