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.

212 lines
3.9 KiB

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