[ATL] cstringt.h: Uncomment and complete Format(UINT nFormatID, ...). It still uses...
[reactos.git] / reactos / sdk / lib / atl / atlpath.h
1 // PROJECT: ReactOS ATL CPathT
2 // LICENSE: Public Domain
3 // PURPOSE: Provides compatibility to Microsoft ATL
4 // PROGRAMMERS: Benedikt Freisen
5
6 #ifndef __ATLPATH_H__
7 #define __ATLPATH_H__
8
9 // WARNING: Untested code
10
11 #pragma once
12
13 #include <atlcore.h>
14 #include <atlstr.h>
15 #include <shlwapi.h>
16
17 namespace ATL
18 {
19
20 template<typename StringType>
21 class CPathT
22 {
23 // const
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); }
54
55 // non-const
56 inline void PathAddBackslashX(LPSTR pszPath) { return PathAddBackslashA(pszPath); }
57 inline void PathAddBackslashX(LPWSTR pszPath) { return 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) { return PathBuildRootA(pszRoot, iDrive); }
63 inline void PathBuildRootX(LPWSTR pszRoot, int iDrive) { return PathBuildRootW(pszRoot, iDrive); }
64 inline void PathCanonicalizeX(LPSTR pszDst, LPCSTR pszSrc) { return PathCanonicalizeA(pszDst, pszSrc); }
65 inline void PathCanonicalizeX(LPWSTR pszDst, LPCWSTR pszSrc) { return PathCanonicalizeW(pszDst, pszSrc); }
66 inline void PathCombineX(LPSTR pszPathOut, LPCSTR pszPathIn, LPCSTR pszMore) { return PathCombineA(pszPathOut, pszPathIn, pszMore); }
67 inline void PathCombineX(LPWSTR pszPathOut, LPCWSTR pszPathIn, LPCWSTR pszMore) { return 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) { return PathQuoteSpacesA(pszPath); }
77 inline void PathQuoteSpacesX(LPWSTR pszPath) { return 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) { return PathRemoveArgsA(pszPath); }
81 inline void PathRemoveArgsX(LPWSTR pszPath) { return PathRemoveArgsW(pszPath); }
82 inline void PathRemoveBackslashX(LPSTR pszPath) { return PathRemoveBackslashA(pszPath); }
83 inline void PathRemoveBackslashX(LPWSTR pszPath) { return PathRemoveBackslashW(pszPath); }
84 inline void PathRemoveBlanksX(LPSTR pszPath) { return PathRemoveBlanksA(pszPath); }
85 inline void PathRemoveBlanksX(LPWSTR pszPath) { return PathRemoveBlanksW(pszPath); }
86 inline void PathRemoveExtensionX(LPSTR pszPath) { return PathRemoveExtensionA(pszPath); }
87 inline void PathRemoveExtensionX(LPWSTR pszPath) { return 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) { return PathStripPathA(pszPath); }
93 inline void PathStripPathX(LPWSTR pszPath) { return 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) { return PathUnquoteSpacesA(pszPath); }
97 inline void PathUnquoteSpacesX(LPWSTR pszPath) { return PathUnquoteSpacesW(pszPath); }
98
99 public:
100 typedef typename StringType::PCXSTR PCXSTR;
101 typedef typename StringType::PXSTR PXSTR;
102 typedef typename StringType::XCHAR XCHAR;
103
104 StringType m_strPath;
105
106 CPathT(PCXSTR pszPath)
107 {
108 m_strPath = StringType(pszPath);
109 }
110
111 CPathT(const CPathT<StringType>& path)
112 {
113 m_strPath = path.m_strPath;
114 }
115
116 CPathT() throw()
117 {
118 // do nothing, m_strPath initializes itself
119 }
120
121 void AddBackslash()
122 {
123 PXSTR str = m_strPath.GetBuffer(MAX_PATH);
124 PathAddBackslashX(str);
125 m_strPath.ReleaseBuffer();
126 }
127
128 BOOL AddExtension(PCXSTR pszExtension)
129 {
130 PXSTR str = m_strPath.GetBuffer(MAX_PATH);
131 BOOL result = PathAddExtensionX(str, pszExtension);
132 m_strPath.ReleaseBuffer();
133 return result;
134 }
135
136 BOOL Append(PCXSTR pszMore)
137 {
138 PXSTR str = m_strPath.GetBuffer(MAX_PATH);
139 BOOL result = PathAppendX(str, pszMore);
140 m_strPath.ReleaseBuffer();
141 return result;
142 }
143
144 void BuildRoot(int iDrive)
145 {
146 PXSTR str = m_strPath.GetBuffer(4);
147 PathBuildRootX(str, iDrive);
148 m_strPath.ReleaseBuffer();
149 }
150
151 void Canonicalize()
152 {
153 StringType strTemp;
154 PXSTR str = strTemp.GetBuffer(MAX_PATH);
155 PathCanonicalizeX(str, m_strPath);
156 strTemp.ReleaseBuffer();
157 m_strPath = strTemp;
158 }
159
160 void Combine(PCXSTR pszDir, PCXSTR pszFile)
161 {
162 PXSTR str = m_strPath.GetBuffer(MAX_PATH);
163 PathCombineX(str, pszDir, pszFile);
164 m_strPath.ReleaseBuffer();
165 }
166
167 CPathT<StringType> CommonPrefix(PCXSTR pszOther)
168 {
169 StringType result;
170 result.SetString(m_strPath, PathCommonPrefixX(m_strPath, pszOther, NULL));
171 return result;
172 }
173
174 BOOL CompactPath(HDC hDC, UINT nWidth)
175 {
176 PXSTR str = m_strPath.GetBuffer(MAX_PATH);
177 BOOL result = PathCompactPathX(hDC, str, nWidth);
178 m_strPath.ReleaseBuffer();
179 return result;
180 }
181
182 BOOL CompactPathEx(UINT nMaxChars, DWORD dwFlags = 0)
183 {
184 StringType strTemp;
185 PXSTR str = strTemp.GetBuffer(nMaxChars);
186 BOOL result = PathCompactPathExX(str, m_strPath, nMaxChars, dwFlags);
187 strTemp.ReleaseBuffer();
188 m_strPath = strTemp;
189 return result;
190 }
191
192 BOOL FileExists() const
193 {
194 return PathFileExistsX(m_strPath);
195 }
196
197 int FindExtension() const
198 {
199 return PathFindExtensionX(m_strPath);
200 }
201
202 int FindFileName() const
203 {
204 return PathFindFileNameX(m_strPath);
205 }
206
207 int GetDriveNumber() const
208 {
209 return PathGetDriveNumberX(m_strPath);
210 }
211
212 StringType GetExtension() const
213 {
214 return StringType(PathFindExtensionX(m_strPath));
215 }
216
217 BOOL IsDirectory() const
218 {
219 return PathIsDirectoryX(m_strPath);
220 }
221
222 BOOL IsFileSpec() const
223 {
224 return PathIsFileSpecX(m_strPath);
225 }
226
227 BOOL IsPrefix(PCXSTR pszPrefix) const
228 {
229 return PathIsPrefixX(m_strPath);
230 }
231
232 BOOL IsRelative() const
233 {
234 return PathIsRelativeX(m_strPath);
235 }
236
237 BOOL IsRoot() const
238 {
239 return PathIsRootX(m_strPath);
240 }
241
242 BOOL IsSameRoot(PCXSTR pszOther) const
243 {
244 return PathIsSameRootX(m_strPath, pszOther);
245 }
246
247 BOOL IsUNC() const
248 {
249 return PathIsUNCX(m_strPath);
250 }
251
252 BOOL IsUNCServer() const
253 {
254 return PathIsUNCServerX(m_strPath);
255 }
256
257 BOOL IsUNCServerShare() const
258 {
259 return PathIsUNCServerShareX(m_strPath);
260 }
261
262 BOOL MakePretty()
263 {
264 PXSTR str = m_strPath.GetBuffer(MAX_PATH);
265 BOOL result = PathMakePrettyX(str);
266 m_strPath.ReleaseBuffer();
267 return result;
268 }
269
270 BOOL MatchSpec(PCXSTR pszSpec) const
271 {
272 return PathMatchSpecX(m_strPath, pszSpec);
273 }
274
275 void QuoteSpaces()
276 {
277 PXSTR str = m_strPath.GetBuffer(MAX_PATH);
278 PathQuoteSpacesX(str);
279 m_strPath.ReleaseBuffer();
280 }
281
282 BOOL RelativePathTo(PCXSTR pszFrom, DWORD dwAttrFrom, PCXSTR pszTo, DWORD dwAttrTo)
283 {
284 PXSTR str = m_strPath.GetBuffer(MAX_PATH);
285 BOOL result = PathRelativePathToX(str, pszFrom, dwAttrFrom, pszTo, dwAttrTo);
286 m_strPath.ReleaseBuffer();
287 return result;
288 }
289
290 void RemoveArgs()
291 {
292 PXSTR str = m_strPath.GetBuffer(MAX_PATH);
293 PathRemoveArgsX(str);
294 m_strPath.ReleaseBuffer();
295 }
296
297 void RemoveBackslash()
298 {
299 PXSTR str = m_strPath.GetBuffer(MAX_PATH);
300 PathRemoveBackslashX(str);
301 m_strPath.ReleaseBuffer();
302 }
303
304 void RemoveBlanks()
305 {
306 PXSTR str = m_strPath.GetBuffer(MAX_PATH);
307 PathRemoveBlanksX(str);
308 m_strPath.ReleaseBuffer();
309 }
310
311 void RemoveExtension()
312 {
313 PXSTR str = m_strPath.GetBuffer(MAX_PATH);
314 PathRemoveExtensionX(str);
315 m_strPath.ReleaseBuffer();
316 }
317
318 BOOL RemoveFileSpec()
319 {
320 PXSTR str = m_strPath.GetBuffer(MAX_PATH);
321 BOOL result = PathRemoveFileSpecX(str);
322 m_strPath.ReleaseBuffer();
323 return result;
324 }
325
326 BOOL RenameExtension(PCXSTR pszExtension)
327 {
328 PXSTR str = m_strPath.GetBuffer(MAX_PATH);
329 BOOL result = PathRenameExtensionX(str, pszExtension);
330 m_strPath.ReleaseBuffer();
331 return result;
332 }
333
334 int SkipRoot() const
335 {
336 return PathSkipRootX(m_strPath);
337 }
338
339 void StripPath()
340 {
341 PXSTR str = m_strPath.GetBuffer(MAX_PATH);
342 PathStripPathX(str);
343 m_strPath.ReleaseBuffer();
344 }
345
346 BOOL StripToRoot()
347 {
348 PXSTR str = m_strPath.GetBuffer(MAX_PATH);
349 BOOL result = PathStripToRootX(str);
350 m_strPath.ReleaseBuffer();
351 return result;
352 }
353
354 void UnquoteSpaces()
355 {
356 PXSTR str = m_strPath.GetBuffer(MAX_PATH);
357 PathUnquoteSpacesX(str);
358 m_strPath.ReleaseBuffer();
359 }
360
361 operator const StringType&() const throw()
362 {
363 return m_strPath;
364 }
365
366 operator PCXSTR() const throw()
367 {
368 return m_strPath;
369 }
370
371 operator StringType&() throw()
372 {
373 return m_strPath;
374 }
375
376 CPathT<StringType>& operator+=(PCXSTR pszMore)
377 {
378 m_strPath += pszMore;
379 }
380
381 };
382
383 typedef CPathT<CString> CPath;
384 typedef CPathT<CStringA> CPathA;
385 typedef CPathT<CStringW> CPathW;
386
387 } // namespace ATL
388
389 #endif