Update to lzma 23.01.

This commit is contained in:
2023-09-24 03:13:03 +01:00
parent 5a6a32f513
commit dda9bcac54
530 changed files with 31937 additions and 14468 deletions

View File

@@ -7,11 +7,13 @@
#include "../../../Common/StringConvert.h"
#include "../../../Windows/FileDir.h"
#include "../../../Windows/FileName.h"
#include "../../../Windows/ErrorMsg.h"
#include "../../../Windows/PropVariant.h"
#include "../../../Windows/PropVariantConv.h"
#include "../Common/ExtractingFilePath.h"
#include "../Common/HashCalc.h"
#include "Extract.h"
#include "SetProperties.h"
@@ -41,6 +43,7 @@ static HRESULT DecompressArchive(
const CExtractOptions &options,
bool calcCrc,
IExtractCallbackUI *callback,
IFolderArchiveExtractCallback *callbackFAE,
CArchiveExtractCallback *ecs,
UString &errorMessage,
UInt64 &stdInProcessed)
@@ -87,20 +90,25 @@ static HRESULT DecompressArchive(
}
}
bool allFilesAreAllowed = wildcardCensor.AreAllAllowed();
const bool allFilesAreAllowed = wildcardCensor.AreAllAllowed();
if (!options.StdInMode)
{
UInt32 numItems;
RINOK(archive->GetNumberOfItems(&numItems));
RINOK(archive->GetNumberOfItems(&numItems))
CReadArcItem item;
for (UInt32 i = 0; i < numItems; i++)
{
if (elimIsPossible || !allFilesAreAllowed)
if (elimIsPossible
|| !allFilesAreAllowed
|| options.ExcludeDirItems
|| options.ExcludeFileItems)
{
RINOK(arc.GetItem(i, item));
RINOK(arc.GetItem(i, item))
if (item.IsDir ? options.ExcludeDirItems : options.ExcludeFileItems)
continue;
}
else
{
@@ -108,7 +116,7 @@ static HRESULT DecompressArchive(
item.IsAltStream = false;
if (!options.NtOptions.AltStreams.Val && arc.Ask_AltStream)
{
RINOK(Archive_IsItem_AltStream(arc.Archive, i, item.IsAltStream));
RINOK(Archive_IsItem_AltStream(arc.Archive, i, item.IsAltStream))
}
#endif
}
@@ -187,7 +195,7 @@ static HRESULT DecompressArchive(
options.NtOptions,
options.StdInMode ? &wildcardCensor : NULL,
&arc,
callback,
callbackFAE,
options.StdOutMode, options.TestMode,
outDir,
removePathParts, false,
@@ -200,14 +208,14 @@ static HRESULT DecompressArchive(
!options.TestMode &&
options.NtOptions.HardLinks.Val)
{
RINOK(ecs->PrepareHardLinks(&realIndices));
RINOK(ecs->PrepareHardLinks(&realIndices))
}
#endif
HRESULT result;
Int32 testMode = (options.TestMode && !calcCrc) ? 1: 0;
const Int32 testMode = (options.TestMode && !calcCrc) ? 1: 0;
CArchiveExtractCallback_Closer ecsCloser(ecs);
@@ -221,7 +229,7 @@ static HRESULT DecompressArchive(
else
result = archive->Extract(&realIndices.Front(), realIndices.Size(), testMode, ecs);
HRESULT res2 = ecsCloser.Close();
const HRESULT res2 = ecsCloser.Close();
if (result == S_OK)
result = res2;
@@ -232,18 +240,18 @@ static HRESULT DecompressArchive(
Sorted list for file paths was sorted with case insensitive compare function.
But FindInSorted function did binary search via case sensitive compare function */
int Find_FileName_InSortedVector(const UStringVector &fileName, const UString &name);
int Find_FileName_InSortedVector(const UStringVector &fileName, const UString &name)
int Find_FileName_InSortedVector(const UStringVector &fileNames, const UString &name);
int Find_FileName_InSortedVector(const UStringVector &fileNames, const UString &name)
{
unsigned left = 0, right = fileName.Size();
unsigned left = 0, right = fileNames.Size();
while (left != right)
{
unsigned mid = (left + right) / 2;
const UString &midValue = fileName[mid];
int compare = CompareFileNames(name, midValue);
if (compare == 0)
const unsigned mid = (unsigned)(((size_t)left + (size_t)right) / 2);
const UString &midVal = fileNames[mid];
const int comp = CompareFileNames(name, midVal);
if (comp == 0)
return (int)mid;
if (compare < 0)
if (comp < 0)
right = mid;
else
left = mid + 1;
@@ -254,6 +262,7 @@ int Find_FileName_InSortedVector(const UStringVector &fileName, const UString &n
HRESULT Extract(
// DECL_EXTERNAL_CODECS_LOC_VARS
CCodecs *codecs,
const CObjectVector<COpenType> &types,
const CIntVector &excludedFormats,
@@ -262,7 +271,8 @@ HRESULT Extract(
const CExtractOptions &options,
IOpenCallbackUI *openCallback,
IExtractCallbackUI *extractCallback,
#ifndef _SFX
IFolderArchiveExtractCallback *faeCallback,
#ifndef Z7_SFX
IHashCalc *hash,
#endif
UString &errorMessage,
@@ -306,17 +316,22 @@ HRESULT Extract(
CArchiveExtractCallback *ecs = new CArchiveExtractCallback;
CMyComPtr<IArchiveExtractCallback> ec(ecs);
bool multi = (numArcs > 1);
ecs->InitForMulti(multi, options.PathMode, options.OverwriteMode,
const bool multi = (numArcs > 1);
ecs->InitForMulti(multi,
options.PathMode,
options.OverwriteMode,
options.ZoneMode,
false // keepEmptyDirParts
);
#ifndef _SFX
#ifndef Z7_SFX
ecs->SetHashMethods(hash);
#endif
if (multi)
{
RINOK(extractCallback->SetTotal(totalPackSize));
RINOK(faeCallback->SetTotal(totalPackSize))
}
UInt64 totalPackProcessed = 0;
@@ -327,12 +342,18 @@ HRESULT Extract(
if (skipArcs[i])
continue;
ecs->InitBeforeNewArchive();
const UString &arcPath = arcPaths[i];
NFind::CFileInfo fi;
if (options.StdInMode)
{
fi.Size = 0;
fi.Attrib = 0;
// do we need ctime and mtime?
fi.ClearBase();
fi.Size = 0; // (UInt64)(Int64)-1;
fi.SetAsFile();
// NTime::GetCurUtc_FiTime(fi.MTime);
// fi.CTime = fi.ATime = fi.MTime;
}
else
{
@@ -345,17 +366,17 @@ HRESULT Extract(
}
/*
#ifndef _NO_CRYPTO
#ifndef Z7_NO_CRYPTO
openCallback->Open_Clear_PasswordWasAsked_Flag();
#endif
*/
RINOK(extractCallback->BeforeOpen(arcPath, options.TestMode));
RINOK(extractCallback->BeforeOpen(arcPath, options.TestMode))
CArchiveLink arcLink;
CObjectVector<COpenType> types2 = types;
/*
#ifndef _SFX
#ifndef Z7_SFX
if (types.IsEmpty())
{
int pos = arcPath.ReverseFind(L'.');
@@ -383,7 +404,7 @@ HRESULT Extract(
*/
COpenOptions op;
#ifndef _SFX
#ifndef Z7_SFX
op.props = &options.Properties;
#endif
op.codecs = codecs;
@@ -399,7 +420,7 @@ HRESULT Extract(
return result;
// arcLink.Set_ErrorsText();
RINOK(extractCallback->OpenResult(codecs, arcLink, arcPath, result));
RINOK(extractCallback->OpenResult(codecs, arcLink, arcPath, result))
if (result != S_OK)
{
@@ -409,6 +430,46 @@ HRESULT Extract(
continue;
}
#if defined(_WIN32) && !defined(UNDER_CE) && !defined(Z7_SFX)
if (options.ZoneMode != NExtract::NZoneIdMode::kNone
&& !options.StdInMode)
{
ReadZoneFile_Of_BaseFile(us2fs(arcPath), ecs->ZoneBuf);
}
#endif
if (arcLink.Arcs.Size() != 0)
{
if (arcLink.GetArc()->IsHashHandler(op))
{
if (!options.TestMode)
{
/* real Extracting to files is possible.
But user can think that hash archive contains real files.
So we block extracting here. */
// v23.00 : we don't break process.
RINOK(extractCallback->OpenResult(codecs, arcLink, arcPath, E_NOTIMPL))
thereAreNotOpenArcs = true;
if (!options.StdInMode)
totalPackProcessed += fi.Size;
continue;
// return E_NOTIMPL; // before v23
}
FString dirPrefix = us2fs(options.HashDir);
if (dirPrefix.IsEmpty())
{
if (!NFile::NDir::GetOnlyDirPrefix(us2fs(arcPath), dirPrefix))
{
// return GetLastError_noZero_HRESULT();
}
}
if (!dirPrefix.IsEmpty())
NName::NormalizeDirPathPrefix(dirPrefix);
ecs->DirPathPrefix_for_HashFiles = dirPrefix;
}
}
if (!options.StdInMode)
{
// numVolumes += arcLink.VolumePaths.Size();
@@ -437,7 +498,7 @@ HRESULT Extract(
if (newPackSize < 0)
newPackSize = 0;
totalPackSize = (UInt64)newPackSize;
RINOK(extractCallback->SetTotal(totalPackSize));
RINOK(faeCallback->SetTotal(totalPackSize))
}
}
}
@@ -445,24 +506,29 @@ HRESULT Extract(
/*
// Now openCallback and extractCallback use same object. So we don't need to send password.
#ifndef _NO_CRYPTO
#ifndef Z7_NO_CRYPTO
bool passwordIsDefined;
UString password;
RINOK(openCallback->Open_GetPasswordIfAny(passwordIsDefined, password));
RINOK(openCallback->Open_GetPasswordIfAny(passwordIsDefined, password))
if (passwordIsDefined)
{
RINOK(extractCallback->SetPassword(password));
RINOK(extractCallback->SetPassword(password))
}
#endif
*/
CArc &arc = arcLink.Arcs.Back();
arc.MTimeDefined = (!options.StdInMode && !fi.IsDevice);
arc.MTime = fi.MTime;
arc.MTime.Def = !options.StdInMode
#ifdef _WIN32
&& !fi.IsDevice
#endif
;
if (arc.MTime.Def)
arc.MTime.Set_From_FiTime(fi.MTime);
UInt64 packProcessed;
bool calcCrc =
#ifndef _SFX
const bool calcCrc =
#ifndef Z7_SFX
(hash != NULL);
#else
false;
@@ -475,7 +541,8 @@ HRESULT Extract(
wildcardCensor,
options,
calcCrc,
extractCallback, ecs, errorMessage, packProcessed));
extractCallback, faeCallback, ecs,
errorMessage, packProcessed))
if (!options.StdInMode)
packProcessed = fi.Size + arcLink.VolumesSize;
@@ -488,8 +555,8 @@ HRESULT Extract(
if (multi || thereAreNotOpenArcs)
{
RINOK(extractCallback->SetTotal(totalPackSize));
RINOK(extractCallback->SetCompleted(&totalPackProcessed));
RINOK(faeCallback->SetTotal(totalPackSize))
RINOK(faeCallback->SetCompleted(&totalPackProcessed))
}
st.NumFolders = ecs->NumFolders;