Skip to content

Commit

Permalink
IsValidPath() Win improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
cristian-anita committed Feb 25, 2020
1 parent 6e4c21a commit 798acb1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
12 changes: 11 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
Version 1.1.2.2:
- Release date: 30 Jan 2020
- New features:
- Improvements:
- relaxed IsValidPath() on Win to allow ':'
- improved IsValidPath() on Win to handle "\\\\?\\" when validating '?'
- Win: prepend "\\\\?\\" to path only if it does not already exist
- Fixed bugs:


Version 1.1.2.1:
- Release date:
- Release date: 27 Nov 2019
- New features:
- added CentOS 8
- Improvements:
Expand Down
2 changes: 1 addition & 1 deletion common.pri
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ CPPDEVTK_VERSION_MAJOR = 1
CPPDEVTK_VERSION_MINOR = 1
CPPDEVTK_VERSION_PATCH = 2
win32 {
CPPDEVTK_VERSION_BUILD = 1
CPPDEVTK_VERSION_BUILD = 2
}


Expand Down
2 changes: 1 addition & 1 deletion include/cppdevtk/config/product_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#define CPPDEVTK_VERSION_MINOR 1 ///< \attention May have maximum 2 digits.
#define CPPDEVTK_VERSION_PATCH 2 ///< \attention May have maximum 2 digits.
#ifdef _WIN32
#define CPPDEVTK_VERSION_BUILD 1
#define CPPDEVTK_VERSION_BUILD 2
#endif

/// Example:
Expand Down
32 changes: 24 additions & 8 deletions src/util/filesystem_utils_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ CPPDEVTK_UTIL_API bool IsValidPath(const QString& path, bool ignorePathSeparator
return false;
}
if (path.contains('\?')) {
CPPDEVTK_LOG_ERROR("path '" << path << "' contains invalid character ?");
return false;
if (!path.startsWith("//?/") || (path.count('?') > 1)) {
CPPDEVTK_LOG_ERROR("path '" << path << "' contains invalid character ?");
return false;
}
}
if (path.contains('*')) {
CPPDEVTK_LOG_ERROR("path '" << path << "' contains invalid character *");
Expand All @@ -94,6 +96,7 @@ CPPDEVTK_UTIL_API bool IsValidPath(const QString& path, bool ignorePathSeparator
}
*/

/*
int cnt = path.count(':');
if (cnt > 1) {
CPPDEVTK_LOG_ERROR("path '" << path << "' contains invalid character :");
Expand All @@ -110,6 +113,7 @@ CPPDEVTK_UTIL_API bool IsValidPath(const QString& path, bool ignorePathSeparator
return false;
}
}
*/

return ignorePathSeparator ? true : !path.contains('/');
}
Expand All @@ -120,7 +124,9 @@ CPPDEVTK_UTIL_API void DeleteFile(const QString& fileName, bool failIfNotExists)
QString nativeFileName = QDir::toNativeSeparators(fileName);
# if (!CPPDEVTK_DISABLE_UNICODE)
if (QDir::isAbsolutePath(fileName)) {
nativeFileName.prepend("\\\\?\\");
if (!nativeFileName.startsWith("\\\\?\\")) {
nativeFileName.prepend("\\\\?\\");
}
}
# endif

Expand Down Expand Up @@ -179,14 +185,18 @@ CPPDEVTK_UTIL_API void CopyFile(const QString& srcFileName, const QString& dstFi
QString nativeSrcFileName = QDir::toNativeSeparators(srcFileName);
# if (!CPPDEVTK_DISABLE_UNICODE)
if (QDir::isAbsolutePath(srcFileName)) {
nativeSrcFileName.prepend("\\\\?\\");
if (!nativeSrcFileName.startsWith("\\\\?\\")) {
nativeSrcFileName.prepend("\\\\?\\");
}
}
# endif

QString nativeDstFileName = QDir::toNativeSeparators(dstFileName);
# if (!CPPDEVTK_DISABLE_UNICODE)
if (QDir::isAbsolutePath(dstFileName)) {
nativeDstFileName.prepend("\\\\?\\");
if (!nativeDstFileName.startsWith("\\\\?\\")) {
nativeDstFileName.prepend("\\\\?\\");
}
}
# endif

Expand Down Expand Up @@ -237,7 +247,9 @@ CPPDEVTK_UTIL_API void MakeDirectory(const QString& dirName, bool failIfExists)
QString nativeDirName = QDir::toNativeSeparators(dirName);
# if (!CPPDEVTK_DISABLE_UNICODE)
if (QDir::isAbsolutePath(dirName)) {
nativeDirName.prepend("\\\\?\\");
if (!nativeDirName.startsWith("\\\\?\\")) {
nativeDirName.prepend("\\\\?\\");
}
}
# endif

Expand Down Expand Up @@ -292,7 +304,9 @@ CPPDEVTK_UTIL_API void RemoveDirectory(const QString& path, bool failIfNotExists
QString nativePath = QDir::toNativeSeparators(path);
# if (!CPPDEVTK_DISABLE_UNICODE)
if (QDir::isAbsolutePath(path)) {
nativePath.prepend("\\\\?\\");
if (!nativePath.startsWith("\\\\?\\")) {
nativePath.prepend("\\\\?\\");
}
}
# endif

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

QString nativeDirAbsPath = QDir::toNativeSeparators(QFileInfo(path).absolutePath());
# if (!CPPDEVTK_DISABLE_UNICODE)
nativeDirAbsPath.prepend("\\\\?\\");
if (!nativeDirAbsPath.startsWith("\\\\?\\")) {
nativeDirAbsPath.prepend("\\\\?\\");
}
# endif

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

0 comments on commit 798acb1

Please sign in to comment.