From 395149956d696e6e3099d8b76d797437f94a6942 Mon Sep 17 00:00:00 2001 From: Igor Pavlov <87184205+ip7z@users.noreply.github.com> Date: Sat, 5 Jul 2025 00:00:00 +0000 Subject: 25.00 --- CPP/Windows/FileName.cpp | 71 +++++++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 28 deletions(-) (limited to 'CPP/Windows/FileName.cpp') diff --git a/CPP/Windows/FileName.cpp b/CPP/Windows/FileName.cpp index 1f4a6da..eb62567 100644 --- a/CPP/Windows/FileName.cpp +++ b/CPP/Windows/FileName.cpp @@ -65,8 +65,15 @@ void NormalizeDirPathPrefix(UString &dirPath) dirPath.Add_PathSepar(); } + +#define IS_LETTER_CHAR(c) ((((unsigned)(int)(c) | 0x20) - (unsigned)'a' <= (unsigned)('z' - 'a'))) +bool IsDrivePath (const wchar_t *s) throw() { return IS_LETTER_CHAR(s[0]) && s[1] == ':' && IS_SEPAR(s[2]); } +// bool IsDriveName2(const wchar_t *s) throw() { return IS_LETTER_CHAR(s[0]) && s[1] == ':' && s[2] == 0; } + #ifdef _WIN32 +bool IsDrivePath2(const wchar_t *s) throw() { return IS_LETTER_CHAR(s[0]) && s[1] == ':'; } + #ifndef USE_UNICODE_FSTRING #ifdef Z7_LONG_PATH static void NormalizeDirSeparators(UString &s) @@ -87,13 +94,6 @@ void NormalizeDirSeparators(FString &s) s.ReplaceOneCharAtPos(i, FCHAR_PATH_SEPARATOR); } -#endif - - -#define IS_LETTER_CHAR(c) ((((unsigned)(int)(c) | 0x20) - (unsigned)'a' <= (unsigned)('z' - 'a'))) - -bool IsDrivePath(const wchar_t *s) throw() { return IS_LETTER_CHAR(s[0]) && s[1] == ':' && IS_SEPAR(s[2]); } - bool IsAltPathPrefix(CFSTR s) throw() { unsigned len = MyStringLen(s); @@ -117,16 +117,23 @@ bool IsAltPathPrefix(CFSTR s) throw() return true; } -#if defined(_WIN32) && !defined(UNDER_CE) +#endif // _WIN32 + -const char * const kSuperPathPrefix = "\\\\?\\"; +const char * const kSuperPathPrefix = + STRING_PATH_SEPARATOR + STRING_PATH_SEPARATOR "?" + STRING_PATH_SEPARATOR; #ifdef Z7_LONG_PATH -static const char * const kSuperUncPrefix = "\\\\?\\UNC\\"; +static const char * const kSuperUncPrefix = + STRING_PATH_SEPARATOR + STRING_PATH_SEPARATOR "?" + STRING_PATH_SEPARATOR "UNC" + STRING_PATH_SEPARATOR; #endif #define IS_DEVICE_PATH(s) (IS_SEPAR((s)[0]) && IS_SEPAR((s)[1]) && (s)[2] == '.' && IS_SEPAR((s)[3])) #define IS_SUPER_PREFIX(s) (IS_SEPAR((s)[0]) && IS_SEPAR((s)[1]) && (s)[2] == '?' && IS_SEPAR((s)[3])) -#define IS_SUPER_OR_DEVICE_PATH(s) (IS_SEPAR((s)[0]) && IS_SEPAR((s)[1]) && ((s)[2] == '?' || (s)[2] == '.') && IS_SEPAR((s)[3])) #define IS_UNC_WITH_SLASH(s) ( \ ((s)[0] == 'U' || (s)[0] == 'u') \ @@ -134,6 +141,16 @@ static const char * const kSuperUncPrefix = "\\\\?\\UNC\\"; && ((s)[2] == 'C' || (s)[2] == 'c') \ && IS_SEPAR((s)[3])) +static const unsigned kDrivePrefixSize = 3; /* c:\ */ + +bool IsSuperPath(const wchar_t *s) throw(); +bool IsSuperPath(const wchar_t *s) throw() { return IS_SUPER_PREFIX(s); } +// bool IsSuperUncPath(const wchar_t *s) throw() { return (IS_SUPER_PREFIX(s) && IS_UNC_WITH_SLASH(s + kSuperPathPrefixSize)); } + +#if defined(_WIN32) && !defined(UNDER_CE) + +#define IS_SUPER_OR_DEVICE_PATH(s) (IS_SEPAR((s)[0]) && IS_SEPAR((s)[1]) && ((s)[2] == '?' || (s)[2] == '.') && IS_SEPAR((s)[3])) +bool IsSuperOrDevicePath(const wchar_t *s) throw() { return IS_SUPER_OR_DEVICE_PATH(s); } bool IsDevicePath(CFSTR s) throw() { #ifdef UNDER_CE @@ -154,7 +171,7 @@ bool IsDevicePath(CFSTR s) throw() if (!IS_DEVICE_PATH(s)) return false; - unsigned len = MyStringLen(s); + const unsigned len = MyStringLen(s); if (len == 6 && s[5] == ':') return true; if (len < 18 || len > 22 || !IsString1PrefixedByString2(s + kDevicePathPrefixSize, "PhysicalDrive")) @@ -174,7 +191,7 @@ bool IsNetworkPath(CFSTR s) throw() return false; if (IsSuperUncPath(s)) return true; - FChar c = s[2]; + const FChar c = s[2]; return (c != '.' && c != '?'); } @@ -187,7 +204,7 @@ unsigned GetNetworkServerPrefixSize(CFSTR s) throw() prefixSize = kSuperUncPathPrefixSize; else { - FChar c = s[2]; + const FChar c = s[2]; if (c == '.' || c == '?') return 0; } @@ -209,14 +226,6 @@ bool IsNetworkShareRootPath(CFSTR s) throw() return s[(unsigned)pos + 1] == 0; } -static const unsigned kDrivePrefixSize = 3; /* c:\ */ - -bool IsDrivePath2(const wchar_t *s) throw() { return IS_LETTER_CHAR(s[0]) && s[1] == ':'; } -// bool IsDriveName2(const wchar_t *s) throw() { return IS_LETTER_CHAR(s[0]) && s[1] == ':' && s[2] == 0; } -bool IsSuperPath(const wchar_t *s) throw() { return IS_SUPER_PREFIX(s); } -bool IsSuperOrDevicePath(const wchar_t *s) throw() { return IS_SUPER_OR_DEVICE_PATH(s); } -// bool IsSuperUncPath(const wchar_t *s) throw() { return (IS_SUPER_PREFIX(s) && IS_UNC_WITH_SLASH(s + kSuperPathPrefixSize)); } - bool IsAltStreamPrefixWithColon(const UString &s) throw() { if (s.IsEmpty()) @@ -349,14 +358,16 @@ unsigned GetRootPrefixSize(CFSTR s) throw() } #endif // USE_UNICODE_FSTRING +#endif // _WIN32 + static unsigned GetRootPrefixSize_Of_NetworkPath(const wchar_t *s) throw() { // Network path: we look "server\path\" as root prefix - int pos = FindSepar(s); + const int pos = FindSepar(s); if (pos < 0) return 0; - int pos2 = FindSepar(s + (unsigned)pos + 1); + const int pos2 = FindSepar(s + (unsigned)pos + 1); if (pos2 < 0) return 0; return (unsigned)(pos + pos2 + 2); @@ -370,7 +381,7 @@ static unsigned GetRootPrefixSize_Of_SimplePath(const wchar_t *s) throw() return 0; if (s[1] == 0 || !IS_SEPAR(s[1])) return 1; - unsigned size = GetRootPrefixSize_Of_NetworkPath(s + 2); + const unsigned size = GetRootPrefixSize_Of_NetworkPath(s + 2); return (size == 0) ? 0 : 2 + size; } @@ -378,17 +389,21 @@ static unsigned GetRootPrefixSize_Of_SuperPath(const wchar_t *s) throw() { if (IS_UNC_WITH_SLASH(s + kSuperPathPrefixSize)) { - unsigned size = GetRootPrefixSize_Of_NetworkPath(s + kSuperUncPathPrefixSize); + const unsigned size = GetRootPrefixSize_Of_NetworkPath(s + kSuperUncPathPrefixSize); return (size == 0) ? 0 : kSuperUncPathPrefixSize + size; } // we support \\?\c:\ paths and volume GUID paths \\?\Volume{GUID}\" - int pos = FindSepar(s + kSuperPathPrefixSize); + const int pos = FindSepar(s + kSuperPathPrefixSize); if (pos < 0) return 0; return kSuperPathPrefixSize + (unsigned)(pos + 1); } +#ifdef _WIN32 unsigned GetRootPrefixSize(const wchar_t *s) throw() +#else +unsigned GetRootPrefixSize_WINDOWS(const wchar_t *s) throw() +#endif { if (IS_DEVICE_PATH(s)) return kDevicePathPrefixSize; @@ -397,7 +412,7 @@ unsigned GetRootPrefixSize(const wchar_t *s) throw() return GetRootPrefixSize_Of_SimplePath(s); } -#else // _WIN32 +#ifndef _WIN32 bool IsAbsolutePath(const wchar_t *s) throw() { return IS_SEPAR(s[0]); } -- cgit v1.2.3-55-g6feb