summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.cpp
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2023-05-04 02:41:16 +1000
committer Vas Crabb <vas@vastheman.com>2023-05-04 02:41:16 +1000
commita504bde3a7462b54fafd5cfc2f52e58d0f3218e1 (patch)
tree8b3108d572b1a0873a6cdbb4e8af1f17179545c3 /3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.cpp
parentbefb9bf4a8cfdb2b693a32e32535b5eac522c5d8 (diff)
3rdparty/lzma: Updated to LZMA SDK version 22.01
Diffstat (limited to '3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.cpp')
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.cpp89
1 files changed, 83 insertions, 6 deletions
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.cpp b/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.cpp
index 06d2ab80895..1baf3e1e300 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.cpp
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.cpp
@@ -2,6 +2,8 @@
#include "StdAfx.h"
+#include "../../../Common/Wildcard.h"
+
#include "../../../Windows/FileDir.h"
#include "../../../Windows/FileName.h"
@@ -11,7 +13,7 @@
using namespace NWindows;
using namespace NFile;
-UString CreateArchiveName(const NFind::CFileInfo &fi, bool keepName)
+static UString CreateArchiveName(const NFind::CFileInfo &fi, bool keepName)
{
FString resultName = fi.Name;
if (!fi.IsDir() && !keepName)
@@ -19,7 +21,7 @@ UString CreateArchiveName(const NFind::CFileInfo &fi, bool keepName)
int dotPos = resultName.ReverseFind_Dot();
if (dotPos > 0)
{
- FString archiveName2 = resultName.Left(dotPos);
+ FString archiveName2 = resultName.Left((unsigned)dotPos);
if (archiveName2.ReverseFind_Dot() < 0)
resultName = archiveName2;
}
@@ -29,7 +31,7 @@ UString CreateArchiveName(const NFind::CFileInfo &fi, bool keepName)
static FString CreateArchiveName2(const FString &path, bool fromPrev, bool keepName)
{
- FString resultName = FTEXT("Archive");
+ FString resultName ("Archive");
if (fromPrev)
{
FString dirPrefix;
@@ -62,7 +64,7 @@ static FString CreateArchiveName2(const FString &path, bool fromPrev, bool keepN
int dotPos = resultName.ReverseFind_Dot();
if (dotPos > 0)
{
- FString name2 = resultName.Left(dotPos);
+ FString name2 = resultName.Left((unsigned)dotPos);
if (name2.ReverseFind_Dot() < 0)
resultName = name2;
}
@@ -72,7 +74,82 @@ static FString CreateArchiveName2(const FString &path, bool fromPrev, bool keepN
return resultName;
}
-UString CreateArchiveName(const UString &path, bool fromPrev, bool keepName)
+
+UString CreateArchiveName(const UStringVector &paths, const NFind::CFileInfo *fi)
{
- return Get_Correct_FsFile_Name(fs2us(CreateArchiveName2(us2fs(path), fromPrev, keepName)));
+ bool keepName = false;
+ /*
+ if (paths.Size() == 1)
+ {
+ const UString &name = paths[0];
+ if (name.Len() > 4)
+ if (CompareFileNames(name.RightPtr(4), L".tar") == 0)
+ keepName = true;
+ }
+ */
+
+ UString name;
+ if (fi)
+ name = CreateArchiveName(*fi, keepName);
+ else
+ {
+ if (paths.IsEmpty())
+ return L"archive";
+ bool fromPrev = (paths.Size() > 1);
+ name = Get_Correct_FsFile_Name(fs2us(CreateArchiveName2(us2fs(paths.Front()), fromPrev, keepName)));
+ }
+
+ UStringVector names;
+
+ {
+ FOR_VECTOR (i, paths)
+ {
+ NFind::CFileInfo fi2;
+ const NFind::CFileInfo *fp;
+ if (fi && paths.Size() == 1)
+ fp = fi;
+ else
+ {
+ if (!fi2.Find(us2fs(paths[i])))
+ continue;
+ fp = &fi2;
+ }
+ names.Add(fs2us(fp->Name));
+ }
+ }
+
+ UString postfix;
+ UInt32 index = 1;
+
+ for (;;)
+ {
+ // we don't want cases when we include archive to itself.
+ // so we find first available name for archive
+ const UString name2 = name + postfix;
+ const UString name2_zip = name2 + L".zip";
+ const UString name2_7z = name2 + L".7z";
+ const UString name2_tar = name2 + L".tar";
+ const UString name2_wim = name2 + L".wim";
+
+ unsigned i = 0;
+
+ for (i = 0; i < names.Size(); i++)
+ {
+ const UString &fname = names[i];
+ if ( 0 == CompareFileNames(fname, name2_zip)
+ || 0 == CompareFileNames(fname, name2_7z)
+ || 0 == CompareFileNames(fname, name2_tar)
+ || 0 == CompareFileNames(fname, name2_wim))
+ break;
+ }
+
+ if (i == names.Size())
+ break;
+ index++;
+ postfix = "_";
+ postfix.Add_UInt32(index);
+ }
+
+ name += postfix;
+ return name;
}