1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2016-2022 - 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(LPCWSTR path
);
36 static void ConvertToBackslash(LPWSTR dest
, LPCWSTR src
, size_t len
);
37 static void ConvertToSlash(LPWSTR path
);
40 * Returns the version string from the VERSION resource of a dll or exe.
41 * \param p_strFilename path to the dll or exe
42 * \return the version string
44 static std::wstring
GetVersionFromFile(LPCWSTR p_strFilename
);
46 #ifdef CSTRING_AVAILABLE
47 static void ConvertToBackslash(CString
& path
);
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 * Removes any of the following namespace prefixes from a path, if found: "\??\", "\\?\", "\\?\UNC\".
106 static void DropPathPrefixes(CString
& path
);
108 static int ReadLink(LPCWSTR filename
, CStringA
* target
= nullptr);
111 * Ensures that the path ends with a folder separator.
112 * If the delimiter already exists, no additional delimiter will be added.
113 * \param path to ensure
115 static void EnsureTrailingPathDelimiter(CString
& path
);
118 * Returns a path guaranteeing that a valid path delimiter follows.
119 * If the delimiter already exists, no additional delimiter will be added.
120 * \param path to ensure
121 * \return path including path delimiter
123 static CString
BuildPathWithPathDelimiter(const CString
& path
);
126 * Trims a possible included trailing folder separator from the provided path.
127 * \param path to trim
129 static void TrimTrailingPathDelimiter(CString
& path
);
132 * ExpandFileName converts the relative file name into a fully qualified path name.
133 * ExpandFileName does not verify that the resulting fully qualified path name
134 * refers to an existing file, or even that the resulting path exists.
135 * \param path to expand
136 * \return fully qualified path name
138 static CString
ExpandFileName(const CString
& path
);
141 * This method will make a path comparable to another path.
142 * It will do the following:
143 * 1.) Modify all characters in the path to be lower case
144 * 2.) Account for ..\'s and .\'s that may occur in the middle of the path and remove them
145 * 3.) Expand a path that has DOS 8.3 file/folder names
146 * 4.) Remove the trailing path delimiter at the end
147 * The function does not account for symlinks at this point in time.
148 * \param path to normalize
149 * \return normalized path
151 static CString
NormalizePath(const CString
& path
);
154 * Compares two paths and returns true if they are logically the same path.
155 * The function does not account for symlinks at this point in time.
156 * \param path1 to compare
157 * \param path2 to compare
158 * \return true if they are the same path
160 static bool IsSamePath(const CString
& path1
, const CString
& path2
);
163 * Checks if two path strings are equal. No conversion of slashes is done!
164 * \remark for slash-independent comparison, use IsEquivalentTo()
166 static bool ArePathStringsEqual(const CString
& sP1
, const CString
& sP2
);
167 static bool ArePathStringsEqualWithCase(const CString
& sP1
, const CString
& sP2
);
169 static CString
GetCopyrightForSelf();
172 * Sets the last-write-time of the file to the current time
174 static bool Touch(const CString
& path
);