1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2016 - TortoiseGit
4 // Copyright (C) 2003-2008, 2013-2014 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 // CSTRING is always available in an MFC build
24 #define CSTRING_AVAILABLE
29 * helper class to handle path strings.
34 CPathUtils() = delete;
35 static BOOL
MakeSureDirectoryPathExists(LPCTSTR path
);
36 static void ConvertToBackslash(LPTSTR dest
, LPCTSTR src
, size_t len
);
38 * Replaces escaped sequences with the corresponding characters in a string.
40 static void Unescape(char * psz
);
43 * Replaces non-URI chars with the corresponding escape sequences.
45 static CStringA
PathEscape(const CStringA
& path
);
48 #ifdef CSTRING_AVAILABLE
50 * returns the filename of a full path
52 static CString
GetFileNameFromPath(CString sPath
);
55 * returns the file extension from a full path
57 static CString
GetFileExtFromPath(const CString
& sPath
);
60 * Returns the long pathname of a path which may be in 8.3 format.
62 static CString
GetLongPathname(const CString
& path
);
65 * Copies a file or a folder from \a srcPath to \a destpath, creating
66 * intermediate folders if necessary. If \a force is TRUE, then files
67 * are overwritten if they already exist.
68 * Folders are just created at the new location, no files in them get
71 static BOOL
FileCopy(CString srcPath
, CString destPath
, BOOL force
= TRUE
);
74 * parses a string for a path or url. If no path or url is found,
75 * an empty string is returned.
76 * \remark if more than one path or url is inside the string, only
77 * the first one is returned.
79 static CString
ParsePathInString(const CString
& Str
);
82 * Returns the path to the installation folder, in our case the TortoiseSVN/bin folder.
83 * \remark the path returned has a trailing backslash
85 static CString
GetAppDirectory(HMODULE hMod
= nullptr);
88 * Returns the path to the installation parent folder, in our case the TortoiseSVN folder.
89 * \remark the path returned has a trailing backslash
91 static CString
GetAppParentDirectory(HMODULE hMod
= nullptr);
93 static CString
GetDocumentsDirectory();
94 static CString
GetProgramsDirectory();
97 * Returns the path to the application data folder, in our case the %APPDATA%TortoiseSVN folder.
98 * \remark the path returned has a trailing backslash
100 static CString
GetAppDataDirectory();
101 static CString
GetLocalAppDataDirectory();
104 * Replaces escaped sequences with the corresponding characters in a string.
106 static CStringA
PathUnescape(const CStringA
& path
);
107 static CStringW
PathUnescape(const CStringW
& path
);
110 * Escapes regexp-specific chars.
112 static CString
PathPatternEscape(const CString
& path
);
114 * Unescapes regexp-specific chars.
116 static CString
PathPatternUnEscape(const CString
& path
);
119 * Returns the version string from the VERSION resource of a dll or exe.
120 * \param p_strFilename path to the dll or exe
121 * \return the version string
123 static CString
GetVersionFromFile(const CString
& p_strFilename
);