xref: /reactos/sdk/lib/atl/atlpath.h (revision d955b932)
1c2c66affSColin Finck // PROJECT:        ReactOS ATL CPathT
2c2c66affSColin Finck // LICENSE:        Public Domain
3c2c66affSColin Finck // PURPOSE:        Provides compatibility to Microsoft ATL
4c2c66affSColin Finck // PROGRAMMERS:    Benedikt Freisen
5c2c66affSColin Finck 
6c2c66affSColin Finck #ifndef __ATLPATH_H__
7c2c66affSColin Finck #define __ATLPATH_H__
8c2c66affSColin Finck 
9c2c66affSColin Finck #pragma once
10c2c66affSColin Finck 
11c2c66affSColin Finck #include <atlcore.h>
12c2c66affSColin Finck #include <atlstr.h>
13c2c66affSColin Finck #include <shlwapi.h>
14c2c66affSColin Finck 
15c2c66affSColin Finck namespace ATL
16c2c66affSColin Finck {
17c2c66affSColin Finck 
18c2c66affSColin Finck template<typename StringType>
19c2c66affSColin Finck class CPathT
20c2c66affSColin Finck {
21c2c66affSColin Finck     // const
PathFileExistsX(LPCSTR pszPath)22e3402acaSMark Jansen     inline BOOL PathFileExistsX(LPCSTR pszPath) const { return PathFileExistsA(pszPath); }
PathFileExistsX(LPCWSTR pszPath)23e3402acaSMark Jansen     inline BOOL PathFileExistsX(LPCWSTR pszPath) const { return PathFileExistsW(pszPath); }
PathFindExtensionX(LPCSTR pszPath)24e3402acaSMark Jansen     inline LPCSTR PathFindExtensionX(LPCSTR pszPath) const { return PathFindExtensionA(pszPath); }
PathFindExtensionX(LPCWSTR pszPath)25e3402acaSMark Jansen     inline LPCWSTR PathFindExtensionX(LPCWSTR pszPath) const { return PathFindExtensionW(pszPath); }
PathFindFileNameX(LPCSTR pszPath)26e3402acaSMark Jansen     inline LPCSTR PathFindFileNameX(LPCSTR pszPath) const { return PathFindFileNameA(pszPath); }
PathFindFileNameX(LPCWSTR pszPath)27e3402acaSMark Jansen     inline LPCWSTR PathFindFileNameX(LPCWSTR pszPath) const { return PathFindFileNameW(pszPath); }
PathGetDriveNumberX(LPCSTR pszPath)28e3402acaSMark Jansen     inline int PathGetDriveNumberX(LPCSTR pszPath) const { return PathGetDriveNumberA(pszPath); }
PathGetDriveNumberX(LPCWSTR pszPath)29e3402acaSMark Jansen     inline int PathGetDriveNumberX(LPCWSTR pszPath) const { return PathGetDriveNumberW(pszPath); }
PathIsDirectoryX(LPCSTR pszPath)30e3402acaSMark Jansen     inline BOOL PathIsDirectoryX(LPCSTR pszPath) const { return PathIsDirectoryA(pszPath); }
PathIsDirectoryX(LPCWSTR pszPath)31e3402acaSMark Jansen     inline BOOL PathIsDirectoryX(LPCWSTR pszPath) const { return PathIsDirectoryW(pszPath); }
PathIsFileSpecX(LPCSTR pszPath)32e3402acaSMark Jansen     inline BOOL PathIsFileSpecX(LPCSTR pszPath) const { return PathIsFileSpecA(pszPath); }
PathIsFileSpecX(LPCWSTR pszPath)33e3402acaSMark Jansen     inline BOOL PathIsFileSpecX(LPCWSTR pszPath) const { return PathIsFileSpecW(pszPath); }
PathIsPrefixX(LPCSTR pszPath,LPCSTR pszPrefix)34c2c66affSColin Finck     inline BOOL PathIsPrefixX(LPCSTR pszPath, LPCSTR pszPrefix) { return PathIsPrefixA(pszPath, pszPrefix); }
PathIsPrefixX(LPCWSTR pszPath,LPCWSTR pszPrefix)35c2c66affSColin Finck     inline BOOL PathIsPrefixX(LPCWSTR pszPath, LPCWSTR pszPrefix) { return PathIsPrefixW(pszPath, pszPrefix); }
PathIsRelativeX(LPCSTR pszPath)36e3402acaSMark Jansen     inline BOOL PathIsRelativeX(LPCSTR pszPath) const { return PathIsRelativeA(pszPath); }
PathIsRelativeX(LPCWSTR pszPath)37e3402acaSMark Jansen     inline BOOL PathIsRelativeX(LPCWSTR pszPath) const { return PathIsRelativeW(pszPath); }
PathIsRootX(LPCSTR pszPath)38e3402acaSMark Jansen     inline BOOL PathIsRootX(LPCSTR pszPath) const { return PathIsRootA(pszPath); }
PathIsRootX(LPCWSTR pszPath)39e3402acaSMark Jansen     inline BOOL PathIsRootX(LPCWSTR pszPath) const { return PathIsRootW(pszPath); }
PathIsSameRootX(LPCSTR pszPath,LPCSTR pszOther)40e3402acaSMark Jansen     inline BOOL PathIsSameRootX(LPCSTR pszPath, LPCSTR pszOther) const { return PathIsSameRootA(pszPath, pszOther); }
PathIsSameRootX(LPCWSTR pszPath,LPCWSTR pszOther)41e3402acaSMark Jansen     inline BOOL PathIsSameRootX(LPCWSTR pszPath, LPCWSTR pszOther) const { return PathIsSameRootW(pszPath, pszOther); }
PathIsUNCX(LPCSTR pszPath)42c2c66affSColin Finck     inline BOOL PathIsUNCX(LPCSTR pszPath) { return PathIsUNCA(pszPath); }
PathIsUNCX(LPCWSTR pszPath)43c2c66affSColin Finck     inline BOOL PathIsUNCX(LPCWSTR pszPath) { return PathIsUNCW(pszPath); }
PathIsUNCServerX(LPCSTR pszPath)44c2c66affSColin Finck     inline BOOL PathIsUNCServerX(LPCSTR pszPath) { return PathIsUNCServerA(pszPath); }
PathIsUNCServerX(LPCWSTR pszPath)45c2c66affSColin Finck     inline BOOL PathIsUNCServerX(LPCWSTR pszPath) { return PathIsUNCServerW(pszPath); }
PathIsUNCServerShareX(LPCSTR pszPath)46c2c66affSColin Finck     inline BOOL PathIsUNCServerShareX(LPCSTR pszPath) { return PathIsUNCServerShareA(pszPath); }
PathIsUNCServerShareX(LPCWSTR pszPath)47c2c66affSColin Finck     inline BOOL PathIsUNCServerShareX(LPCWSTR pszPath) { return PathIsUNCServerShareW(pszPath); }
PathMatchSpecX(LPCSTR pszPath,LPCSTR pszSpec)48e3402acaSMark Jansen     inline BOOL PathMatchSpecX(LPCSTR pszPath, LPCSTR pszSpec) const { return PathMatchSpecA(pszPath, pszSpec); }
PathMatchSpecX(LPCWSTR pszPath,LPCWSTR pszSpec)49e3402acaSMark Jansen     inline BOOL PathMatchSpecX(LPCWSTR pszPath, LPCWSTR pszSpec) const { return PathMatchSpecW(pszPath, pszSpec); }
PathSkipRootX(LPCSTR pszPath)50e3402acaSMark Jansen     inline LPCSTR PathSkipRootX(LPCSTR pszPath) const { return PathSkipRootA(pszPath); }
PathSkipRootX(LPCWSTR pszPath)51e3402acaSMark Jansen     inline LPCWSTR PathSkipRootX(LPCWSTR pszPath) const { return PathSkipRootW(pszPath); }
52c2c66affSColin Finck 
53c2c66affSColin Finck     // non-const
PathAddBackslashX(LPSTR pszPath)54c2c66affSColin Finck     inline void PathAddBackslashX(LPSTR pszPath) { PathAddBackslashA(pszPath); }
PathAddBackslashX(LPWSTR pszPath)55c2c66affSColin Finck     inline void PathAddBackslashX(LPWSTR pszPath) { PathAddBackslashW(pszPath); }
PathAddExtensionX(LPSTR pszPath,LPCSTR pszExt)56c2c66affSColin Finck     inline BOOL PathAddExtensionX(LPSTR pszPath, LPCSTR pszExt) { return PathAddExtensionA(pszPath, pszExt); }
PathAddExtensionX(LPWSTR pszPath,LPCWSTR pszExt)57c2c66affSColin Finck     inline BOOL PathAddExtensionX(LPWSTR pszPath, LPCWSTR pszExt) { return PathAddExtensionW(pszPath, pszExt); }
PathAppendX(LPSTR pszPath,LPCSTR pszMore)58c2c66affSColin Finck     inline BOOL PathAppendX(LPSTR pszPath, LPCSTR pszMore) { return PathAppendA(pszPath, pszMore); }
PathAppendX(LPWSTR pszPath,LPCWSTR pszMore)59c2c66affSColin Finck     inline BOOL PathAppendX(LPWSTR pszPath, LPCWSTR pszMore) { return PathAppendW(pszPath, pszMore); }
PathBuildRootX(LPSTR pszRoot,int iDrive)60c2c66affSColin Finck     inline void PathBuildRootX(LPSTR pszRoot, int iDrive) { PathBuildRootA(pszRoot, iDrive); }
PathBuildRootX(LPWSTR pszRoot,int iDrive)61c2c66affSColin Finck     inline void PathBuildRootX(LPWSTR pszRoot, int iDrive) { PathBuildRootW(pszRoot, iDrive); }
PathCanonicalizeX(LPSTR pszDst,LPCSTR pszSrc)62c2c66affSColin Finck     inline void PathCanonicalizeX(LPSTR pszDst, LPCSTR pszSrc) { PathCanonicalizeA(pszDst, pszSrc); }
PathCanonicalizeX(LPWSTR pszDst,LPCWSTR pszSrc)63c2c66affSColin Finck     inline void PathCanonicalizeX(LPWSTR pszDst, LPCWSTR pszSrc) { PathCanonicalizeW(pszDst, pszSrc); }
PathCombineX(LPSTR pszPathOut,LPCSTR pszPathIn,LPCSTR pszMore)64c2c66affSColin Finck     inline void PathCombineX(LPSTR pszPathOut, LPCSTR pszPathIn, LPCSTR pszMore) { PathCombineA(pszPathOut, pszPathIn, pszMore); }
PathCombineX(LPWSTR pszPathOut,LPCWSTR pszPathIn,LPCWSTR pszMore)65c2c66affSColin Finck     inline void PathCombineX(LPWSTR pszPathOut, LPCWSTR pszPathIn, LPCWSTR pszMore) { PathCombineW(pszPathOut, pszPathIn, pszMore); }
PathCommonPrefixX(LPCSTR pszFile1,LPCSTR pszFile2,LPSTR pszPath)66c2c66affSColin Finck     inline CPathT<StringType> PathCommonPrefixX(LPCSTR pszFile1, LPCSTR pszFile2, LPSTR pszPath) { return PathCommonPrefixA(pszFile1, pszFile2, pszPath); }
PathCommonPrefixX(LPCWSTR pszFile1,LPCWSTR pszFile2,LPWSTR pszPath)67c2c66affSColin Finck     inline CPathT<StringType> PathCommonPrefixX(LPCWSTR pszFile1, LPCWSTR pszFile2, LPWSTR pszPath) { return PathCommonPrefixW(pszFile1, pszFile2, pszPath); }
PathCompactPathX(HDC hDC,LPSTR pszPath,UINT dx)68c2c66affSColin Finck     inline BOOL PathCompactPathX(HDC hDC, LPSTR pszPath, UINT dx) { return PathCompactPathA(hDC, pszPath, dx); }
PathCompactPathX(HDC hDC,LPWSTR pszPath,UINT dx)69c2c66affSColin Finck     inline BOOL PathCompactPathX(HDC hDC, LPWSTR pszPath, UINT dx) { return PathCompactPathW(hDC, pszPath, dx); }
PathCompactPathExX(LPSTR pszOut,LPCSTR pszSrc,UINT cchMax,DWORD dwFlags)70c2c66affSColin Finck     inline BOOL PathCompactPathExX(LPSTR pszOut, LPCSTR pszSrc, UINT cchMax, DWORD dwFlags) { return PathCompactPathExA(pszOut, pszSrc, cchMax, dwFlags); }
PathCompactPathExX(LPWSTR pszOut,LPCWSTR pszSrc,UINT cchMax,DWORD dwFlags)71c2c66affSColin Finck     inline BOOL PathCompactPathExX(LPWSTR pszOut, LPCWSTR pszSrc, UINT cchMax, DWORD dwFlags) { return PathCompactPathExW(pszOut, pszSrc, cchMax, dwFlags); }
PathMakePrettyX(LPSTR pszPath)72c2c66affSColin Finck     inline BOOL PathMakePrettyX(LPSTR pszPath) { return PathMakePrettyA(pszPath); }
PathMakePrettyX(LPWSTR pszPath)73c2c66affSColin Finck     inline BOOL PathMakePrettyX(LPWSTR pszPath) { return PathMakePrettyW(pszPath); }
PathQuoteSpacesX(LPSTR pszPath)74c2c66affSColin Finck     inline void PathQuoteSpacesX(LPSTR pszPath) { PathQuoteSpacesA(pszPath); }
PathQuoteSpacesX(LPWSTR pszPath)75c2c66affSColin Finck     inline void PathQuoteSpacesX(LPWSTR pszPath) { PathQuoteSpacesW(pszPath); }
PathRelativePathToX(LPSTR pszPath,LPCSTR pszFrom,DWORD dwAttrFrom,LPCSTR pszTo,DWORD dwAttrTo)76c2c66affSColin Finck     inline BOOL PathRelativePathToX(LPSTR pszPath, LPCSTR pszFrom, DWORD dwAttrFrom, LPCSTR pszTo, DWORD dwAttrTo) { return PathRelativePathToA(pszPath, pszFrom, dwAttrFrom, pszTo, dwAttrTo); }
PathRelativePathToX(LPWSTR pszPath,LPCWSTR pszFrom,DWORD dwAttrFrom,LPCWSTR pszTo,DWORD dwAttrTo)77c2c66affSColin Finck     inline BOOL PathRelativePathToX(LPWSTR pszPath, LPCWSTR pszFrom, DWORD dwAttrFrom, LPCWSTR pszTo, DWORD dwAttrTo) { return PathRelativePathToW(pszPath, pszFrom, dwAttrFrom, pszTo, dwAttrTo); }
PathRemoveArgsX(LPSTR pszPath)78c2c66affSColin Finck     inline void PathRemoveArgsX(LPSTR pszPath) { PathRemoveArgsA(pszPath); }
PathRemoveArgsX(LPWSTR pszPath)79c2c66affSColin Finck     inline void PathRemoveArgsX(LPWSTR pszPath) { PathRemoveArgsW(pszPath); }
PathRemoveBackslashX(LPSTR pszPath)80c2c66affSColin Finck     inline void PathRemoveBackslashX(LPSTR pszPath) { PathRemoveBackslashA(pszPath); }
PathRemoveBackslashX(LPWSTR pszPath)81c2c66affSColin Finck     inline void PathRemoveBackslashX(LPWSTR pszPath) { PathRemoveBackslashW(pszPath); }
PathRemoveBlanksX(LPSTR pszPath)82c2c66affSColin Finck     inline void PathRemoveBlanksX(LPSTR pszPath) { PathRemoveBlanksA(pszPath); }
PathRemoveBlanksX(LPWSTR pszPath)83c2c66affSColin Finck     inline void PathRemoveBlanksX(LPWSTR pszPath) { PathRemoveBlanksW(pszPath); }
PathRemoveExtensionX(LPSTR pszPath)84c2c66affSColin Finck     inline void PathRemoveExtensionX(LPSTR pszPath) { PathRemoveExtensionA(pszPath); }
PathRemoveExtensionX(LPWSTR pszPath)85c2c66affSColin Finck     inline void PathRemoveExtensionX(LPWSTR pszPath) { PathRemoveExtensionW(pszPath); }
PathRemoveFileSpecX(LPSTR pszPath)86c2c66affSColin Finck     inline BOOL PathRemoveFileSpecX(LPSTR pszPath) { return PathRemoveFileSpecA(pszPath); }
PathRemoveFileSpecX(LPWSTR pszPath)87c2c66affSColin Finck     inline BOOL PathRemoveFileSpecX(LPWSTR pszPath) { return PathRemoveFileSpecW(pszPath); }
PathRenameExtensionX(LPSTR pszPath,LPCSTR pszExt)88c2c66affSColin Finck     inline BOOL PathRenameExtensionX(LPSTR pszPath, LPCSTR pszExt) { return PathRenameExtensionA(pszPath, pszExt); }
PathRenameExtensionX(LPWSTR pszPath,LPCWSTR pszExt)89c2c66affSColin Finck     inline BOOL PathRenameExtensionX(LPWSTR pszPath, LPCWSTR pszExt) { return PathRenameExtensionW(pszPath, pszExt); }
PathStripPathX(LPSTR pszPath)90c2c66affSColin Finck     inline void PathStripPathX(LPSTR pszPath) { PathStripPathA(pszPath); }
PathStripPathX(LPWSTR pszPath)91c2c66affSColin Finck     inline void PathStripPathX(LPWSTR pszPath) { PathStripPathW(pszPath); }
PathStripToRootX(LPSTR pszPath)92c2c66affSColin Finck     inline BOOL PathStripToRootX(LPSTR pszPath) { return PathStripToRootA(pszPath); }
PathStripToRootX(LPWSTR pszPath)93c2c66affSColin Finck     inline BOOL PathStripToRootX(LPWSTR pszPath) { return PathStripToRootW(pszPath); }
PathUnquoteSpacesX(LPSTR pszPath)94c2c66affSColin Finck     inline void PathUnquoteSpacesX(LPSTR pszPath) { PathUnquoteSpacesA(pszPath); }
PathUnquoteSpacesX(LPWSTR pszPath)95c2c66affSColin Finck     inline void PathUnquoteSpacesX(LPWSTR pszPath) { PathUnquoteSpacesW(pszPath); }
96c2c66affSColin Finck 
97c2c66affSColin Finck public:
98c2c66affSColin Finck     typedef typename StringType::PCXSTR PCXSTR;
99c2c66affSColin Finck     typedef typename StringType::PXSTR PXSTR;
100c2c66affSColin Finck     typedef typename StringType::XCHAR XCHAR;
101c2c66affSColin Finck 
102c2c66affSColin Finck     StringType m_strPath;
103c2c66affSColin Finck 
CPathT(PCXSTR pszPath)104c2c66affSColin Finck     CPathT(PCXSTR pszPath)
105c2c66affSColin Finck     {
106c2c66affSColin Finck         m_strPath = StringType(pszPath);
107c2c66affSColin Finck     }
108c2c66affSColin Finck 
CPathT(const CPathT<StringType> & path)109c2c66affSColin Finck     CPathT(const CPathT<StringType>& path)
110c2c66affSColin Finck     {
111c2c66affSColin Finck         m_strPath = path.m_strPath;
112c2c66affSColin Finck     }
113c2c66affSColin Finck 
CPathT()114*d955b932SKatayama Hirofumi MZ     CPathT() noexcept
115c2c66affSColin Finck     {
116c2c66affSColin Finck         // do nothing, m_strPath initializes itself
117c2c66affSColin Finck     }
118c2c66affSColin Finck 
AddBackslash()119c2c66affSColin Finck     void AddBackslash()
120c2c66affSColin Finck     {
121c2c66affSColin Finck         PXSTR str = m_strPath.GetBuffer(MAX_PATH);
122c2c66affSColin Finck         PathAddBackslashX(str);
123c2c66affSColin Finck         m_strPath.ReleaseBuffer();
124c2c66affSColin Finck     }
125c2c66affSColin Finck 
AddExtension(PCXSTR pszExtension)126c2c66affSColin Finck     BOOL AddExtension(PCXSTR pszExtension)
127c2c66affSColin Finck     {
128c2c66affSColin Finck         PXSTR str = m_strPath.GetBuffer(MAX_PATH);
129c2c66affSColin Finck         BOOL result = PathAddExtensionX(str, pszExtension);
130c2c66affSColin Finck         m_strPath.ReleaseBuffer();
131c2c66affSColin Finck         return result;
132c2c66affSColin Finck     }
133c2c66affSColin Finck 
Append(PCXSTR pszMore)134c2c66affSColin Finck     BOOL Append(PCXSTR pszMore)
135c2c66affSColin Finck     {
136c2c66affSColin Finck         PXSTR str = m_strPath.GetBuffer(MAX_PATH);
137c2c66affSColin Finck         BOOL result = PathAppendX(str, pszMore);
138c2c66affSColin Finck         m_strPath.ReleaseBuffer();
139c2c66affSColin Finck         return result;
140c2c66affSColin Finck     }
141c2c66affSColin Finck 
BuildRoot(int iDrive)142c2c66affSColin Finck     void BuildRoot(int iDrive)
143c2c66affSColin Finck     {
144c2c66affSColin Finck         PXSTR str = m_strPath.GetBuffer(4);
145c2c66affSColin Finck         PathBuildRootX(str, iDrive);
146c2c66affSColin Finck         m_strPath.ReleaseBuffer();
147c2c66affSColin Finck     }
148c2c66affSColin Finck 
Canonicalize()149c2c66affSColin Finck     void Canonicalize()
150c2c66affSColin Finck     {
151c2c66affSColin Finck         StringType strTemp;
152c2c66affSColin Finck         PXSTR str = strTemp.GetBuffer(MAX_PATH);
153c2c66affSColin Finck         PathCanonicalizeX(str, m_strPath);
154c2c66affSColin Finck         strTemp.ReleaseBuffer();
155c2c66affSColin Finck         m_strPath = strTemp;
156c2c66affSColin Finck     }
157c2c66affSColin Finck 
Combine(PCXSTR pszDir,PCXSTR pszFile)158c2c66affSColin Finck     void Combine(PCXSTR pszDir, PCXSTR pszFile)
159c2c66affSColin Finck     {
160c2c66affSColin Finck         PXSTR str = m_strPath.GetBuffer(MAX_PATH);
161c2c66affSColin Finck         PathCombineX(str, pszDir, pszFile);
162c2c66affSColin Finck         m_strPath.ReleaseBuffer();
163c2c66affSColin Finck     }
164c2c66affSColin Finck 
CommonPrefix(PCXSTR pszOther)165c2c66affSColin Finck     CPathT<StringType> CommonPrefix(PCXSTR pszOther)
166c2c66affSColin Finck     {
167c2c66affSColin Finck         StringType result;
168c2c66affSColin Finck         result.SetString(m_strPath, PathCommonPrefixX(m_strPath, pszOther, NULL));
169c2c66affSColin Finck         return result;
170c2c66affSColin Finck     }
171c2c66affSColin Finck 
CompactPath(HDC hDC,UINT nWidth)172c2c66affSColin Finck     BOOL CompactPath(HDC hDC, UINT nWidth)
173c2c66affSColin Finck     {
174c2c66affSColin Finck         PXSTR str = m_strPath.GetBuffer(MAX_PATH);
175c2c66affSColin Finck         BOOL result = PathCompactPathX(hDC, str, nWidth);
176c2c66affSColin Finck         m_strPath.ReleaseBuffer();
177c2c66affSColin Finck         return result;
178c2c66affSColin Finck     }
179c2c66affSColin Finck 
180c2c66affSColin Finck     BOOL CompactPathEx(UINT nMaxChars, DWORD dwFlags = 0)
181c2c66affSColin Finck     {
182c2c66affSColin Finck         StringType strTemp;
183c2c66affSColin Finck         PXSTR str = strTemp.GetBuffer(nMaxChars);
184c2c66affSColin Finck         BOOL result = PathCompactPathExX(str, m_strPath, nMaxChars, dwFlags);
185c2c66affSColin Finck         strTemp.ReleaseBuffer();
186c2c66affSColin Finck         m_strPath = strTemp;
187c2c66affSColin Finck         return result;
188c2c66affSColin Finck     }
189c2c66affSColin Finck 
FileExists()190c2c66affSColin Finck     BOOL FileExists() const
191c2c66affSColin Finck     {
192c2c66affSColin Finck         return PathFileExistsX(m_strPath);
193c2c66affSColin Finck     }
194c2c66affSColin Finck 
FindExtension()195c2c66affSColin Finck     int FindExtension() const
196c2c66affSColin Finck     {
197e3402acaSMark Jansen         PCXSTR extension = PathFindExtensionX(m_strPath);
198e3402acaSMark Jansen         if (*extension == '\0')
199e3402acaSMark Jansen             return -1;
200e3402acaSMark Jansen 
201e3402acaSMark Jansen         PCXSTR str = m_strPath;
202e3402acaSMark Jansen         return (int)(extension - str);
203c2c66affSColin Finck     }
204c2c66affSColin Finck 
FindFileName()205c2c66affSColin Finck     int FindFileName() const
206c2c66affSColin Finck     {
207e3402acaSMark Jansen         PCXSTR filename = PathFindFileNameX(m_strPath);
208e3402acaSMark Jansen         if (*filename == '\0')
209e3402acaSMark Jansen             return -1;
210e3402acaSMark Jansen 
211e3402acaSMark Jansen         PCXSTR str = m_strPath;
212e3402acaSMark Jansen         return (int)(filename - str);
213c2c66affSColin Finck     }
214c2c66affSColin Finck 
GetDriveNumber()215c2c66affSColin Finck     int GetDriveNumber() const
216c2c66affSColin Finck     {
217c2c66affSColin Finck         return PathGetDriveNumberX(m_strPath);
218c2c66affSColin Finck     }
219c2c66affSColin Finck 
GetExtension()220c2c66affSColin Finck     StringType GetExtension() const
221c2c66affSColin Finck     {
222c2c66affSColin Finck         return StringType(PathFindExtensionX(m_strPath));
223c2c66affSColin Finck     }
224c2c66affSColin Finck 
IsDirectory()225c2c66affSColin Finck     BOOL IsDirectory() const
226c2c66affSColin Finck     {
227c2c66affSColin Finck         return PathIsDirectoryX(m_strPath);
228c2c66affSColin Finck     }
229c2c66affSColin Finck 
IsFileSpec()230c2c66affSColin Finck     BOOL IsFileSpec() const
231c2c66affSColin Finck     {
232c2c66affSColin Finck         return PathIsFileSpecX(m_strPath);
233c2c66affSColin Finck     }
234c2c66affSColin Finck 
IsPrefix(PCXSTR pszPrefix)235c2c66affSColin Finck     BOOL IsPrefix(PCXSTR pszPrefix) const
236c2c66affSColin Finck     {
237c2c66affSColin Finck         return PathIsPrefixX(m_strPath);
238c2c66affSColin Finck     }
239c2c66affSColin Finck 
IsRelative()240c2c66affSColin Finck     BOOL IsRelative() const
241c2c66affSColin Finck     {
242c2c66affSColin Finck         return PathIsRelativeX(m_strPath);
243c2c66affSColin Finck     }
244c2c66affSColin Finck 
IsRoot()245c2c66affSColin Finck     BOOL IsRoot() const
246c2c66affSColin Finck     {
247c2c66affSColin Finck         return PathIsRootX(m_strPath);
248c2c66affSColin Finck     }
249c2c66affSColin Finck 
IsSameRoot(PCXSTR pszOther)250c2c66affSColin Finck     BOOL IsSameRoot(PCXSTR pszOther) const
251c2c66affSColin Finck     {
252c2c66affSColin Finck         return PathIsSameRootX(m_strPath, pszOther);
253c2c66affSColin Finck     }
254c2c66affSColin Finck 
IsUNC()255c2c66affSColin Finck     BOOL IsUNC() const
256c2c66affSColin Finck     {
257c2c66affSColin Finck         return PathIsUNCX(m_strPath);
258c2c66affSColin Finck     }
259c2c66affSColin Finck 
IsUNCServer()260c2c66affSColin Finck     BOOL IsUNCServer() const
261c2c66affSColin Finck     {
262c2c66affSColin Finck         return PathIsUNCServerX(m_strPath);
263c2c66affSColin Finck     }
264c2c66affSColin Finck 
IsUNCServerShare()265c2c66affSColin Finck     BOOL IsUNCServerShare() const
266c2c66affSColin Finck     {
267c2c66affSColin Finck         return PathIsUNCServerShareX(m_strPath);
268c2c66affSColin Finck     }
269c2c66affSColin Finck 
MakePretty()270c2c66affSColin Finck     BOOL MakePretty()
271c2c66affSColin Finck     {
272c2c66affSColin Finck         PXSTR str = m_strPath.GetBuffer(MAX_PATH);
273c2c66affSColin Finck         BOOL result = PathMakePrettyX(str);
274c2c66affSColin Finck         m_strPath.ReleaseBuffer();
275c2c66affSColin Finck         return result;
276c2c66affSColin Finck     }
277c2c66affSColin Finck 
MatchSpec(PCXSTR pszSpec)278c2c66affSColin Finck     BOOL MatchSpec(PCXSTR pszSpec) const
279c2c66affSColin Finck     {
280c2c66affSColin Finck         return PathMatchSpecX(m_strPath, pszSpec);
281c2c66affSColin Finck     }
282c2c66affSColin Finck 
QuoteSpaces()283c2c66affSColin Finck     void QuoteSpaces()
284c2c66affSColin Finck     {
285c2c66affSColin Finck         PXSTR str = m_strPath.GetBuffer(MAX_PATH);
286c2c66affSColin Finck         PathQuoteSpacesX(str);
287c2c66affSColin Finck         m_strPath.ReleaseBuffer();
288c2c66affSColin Finck     }
289c2c66affSColin Finck 
RelativePathTo(PCXSTR pszFrom,DWORD dwAttrFrom,PCXSTR pszTo,DWORD dwAttrTo)290c2c66affSColin Finck     BOOL RelativePathTo(PCXSTR pszFrom, DWORD dwAttrFrom, PCXSTR pszTo, DWORD dwAttrTo)
291c2c66affSColin Finck     {
292c2c66affSColin Finck         PXSTR str = m_strPath.GetBuffer(MAX_PATH);
293c2c66affSColin Finck         BOOL result = PathRelativePathToX(str, pszFrom, dwAttrFrom, pszTo, dwAttrTo);
294c2c66affSColin Finck         m_strPath.ReleaseBuffer();
295c2c66affSColin Finck         return result;
296c2c66affSColin Finck     }
297c2c66affSColin Finck 
RemoveArgs()298c2c66affSColin Finck     void RemoveArgs()
299c2c66affSColin Finck     {
300c2c66affSColin Finck         PXSTR str = m_strPath.GetBuffer(MAX_PATH);
301c2c66affSColin Finck         PathRemoveArgsX(str);
302c2c66affSColin Finck         m_strPath.ReleaseBuffer();
303c2c66affSColin Finck     }
304c2c66affSColin Finck 
RemoveBackslash()305c2c66affSColin Finck     void RemoveBackslash()
306c2c66affSColin Finck     {
307c2c66affSColin Finck         PXSTR str = m_strPath.GetBuffer(MAX_PATH);
308c2c66affSColin Finck         PathRemoveBackslashX(str);
309c2c66affSColin Finck         m_strPath.ReleaseBuffer();
310c2c66affSColin Finck     }
311c2c66affSColin Finck 
RemoveBlanks()312c2c66affSColin Finck     void RemoveBlanks()
313c2c66affSColin Finck     {
314c2c66affSColin Finck         PXSTR str = m_strPath.GetBuffer(MAX_PATH);
315c2c66affSColin Finck         PathRemoveBlanksX(str);
316c2c66affSColin Finck         m_strPath.ReleaseBuffer();
317c2c66affSColin Finck     }
318c2c66affSColin Finck 
RemoveExtension()319c2c66affSColin Finck     void RemoveExtension()
320c2c66affSColin Finck     {
321c2c66affSColin Finck         PXSTR str = m_strPath.GetBuffer(MAX_PATH);
322c2c66affSColin Finck         PathRemoveExtensionX(str);
323c2c66affSColin Finck         m_strPath.ReleaseBuffer();
324c2c66affSColin Finck     }
325c2c66affSColin Finck 
RemoveFileSpec()326c2c66affSColin Finck     BOOL RemoveFileSpec()
327c2c66affSColin Finck     {
328c2c66affSColin Finck         PXSTR str = m_strPath.GetBuffer(MAX_PATH);
329c2c66affSColin Finck         BOOL result = PathRemoveFileSpecX(str);
330c2c66affSColin Finck         m_strPath.ReleaseBuffer();
331c2c66affSColin Finck         return result;
332c2c66affSColin Finck     }
333c2c66affSColin Finck 
RenameExtension(PCXSTR pszExtension)334c2c66affSColin Finck     BOOL RenameExtension(PCXSTR pszExtension)
335c2c66affSColin Finck     {
336c2c66affSColin Finck         PXSTR str = m_strPath.GetBuffer(MAX_PATH);
337c2c66affSColin Finck         BOOL result = PathRenameExtensionX(str, pszExtension);
338c2c66affSColin Finck         m_strPath.ReleaseBuffer();
339c2c66affSColin Finck         return result;
340c2c66affSColin Finck     }
341c2c66affSColin Finck 
SkipRoot()342c2c66affSColin Finck     int SkipRoot() const
343c2c66affSColin Finck     {
344e3402acaSMark Jansen         PCXSTR str = m_strPath;
345e3402acaSMark Jansen         return (int)(PathSkipRootX(m_strPath) - str);
346c2c66affSColin Finck     }
347c2c66affSColin Finck 
StripPath()348c2c66affSColin Finck     void StripPath()
349c2c66affSColin Finck     {
350c2c66affSColin Finck         PXSTR str = m_strPath.GetBuffer(MAX_PATH);
351c2c66affSColin Finck         PathStripPathX(str);
352c2c66affSColin Finck         m_strPath.ReleaseBuffer();
353c2c66affSColin Finck     }
354c2c66affSColin Finck 
StripToRoot()355c2c66affSColin Finck     BOOL StripToRoot()
356c2c66affSColin Finck     {
357c2c66affSColin Finck         PXSTR str = m_strPath.GetBuffer(MAX_PATH);
358c2c66affSColin Finck         BOOL result = PathStripToRootX(str);
359c2c66affSColin Finck         m_strPath.ReleaseBuffer();
360c2c66affSColin Finck         return result;
361c2c66affSColin Finck     }
362c2c66affSColin Finck 
UnquoteSpaces()363c2c66affSColin Finck     void UnquoteSpaces()
364c2c66affSColin Finck     {
365c2c66affSColin Finck         PXSTR str = m_strPath.GetBuffer(MAX_PATH);
366c2c66affSColin Finck         PathUnquoteSpacesX(str);
367c2c66affSColin Finck         m_strPath.ReleaseBuffer();
368c2c66affSColin Finck     }
369c2c66affSColin Finck 
370*d955b932SKatayama Hirofumi MZ     operator const StringType&() const noexcept
371c2c66affSColin Finck     {
372c2c66affSColin Finck         return m_strPath;
373c2c66affSColin Finck     }
374c2c66affSColin Finck 
PCXSTR()375*d955b932SKatayama Hirofumi MZ     operator PCXSTR() const noexcept
376c2c66affSColin Finck     {
377c2c66affSColin Finck         return m_strPath;
378c2c66affSColin Finck     }
379c2c66affSColin Finck 
380*d955b932SKatayama Hirofumi MZ     operator StringType&() noexcept
381c2c66affSColin Finck     {
382c2c66affSColin Finck         return m_strPath;
383c2c66affSColin Finck     }
384c2c66affSColin Finck 
385c2c66affSColin Finck     CPathT<StringType>& operator+=(PCXSTR pszMore)
386c2c66affSColin Finck     {
387e3402acaSMark Jansen         Append(pszMore);
388e3402acaSMark Jansen         return *this;
389c2c66affSColin Finck     }
390c2c66affSColin Finck 
391c2c66affSColin Finck };
392c2c66affSColin Finck 
393c2c66affSColin Finck typedef CPathT<CString> CPath;
394c2c66affSColin Finck typedef CPathT<CStringA> CPathA;
395c2c66affSColin Finck typedef CPathT<CStringW> CPathW;
396c2c66affSColin Finck 
397c2c66affSColin Finck }  // namespace ATL
398c2c66affSColin Finck 
399c2c66affSColin Finck #endif
400