summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.cpp
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2023-12-06 07:58:49 +1100
committer Vas Crabb <vas@vastheman.com>2023-12-06 07:58:49 +1100
commit79bef1e23049fdac25f1fefd132e0b6c7d2cc3a1 (patch)
tree643e9313fe86f583c4022c338677cbc12b761df7 /3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.cpp
parent512ccf0c7c9b4f08e41038b2ed2de220e140385b (diff)
3rdparty/lzma: Updated to version 23.01.
Diffstat (limited to '3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.cpp')
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.cpp233
1 files changed, 127 insertions, 106 deletions
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.cpp b/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.cpp
index 1baf3e1e300..1c0c3a821b1 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.cpp
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/ArchiveName.cpp
@@ -2,154 +2,175 @@
#include "StdAfx.h"
+#include "../../../../C/Sort.h"
+
#include "../../../Common/Wildcard.h"
+#include "../../../Common/StringToInt.h"
#include "../../../Windows/FileDir.h"
#include "../../../Windows/FileName.h"
-#include "ExtractingFilePath.h"
#include "ArchiveName.h"
+#include "ExtractingFilePath.h"
using namespace NWindows;
using namespace NFile;
-static UString CreateArchiveName(const NFind::CFileInfo &fi, bool keepName)
+
+static const char *g_ArcExts =
+ "7z"
+ "\0" "zip"
+ "\0" "tar"
+ "\0" "wim"
+ "\0";
+
+static const char *g_HashExts =
+ "sha256"
+ "\0";
+
+
+UString CreateArchiveName(
+ const UStringVector &paths,
+ bool isHash,
+ const NFind::CFileInfo *fi,
+ UString &baseName)
{
- FString resultName = fi.Name;
- if (!fi.IsDir() && !keepName)
+ bool keepName = isHash;
+ /*
+ if (paths.Size() == 1)
{
- int dotPos = resultName.ReverseFind_Dot();
- if (dotPos > 0)
- {
- FString archiveName2 = resultName.Left((unsigned)dotPos);
- if (archiveName2.ReverseFind_Dot() < 0)
- resultName = archiveName2;
- }
+ const UString &name = paths[0];
+ if (name.Len() > 4)
+ if (CompareFileNames(name.RightPtr(4), L".tar") == 0)
+ keepName = true;
}
- return Get_Correct_FsFile_Name(fs2us(resultName));
-}
+ */
-static FString CreateArchiveName2(const FString &path, bool fromPrev, bool keepName)
-{
- FString resultName ("Archive");
- if (fromPrev)
+ UString name ("Archive");
+ NFind::CFileInfo fi3;
+ if (paths.Size() > 1)
+ fi = NULL;
+ if (!fi && paths.Size() != 0)
{
- FString dirPrefix;
- if (NDir::GetOnlyDirPrefix(path, dirPrefix))
+ const UString &path = paths.Front();
+ if (paths.Size() == 1)
{
- 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();
- NFind::CFileInfo fi;
- if (fi.Find(dirPrefix))
- resultName = fi.Name;
- }
- }
+ if (fi3.Find(us2fs(path)))
+ fi = &fi3;
}
- }
- else
- {
- NFind::CFileInfo fi;
- if (fi.Find(path))
+ else
{
- resultName = fi.Name;
- if (!fi.IsDir() && !keepName)
+ // we try to use name of parent folder
+ FString dirPrefix;
+ if (NDir::GetOnlyDirPrefix(us2fs(path), dirPrefix))
{
- int dotPos = resultName.ReverseFind_Dot();
- if (dotPos > 0)
+ if (!dirPrefix.IsEmpty() && IsPathSepar(dirPrefix.Back()))
{
- FString name2 = resultName.Left((unsigned)dotPos);
- if (name2.ReverseFind_Dot() < 0)
- resultName = name2;
+ #if defined(_WIN32) && !defined(UNDER_CE)
+ if (NName::IsDriveRootPath_SuperAllowed(dirPrefix))
+ {
+ if (path != fs2us(dirPrefix))
+ name = dirPrefix[dirPrefix.Len() - 3]; // only letter
+ }
+ else
+ #endif
+ {
+ dirPrefix.DeleteBack();
+ if (!dirPrefix.IsEmpty())
+ {
+ const int slash = dirPrefix.ReverseFind_PathSepar();
+ if (slash >= 0 && slash != (int)dirPrefix.Len() - 1)
+ name = dirPrefix.Ptr(slash + 1);
+ else if (fi3.Find(dirPrefix))
+ name = fs2us(fi3.Name);
+ }
+ }
}
}
}
}
- return resultName;
-}
-
-UString CreateArchiveName(const UStringVector &paths, const NFind::CFileInfo *fi)
-{
- 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)));
+ name = fs2us(fi->Name);
+ if (!fi->IsDir() && !keepName)
+ {
+ const int dotPos = name.Find(L'.');
+ if (dotPos > 0 && name.Find(L'.', (unsigned)dotPos + 1) < 0)
+ name.DeleteFrom((unsigned)dotPos);
+ }
}
+ name = Get_Correct_FsFile_Name(name);
- UStringVector names;
-
+ CRecordVector<UInt32> ids;
+ bool simple_IsAllowed = true;
+ // for (int y = 0; y < 10000; y++) // for debug
{
+ // ids.Clear();
+ UString n;
+
FOR_VECTOR (i, paths)
{
- NFind::CFileInfo fi2;
- const NFind::CFileInfo *fp;
- if (fi && paths.Size() == 1)
- fp = fi;
- else
+ const UString &a = paths[i];
+ const int slash = a.ReverseFind_PathSepar();
+ // if (name.Len() >= a.Len() - slash + 1) continue;
+ const wchar_t *s = a.Ptr(slash + 1);
+ if (!IsPath1PrefixedByPath2(s, name))
+ continue;
+ s += name.Len();
+ const char *exts = isHash ? g_HashExts : g_ArcExts;
+
+ for (;;)
{
- if (!fi2.Find(us2fs(paths[i])))
+ const char *ext = exts;
+ const unsigned len = MyStringLen(ext);
+ if (len == 0)
+ break;
+ exts += len + 1;
+ n = s;
+ if (n.Len() <= len)
+ continue;
+ if (!StringsAreEqualNoCase_Ascii(n.RightPtr(len), ext))
+ continue;
+ n.DeleteFrom(n.Len() - len);
+ if (n.Back() != '.')
+ continue;
+ n.DeleteBack();
+ if (n.IsEmpty())
+ {
+ simple_IsAllowed = false;
+ break;
+ }
+ if (n.Len() < 2)
+ continue;
+ if (n[0] != '_')
continue;
- fp = &fi2;
+ const wchar_t *end;
+ const UInt32 v = ConvertStringToUInt32(n.Ptr(1), &end);
+ if (*end != 0)
+ continue;
+ ids.Add(v);
+ break;
}
- names.Add(fs2us(fp->Name));
}
}
- UString postfix;
- UInt32 index = 1;
-
- for (;;)
+ baseName = name;
+ if (!simple_IsAllowed)
{
- // 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++)
+ HeapSort(&ids.Front(), ids.Size());
+ UInt32 v = 2;
+ const unsigned num = ids.Size();
+ for (unsigned i = 0; i < num; 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))
+ const UInt32 id = ids[i];
+ if (id > v)
break;
+ if (id == v)
+ v = id + 1;
}
-
- if (i == names.Size())
- break;
- index++;
- postfix = "_";
- postfix.Add_UInt32(index);
+ name += '_';
+ name.Add_UInt32(v);
}
-
- name += postfix;
return name;
}