diff options
Diffstat (limited to '3rdparty/lzma/CPP/7zip/UI/Common/ExtractingFilePath.cpp')
-rw-r--r-- | 3rdparty/lzma/CPP/7zip/UI/Common/ExtractingFilePath.cpp | 113 |
1 files changed, 86 insertions, 27 deletions
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/ExtractingFilePath.cpp b/3rdparty/lzma/CPP/7zip/UI/Common/ExtractingFilePath.cpp index 39e67b7f2ed..88da4ad36c0 100644 --- a/3rdparty/lzma/CPP/7zip/UI/Common/ExtractingFilePath.cpp +++ b/3rdparty/lzma/CPP/7zip/UI/Common/ExtractingFilePath.cpp @@ -8,6 +8,18 @@ #include "ExtractingFilePath.h" +extern +bool g_PathTrailReplaceMode; +bool g_PathTrailReplaceMode = + #ifdef _WIN32 + true + #else + false + #endif + ; + + +#ifdef _WIN32 static void ReplaceIncorrectChars(UString &s) { { @@ -22,24 +34,60 @@ static void ReplaceIncorrectChars(UString &s) || #endif c == WCHAR_PATH_SEPARATOR) - s.ReplaceOneCharAtPos(i, '_'); + { + #if WCHAR_PATH_SEPARATOR != L'/' + // 22.00 : WSL replacement for backslash + if (c == WCHAR_PATH_SEPARATOR) + c = WCHAR_IN_FILE_NAME_BACKSLASH_REPLACEMENT; + else + #endif + c = '_'; + s.ReplaceOneCharAtPos(i, + c + // (wchar_t)(0xf000 + c) // 21.02 debug: WSL encoding for unsupported characters + ); + } } } - #ifdef _WIN32 + if (g_PathTrailReplaceMode) { - for (unsigned i = s.Len(); i != 0;) + /* + // if (g_PathTrailReplaceMode == 1) { - wchar_t c = s[--i]; - if (c != '.' && c != ' ') - break; - s.ReplaceOneCharAtPos(i, '_'); + if (!s.IsEmpty()) + { + wchar_t c = s.Back(); + if (c == '.' || c == ' ') + { + // s += (wchar_t)(0x9c); // STRING TERMINATOR + s += (wchar_t)'_'; + } + } + } + else + */ + { + unsigned i; + for (i = s.Len(); i != 0;) + { + wchar_t c = s[i - 1]; + if (c != '.' && c != ' ') + break; + i--; + s.ReplaceOneCharAtPos(i, '_'); + // s.ReplaceOneCharAtPos(i, (c == ' ' ? (wchar_t)(0x2423) : (wchar_t)0x00B7)); + } + /* + if (g_PathTrailReplaceMode > 1 && i != s.Len()) + { + s.DeleteFrom(i); + } + */ } } - #endif } - -#ifdef _WIN32 +#endif /* WinXP-64 doesn't support ':', '\\' and '/' symbols in name of alt stream. But colon in postfix ":$DATA" is allowed. @@ -61,9 +109,11 @@ void Correct_AltStream_Name(UString &s) s.ReplaceOneCharAtPos(i, '_'); } if (s.IsEmpty()) - s = L'_'; + s = '_'; } +#ifdef _WIN32 + static const unsigned g_ReservedWithNum_Index = 4; static const char * const g_ReservedNames[] = @@ -74,7 +124,7 @@ static const char * const g_ReservedNames[] = static bool IsSupportedName(const UString &name) { - for (unsigned i = 0; i < ARRAY_SIZE(g_ReservedNames); i++) + for (unsigned i = 0; i < Z7_ARRAY_SIZE(g_ReservedNames); i++) { const char *reservedName = g_ReservedNames[i]; unsigned len = MyStringLen(reservedName); @@ -112,7 +162,10 @@ static void CorrectUnsupportedName(UString &name) static void Correct_PathPart(UString &s) { // "." and ".." - if (s[0] == '.' && (s[1] == 0 || s[1] == '.' && s[2] == 0)) + if (s.IsEmpty()) + return; + + if (s[0] == '.' && (s[1] == 0 || (s[1] == '.' && s[2] == 0))) s.Empty(); #ifdef _WIN32 else @@ -120,8 +173,8 @@ static void Correct_PathPart(UString &s) #endif } -// static const wchar_t *k_EmptyReplaceName = L"[]"; -static const wchar_t k_EmptyReplaceName = L'_'; +// static const char * const k_EmptyReplaceName = "[]"; +static const char k_EmptyReplaceName = '_'; UString Get_Correct_FsFile_Name(const UString &name) { @@ -138,7 +191,7 @@ UString Get_Correct_FsFile_Name(const UString &name) } -void Correct_FsPath(bool absIsAllowed, UStringVector &parts, bool isDir) +void Correct_FsPath(bool absIsAllowed, bool keepAndReplaceEmptyPrefixes, UStringVector &parts, bool isDir) { unsigned i = 0; @@ -147,6 +200,7 @@ void Correct_FsPath(bool absIsAllowed, UStringVector &parts, bool isDir) #if defined(_WIN32) && !defined(UNDER_CE) bool isDrive = false; #endif + if (parts[0].IsEmpty()) { i = 1; @@ -157,7 +211,7 @@ void Correct_FsPath(bool absIsAllowed, UStringVector &parts, bool isDir) if (parts.Size() > 2 && parts[2] == L"?") { i = 3; - if (parts.Size() > 3 && NWindows::NFile::NName::IsDrivePath2(parts[3])) + if (parts.Size() > 3 && NWindows::NFile::NName::IsDrivePath2(parts[3])) { isDrive = true; i = 4; @@ -176,16 +230,19 @@ void Correct_FsPath(bool absIsAllowed, UStringVector &parts, bool isDir) if (isDrive) { // we convert "c:name" to "c:\name", if absIsAllowed path. - const UString &ds = parts[i - 1]; - if (ds.Len() != 2) + UString &ds = parts[i - 1]; + if (ds.Len() > 2) { - UString s = ds.Ptr(2); - parts.Insert(i, s); + parts.Insert(i, ds.Ptr(2)); + ds.DeleteFrom(2); } } #endif } + if (i != 0) + keepAndReplaceEmptyPrefixes = false; + for (; i < parts.Size();) { UString &s = parts[i]; @@ -194,15 +251,17 @@ void Correct_FsPath(bool absIsAllowed, UStringVector &parts, bool isDir) if (s.IsEmpty()) { - if (isDir || i != parts.Size() - 1) - { - parts.Delete(i); - continue; - } + if (!keepAndReplaceEmptyPrefixes) + if (isDir || i != parts.Size() - 1) + { + parts.Delete(i); + continue; + } s = k_EmptyReplaceName; } else { + keepAndReplaceEmptyPrefixes = false; #ifdef _WIN32 CorrectUnsupportedName(s); #endif @@ -214,7 +273,7 @@ void Correct_FsPath(bool absIsAllowed, UStringVector &parts, bool isDir) if (!isDir) { if (parts.IsEmpty()) - parts.Add(k_EmptyReplaceName); + parts.Add((UString)k_EmptyReplaceName); else { UString &s = parts.Back(); |