1 // PROJECT: ReactOS ATL CPathT
2 // LICENSE: Public Domain
3 // PURPOSE: Provides compatibility to Microsoft ATL
4 // PROGRAMMERS: Benedikt Freisen
9 // WARNING: Untested code
20 template<typename StringType
>
24 inline BOOL
PathFileExistsX(LPCSTR pszPath
) { return PathFileExistsA(pszPath
); }
25 inline BOOL
PathFileExistsX(LPCWSTR pszPath
) { return PathFileExistsW(pszPath
); }
26 inline int PathFindExtensionX(LPCSTR pszPath
) { return PathFindExtensionA(pszPath
); }
27 inline int PathFindExtensionX(LPCWSTR pszPath
) { return PathFindExtensionW(pszPath
); }
28 inline int PathFindFileNameX(LPCSTR pszPath
) { return PathFindFileNameA(pszPath
); }
29 inline int PathFindFileNameX(LPCWSTR pszPath
) { return PathFindFileNameW(pszPath
); }
30 inline int PathGetDriveNumberX(LPCSTR pszPath
) { return PathGetDriveNumberA(pszPath
); }
31 inline int PathGetDriveNumberX(LPCWSTR pszPath
) { return PathGetDriveNumberW(pszPath
); }
32 inline BOOL
PathIsDirectoryX(LPCSTR pszPath
) { return PathIsDirectoryA(pszPath
); }
33 inline BOOL
PathIsDirectoryX(LPCWSTR pszPath
) { return PathIsDirectoryW(pszPath
); }
34 inline BOOL
PathIsFileSpecX(LPCSTR pszPath
) { return PathIsFileSpecA(pszPath
); }
35 inline BOOL
PathIsFileSpecX(LPCWSTR pszPath
) { return PathIsFileSpecW(pszPath
); }
36 inline BOOL
PathIsPrefixX(LPCSTR pszPath
, LPCSTR pszPrefix
) { return PathIsPrefixA(pszPath
, pszPrefix
); }
37 inline BOOL
PathIsPrefixX(LPCWSTR pszPath
, LPCWSTR pszPrefix
) { return PathIsPrefixW(pszPath
, pszPrefix
); }
38 inline BOOL
PathIsRelativeX(LPCSTR pszPath
) { return PathIsRelativeA(pszPath
); }
39 inline BOOL
PathIsRelativeX(LPCWSTR pszPath
) { return PathIsRelativeW(pszPath
); }
40 inline BOOL
PathIsRootX(LPCSTR pszPath
) { return PathIsRootA(pszPath
); }
41 inline BOOL
PathIsRootX(LPCWSTR pszPath
) { return PathIsRootW(pszPath
); }
42 inline BOOL
PathIsSameRootX(LPCSTR pszPath
, LPCSTR pszOther
) { return PathIsSameRootA(pszPath
, pszOther
); }
43 inline BOOL
PathIsSameRootX(LPCWSTR pszPath
, LPCWSTR pszOther
) { return PathIsSameRootW(pszPath
, pszOther
); }
44 inline BOOL
PathIsUNCX(LPCSTR pszPath
) { return PathIsUNCA(pszPath
); }
45 inline BOOL
PathIsUNCX(LPCWSTR pszPath
) { return PathIsUNCW(pszPath
); }
46 inline BOOL
PathIsUNCServerX(LPCSTR pszPath
) { return PathIsUNCServerA(pszPath
); }
47 inline BOOL
PathIsUNCServerX(LPCWSTR pszPath
) { return PathIsUNCServerW(pszPath
); }
48 inline BOOL
PathIsUNCServerShareX(LPCSTR pszPath
) { return PathIsUNCServerShareA(pszPath
); }
49 inline BOOL
PathIsUNCServerShareX(LPCWSTR pszPath
) { return PathIsUNCServerShareW(pszPath
); }
50 inline BOOL
PathMatchSpecX(LPCSTR pszPath
, LPCSTR pszSpec
) { return PathMatchSpecA(pszPath
, pszSpec
); }
51 inline BOOL
PathMatchSpecX(LPCWSTR pszPath
, LPCWSTR pszSpec
) { return PathMatchSpecW(pszPath
, pszSpec
); }
52 inline int PathSkipRootX(LPCSTR pszPath
) { return PathSkipRootA(pszPath
); }
53 inline int PathSkipRootX(LPCWSTR pszPath
) { return PathSkipRootW(pszPath
); }
56 inline void PathAddBackslashX(LPSTR pszPath
) { PathAddBackslashA(pszPath
); }
57 inline void PathAddBackslashX(LPWSTR pszPath
) { PathAddBackslashW(pszPath
); }
58 inline BOOL
PathAddExtensionX(LPSTR pszPath
, LPCSTR pszExt
) { return PathAddExtensionA(pszPath
, pszExt
); }
59 inline BOOL
PathAddExtensionX(LPWSTR pszPath
, LPCWSTR pszExt
) { return PathAddExtensionW(pszPath
, pszExt
); }
60 inline BOOL
PathAppendX(LPSTR pszPath
, LPCSTR pszMore
) { return PathAppendA(pszPath
, pszMore
); }
61 inline BOOL
PathAppendX(LPWSTR pszPath
, LPCWSTR pszMore
) { return PathAppendW(pszPath
, pszMore
); }
62 inline void PathBuildRootX(LPSTR pszRoot
, int iDrive
) { PathBuildRootA(pszRoot
, iDrive
); }
63 inline void PathBuildRootX(LPWSTR pszRoot
, int iDrive
) { PathBuildRootW(pszRoot
, iDrive
); }
64 inline void PathCanonicalizeX(LPSTR pszDst
, LPCSTR pszSrc
) { PathCanonicalizeA(pszDst
, pszSrc
); }
65 inline void PathCanonicalizeX(LPWSTR pszDst
, LPCWSTR pszSrc
) { PathCanonicalizeW(pszDst
, pszSrc
); }
66 inline void PathCombineX(LPSTR pszPathOut
, LPCSTR pszPathIn
, LPCSTR pszMore
) { PathCombineA(pszPathOut
, pszPathIn
, pszMore
); }
67 inline void PathCombineX(LPWSTR pszPathOut
, LPCWSTR pszPathIn
, LPCWSTR pszMore
) { PathCombineW(pszPathOut
, pszPathIn
, pszMore
); }
68 inline CPathT
<StringType
> PathCommonPrefixX(LPCSTR pszFile1
, LPCSTR pszFile2
, LPSTR pszPath
) { return PathCommonPrefixA(pszFile1
, pszFile2
, pszPath
); }
69 inline CPathT
<StringType
> PathCommonPrefixX(LPCWSTR pszFile1
, LPCWSTR pszFile2
, LPWSTR pszPath
) { return PathCommonPrefixW(pszFile1
, pszFile2
, pszPath
); }
70 inline BOOL
PathCompactPathX(HDC hDC
, LPSTR pszPath
, UINT dx
) { return PathCompactPathA(hDC
, pszPath
, dx
); }
71 inline BOOL
PathCompactPathX(HDC hDC
, LPWSTR pszPath
, UINT dx
) { return PathCompactPathW(hDC
, pszPath
, dx
); }
72 inline BOOL
PathCompactPathExX(LPSTR pszOut
, LPCSTR pszSrc
, UINT cchMax
, DWORD dwFlags
) { return PathCompactPathExA(pszOut
, pszSrc
, cchMax
, dwFlags
); }
73 inline BOOL
PathCompactPathExX(LPWSTR pszOut
, LPCWSTR pszSrc
, UINT cchMax
, DWORD dwFlags
) { return PathCompactPathExW(pszOut
, pszSrc
, cchMax
, dwFlags
); }
74 inline BOOL
PathMakePrettyX(LPSTR pszPath
) { return PathMakePrettyA(pszPath
); }
75 inline BOOL
PathMakePrettyX(LPWSTR pszPath
) { return PathMakePrettyW(pszPath
); }
76 inline void PathQuoteSpacesX(LPSTR pszPath
) { PathQuoteSpacesA(pszPath
); }
77 inline void PathQuoteSpacesX(LPWSTR pszPath
) { PathQuoteSpacesW(pszPath
); }
78 inline BOOL
PathRelativePathToX(LPSTR pszPath
, LPCSTR pszFrom
, DWORD dwAttrFrom
, LPCSTR pszTo
, DWORD dwAttrTo
) { return PathRelativePathToA(pszPath
, pszFrom
, dwAttrFrom
, pszTo
, dwAttrTo
); }
79 inline BOOL
PathRelativePathToX(LPWSTR pszPath
, LPCWSTR pszFrom
, DWORD dwAttrFrom
, LPCWSTR pszTo
, DWORD dwAttrTo
) { return PathRelativePathToW(pszPath
, pszFrom
, dwAttrFrom
, pszTo
, dwAttrTo
); }
80 inline void PathRemoveArgsX(LPSTR pszPath
) { PathRemoveArgsA(pszPath
); }
81 inline void PathRemoveArgsX(LPWSTR pszPath
) { PathRemoveArgsW(pszPath
); }
82 inline void PathRemoveBackslashX(LPSTR pszPath
) { PathRemoveBackslashA(pszPath
); }
83 inline void PathRemoveBackslashX(LPWSTR pszPath
) { PathRemoveBackslashW(pszPath
); }
84 inline void PathRemoveBlanksX(LPSTR pszPath
) { PathRemoveBlanksA(pszPath
); }
85 inline void PathRemoveBlanksX(LPWSTR pszPath
) { PathRemoveBlanksW(pszPath
); }
86 inline void PathRemoveExtensionX(LPSTR pszPath
) { PathRemoveExtensionA(pszPath
); }
87 inline void PathRemoveExtensionX(LPWSTR pszPath
) { PathRemoveExtensionW(pszPath
); }
88 inline BOOL
PathRemoveFileSpecX(LPSTR pszPath
) { return PathRemoveFileSpecA(pszPath
); }
89 inline BOOL
PathRemoveFileSpecX(LPWSTR pszPath
) { return PathRemoveFileSpecW(pszPath
); }
90 inline BOOL
PathRenameExtensionX(LPSTR pszPath
, LPCSTR pszExt
) { return PathRenameExtensionA(pszPath
, pszExt
); }
91 inline BOOL
PathRenameExtensionX(LPWSTR pszPath
, LPCWSTR pszExt
) { return PathRenameExtensionW(pszPath
, pszExt
); }
92 inline void PathStripPathX(LPSTR pszPath
) { PathStripPathA(pszPath
); }
93 inline void PathStripPathX(LPWSTR pszPath
) { PathStripPathW(pszPath
); }
94 inline BOOL
PathStripToRootX(LPSTR pszPath
) { return PathStripToRootA(pszPath
); }
95 inline BOOL
PathStripToRootX(LPWSTR pszPath
) { return PathStripToRootW(pszPath
); }
96 inline void PathUnquoteSpacesX(LPSTR pszPath
) { PathUnquoteSpacesA(pszPath
); }
97 inline void PathUnquoteSpacesX(LPWSTR pszPath
) { PathUnquoteSpacesW(pszPath
); }
100 typedef typename
StringType::PCXSTR PCXSTR
;
101 typedef typename
StringType::PXSTR PXSTR
;
102 typedef typename
StringType::XCHAR XCHAR
;
104 StringType m_strPath
;
106 CPathT(PCXSTR pszPath
)
108 m_strPath
= StringType(pszPath
);
111 CPathT(const CPathT
<StringType
>& path
)
113 m_strPath
= path
.m_strPath
;
118 // do nothing, m_strPath initializes itself
123 PXSTR str
= m_strPath
.GetBuffer(MAX_PATH
);
124 PathAddBackslashX(str
);
125 m_strPath
.ReleaseBuffer();
128 BOOL
AddExtension(PCXSTR pszExtension
)
130 PXSTR str
= m_strPath
.GetBuffer(MAX_PATH
);
131 BOOL result
= PathAddExtensionX(str
, pszExtension
);
132 m_strPath
.ReleaseBuffer();
136 BOOL
Append(PCXSTR pszMore
)
138 PXSTR str
= m_strPath
.GetBuffer(MAX_PATH
);
139 BOOL result
= PathAppendX(str
, pszMore
);
140 m_strPath
.ReleaseBuffer();
144 void BuildRoot(int iDrive
)
146 PXSTR str
= m_strPath
.GetBuffer(4);
147 PathBuildRootX(str
, iDrive
);
148 m_strPath
.ReleaseBuffer();
154 PXSTR str
= strTemp
.GetBuffer(MAX_PATH
);
155 PathCanonicalizeX(str
, m_strPath
);
156 strTemp
.ReleaseBuffer();
160 void Combine(PCXSTR pszDir
, PCXSTR pszFile
)
162 PXSTR str
= m_strPath
.GetBuffer(MAX_PATH
);
163 PathCombineX(str
, pszDir
, pszFile
);
164 m_strPath
.ReleaseBuffer();
167 CPathT
<StringType
> CommonPrefix(PCXSTR pszOther
)
170 result
.SetString(m_strPath
, PathCommonPrefixX(m_strPath
, pszOther
, NULL
));
174 BOOL
CompactPath(HDC hDC
, UINT nWidth
)
176 PXSTR str
= m_strPath
.GetBuffer(MAX_PATH
);
177 BOOL result
= PathCompactPathX(hDC
, str
, nWidth
);
178 m_strPath
.ReleaseBuffer();
182 BOOL
CompactPathEx(UINT nMaxChars
, DWORD dwFlags
= 0)
185 PXSTR str
= strTemp
.GetBuffer(nMaxChars
);
186 BOOL result
= PathCompactPathExX(str
, m_strPath
, nMaxChars
, dwFlags
);
187 strTemp
.ReleaseBuffer();
192 BOOL
FileExists() const
194 return PathFileExistsX(m_strPath
);
197 int FindExtension() const
199 return PathFindExtensionX(m_strPath
);
202 int FindFileName() const
204 return PathFindFileNameX(m_strPath
);
207 int GetDriveNumber() const
209 return PathGetDriveNumberX(m_strPath
);
212 StringType
GetExtension() const
214 return StringType(PathFindExtensionX(m_strPath
));
217 BOOL
IsDirectory() const
219 return PathIsDirectoryX(m_strPath
);
222 BOOL
IsFileSpec() const
224 return PathIsFileSpecX(m_strPath
);
227 BOOL
IsPrefix(PCXSTR pszPrefix
) const
229 return PathIsPrefixX(m_strPath
);
232 BOOL
IsRelative() const
234 return PathIsRelativeX(m_strPath
);
239 return PathIsRootX(m_strPath
);
242 BOOL
IsSameRoot(PCXSTR pszOther
) const
244 return PathIsSameRootX(m_strPath
, pszOther
);
249 return PathIsUNCX(m_strPath
);
252 BOOL
IsUNCServer() const
254 return PathIsUNCServerX(m_strPath
);
257 BOOL
IsUNCServerShare() const
259 return PathIsUNCServerShareX(m_strPath
);
264 PXSTR str
= m_strPath
.GetBuffer(MAX_PATH
);
265 BOOL result
= PathMakePrettyX(str
);
266 m_strPath
.ReleaseBuffer();
270 BOOL
MatchSpec(PCXSTR pszSpec
) const
272 return PathMatchSpecX(m_strPath
, pszSpec
);
277 PXSTR str
= m_strPath
.GetBuffer(MAX_PATH
);
278 PathQuoteSpacesX(str
);
279 m_strPath
.ReleaseBuffer();
282 BOOL
RelativePathTo(PCXSTR pszFrom
, DWORD dwAttrFrom
, PCXSTR pszTo
, DWORD dwAttrTo
)
284 PXSTR str
= m_strPath
.GetBuffer(MAX_PATH
);
285 BOOL result
= PathRelativePathToX(str
, pszFrom
, dwAttrFrom
, pszTo
, dwAttrTo
);
286 m_strPath
.ReleaseBuffer();
292 PXSTR str
= m_strPath
.GetBuffer(MAX_PATH
);
293 PathRemoveArgsX(str
);
294 m_strPath
.ReleaseBuffer();
297 void RemoveBackslash()
299 PXSTR str
= m_strPath
.GetBuffer(MAX_PATH
);
300 PathRemoveBackslashX(str
);
301 m_strPath
.ReleaseBuffer();
306 PXSTR str
= m_strPath
.GetBuffer(MAX_PATH
);
307 PathRemoveBlanksX(str
);
308 m_strPath
.ReleaseBuffer();
311 void RemoveExtension()
313 PXSTR str
= m_strPath
.GetBuffer(MAX_PATH
);
314 PathRemoveExtensionX(str
);
315 m_strPath
.ReleaseBuffer();
318 BOOL
RemoveFileSpec()
320 PXSTR str
= m_strPath
.GetBuffer(MAX_PATH
);
321 BOOL result
= PathRemoveFileSpecX(str
);
322 m_strPath
.ReleaseBuffer();
326 BOOL
RenameExtension(PCXSTR pszExtension
)
328 PXSTR str
= m_strPath
.GetBuffer(MAX_PATH
);
329 BOOL result
= PathRenameExtensionX(str
, pszExtension
);
330 m_strPath
.ReleaseBuffer();
336 return PathSkipRootX(m_strPath
);
341 PXSTR str
= m_strPath
.GetBuffer(MAX_PATH
);
343 m_strPath
.ReleaseBuffer();
348 PXSTR str
= m_strPath
.GetBuffer(MAX_PATH
);
349 BOOL result
= PathStripToRootX(str
);
350 m_strPath
.ReleaseBuffer();
356 PXSTR str
= m_strPath
.GetBuffer(MAX_PATH
);
357 PathUnquoteSpacesX(str
);
358 m_strPath
.ReleaseBuffer();
361 operator const StringType
&() const throw()
366 operator PCXSTR() const throw()
371 operator StringType
&() throw()
376 CPathT
<StringType
>& operator+=(PCXSTR pszMore
)
378 m_strPath
+= pszMore
;
383 typedef CPathT
<CString
> CPath
;
384 typedef CPathT
<CStringA
> CPathA
;
385 typedef CPathT
<CStringW
> CPathW
;