aboutsummaryrefslogtreecommitdiff
path: root/CPP/Windows/FileName.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--CPP/Windows/FileName.cpp79
1 files changed, 48 insertions, 31 deletions
diff --git a/CPP/Windows/FileName.cpp b/CPP/Windows/FileName.cpp
index c16b3d4..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')))
70bool 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
75bool 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
72static void NormalizeDirSeparators(UString &s) 79static 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
95bool IsDrivePath(const wchar_t *s) throw() { return IS_LETTER_CHAR(s[0]) && s[1] == ':' && IS_SEPAR(s[2]); }
96
97bool IsAltPathPrefix(CFSTR s) throw() 97bool 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
122const char * const kSuperPathPrefix = "\\\\?\\"; 123const 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
124static const char * const kSuperUncPrefix = "\\\\?\\UNC\\"; 128static 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
144static const unsigned kDrivePrefixSize = 3; /* c:\ */
145
146bool IsSuperPath(const wchar_t *s) throw();
147bool 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]))
153bool IsSuperOrDevicePath(const wchar_t *s) throw() { return IS_SUPER_OR_DEVICE_PATH(s); }
137bool IsDevicePath(CFSTR s) throw() 154bool 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
212static const unsigned kDrivePrefixSize = 3; /* c:\ */
213
214bool 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; }
216bool IsSuperPath(const wchar_t *s) throw() { return IS_SUPER_PREFIX(s); }
217bool 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
220bool IsAltStreamPrefixWithColon(const UString &s) throw() 229bool IsAltStreamPrefixWithColon(const UString &s) throw()
221{ 230{
222 if (s.IsEmpty()) 231 if (s.IsEmpty())
@@ -278,12 +287,14 @@ bool IsAbsolutePath(const wchar_t *s) throw()
278int FindAltStreamColon(CFSTR path) throw() 287int FindAltStreamColon(CFSTR path) throw()
279{ 288{
280 unsigned i = 0; 289 unsigned i = 0;
281 if (IsDrivePath2(path)) 290 if (IsSuperPath(path))
282 i = 2; 291 i = kSuperPathPrefixSize;
292 if (IsDrivePath2(path + i))
293 i += 2;
283 int colonPos = -1; 294 int colonPos = -1;
284 for (;; i++) 295 for (;; i++)
285 { 296 {
286 FChar c = path[i]; 297 const FChar c = path[i];
287 if (c == 0) 298 if (c == 0)
288 return colonPos; 299 return colonPos;
289 if (c == ':') 300 if (c == ':')
@@ -347,14 +358,16 @@ unsigned GetRootPrefixSize(CFSTR s) throw()
347} 358}
348 359
349#endif // USE_UNICODE_FSTRING 360#endif // USE_UNICODE_FSTRING
361#endif // _WIN32
362
350 363
351static unsigned GetRootPrefixSize_Of_NetworkPath(const wchar_t *s) throw() 364static unsigned GetRootPrefixSize_Of_NetworkPath(const wchar_t *s) throw()
352{ 365{
353 // Network path: we look "server\path\" as root prefix 366 // Network path: we look "server\path\" as root prefix
354 int pos = FindSepar(s); 367 const int pos = FindSepar(s);
355 if (pos < 0) 368 if (pos < 0)
356 return 0; 369 return 0;
357 int pos2 = FindSepar(s + (unsigned)pos + 1); 370 const int pos2 = FindSepar(s + (unsigned)pos + 1);
358 if (pos2 < 0) 371 if (pos2 < 0)
359 return 0; 372 return 0;
360 return (unsigned)(pos + pos2 + 2); 373 return (unsigned)(pos + pos2 + 2);
@@ -368,7 +381,7 @@ static unsigned GetRootPrefixSize_Of_SimplePath(const wchar_t *s) throw()
368 return 0; 381 return 0;
369 if (s[1] == 0 || !IS_SEPAR(s[1])) 382 if (s[1] == 0 || !IS_SEPAR(s[1]))
370 return 1; 383 return 1;
371 unsigned size = GetRootPrefixSize_Of_NetworkPath(s + 2); 384 const unsigned size = GetRootPrefixSize_Of_NetworkPath(s + 2);
372 return (size == 0) ? 0 : 2 + size; 385 return (size == 0) ? 0 : 2 + size;
373} 386}
374 387
@@ -376,17 +389,21 @@ static unsigned GetRootPrefixSize_Of_SuperPath(const wchar_t *s) throw()
376{ 389{
377 if (IS_UNC_WITH_SLASH(s + kSuperPathPrefixSize)) 390 if (IS_UNC_WITH_SLASH(s + kSuperPathPrefixSize))
378 { 391 {
379 unsigned size = GetRootPrefixSize_Of_NetworkPath(s + kSuperUncPathPrefixSize); 392 const unsigned size = GetRootPrefixSize_Of_NetworkPath(s + kSuperUncPathPrefixSize);
380 return (size == 0) ? 0 : kSuperUncPathPrefixSize + size; 393 return (size == 0) ? 0 : kSuperUncPathPrefixSize + size;
381 } 394 }
382 // we support \\?\c:\ paths and volume GUID paths \\?\Volume{GUID}\" 395 // we support \\?\c:\ paths and volume GUID paths \\?\Volume{GUID}\"
383 int pos = FindSepar(s + kSuperPathPrefixSize); 396 const int pos = FindSepar(s + kSuperPathPrefixSize);
384 if (pos < 0) 397 if (pos < 0)
385 return 0; 398 return 0;
386 return kSuperPathPrefixSize + (unsigned)(pos + 1); 399 return kSuperPathPrefixSize + (unsigned)(pos + 1);
387} 400}
388 401
402#ifdef _WIN32
389unsigned GetRootPrefixSize(const wchar_t *s) throw() 403unsigned GetRootPrefixSize(const wchar_t *s) throw()
404#else
405unsigned GetRootPrefixSize_WINDOWS(const wchar_t *s) throw()
406#endif
390{ 407{
391 if (IS_DEVICE_PATH(s)) 408 if (IS_DEVICE_PATH(s))
392 return kDevicePathPrefixSize; 409 return kDevicePathPrefixSize;
@@ -395,7 +412,7 @@ unsigned GetRootPrefixSize(const wchar_t *s) throw()
395 return GetRootPrefixSize_Of_SimplePath(s); 412 return GetRootPrefixSize_Of_SimplePath(s);
396} 413}
397 414
398#else // _WIN32 415#ifndef _WIN32
399 416
400bool IsAbsolutePath(const wchar_t *s) throw() { return IS_SEPAR(s[0]); } 417bool IsAbsolutePath(const wchar_t *s) throw() { return IS_SEPAR(s[0]); }
401 418