diff options
Diffstat (limited to 'CPP/Windows/FileName.cpp')
| -rw-r--r-- | CPP/Windows/FileName.cpp | 71 |
1 files changed, 43 insertions, 28 deletions
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) | |||
| 65 | dirPath.Add_PathSepar(); | 65 | dirPath.Add_PathSepar(); |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | |||
| 69 | #define IS_LETTER_CHAR(c) ((((unsigned)(int)(c) | 0x20) - (unsigned)'a' <= (unsigned)('z' - 'a'))) | ||
| 70 | bool IsDrivePath (const wchar_t *s) throw() { return IS_LETTER_CHAR(s[0]) && s[1] == ':' && IS_SEPAR(s[2]); } | ||
| 71 | // bool IsDriveName2(const wchar_t *s) throw() { return IS_LETTER_CHAR(s[0]) && s[1] == ':' && s[2] == 0; } | ||
| 72 | |||
| 68 | #ifdef _WIN32 | 73 | #ifdef _WIN32 |
| 69 | 74 | ||
| 75 | bool IsDrivePath2(const wchar_t *s) throw() { return IS_LETTER_CHAR(s[0]) && s[1] == ':'; } | ||
| 76 | |||
| 70 | #ifndef USE_UNICODE_FSTRING | 77 | #ifndef USE_UNICODE_FSTRING |
| 71 | #ifdef Z7_LONG_PATH | 78 | #ifdef Z7_LONG_PATH |
| 72 | static void NormalizeDirSeparators(UString &s) | 79 | static void NormalizeDirSeparators(UString &s) |
| @@ -87,13 +94,6 @@ void NormalizeDirSeparators(FString &s) | |||
| 87 | s.ReplaceOneCharAtPos(i, FCHAR_PATH_SEPARATOR); | 94 | s.ReplaceOneCharAtPos(i, FCHAR_PATH_SEPARATOR); |
| 88 | } | 95 | } |
| 89 | 96 | ||
| 90 | #endif | ||
| 91 | |||
| 92 | |||
| 93 | #define IS_LETTER_CHAR(c) ((((unsigned)(int)(c) | 0x20) - (unsigned)'a' <= (unsigned)('z' - 'a'))) | ||
| 94 | |||
| 95 | bool IsDrivePath(const wchar_t *s) throw() { return IS_LETTER_CHAR(s[0]) && s[1] == ':' && IS_SEPAR(s[2]); } | ||
| 96 | |||
| 97 | bool IsAltPathPrefix(CFSTR s) throw() | 97 | bool IsAltPathPrefix(CFSTR s) throw() |
| 98 | { | 98 | { |
| 99 | unsigned len = MyStringLen(s); | 99 | unsigned len = MyStringLen(s); |
| @@ -117,16 +117,23 @@ bool IsAltPathPrefix(CFSTR s) throw() | |||
| 117 | return true; | 117 | return true; |
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | #if defined(_WIN32) && !defined(UNDER_CE) | 120 | #endif // _WIN32 |
| 121 | |||
| 121 | 122 | ||
| 122 | const char * const kSuperPathPrefix = "\\\\?\\"; | 123 | const char * const kSuperPathPrefix = |
| 124 | STRING_PATH_SEPARATOR | ||
| 125 | STRING_PATH_SEPARATOR "?" | ||
| 126 | STRING_PATH_SEPARATOR; | ||
| 123 | #ifdef Z7_LONG_PATH | 127 | #ifdef Z7_LONG_PATH |
| 124 | static const char * const kSuperUncPrefix = "\\\\?\\UNC\\"; | 128 | static const char * const kSuperUncPrefix = |
| 129 | STRING_PATH_SEPARATOR | ||
| 130 | STRING_PATH_SEPARATOR "?" | ||
| 131 | STRING_PATH_SEPARATOR "UNC" | ||
| 132 | STRING_PATH_SEPARATOR; | ||
| 125 | #endif | 133 | #endif |
| 126 | 134 | ||
| 127 | #define IS_DEVICE_PATH(s) (IS_SEPAR((s)[0]) && IS_SEPAR((s)[1]) && (s)[2] == '.' && IS_SEPAR((s)[3])) | 135 | #define IS_DEVICE_PATH(s) (IS_SEPAR((s)[0]) && IS_SEPAR((s)[1]) && (s)[2] == '.' && IS_SEPAR((s)[3])) |
| 128 | #define IS_SUPER_PREFIX(s) (IS_SEPAR((s)[0]) && IS_SEPAR((s)[1]) && (s)[2] == '?' && IS_SEPAR((s)[3])) | 136 | #define IS_SUPER_PREFIX(s) (IS_SEPAR((s)[0]) && IS_SEPAR((s)[1]) && (s)[2] == '?' && IS_SEPAR((s)[3])) |
| 129 | #define IS_SUPER_OR_DEVICE_PATH(s) (IS_SEPAR((s)[0]) && IS_SEPAR((s)[1]) && ((s)[2] == '?' || (s)[2] == '.') && IS_SEPAR((s)[3])) | ||
| 130 | 137 | ||
| 131 | #define IS_UNC_WITH_SLASH(s) ( \ | 138 | #define IS_UNC_WITH_SLASH(s) ( \ |
| 132 | ((s)[0] == 'U' || (s)[0] == 'u') \ | 139 | ((s)[0] == 'U' || (s)[0] == 'u') \ |
| @@ -134,6 +141,16 @@ static const char * const kSuperUncPrefix = "\\\\?\\UNC\\"; | |||
| 134 | && ((s)[2] == 'C' || (s)[2] == 'c') \ | 141 | && ((s)[2] == 'C' || (s)[2] == 'c') \ |
| 135 | && IS_SEPAR((s)[3])) | 142 | && IS_SEPAR((s)[3])) |
| 136 | 143 | ||
| 144 | static const unsigned kDrivePrefixSize = 3; /* c:\ */ | ||
| 145 | |||
| 146 | bool IsSuperPath(const wchar_t *s) throw(); | ||
| 147 | bool IsSuperPath(const wchar_t *s) throw() { return IS_SUPER_PREFIX(s); } | ||
| 148 | // bool IsSuperUncPath(const wchar_t *s) throw() { return (IS_SUPER_PREFIX(s) && IS_UNC_WITH_SLASH(s + kSuperPathPrefixSize)); } | ||
| 149 | |||
| 150 | #if defined(_WIN32) && !defined(UNDER_CE) | ||
| 151 | |||
| 152 | #define IS_SUPER_OR_DEVICE_PATH(s) (IS_SEPAR((s)[0]) && IS_SEPAR((s)[1]) && ((s)[2] == '?' || (s)[2] == '.') && IS_SEPAR((s)[3])) | ||
| 153 | bool IsSuperOrDevicePath(const wchar_t *s) throw() { return IS_SUPER_OR_DEVICE_PATH(s); } | ||
| 137 | bool IsDevicePath(CFSTR s) throw() | 154 | bool IsDevicePath(CFSTR s) throw() |
| 138 | { | 155 | { |
| 139 | #ifdef UNDER_CE | 156 | #ifdef UNDER_CE |
| @@ -154,7 +171,7 @@ bool IsDevicePath(CFSTR s) throw() | |||
| 154 | 171 | ||
| 155 | if (!IS_DEVICE_PATH(s)) | 172 | if (!IS_DEVICE_PATH(s)) |
| 156 | return false; | 173 | return false; |
| 157 | unsigned len = MyStringLen(s); | 174 | const unsigned len = MyStringLen(s); |
| 158 | if (len == 6 && s[5] == ':') | 175 | if (len == 6 && s[5] == ':') |
| 159 | return true; | 176 | return true; |
| 160 | if (len < 18 || len > 22 || !IsString1PrefixedByString2(s + kDevicePathPrefixSize, "PhysicalDrive")) | 177 | if (len < 18 || len > 22 || !IsString1PrefixedByString2(s + kDevicePathPrefixSize, "PhysicalDrive")) |
| @@ -174,7 +191,7 @@ bool IsNetworkPath(CFSTR s) throw() | |||
| 174 | return false; | 191 | return false; |
| 175 | if (IsSuperUncPath(s)) | 192 | if (IsSuperUncPath(s)) |
| 176 | return true; | 193 | return true; |
| 177 | FChar c = s[2]; | 194 | const FChar c = s[2]; |
| 178 | return (c != '.' && c != '?'); | 195 | return (c != '.' && c != '?'); |
| 179 | } | 196 | } |
| 180 | 197 | ||
| @@ -187,7 +204,7 @@ unsigned GetNetworkServerPrefixSize(CFSTR s) throw() | |||
| 187 | prefixSize = kSuperUncPathPrefixSize; | 204 | prefixSize = kSuperUncPathPrefixSize; |
| 188 | else | 205 | else |
| 189 | { | 206 | { |
| 190 | FChar c = s[2]; | 207 | const FChar c = s[2]; |
| 191 | if (c == '.' || c == '?') | 208 | if (c == '.' || c == '?') |
| 192 | return 0; | 209 | return 0; |
| 193 | } | 210 | } |
| @@ -209,14 +226,6 @@ bool IsNetworkShareRootPath(CFSTR s) throw() | |||
| 209 | return s[(unsigned)pos + 1] == 0; | 226 | return s[(unsigned)pos + 1] == 0; |
| 210 | } | 227 | } |
| 211 | 228 | ||
| 212 | static const unsigned kDrivePrefixSize = 3; /* c:\ */ | ||
| 213 | |||
| 214 | bool IsDrivePath2(const wchar_t *s) throw() { return IS_LETTER_CHAR(s[0]) && s[1] == ':'; } | ||
| 215 | // bool IsDriveName2(const wchar_t *s) throw() { return IS_LETTER_CHAR(s[0]) && s[1] == ':' && s[2] == 0; } | ||
| 216 | bool IsSuperPath(const wchar_t *s) throw() { return IS_SUPER_PREFIX(s); } | ||
| 217 | bool IsSuperOrDevicePath(const wchar_t *s) throw() { return IS_SUPER_OR_DEVICE_PATH(s); } | ||
| 218 | // bool IsSuperUncPath(const wchar_t *s) throw() { return (IS_SUPER_PREFIX(s) && IS_UNC_WITH_SLASH(s + kSuperPathPrefixSize)); } | ||
| 219 | |||
| 220 | bool IsAltStreamPrefixWithColon(const UString &s) throw() | 229 | bool IsAltStreamPrefixWithColon(const UString &s) throw() |
| 221 | { | 230 | { |
| 222 | if (s.IsEmpty()) | 231 | if (s.IsEmpty()) |
| @@ -349,14 +358,16 @@ unsigned GetRootPrefixSize(CFSTR s) throw() | |||
| 349 | } | 358 | } |
| 350 | 359 | ||
| 351 | #endif // USE_UNICODE_FSTRING | 360 | #endif // USE_UNICODE_FSTRING |
| 361 | #endif // _WIN32 | ||
| 362 | |||
| 352 | 363 | ||
| 353 | static unsigned GetRootPrefixSize_Of_NetworkPath(const wchar_t *s) throw() | 364 | static unsigned GetRootPrefixSize_Of_NetworkPath(const wchar_t *s) throw() |
| 354 | { | 365 | { |
| 355 | // Network path: we look "server\path\" as root prefix | 366 | // Network path: we look "server\path\" as root prefix |
| 356 | int pos = FindSepar(s); | 367 | const int pos = FindSepar(s); |
| 357 | if (pos < 0) | 368 | if (pos < 0) |
| 358 | return 0; | 369 | return 0; |
| 359 | int pos2 = FindSepar(s + (unsigned)pos + 1); | 370 | const int pos2 = FindSepar(s + (unsigned)pos + 1); |
| 360 | if (pos2 < 0) | 371 | if (pos2 < 0) |
| 361 | return 0; | 372 | return 0; |
| 362 | return (unsigned)(pos + pos2 + 2); | 373 | return (unsigned)(pos + pos2 + 2); |
| @@ -370,7 +381,7 @@ static unsigned GetRootPrefixSize_Of_SimplePath(const wchar_t *s) throw() | |||
| 370 | return 0; | 381 | return 0; |
| 371 | if (s[1] == 0 || !IS_SEPAR(s[1])) | 382 | if (s[1] == 0 || !IS_SEPAR(s[1])) |
| 372 | return 1; | 383 | return 1; |
| 373 | unsigned size = GetRootPrefixSize_Of_NetworkPath(s + 2); | 384 | const unsigned size = GetRootPrefixSize_Of_NetworkPath(s + 2); |
| 374 | return (size == 0) ? 0 : 2 + size; | 385 | return (size == 0) ? 0 : 2 + size; |
| 375 | } | 386 | } |
| 376 | 387 | ||
| @@ -378,17 +389,21 @@ static unsigned GetRootPrefixSize_Of_SuperPath(const wchar_t *s) throw() | |||
| 378 | { | 389 | { |
| 379 | if (IS_UNC_WITH_SLASH(s + kSuperPathPrefixSize)) | 390 | if (IS_UNC_WITH_SLASH(s + kSuperPathPrefixSize)) |
| 380 | { | 391 | { |
| 381 | unsigned size = GetRootPrefixSize_Of_NetworkPath(s + kSuperUncPathPrefixSize); | 392 | const unsigned size = GetRootPrefixSize_Of_NetworkPath(s + kSuperUncPathPrefixSize); |
| 382 | return (size == 0) ? 0 : kSuperUncPathPrefixSize + size; | 393 | return (size == 0) ? 0 : kSuperUncPathPrefixSize + size; |
| 383 | } | 394 | } |
| 384 | // we support \\?\c:\ paths and volume GUID paths \\?\Volume{GUID}\" | 395 | // we support \\?\c:\ paths and volume GUID paths \\?\Volume{GUID}\" |
| 385 | int pos = FindSepar(s + kSuperPathPrefixSize); | 396 | const int pos = FindSepar(s + kSuperPathPrefixSize); |
| 386 | if (pos < 0) | 397 | if (pos < 0) |
| 387 | return 0; | 398 | return 0; |
| 388 | return kSuperPathPrefixSize + (unsigned)(pos + 1); | 399 | return kSuperPathPrefixSize + (unsigned)(pos + 1); |
| 389 | } | 400 | } |
| 390 | 401 | ||
| 402 | #ifdef _WIN32 | ||
| 391 | unsigned GetRootPrefixSize(const wchar_t *s) throw() | 403 | unsigned GetRootPrefixSize(const wchar_t *s) throw() |
| 404 | #else | ||
| 405 | unsigned GetRootPrefixSize_WINDOWS(const wchar_t *s) throw() | ||
| 406 | #endif | ||
| 392 | { | 407 | { |
| 393 | if (IS_DEVICE_PATH(s)) | 408 | if (IS_DEVICE_PATH(s)) |
| 394 | return kDevicePathPrefixSize; | 409 | return kDevicePathPrefixSize; |
| @@ -397,7 +412,7 @@ unsigned GetRootPrefixSize(const wchar_t *s) throw() | |||
| 397 | return GetRootPrefixSize_Of_SimplePath(s); | 412 | return GetRootPrefixSize_Of_SimplePath(s); |
| 398 | } | 413 | } |
| 399 | 414 | ||
| 400 | #else // _WIN32 | 415 | #ifndef _WIN32 |
| 401 | 416 | ||
| 402 | bool IsAbsolutePath(const wchar_t *s) throw() { return IS_SEPAR(s[0]); } | 417 | bool IsAbsolutePath(const wchar_t *s) throw() { return IS_SEPAR(s[0]); } |
| 403 | 418 | ||
