summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/lzma/CPP/7zip/UI/Console/ExtractCallbackConsole.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/lzma/CPP/7zip/UI/Console/ExtractCallbackConsole.cpp')
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Console/ExtractCallbackConsole.cpp233
1 files changed, 159 insertions, 74 deletions
diff --git a/3rdparty/lzma/CPP/7zip/UI/Console/ExtractCallbackConsole.cpp b/3rdparty/lzma/CPP/7zip/UI/Console/ExtractCallbackConsole.cpp
index 8dac7fbc3e9..dd7a2145ae8 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Console/ExtractCallbackConsole.cpp
+++ b/3rdparty/lzma/CPP/7zip/UI/Console/ExtractCallbackConsole.cpp
@@ -11,7 +11,7 @@
#include "../../../Windows/ErrorMsg.h"
#include "../../../Windows/PropVariantConv.h"
-#ifndef _7ZIP_ST
+#ifndef Z7_ST
#include "../../../Windows/Synchronization.h"
#endif
@@ -32,7 +32,7 @@ static HRESULT CheckBreak2()
return NConsoleClose::TestBreakSignal() ? E_ABORT : S_OK;
}
-static const char *kError = "ERROR: ";
+static const char * const kError = "ERROR: ";
void CExtractScanConsole::StartScanning()
@@ -56,18 +56,27 @@ HRESULT CExtractScanConsole::ScanProgress(const CDirItemsStat &st, const FString
HRESULT CExtractScanConsole::ScanError(const FString &path, DWORD systemError)
{
+ // 22.00:
+ // ScanErrors.AddError(path, systemError);
+
ClosePercentsAndFlush();
if (_se)
{
- *_se << endl << kError << NError::MyFormatMessage(systemError) << endl <<
- fs2us(path) << endl << endl;
+ *_se << endl << kError << NError::MyFormatMessage(systemError) << endl;
+ _se->NormalizePrint_UString(fs2us(path));
+ *_se << endl << endl;
_se->Flush();
}
return HRESULT_FROM_WIN32(systemError);
+
+ // 22.00: commented
+ // CommonError(path, systemError, true);
+ // return S_OK;
}
+void Print_UInt64_and_String(AString &s, UInt64 val, const char *name);
void Print_UInt64_and_String(AString &s, UInt64 val, const char *name)
{
char temp[32];
@@ -77,6 +86,7 @@ void Print_UInt64_and_String(AString &s, UInt64 val, const char *name)
s += name;
}
+void PrintSize_bytes_Smart(AString &s, UInt64 val);
void PrintSize_bytes_Smart(AString &s, UInt64 val)
{
Print_UInt64_and_String(s, val, "bytes");
@@ -95,6 +105,17 @@ void PrintSize_bytes_Smart(AString &s, UInt64 val)
s += ')';
}
+static void PrintSize_bytes_Smart_comma(AString &s, UInt64 val)
+{
+ if (val == (UInt64)(Int64)-1)
+ return;
+ s += ", ";
+ PrintSize_bytes_Smart(s, val);
+}
+
+
+
+void Print_DirItemsStat(AString &s, const CDirItemsStat &st);
void Print_DirItemsStat(AString &s, const CDirItemsStat &st)
{
if (st.NumDirs != 0)
@@ -103,17 +124,49 @@ void Print_DirItemsStat(AString &s, const CDirItemsStat &st)
s += ", ";
}
Print_UInt64_and_String(s, st.NumFiles, st.NumFiles == 1 ? "file" : "files");
- s += ", ";
- PrintSize_bytes_Smart(s, st.FilesSize);
+ PrintSize_bytes_Smart_comma(s, st.FilesSize);
if (st.NumAltStreams != 0)
{
s.Add_LF();
Print_UInt64_and_String(s, st.NumAltStreams, "alternate streams");
- s += ", ";
- PrintSize_bytes_Smart(s, st.AltStreamsSize);
+ PrintSize_bytes_Smart_comma(s, st.AltStreamsSize);
+ }
+}
+
+
+void Print_DirItemsStat2(AString &s, const CDirItemsStat2 &st);
+void Print_DirItemsStat2(AString &s, const CDirItemsStat2 &st)
+{
+ Print_DirItemsStat(s, (CDirItemsStat &)st);
+ bool needLF = true;
+ if (st.Anti_NumDirs != 0)
+ {
+ if (needLF)
+ s.Add_LF();
+ needLF = false;
+ Print_UInt64_and_String(s, st.Anti_NumDirs, st.Anti_NumDirs == 1 ? "anti-folder" : "anti-folders");
+ }
+ if (st.Anti_NumFiles != 0)
+ {
+ if (needLF)
+ s.Add_LF();
+ else
+ s += ", ";
+ needLF = false;
+ Print_UInt64_and_String(s, st.Anti_NumFiles, st.Anti_NumFiles == 1 ? "anti-file" : "anti-files");
+ }
+ if (st.Anti_NumAltStreams != 0)
+ {
+ if (needLF)
+ s.Add_LF();
+ else
+ s += ", ";
+ needLF = false;
+ Print_UInt64_and_String(s, st.Anti_NumAltStreams, "anti-alternate-streams");
}
}
+
void CExtractScanConsole::PrintStat(const CDirItemsStat &st)
{
if (_so)
@@ -130,7 +183,7 @@ void CExtractScanConsole::PrintStat(const CDirItemsStat &st)
-#ifndef _7ZIP_ST
+#ifndef Z7_ST
static NSynchronization::CCriticalSection g_CriticalSection;
#define MT_LOCK NSynchronization::CCriticalSectionLock lock(g_CriticalSection);
#else
@@ -138,33 +191,34 @@ static NSynchronization::CCriticalSection g_CriticalSection;
#endif
-static const char *kTestString = "T";
-static const char *kExtractString = "-";
-static const char *kSkipString = ".";
+static const char * const kTestString = "T";
+static const char * const kExtractString = "-";
+static const char * const kSkipString = ".";
+static const char * const kReadString = "H";
-// static const char *kCantAutoRename = "can not create file with auto name\n";
-// static const char *kCantRenameFile = "can not rename existing file\n";
-// static const char *kCantDeleteOutputFile = "can not delete output file ";
+// static const char * const kCantAutoRename = "cannot create file with auto name\n";
+// static const char * const kCantRenameFile = "cannot rename existing file\n";
+// static const char * const kCantDeleteOutputFile = "cannot delete output file ";
-static const char *kMemoryExceptionMessage = "Can't allocate required memory!";
+static const char * const kMemoryExceptionMessage = "Can't allocate required memory!";
-static const char *kExtracting = "Extracting archive: ";
-static const char *kTesting = "Testing archive: ";
+static const char * const kExtracting = "Extracting archive: ";
+static const char * const kTesting = "Testing archive: ";
-static const char *kEverythingIsOk = "Everything is Ok";
-static const char *kNoFiles = "No files to process";
+static const char * const kEverythingIsOk = "Everything is Ok";
+static const char * const kNoFiles = "No files to process";
-static const char *kUnsupportedMethod = "Unsupported Method";
-static const char *kCrcFailed = "CRC Failed";
-static const char *kCrcFailedEncrypted = "CRC Failed in encrypted file. Wrong password?";
-static const char *kDataError = "Data Error";
-static const char *kDataErrorEncrypted = "Data Error in encrypted file. Wrong password?";
-static const char *kUnavailableData = "Unavailable data";
-static const char *kUnexpectedEnd = "Unexpected end of data";
-static const char *kDataAfterEnd = "There are some data after the end of the payload data";
-static const char *kIsNotArc = "Is not archive";
-static const char *kHeadersError = "Headers Error";
-static const char *kWrongPassword = "Wrong password";
+static const char * const kUnsupportedMethod = "Unsupported Method";
+static const char * const kCrcFailed = "CRC Failed";
+static const char * const kCrcFailedEncrypted = "CRC Failed in encrypted file. Wrong password?";
+static const char * const kDataError = "Data Error";
+static const char * const kDataErrorEncrypted = "Data Error in encrypted file. Wrong password?";
+static const char * const kUnavailableData = "Unavailable data";
+static const char * const kUnexpectedEnd = "Unexpected end of data";
+static const char * const kDataAfterEnd = "There are some data after the end of the payload data";
+static const char * const kIsNotArc = "Is not archive";
+static const char * const kHeadersError = "Headers Error";
+static const char * const kWrongPassword = "Wrong password";
static const char * const k_ErrorFlagsMessages[] =
{
@@ -181,7 +235,7 @@ static const char * const k_ErrorFlagsMessages[] =
, "CRC Error"
};
-STDMETHODIMP CExtractCallbackConsole::SetTotal(UInt64 size)
+Z7_COM7F_IMF(CExtractCallbackConsole::SetTotal(UInt64 size))
{
MT_LOCK
@@ -193,7 +247,7 @@ STDMETHODIMP CExtractCallbackConsole::SetTotal(UInt64 size)
return CheckBreak2();
}
-STDMETHODIMP CExtractCallbackConsole::SetCompleted(const UInt64 *completeValue)
+Z7_COM7F_IMF(CExtractCallbackConsole::SetCompleted(const UInt64 *completeValue))
{
MT_LOCK
@@ -206,12 +260,14 @@ STDMETHODIMP CExtractCallbackConsole::SetCompleted(const UInt64 *completeValue)
return CheckBreak2();
}
-static const char *kTab = " ";
+static const char * const kTab = " ";
static void PrintFileInfo(CStdOutStream *_so, const wchar_t *path, const FILETIME *ft, const UInt64 *size)
{
- *_so << kTab << "Path: " << path << endl;
- if (size)
+ *_so << kTab << "Path: ";
+ _so->NormalizePrint_wstr(path);
+ *_so << endl;
+ if (size && *size != (UInt64)(Int64)-1)
{
AString s;
PrintSize_bytes_Smart(s, *size);
@@ -220,21 +276,19 @@ static void PrintFileInfo(CStdOutStream *_so, const wchar_t *path, const FILETIM
if (ft)
{
char temp[64];
- FILETIME locTime;
- if (FileTimeToLocalFileTime(ft, &locTime))
- if (ConvertFileTimeToString(locTime, temp, true, true))
- *_so << kTab << "Modified: " << temp << endl;
+ if (ConvertUtcFileTimeToString(*ft, temp, kTimestampPrintLevel_SEC))
+ *_so << kTab << "Modified: " << temp << endl;
}
}
-STDMETHODIMP CExtractCallbackConsole::AskOverwrite(
+Z7_COM7F_IMF(CExtractCallbackConsole::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))
{
MT_LOCK
- RINOK(CheckBreak2());
+ RINOK(CheckBreak2())
ClosePercentsAndFlush();
@@ -248,7 +302,7 @@ STDMETHODIMP CExtractCallbackConsole::AskOverwrite(
NUserAnswerMode::EEnum overwriteAnswer = ScanUserYesNoAllQuit(_so);
- switch (overwriteAnswer)
+ switch ((int)overwriteAnswer)
{
case NUserAnswerMode::kQuit: return E_ABORT;
case NUserAnswerMode::kNo: *answer = NOverwriteAnswer::kNo; break;
@@ -256,6 +310,8 @@ STDMETHODIMP CExtractCallbackConsole::AskOverwrite(
case NUserAnswerMode::kYesAll: *answer = NOverwriteAnswer::kYesToAll; break;
case NUserAnswerMode::kYes: *answer = NOverwriteAnswer::kYes; break;
case NUserAnswerMode::kAutoRenameAll: *answer = NOverwriteAnswer::kAutoRename; break;
+ case NUserAnswerMode::kEof: return E_ABORT;
+ case NUserAnswerMode::kError: return E_FAIL;
default: return E_FAIL;
}
@@ -269,7 +325,7 @@ STDMETHODIMP CExtractCallbackConsole::AskOverwrite(
return CheckBreak2();
}
-STDMETHODIMP CExtractCallbackConsole::PrepareOperation(const wchar_t *name, Int32 /* isFolder */, Int32 askExtractMode, const UInt64 *position)
+Z7_COM7F_IMF(CExtractCallbackConsole::PrepareOperation(const wchar_t *name, Int32 isFolder, Int32 askExtractMode, const UInt64 *position))
{
MT_LOCK
@@ -283,8 +339,9 @@ STDMETHODIMP CExtractCallbackConsole::PrepareOperation(const wchar_t *name, Int3
case NArchive::NExtract::NAskMode::kExtract: s = kExtractString; break;
case NArchive::NExtract::NAskMode::kTest: s = kTestString; break;
case NArchive::NExtract::NAskMode::kSkip: s = kSkipString; requiredLevel = 2; break;
+ case NArchive::NExtract::NAskMode::kReadExternal: s = kReadString; requiredLevel = 0; break;
default: s = "???"; requiredLevel = 2;
- };
+ }
bool show2 = (LogLevel >= requiredLevel && _so);
@@ -299,7 +356,16 @@ STDMETHODIMP CExtractCallbackConsole::PrepareOperation(const wchar_t *name, Int3
_tempU.Empty();
if (name)
+ {
_tempU = name;
+ _so->Normalize_UString(_tempU);
+ // 21.04
+ if (isFolder)
+ {
+ if (!_tempU.IsEmpty() && _tempU.Back() != WCHAR_PATH_SEPARATOR)
+ _tempU.Add_PathSepar();
+ }
+ }
_so->PrintUString(_tempU, _tempA);
if (position)
*_so << " <" << *position << ">";
@@ -328,11 +394,11 @@ STDMETHODIMP CExtractCallbackConsole::PrepareOperation(const wchar_t *name, Int3
return CheckBreak2();
}
-STDMETHODIMP CExtractCallbackConsole::MessageError(const wchar_t *message)
+Z7_COM7F_IMF(CExtractCallbackConsole::MessageError(const wchar_t *message))
{
MT_LOCK
- RINOK(CheckBreak2());
+ RINOK(CheckBreak2())
NumFileErrors_in_Current++;
NumFileErrors++;
@@ -347,6 +413,7 @@ STDMETHODIMP CExtractCallbackConsole::MessageError(const wchar_t *message)
return CheckBreak2();
}
+void SetExtractErrorMessage(Int32 opRes, Int32 encrypted, AString &dest);
void SetExtractErrorMessage(Int32 opRes, Int32 encrypted, AString &dest)
{
dest.Empty();
@@ -388,14 +455,12 @@ void SetExtractErrorMessage(Int32 opRes, Int32 encrypted, AString &dest)
dest += s;
else
{
- char temp[16];
- ConvertUInt32ToString(opRes, temp);
dest += "Error #";
- dest += temp;
+ dest.Add_UInt32((UInt32)opRes);
}
}
-STDMETHODIMP CExtractCallbackConsole::SetOperationResult(Int32 opRes, Int32 encrypted)
+Z7_COM7F_IMF(CExtractCallbackConsole::SetOperationResult(Int32 opRes, Int32 encrypted))
{
MT_LOCK
@@ -422,7 +487,10 @@ STDMETHODIMP CExtractCallbackConsole::SetOperationResult(Int32 opRes, Int32 encr
*_se << s;
if (!_currentName.IsEmpty())
- *_se << " : " << _currentName;
+ {
+ *_se << " : ";
+ _se->NormalizePrint_UString(_currentName);
+ }
*_se << endl;
_se->Flush();
}
@@ -431,7 +499,7 @@ STDMETHODIMP CExtractCallbackConsole::SetOperationResult(Int32 opRes, Int32 encr
return CheckBreak2();
}
-STDMETHODIMP CExtractCallbackConsole::ReportExtractResult(Int32 opRes, Int32 encrypted, const wchar_t *name)
+Z7_COM7F_IMF(CExtractCallbackConsole::ReportExtractResult(Int32 opRes, Int32 encrypted, const wchar_t *name))
{
if (opRes != NArchive::NExtract::NOperationResult::kOK)
{
@@ -444,7 +512,7 @@ STDMETHODIMP CExtractCallbackConsole::ReportExtractResult(Int32 opRes, Int32 enc
-#ifndef _NO_CRYPTO
+#ifndef Z7_NO_CRYPTO
HRESULT CExtractCallbackConsole::SetPassword(const UString &password)
{
@@ -453,7 +521,7 @@ HRESULT CExtractCallbackConsole::SetPassword(const UString &password)
return S_OK;
}
-STDMETHODIMP CExtractCallbackConsole::CryptoGetTextPassword(BSTR *password)
+Z7_COM7F_IMF(CExtractCallbackConsole::CryptoGetTextPassword(BSTR *password))
{
COM_TRY_BEGIN
MT_LOCK
@@ -465,7 +533,7 @@ STDMETHODIMP CExtractCallbackConsole::CryptoGetTextPassword(BSTR *password)
HRESULT CExtractCallbackConsole::BeforeOpen(const wchar_t *name, bool testMode)
{
- RINOK(CheckBreak2());
+ RINOK(CheckBreak2())
NumTryArcs++;
ThereIsError_in_Current = false;
@@ -474,7 +542,11 @@ HRESULT CExtractCallbackConsole::BeforeOpen(const wchar_t *name, bool testMode)
ClosePercents_for_so();
if (_so)
- *_so << endl << (testMode ? kTesting : kExtracting) << name << endl;
+ {
+ *_so << endl << (testMode ? kTesting : kExtracting);
+ _so->NormalizePrint_wstr(name);
+ *_so << endl;
+ }
if (NeedPercents())
_percent.Command = "Open";
@@ -488,7 +560,7 @@ static AString GetOpenArcErrorMessage(UInt32 errorFlags)
{
AString s;
- for (unsigned i = 0; i < ARRAY_SIZE(k_ErrorFlagsMessages); i++)
+ for (unsigned i = 0; i < Z7_ARRAY_SIZE(k_ErrorFlagsMessages); i++)
{
UInt32 f = (1 << i);
if ((errorFlags & f) == 0)
@@ -514,6 +586,7 @@ static AString GetOpenArcErrorMessage(UInt32 errorFlags)
return s;
}
+void PrintErrorFlags(CStdOutStream &so, const char *s, UInt32 errorFlags);
void PrintErrorFlags(CStdOutStream &so, const char *s, UInt32 errorFlags)
{
if (errorFlags == 0)
@@ -521,29 +594,31 @@ void PrintErrorFlags(CStdOutStream &so, const char *s, UInt32 errorFlags)
so << s << endl << GetOpenArcErrorMessage(errorFlags) << endl;
}
-void Add_Messsage_Pre_ArcType(UString &s, const char *pre, const wchar_t *arcType)
+static void Add_Messsage_Pre_ArcType(UString &s, const char *pre, const wchar_t *arcType)
{
s.Add_LF();
- s.AddAscii(pre);
- s.AddAscii(" as [");
+ s += pre;
+ s += " as [";
s += arcType;
- s.AddAscii("] archive");
+ s += "] archive";
}
+void Print_ErrorFormatIndex_Warning(CStdOutStream *_so, const CCodecs *codecs, const CArc &arc);
void Print_ErrorFormatIndex_Warning(CStdOutStream *_so, const CCodecs *codecs, const CArc &arc)
{
const CArcErrorInfo &er = arc.ErrorInfo;
- UString s = L"WARNING:\n";
- s += arc.Path;
+ *_so << "WARNING:\n";
+ _so->NormalizePrint_UString(arc.Path);
+ UString s;
if (arc.FormatIndex == er.ErrorFormatIndex)
{
s.Add_LF();
- s.AddAscii("The archive is open with offset");
+ s += "The archive is open with offset";
}
else
{
- Add_Messsage_Pre_ArcType(s, "Can not open the file", codecs->GetFormatNamePtr(er.ErrorFormatIndex));
+ Add_Messsage_Pre_ArcType(s, "Cannot open the file", codecs->GetFormatNamePtr(er.ErrorFormatIndex));
Add_Messsage_Pre_ArcType(s, "The file is open", codecs->GetFormatNamePtr(arc.FormatIndex));
}
@@ -580,7 +655,10 @@ HRESULT CExtractCallbackConsole::OpenResult(
{
*_se << endl;
if (level != 0)
- *_se << arc.Path << endl;
+ {
+ _se->NormalizePrint_UString(arc.Path);
+ *_se << endl;
+ }
}
if (errorFlags != 0)
@@ -614,7 +692,10 @@ HRESULT CExtractCallbackConsole::OpenResult(
{
*_so << endl;
if (level != 0)
- *_so << arc.Path << endl;
+ {
+ _so->NormalizePrint_UString(arc.Path);
+ *_so << endl;
+ }
}
if (warningFlags != 0)
@@ -658,7 +739,7 @@ HRESULT CExtractCallbackConsole::OpenResult(
{
if (_so)
{
- RINOK(Print_OpenArchive_Props(*_so, codecs, arcLink));
+ RINOK(Print_OpenArchive_Props(*_so, codecs, arcLink))
*_so << endl;
}
}
@@ -669,9 +750,11 @@ HRESULT CExtractCallbackConsole::OpenResult(
_so->Flush();
if (_se)
{
- *_se << kError << name << endl;
- HRESULT res = Print_OpenArchive_Error(*_se, codecs, arcLink);
- RINOK(res);
+ *_se << kError;
+ _se->NormalizePrint_wstr(name);
+ *_se << endl;
+ const HRESULT res = Print_OpenArchive_Error(*_se, codecs, arcLink);
+ RINOK(res)
if (result == S_FALSE)
{
}
@@ -745,7 +828,9 @@ HRESULT CExtractCallbackConsole::ExtractResult(HRESULT result)
else
{
NumArcsWithError++;
- if (result == E_ABORT || result == ERROR_DISK_FULL)
+ if (result == E_ABORT
+ || result == HRESULT_FROM_WIN32(ERROR_DISK_FULL)
+ )
return result;
if (_se)