Skip to content

Commit 798acb1

Browse files
IsValidPath() Win improvements
1 parent 6e4c21a commit 798acb1

File tree

4 files changed

+37
-11
lines changed

4 files changed

+37
-11
lines changed

ChangeLog

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1+
Version 1.1.2.2:
2+
- Release date: 30 Jan 2020
3+
- New features:
4+
- Improvements:
5+
- relaxed IsValidPath() on Win to allow ':'
6+
- improved IsValidPath() on Win to handle "\\\\?\\" when validating '?'
7+
- Win: prepend "\\\\?\\" to path only if it does not already exist
8+
- Fixed bugs:
9+
10+
111
Version 1.1.2.1:
2-
- Release date:
12+
- Release date: 27 Nov 2019
313
- New features:
414
- added CentOS 8
515
- Improvements:

common.pri

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ CPPDEVTK_VERSION_MAJOR = 1
6060
CPPDEVTK_VERSION_MINOR = 1
6161
CPPDEVTK_VERSION_PATCH = 2
6262
win32 {
63-
CPPDEVTK_VERSION_BUILD = 1
63+
CPPDEVTK_VERSION_BUILD = 2
6464
}
6565

6666

include/cppdevtk/config/product_info.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
#define CPPDEVTK_VERSION_MINOR 1 ///< \attention May have maximum 2 digits.
5252
#define CPPDEVTK_VERSION_PATCH 2 ///< \attention May have maximum 2 digits.
5353
#ifdef _WIN32
54-
#define CPPDEVTK_VERSION_BUILD 1
54+
#define CPPDEVTK_VERSION_BUILD 2
5555
#endif
5656

5757
/// Example:

src/util/filesystem_utils_win.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ CPPDEVTK_UTIL_API bool IsValidPath(const QString& path, bool ignorePathSeparator
7575
return false;
7676
}
7777
if (path.contains('\?')) {
78-
CPPDEVTK_LOG_ERROR("path '" << path << "' contains invalid character ?");
79-
return false;
78+
if (!path.startsWith("//?/") || (path.count('?') > 1)) {
79+
CPPDEVTK_LOG_ERROR("path '" << path << "' contains invalid character ?");
80+
return false;
81+
}
8082
}
8183
if (path.contains('*')) {
8284
CPPDEVTK_LOG_ERROR("path '" << path << "' contains invalid character *");
@@ -94,6 +96,7 @@ CPPDEVTK_UTIL_API bool IsValidPath(const QString& path, bool ignorePathSeparator
9496
}
9597
*/
9698

99+
/*
97100
int cnt = path.count(':');
98101
if (cnt > 1) {
99102
CPPDEVTK_LOG_ERROR("path '" << path << "' contains invalid character :");
@@ -110,6 +113,7 @@ CPPDEVTK_UTIL_API bool IsValidPath(const QString& path, bool ignorePathSeparator
110113
return false;
111114
}
112115
}
116+
*/
113117

114118
return ignorePathSeparator ? true : !path.contains('/');
115119
}
@@ -120,7 +124,9 @@ CPPDEVTK_UTIL_API void DeleteFile(const QString& fileName, bool failIfNotExists)
120124
QString nativeFileName = QDir::toNativeSeparators(fileName);
121125
# if (!CPPDEVTK_DISABLE_UNICODE)
122126
if (QDir::isAbsolutePath(fileName)) {
123-
nativeFileName.prepend("\\\\?\\");
127+
if (!nativeFileName.startsWith("\\\\?\\")) {
128+
nativeFileName.prepend("\\\\?\\");
129+
}
124130
}
125131
# endif
126132

@@ -179,14 +185,18 @@ CPPDEVTK_UTIL_API void CopyFile(const QString& srcFileName, const QString& dstFi
179185
QString nativeSrcFileName = QDir::toNativeSeparators(srcFileName);
180186
# if (!CPPDEVTK_DISABLE_UNICODE)
181187
if (QDir::isAbsolutePath(srcFileName)) {
182-
nativeSrcFileName.prepend("\\\\?\\");
188+
if (!nativeSrcFileName.startsWith("\\\\?\\")) {
189+
nativeSrcFileName.prepend("\\\\?\\");
190+
}
183191
}
184192
# endif
185193

186194
QString nativeDstFileName = QDir::toNativeSeparators(dstFileName);
187195
# if (!CPPDEVTK_DISABLE_UNICODE)
188196
if (QDir::isAbsolutePath(dstFileName)) {
189-
nativeDstFileName.prepend("\\\\?\\");
197+
if (!nativeDstFileName.startsWith("\\\\?\\")) {
198+
nativeDstFileName.prepend("\\\\?\\");
199+
}
190200
}
191201
# endif
192202

@@ -237,7 +247,9 @@ CPPDEVTK_UTIL_API void MakeDirectory(const QString& dirName, bool failIfExists)
237247
QString nativeDirName = QDir::toNativeSeparators(dirName);
238248
# if (!CPPDEVTK_DISABLE_UNICODE)
239249
if (QDir::isAbsolutePath(dirName)) {
240-
nativeDirName.prepend("\\\\?\\");
250+
if (!nativeDirName.startsWith("\\\\?\\")) {
251+
nativeDirName.prepend("\\\\?\\");
252+
}
241253
}
242254
# endif
243255

@@ -292,7 +304,9 @@ CPPDEVTK_UTIL_API void RemoveDirectory(const QString& path, bool failIfNotExists
292304
QString nativePath = QDir::toNativeSeparators(path);
293305
# if (!CPPDEVTK_DISABLE_UNICODE)
294306
if (QDir::isAbsolutePath(path)) {
295-
nativePath.prepend("\\\\?\\");
307+
if (!nativePath.startsWith("\\\\?\\")) {
308+
nativePath.prepend("\\\\?\\");
309+
}
296310
}
297311
# endif
298312

@@ -351,7 +365,9 @@ CPPDEVTK_UTIL_API void GetFileSystemSpaceInfo(const QString& path, FileSystemSpa
351365

352366
QString nativeDirAbsPath = QDir::toNativeSeparators(QFileInfo(path).absolutePath());
353367
# if (!CPPDEVTK_DISABLE_UNICODE)
354-
nativeDirAbsPath.prepend("\\\\?\\");
368+
if (!nativeDirAbsPath.startsWith("\\\\?\\")) {
369+
nativeDirAbsPath.prepend("\\\\?\\");
370+
}
355371
# endif
356372

357373
if (!GetDiskFreeSpaceEx(CPPDEVTK_Q2T(nativeDirAbsPath).c_str(), &freeBytesAvailable, &totalNumberOfBytes,

0 commit comments

Comments
 (0)