diff options
Diffstat (limited to '3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.cpp')
-rw-r--r-- | 3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.cpp | 68 |
1 files changed, 46 insertions, 22 deletions
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.cpp b/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.cpp index 17947dcef43..06d2ab80895 100644 --- a/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.cpp +++ b/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.cpp @@ -2,53 +2,77 @@ #include "StdAfx.h" -#include "Windows/FileDir.h" -#include "Windows/FileFind.h" +#include "../../../Windows/FileDir.h" +#include "../../../Windows/FileName.h" #include "ExtractingFilePath.h" +#include "ArchiveName.h" using namespace NWindows; +using namespace NFile; -static FString CreateArchiveName2(const FString &srcName, bool fromPrev, bool keepName) +UString CreateArchiveName(const NFind::CFileInfo &fi, bool keepName) +{ + FString resultName = fi.Name; + if (!fi.IsDir() && !keepName) + { + int dotPos = resultName.ReverseFind_Dot(); + if (dotPos > 0) + { + FString archiveName2 = resultName.Left(dotPos); + if (archiveName2.ReverseFind_Dot() < 0) + resultName = archiveName2; + } + } + return Get_Correct_FsFile_Name(fs2us(resultName)); +} + +static FString CreateArchiveName2(const FString &path, bool fromPrev, bool keepName) { FString resultName = FTEXT("Archive"); if (fromPrev) { FString dirPrefix; - if (NFile::NDirectory::GetOnlyDirPrefix(srcName, dirPrefix)) + if (NDir::GetOnlyDirPrefix(path, dirPrefix)) { - if (dirPrefix.Length() > 0) - if (dirPrefix.Back() == FCHAR_PATH_SEPARATOR) + if (!dirPrefix.IsEmpty() && IsPathSepar(dirPrefix.Back())) + { + #if defined(_WIN32) && !defined(UNDER_CE) + if (NName::IsDriveRootPath_SuperAllowed(dirPrefix)) + resultName = dirPrefix[dirPrefix.Len() - 3]; // only letter + else + #endif { dirPrefix.DeleteBack(); - NFile::NFind::CFileInfo fileInfo; - if (fileInfo.Find(dirPrefix)) - resultName = fileInfo.Name; + NFind::CFileInfo fi; + if (fi.Find(dirPrefix)) + resultName = fi.Name; } + } } } else { - NFile::NFind::CFileInfo fileInfo; - if (!fileInfo.Find(srcName)) - // return resultName; - return srcName; - resultName = fileInfo.Name; - if (!fileInfo.IsDir() && !keepName) + NFind::CFileInfo fi; + if (fi.Find(path)) { - int dotPos = resultName.ReverseFind('.'); - if (dotPos > 0) + resultName = fi.Name; + if (!fi.IsDir() && !keepName) { - FString archiveName2 = resultName.Left(dotPos); - if (archiveName2.ReverseFind(FTEXT('.')) < 0) - resultName = archiveName2; + int dotPos = resultName.ReverseFind_Dot(); + if (dotPos > 0) + { + FString name2 = resultName.Left(dotPos); + if (name2.ReverseFind_Dot() < 0) + resultName = name2; + } } } } return resultName; } -UString CreateArchiveName(const UString &srcName, bool fromPrev, bool keepName) +UString CreateArchiveName(const UString &path, bool fromPrev, bool keepName) { - return GetCorrectFsPath(fs2us(CreateArchiveName2(us2fs(srcName), fromPrev, keepName))); + return Get_Correct_FsFile_Name(fs2us(CreateArchiveName2(us2fs(path), fromPrev, keepName))); } |