This commit is contained in:
Igor Pavlov
2023-12-22 17:17:05 +00:00
committed by Kornel
parent ec44a8a070
commit a36c48cece
954 changed files with 42199 additions and 25482 deletions

View File

@@ -17,7 +17,7 @@
#include "../../Common/StreamUtils.h"
#include "../Common/ExtractingFilePath.h"
#ifndef _SFX
#ifndef Z7_SFX
#include "../Common/ZipRegistry.h"
#endif
@@ -28,7 +28,7 @@
#include "FormatUtils.h"
#include "LangUtils.h"
#include "OverwriteDialog.h"
#ifndef _NO_CRYPTO
#ifndef Z7_NO_CRYPTO
#include "PasswordDialog.h"
#endif
#include "PropertyName.h"
@@ -48,7 +48,7 @@ void CExtractCallbackImp::Init()
NumArchiveErrors = 0;
ThereAreMessageErrors = false;
#ifndef _SFX
#ifndef Z7_SFX
NumFolders = NumFiles = 0;
NeedAddFile = false;
#endif
@@ -60,29 +60,27 @@ void CExtractCallbackImp::AddError_Message(LPCWSTR s)
ProgressDialog->Sync.AddError_Message(s);
}
#ifndef _SFX
#ifndef Z7_SFX
STDMETHODIMP CExtractCallbackImp::SetNumFiles(UInt64
#ifndef _SFX
numFiles
#endif
)
Z7_COM7F_IMF(CExtractCallbackImp::SetNumFiles(UInt64 numFiles))
{
#ifndef _SFX
#ifdef Z7_SFX
UNUSED_VAR(numFiles)
#else
ProgressDialog->Sync.Set_NumFilesTotal(numFiles);
#endif
#endif
return S_OK;
}
#endif
STDMETHODIMP CExtractCallbackImp::SetTotal(UInt64 total)
Z7_COM7F_IMF(CExtractCallbackImp::SetTotal(UInt64 total))
{
ProgressDialog->Sync.Set_NumBytesTotal(total);
return S_OK;
}
STDMETHODIMP CExtractCallbackImp::SetCompleted(const UInt64 *value)
Z7_COM7F_IMF(CExtractCallbackImp::SetCompleted(const UInt64 *value))
{
return ProgressDialog->Sync.Set_NumBytesCur(value);
}
@@ -139,7 +137,7 @@ HRESULT CExtractCallbackImp::Open_Finished()
return ProgressDialog->Sync.CheckStop();
}
#ifndef _NO_CRYPTO
#ifndef Z7_NO_CRYPTO
HRESULT CExtractCallbackImp::Open_CryptoGetTextPassword(BSTR *password)
{
@@ -168,8 +166,8 @@ void CExtractCallbackImp::Open_Clear_PasswordWasAsked_Flag()
#endif
#ifndef _SFX
STDMETHODIMP CExtractCallbackImp::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)
#ifndef Z7_SFX
Z7_COM7F_IMF(CExtractCallbackImp::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize))
{
ProgressDialog->Sync.Set_Ratio(inSize, outSize);
return S_OK;
@@ -177,13 +175,13 @@ STDMETHODIMP CExtractCallbackImp::SetRatioInfo(const UInt64 *inSize, const UInt6
#endif
/*
STDMETHODIMP CExtractCallbackImp::SetTotalFiles(UInt64 total)
Z7_COM7F_IMF(CExtractCallbackImp::SetTotalFiles(UInt64 total)
{
ProgressDialog->Sync.SetNumFilesTotal(total);
return S_OK;
}
STDMETHODIMP CExtractCallbackImp::SetCompletedFiles(const UInt64 *value)
Z7_COM7F_IMF(CExtractCallbackImp::SetCompletedFiles(const UInt64 *value)
{
if (value != NULL)
ProgressDialog->Sync.SetNumFilesCur(*value);
@@ -191,10 +189,10 @@ STDMETHODIMP CExtractCallbackImp::SetCompletedFiles(const UInt64 *value)
}
*/
STDMETHODIMP CExtractCallbackImp::AskOverwrite(
Z7_COM7F_IMF(CExtractCallbackImp::AskOverwrite(
const wchar_t *existName, const FILETIME *existTime, const UInt64 *existSize,
const wchar_t *newName, const FILETIME *newTime, const UInt64 *newSize,
Int32 *answer)
Int32 *answer))
{
COverwriteDialog dialog;
@@ -223,7 +221,7 @@ STDMETHODIMP CExtractCallbackImp::AskOverwrite(
}
STDMETHODIMP CExtractCallbackImp::PrepareOperation(const wchar_t *name, Int32 isFolder, Int32 askExtractMode, const UInt64 * /* position */)
Z7_COM7F_IMF(CExtractCallbackImp::PrepareOperation(const wchar_t *name, Int32 isFolder, Int32 askExtractMode, const UInt64 * /* position */))
{
_isFolder = IntToBool(isFolder);
_currentFilePath = name;
@@ -241,7 +239,7 @@ STDMETHODIMP CExtractCallbackImp::PrepareOperation(const wchar_t *name, Int32 is
return ProgressDialog->Sync.Set_Status2(*msg, name, IntToBool(isFolder));
}
STDMETHODIMP CExtractCallbackImp::MessageError(const wchar_t *s)
Z7_COM7F_IMF(CExtractCallbackImp::MessageError(const wchar_t *s))
{
AddError_Message(s);
return S_OK;
@@ -254,9 +252,9 @@ HRESULT CExtractCallbackImp::MessageError(const char *message, const FString &pa
return S_OK;
}
#ifndef _SFX
#ifndef Z7_SFX
STDMETHODIMP CExtractCallbackImp::ShowMessage(const wchar_t *s)
Z7_COM7F_IMF(CExtractCallbackImp::ShowMessage(const wchar_t *s))
{
AddError_Message(s);
return S_OK;
@@ -272,25 +270,33 @@ void SetExtractErrorMessage(Int32 opRes, Int32 encrypted, const wchar_t *fileNam
if (opRes == NArchive::NExtract::NOperationResult::kOK)
return;
#ifndef Z7_SFX
UINT messageID = 0;
#endif
UINT id = 0;
switch (opRes)
{
case NArchive::NExtract::NOperationResult::kUnsupportedMethod:
#ifndef Z7_SFX
messageID = IDS_EXTRACT_MESSAGE_UNSUPPORTED_METHOD;
#endif
id = IDS_EXTRACT_MSG_UNSUPPORTED_METHOD;
break;
case NArchive::NExtract::NOperationResult::kDataError:
#ifndef Z7_SFX
messageID = encrypted ?
IDS_EXTRACT_MESSAGE_DATA_ERROR_ENCRYPTED:
IDS_EXTRACT_MESSAGE_DATA_ERROR;
#endif
id = IDS_EXTRACT_MSG_DATA_ERROR;
break;
case NArchive::NExtract::NOperationResult::kCRCError:
#ifndef Z7_SFX
messageID = encrypted ?
IDS_EXTRACT_MESSAGE_CRC_ERROR_ENCRYPTED:
IDS_EXTRACT_MESSAGE_CRC_ERROR;
#endif
id = IDS_EXTRACT_MSG_CRC_ERROR;
break;
case NArchive::NExtract::NOperationResult::kUnavailable:
@@ -319,18 +325,19 @@ void SetExtractErrorMessage(Int32 opRes, Int32 encrypted, const wchar_t *fileNam
}
UString msg;
UString msgOld;
#ifndef _SFX
#ifndef Z7_SFX
UString msgOld;
#ifdef Z7_LANG
if (id != 0)
LangString_OnlyFromLangFile(id, msg);
if (messageID != 0 && msg.IsEmpty())
LangString_OnlyFromLangFile(messageID, msgOld);
#endif
#endif
if (msg.IsEmpty() && !msgOld.IsEmpty())
s = MyFormatNew(msgOld, fileName);
else
#endif
{
if (msg.IsEmpty() && id != 0)
LangString(id, msg);
@@ -339,7 +346,7 @@ void SetExtractErrorMessage(Int32 opRes, Int32 encrypted, const wchar_t *fileNam
else
{
s += "Error #";
s.Add_UInt32(opRes);
s.Add_UInt32((UInt32)opRes);
}
if (encrypted && opRes != NArchive::NExtract::NOperationResult::kWrongPassword)
@@ -354,7 +361,7 @@ void SetExtractErrorMessage(Int32 opRes, Int32 encrypted, const wchar_t *fileNam
}
}
STDMETHODIMP CExtractCallbackImp::SetOperationResult(Int32 opRes, Int32 encrypted)
Z7_COM7F_IMF(CExtractCallbackImp::SetOperationResult(Int32 opRes, Int32 encrypted))
{
switch (opRes)
{
@@ -369,7 +376,7 @@ STDMETHODIMP CExtractCallbackImp::SetOperationResult(Int32 opRes, Int32 encrypte
}
}
#ifndef _SFX
#ifndef Z7_SFX
if (_isFolder)
NumFolders++;
else
@@ -380,7 +387,7 @@ STDMETHODIMP CExtractCallbackImp::SetOperationResult(Int32 opRes, Int32 encrypte
return S_OK;
}
STDMETHODIMP CExtractCallbackImp::ReportExtractResult(Int32 opRes, Int32 encrypted, const wchar_t *name)
Z7_COM7F_IMF(CExtractCallbackImp::ReportExtractResult(Int32 opRes, Int32 encrypted, const wchar_t *name))
{
if (opRes != NArchive::NExtract::NOperationResult::kOK)
{
@@ -397,8 +404,8 @@ STDMETHODIMP CExtractCallbackImp::ReportExtractResult(Int32 opRes, Int32 encrypt
HRESULT CExtractCallbackImp::BeforeOpen(const wchar_t *name, bool /* testMode */)
{
#ifndef _SFX
RINOK(ProgressDialog->Sync.CheckStop());
#ifndef Z7_SFX
RINOK(ProgressDialog->Sync.CheckStop())
ProgressDialog->Sync.Set_TitleFileName(name);
#endif
_currentArchivePath = name;
@@ -408,17 +415,17 @@ HRESULT CExtractCallbackImp::BeforeOpen(const wchar_t *name, bool /* testMode */
HRESULT CExtractCallbackImp::SetCurrentFilePath2(const wchar_t *path)
{
_currentFilePath = path;
#ifndef _SFX
#ifndef Z7_SFX
ProgressDialog->Sync.Set_FilePath(path);
#endif
return S_OK;
}
#ifndef _SFX
#ifndef Z7_SFX
HRESULT CExtractCallbackImp::SetCurrentFilePath(const wchar_t *path)
Z7_COM7F_IMF(CExtractCallbackImp::SetCurrentFilePath(const wchar_t *path))
{
#ifndef _SFX
#ifndef Z7_SFX
if (NeedAddFile)
NumFiles++;
NeedAddFile = true;
@@ -457,7 +464,7 @@ UString GetOpenArcErrorMessage(UInt32 errorFlags)
{
UString s;
for (unsigned i = 0; i < ARRAY_SIZE(k_ErrorFlagsIds); i++)
for (unsigned i = 0; i < Z7_ARRAY_SIZE(k_ErrorFlagsIds); i++)
{
UInt32 f = ((UInt32)1 << i);
if ((errorFlags & f) == 0)
@@ -649,7 +656,7 @@ HRESULT CExtractCallbackImp::ExtractResult(HRESULT result)
return S_OK;
}
#ifndef _NO_CRYPTO
#ifndef Z7_NO_CRYPTO
HRESULT CExtractCallbackImp::SetPassword(const UString &password)
{
@@ -658,14 +665,14 @@ HRESULT CExtractCallbackImp::SetPassword(const UString &password)
return S_OK;
}
STDMETHODIMP CExtractCallbackImp::CryptoGetTextPassword(BSTR *password)
Z7_COM7F_IMF(CExtractCallbackImp::CryptoGetTextPassword(BSTR *password))
{
PasswordWasAsked = true;
if (!PasswordIsDefined)
{
CPasswordDialog dialog;
#ifndef _SFX
bool showPassword = NExtract::Read_ShowPassword();
#ifndef Z7_SFX
const bool showPassword = NExtract::Read_ShowPassword();
dialog.ShowPassword = showPassword;
#endif
ProgressDialog->WaitCreating();
@@ -673,7 +680,7 @@ STDMETHODIMP CExtractCallbackImp::CryptoGetTextPassword(BSTR *password)
return E_ABORT;
Password = dialog.Password;
PasswordIsDefined = true;
#ifndef _SFX
#ifndef Z7_SFX
if (dialog.ShowPassword != showPassword)
NExtract::Save_ShowPassword(dialog.ShowPassword);
#endif
@@ -683,24 +690,24 @@ STDMETHODIMP CExtractCallbackImp::CryptoGetTextPassword(BSTR *password)
#endif
#ifndef _SFX
#ifndef Z7_SFX
STDMETHODIMP CExtractCallbackImp::AskWrite(
Z7_COM7F_IMF(CExtractCallbackImp::AskWrite(
const wchar_t *srcPath, Int32 srcIsFolder,
const FILETIME *srcTime, const UInt64 *srcSize,
const wchar_t *destPath,
BSTR *destPathResult,
Int32 *writeAnswer)
Int32 *writeAnswer))
{
UString destPathResultTemp = destPath;
// RINOK(StringToBstr(destPath, destPathResult));
*destPathResult = 0;
*destPathResult = NULL;
*writeAnswer = BoolToInt(false);
FString destPathSys = us2fs(destPath);
bool srcIsFolderSpec = IntToBool(srcIsFolder);
const bool srcIsFolderSpec = IntToBool(srcIsFolder);
CFileInfo destFileInfo;
if (destFileInfo.Find(destPathSys))
@@ -709,7 +716,7 @@ STDMETHODIMP CExtractCallbackImp::AskWrite(
{
if (!destFileInfo.IsDir())
{
RINOK(MessageError("Cannot replace file with folder with same name", destPathSys));
RINOK(MessageError("Cannot replace file with folder with same name", destPathSys))
return E_ABORT;
}
*writeAnswer = BoolToInt(false);
@@ -718,12 +725,12 @@ STDMETHODIMP CExtractCallbackImp::AskWrite(
if (destFileInfo.IsDir())
{
RINOK(MessageError("Cannot replace folder with file with same name", destPathSys));
RINOK(MessageError("Cannot replace folder with file with same name", destPathSys))
*writeAnswer = BoolToInt(false);
return S_OK;
}
switch (OverwriteMode)
switch ((int)OverwriteMode)
{
case NExtract::NOverwriteMode::kSkip:
return S_OK;
@@ -731,7 +738,7 @@ STDMETHODIMP CExtractCallbackImp::AskWrite(
{
Int32 overwriteResult;
UString destPathSpec = destPath;
int slashPos = destPathSpec.ReverseFind_PathSepar();
const int slashPos = destPathSpec.ReverseFind_PathSepar();
destPathSpec.DeleteFrom((unsigned)(slashPos + 1));
destPathSpec += fs2us(destFileInfo.Name);
@@ -740,7 +747,7 @@ STDMETHODIMP CExtractCallbackImp::AskWrite(
&destFileInfo.MTime, &destFileInfo.Size,
srcPath,
srcTime, srcSize,
&overwriteResult));
&overwriteResult))
switch (overwriteResult)
{
@@ -763,7 +770,7 @@ STDMETHODIMP CExtractCallbackImp::AskWrite(
{
if (!AutoRenamePath(destPathSys))
{
RINOK(MessageError("Cannot create name for file", destPathSys));
RINOK(MessageError("Cannot create name for file", destPathSys))
return E_ABORT;
}
destPathResultTemp = fs2us(destPathSys);
@@ -774,7 +781,7 @@ STDMETHODIMP CExtractCallbackImp::AskWrite(
if (!NDir::DeleteFileAlways(destPathSys))
if (GetLastError() != ERROR_FILE_NOT_FOUND)
{
RINOK(MessageError("Cannot delete output file", destPathSys));
RINOK(MessageError("Cannot delete output file", destPathSys))
return E_ABORT;
}
}
@@ -784,7 +791,7 @@ STDMETHODIMP CExtractCallbackImp::AskWrite(
}
STDMETHODIMP CExtractCallbackImp::UseExtractToStream(Int32 *res)
Z7_COM7F_IMF(CExtractCallbackImp::UseExtractToStream(Int32 *res))
{
*res = BoolToInt(StreamMode);
return S_OK;
@@ -794,7 +801,7 @@ static HRESULT GetTime(IGetProp *getProp, PROPID propID, FILETIME &ft, bool &ftD
{
ftDefined = false;
NCOM::CPropVariant prop;
RINOK(getProp->GetProp(propID, &prop));
RINOK(getProp->GetProp(propID, &prop))
if (prop.vt == VT_FILETIME)
{
ft = prop.filetime;
@@ -810,7 +817,7 @@ static HRESULT GetItemBoolProp(IGetProp *getProp, PROPID propID, bool &result)
{
NCOM::CPropVariant prop;
result = false;
RINOK(getProp->GetProp(propID, &prop));
RINOK(getProp->GetProp(propID, &prop))
if (prop.vt == VT_BOOL)
result = VARIANT_BOOLToBool(prop.boolVal);
else if (prop.vt != VT_EMPTY)
@@ -819,13 +826,13 @@ static HRESULT GetItemBoolProp(IGetProp *getProp, PROPID propID, bool &result)
}
STDMETHODIMP CExtractCallbackImp::GetStream7(const wchar_t *name,
Z7_COM7F_IMF(CExtractCallbackImp::GetStream7(const wchar_t *name,
Int32 isDir,
ISequentialOutStream **outStream, Int32 askExtractMode,
IGetProp *getProp)
IGetProp *getProp))
{
COM_TRY_BEGIN
*outStream = 0;
*outStream = NULL;
_newVirtFileWasAdded = false;
_hashStreamWasUsed = false;
_needUpdateStat = false;
@@ -841,20 +848,20 @@ STDMETHODIMP CExtractCallbackImp::GetStream7(const wchar_t *name,
_filePath = name;
_isFolder = IntToBool(isDir);
_curSize = 0;
_curSizeDefined = false;
_curSize_Defined = false;
UInt64 size = 0;
bool sizeDefined;
{
NCOM::CPropVariant prop;
RINOK(getProp->GetProp(kpidSize, &prop));
RINOK(getProp->GetProp(kpidSize, &prop))
sizeDefined = ConvertPropVariantToUInt64(prop, size);
}
if (sizeDefined)
{
_curSize = size;
_curSizeDefined = true;
_curSize_Defined = true;
}
if (askExtractMode != NArchive::NExtract::NAskMode::kExtract &&
@@ -874,12 +881,12 @@ STDMETHODIMP CExtractCallbackImp::GetStream7(const wchar_t *name,
file.IsAltStream = _isAltStream;
file.Size = 0;
RINOK(GetTime(getProp, kpidCTime, file.CTime, file.CTimeDefined));
RINOK(GetTime(getProp, kpidATime, file.ATime, file.ATimeDefined));
RINOK(GetTime(getProp, kpidMTime, file.MTime, file.MTimeDefined));
RINOK(GetTime(getProp, kpidCTime, file.CTime, file.CTimeDefined))
RINOK(GetTime(getProp, kpidATime, file.ATime, file.ATimeDefined))
RINOK(GetTime(getProp, kpidMTime, file.MTime, file.MTimeDefined))
NCOM::CPropVariant prop;
RINOK(getProp->GetProp(kpidAttrib, &prop));
RINOK(getProp->GetProp(kpidAttrib, &prop))
if (prop.vt == VT_UI4)
{
file.Attrib = prop.ulVal;
@@ -909,7 +916,7 @@ STDMETHODIMP CExtractCallbackImp::GetStream7(const wchar_t *name,
COM_TRY_END
}
STDMETHODIMP CExtractCallbackImp::PrepareOperation7(Int32 askExtractMode)
Z7_COM7F_IMF(CExtractCallbackImp::PrepareOperation7(Int32 askExtractMode))
{
COM_TRY_BEGIN
_needUpdateStat = (
@@ -934,21 +941,21 @@ STDMETHODIMP CExtractCallbackImp::PrepareOperation7(Int32 askExtractMode)
COM_TRY_END
}
STDMETHODIMP CExtractCallbackImp::SetOperationResult8(Int32 opRes, Int32 encrypted, UInt64 size)
Z7_COM7F_IMF(CExtractCallbackImp::SetOperationResult8(Int32 opRes, Int32 encrypted, UInt64 size))
{
COM_TRY_BEGIN
if (VirtFileSystem && _newVirtFileWasAdded)
{
// FIXME: probably we must request file size from VirtFileSystem
// _curSize = VirtFileSystem->GetLastFileSize()
// _curSizeDefined = true;
RINOK(VirtFileSystemSpec->CloseMemFile());
// _curSize_Defined = true;
RINOK(VirtFileSystemSpec->CloseMemFile())
}
if (_hashStream && _hashStreamWasUsed)
{
_hashStreamSpec->_hash->Final(_isFolder, _isAltStream, _filePath);
_curSize = _hashStreamSpec->GetSize();
_curSizeDefined = true;
_curSize_Defined = true;
_hashStreamSpec->ReleaseStream();
_hashStreamWasUsed = false;
}
@@ -965,7 +972,7 @@ STDMETHODIMP CExtractCallbackImp::SetOperationResult8(Int32 opRes, Int32 encrypt
// static const UInt32 kBlockSize = ((UInt32)1 << 31);
STDMETHODIMP CVirtFileSystem::Write(const void *data, UInt32 size, UInt32 *processedSize)
Z7_COM7F_IMF(CVirtFileSystem::Write(const void *data, UInt32 size, UInt32 *processedSize))
{
if (processedSize)
*processedSize = 0;
@@ -1002,7 +1009,7 @@ STDMETHODIMP CVirtFileSystem::Write(const void *data, UInt32 size, UInt32 *proce
}
_fileMode = true;
}
RINOK(FlushToDisk(false));
RINOK(FlushToDisk(false))
return _outFileStream->Write(data, size, processedSize);
}
@@ -1026,7 +1033,7 @@ HRESULT CVirtFileSystem::FlushToDisk(bool closeLast)
// MessageBoxMyError(UString("Can't create file ") + fs2us(tempFilePath));
}
_fileIsOpen = true;
RINOK(WriteStream(_outFileStream, file.Data, (size_t)file.Size));
RINOK(WriteStream(_outFileStream, file.Data, (size_t)file.Size))
}
if (_numFlushed == Files.Size() - 1 && !closeLast)
break;