diff options
Diffstat (limited to 'src/libs/7zip/unix/CPP/7zip/UI/Console')
19 files changed, 33 insertions, 2663 deletions
diff --git a/src/libs/7zip/unix/CPP/7zip/UI/Console/BenchCon.cpp b/src/libs/7zip/unix/CPP/7zip/UI/Console/BenchCon.cpp deleted file mode 100644 index 35e868c9b..000000000 --- a/src/libs/7zip/unix/CPP/7zip/UI/Console/BenchCon.cpp +++ /dev/null @@ -1,297 +0,0 @@ -// BenchCon.cpp - -#include "StdAfx.h" - -#include "../../../Common/IntToString.h" -#include "../../../Common/MyCom.h" - -#if !defined(_7ZIP_ST) || defined(_WIN32) -#include "../../../Windows/System.h" -#endif - -#include "../Common/Bench.h" - -#include "BenchCon.h" -#include "ConsoleClose.h" - -struct CTotalBenchRes -{ - UInt64 NumIterations; - UInt64 Rating; - UInt64 Usage; - UInt64 RPU; - void Init() { NumIterations = 0; Rating = 0; Usage = 0; RPU = 0; } - void Normalize() - { - if (NumIterations == 0) - return; - Rating /= NumIterations; - Usage /= NumIterations; - RPU /= NumIterations; - NumIterations = 1; - } - void SetMid(const CTotalBenchRes &r1, const CTotalBenchRes &r2) - { - Rating = (r1.Rating + r2.Rating) / 2; - Usage = (r1.Usage + r2.Usage) / 2; - RPU = (r1.RPU + r2.RPU) / 2; - NumIterations = (r1.NumIterations + r2.NumIterations) / 2; - } -}; - -struct CBenchCallback: public IBenchCallback -{ - CTotalBenchRes EncodeRes; - CTotalBenchRes DecodeRes; - FILE *f; - void Init() { EncodeRes.Init(); DecodeRes.Init(); } - void Normalize() { EncodeRes.Normalize(); DecodeRes.Normalize(); } - UInt32 dictionarySize; - HRESULT SetEncodeResult(const CBenchInfo &info, bool final); - HRESULT SetDecodeResult(const CBenchInfo &info, bool final); -}; - -static void NormalizeVals(UInt64 &v1, UInt64 &v2) -{ - while (v1 > 1000000) - { - v1 >>= 1; - v2 >>= 1; - } -} - -static UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime, UInt64 freq) -{ - UInt64 elTime = elapsedTime; - NormalizeVals(freq, elTime); - if (elTime == 0) - elTime = 1; - return value * freq / elTime; -} - -static void PrintNumber(FILE *f, UInt64 value, int size) -{ - char s[32]; - ConvertUInt64ToString(value, s); - fprintf(f, " "); - for (int len = (int)strlen(s); len < size; len++) - fprintf(f, " "); - fputs(s, f); -} - -static void PrintRating(FILE *f, UInt64 rating) -{ - PrintNumber(f, rating / 1000000, 6); -} - -static void PrintResults(FILE *f, UInt64 usage, UInt64 rpu, UInt64 rating) -{ - PrintNumber(f, (usage + 5000) / 10000, 5); - PrintRating(f, rpu); - PrintRating(f, rating); -} - - -static void PrintResults(FILE *f, const CBenchInfo &info, UInt64 rating, CTotalBenchRes &res) -{ - UInt64 speed = MyMultDiv64(info.UnpackSize, info.GlobalTime, info.GlobalFreq); - PrintNumber(f, speed / 1024, 7); - UInt64 usage = GetUsage(info); - UInt64 rpu = GetRatingPerUsage(info, rating); - PrintResults(f, usage, rpu, rating); - res.NumIterations++; - res.RPU += rpu; - res.Rating += rating; - res.Usage += usage; -} - -static void PrintTotals(FILE *f, const CTotalBenchRes &res) -{ - fprintf(f, " "); - PrintResults(f, res.Usage, res.RPU, res.Rating); -} - - -HRESULT CBenchCallback::SetEncodeResult(const CBenchInfo &info, bool final) -{ - if (NConsoleClose::TestBreakSignal()) - return E_ABORT; - if (final) - { - UInt64 rating = GetCompressRating(dictionarySize, info.GlobalTime, info.GlobalFreq, info.UnpackSize); - PrintResults(f, info, rating, EncodeRes); - } - return S_OK; -} - -static const char *kSep = " | "; - - -HRESULT CBenchCallback::SetDecodeResult(const CBenchInfo &info, bool final) -{ - if (NConsoleClose::TestBreakSignal()) - return E_ABORT; - if (final) - { - UInt64 rating = GetDecompressRating(info.GlobalTime, info.GlobalFreq, info.UnpackSize, info.PackSize, info.NumIterations); - fputs(kSep, f); - CBenchInfo info2 = info; - info2.UnpackSize *= info2.NumIterations; - info2.PackSize *= info2.NumIterations; - info2.NumIterations = 1; - PrintResults(f, info2, rating, DecodeRes); - } - return S_OK; -} - -static void PrintRequirements(FILE *f, const char *sizeString, UInt64 size, const char *threadsString, UInt32 numThreads) -{ - fprintf(f, "\nRAM %s ", sizeString); - PrintNumber(f, (size >> 20), 5); - fprintf(f, " MB, # %s %3d", threadsString, (unsigned int)numThreads); -} - -HRESULT LzmaBenchCon( - DECL_EXTERNAL_CODECS_LOC_VARS - FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary) -{ - if (!CrcInternalTest()) - return S_FALSE; - #ifndef _7ZIP_ST - UInt64 ramSize = NWindows::NSystem::GetRamSize(); // - UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors(); - PrintRequirements(f, "size: ", ramSize, "CPU hardware threads:", numCPUs); - if (numThreads == (UInt32)-1) - numThreads = numCPUs; - if (numThreads > 1) - numThreads &= ~1; - if (dictionary == (UInt32)-1) - { - int dicSizeLog; - for (dicSizeLog = 25; dicSizeLog > kBenchMinDicLogSize; dicSizeLog--) - if (GetBenchMemoryUsage(numThreads, ((UInt32)1 << dicSizeLog)) + (8 << 20) <= ramSize) - break; - dictionary = (1 << dicSizeLog); - } - #else - if (dictionary == (UInt32)-1) - dictionary = (1 << 22); - numThreads = 1; - #endif - - PrintRequirements(f, "usage:", GetBenchMemoryUsage(numThreads, dictionary), "Benchmark threads: ", numThreads); - - CBenchCallback callback; - callback.Init(); - callback.f = f; - - fprintf(f, "\n\nDict Compressing | Decompressing\n "); - int j; - for (j = 0; j < 2; j++) - { - fprintf(f, " Speed Usage R/U Rating"); - if (j == 0) - fputs(kSep, f); - } - fprintf(f, "\n "); - for (j = 0; j < 2; j++) - { - fprintf(f, " KB/s %% MIPS MIPS"); - if (j == 0) - fputs(kSep, f); - } - fprintf(f, "\n\n"); - for (UInt32 i = 0; i < numIterations; i++) - { - const int kStartDicLog = 22; - int pow = (dictionary < ((UInt32)1 << kStartDicLog)) ? kBenchMinDicLogSize : kStartDicLog; - while (((UInt32)1 << pow) > dictionary) - pow--; - for (; ((UInt32)1 << pow) <= dictionary; pow++) - { - fprintf(f, "%2d:", pow); - callback.dictionarySize = (UInt32)1 << pow; - HRESULT res = LzmaBench( - EXTERNAL_CODECS_LOC_VARS - numThreads, callback.dictionarySize, &callback); - fprintf(f, "\n"); - RINOK(res); - } - } - callback.Normalize(); - fprintf(f, "----------------------------------------------------------------\nAvr:"); - PrintTotals(f, callback.EncodeRes); - fprintf(f, " "); - PrintTotals(f, callback.DecodeRes); - fprintf(f, "\nTot:"); - CTotalBenchRes midRes; - midRes.SetMid(callback.EncodeRes, callback.DecodeRes); - PrintTotals(f, midRes); - fprintf(f, "\n"); - return S_OK; -} - -struct CTempValues -{ - UInt64 *Values; - CTempValues(UInt32 num) { Values = new UInt64[num]; } - ~CTempValues() { delete []Values; } -}; - -HRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary) -{ - if (!CrcInternalTest()) - return S_FALSE; - - #ifndef _7ZIP_ST - UInt64 ramSize = NWindows::NSystem::GetRamSize(); - UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors(); - PrintRequirements(f, "size: ", ramSize, "CPU hardware threads:", numCPUs); - if (numThreads == (UInt32)-1) - numThreads = numCPUs; - #else - numThreads = 1; - #endif - if (dictionary == (UInt32)-1) - dictionary = (1 << 24); - - CTempValues speedTotals(numThreads); - fprintf(f, "\n\nSize"); - for (UInt32 ti = 0; ti < numThreads; ti++) - { - fprintf(f, " %5d", ti + 1); - speedTotals.Values[ti] = 0; - } - fprintf(f, "\n\n"); - - UInt64 numSteps = 0; - for (UInt32 i = 0; i < numIterations; i++) - { - for (int pow = 10; pow < 32; pow++) - { - UInt32 bufSize = (UInt32)1 << pow; - if (bufSize > dictionary) - break; - fprintf(f, "%2d: ", pow); - UInt64 speed; - for (UInt32 ti = 0; ti < numThreads; ti++) - { - if (NConsoleClose::TestBreakSignal()) - return E_ABORT; - RINOK(CrcBench(ti + 1, bufSize, speed)); - PrintNumber(f, (speed >> 20), 5); - speedTotals.Values[ti] += speed; - } - fprintf(f, "\n"); - numSteps++; - } - } - if (numSteps != 0) - { - fprintf(f, "\nAvg:"); - for (UInt32 ti = 0; ti < numThreads; ti++) - PrintNumber(f, ((speedTotals.Values[ti] / numSteps) >> 20), 5); - fprintf(f, "\n"); - } - return S_OK; -} diff --git a/src/libs/7zip/unix/CPP/7zip/UI/Console/BenchCon.h b/src/libs/7zip/unix/CPP/7zip/UI/Console/BenchCon.h deleted file mode 100644 index 966a83a6a..000000000 --- a/src/libs/7zip/unix/CPP/7zip/UI/Console/BenchCon.h +++ /dev/null @@ -1,16 +0,0 @@ -// BenchCon.h - -#ifndef __BENCH_CON_H -#define __BENCH_CON_H - -#include <stdio.h> - -#include "../../Common/CreateCoder.h" - -HRESULT LzmaBenchCon( - DECL_EXTERNAL_CODECS_LOC_VARS - FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary); - -HRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary); - -#endif diff --git a/src/libs/7zip/unix/CPP/7zip/UI/Console/Console.pri b/src/libs/7zip/unix/CPP/7zip/UI/Console/Console.pri new file mode 100644 index 000000000..cdb025475 --- /dev/null +++ b/src/libs/7zip/unix/CPP/7zip/UI/Console/Console.pri @@ -0,0 +1,2 @@ +HEADERS += $$7ZIP_BASE/CPP/7zip/UI/Console/PercentPrinter.h +SOURCES += $$7ZIP_BASE/CPP/7zip/UI/Console/PercentPrinter.cpp diff --git a/src/libs/7zip/unix/CPP/7zip/UI/Console/ConsoleClose.cpp b/src/libs/7zip/unix/CPP/7zip/UI/Console/ConsoleClose.cpp deleted file mode 100644 index 9bb2082bf..000000000 --- a/src/libs/7zip/unix/CPP/7zip/UI/Console/ConsoleClose.cpp +++ /dev/null @@ -1,49 +0,0 @@ -// ConsoleClose.cpp - -#include "StdAfx.h" - -#include "ConsoleClose.h" - -#include <signal.h> - -static int g_BreakCounter = 0; -static const int kBreakAbortThreshold = 2; - -namespace NConsoleClose { - -static void HandlerRoutine(int) -{ - g_BreakCounter++; - if (g_BreakCounter < kBreakAbortThreshold) - return ; - exit(EXIT_FAILURE); -} - -bool TestBreakSignal() -{ - return (g_BreakCounter > 0); -} - -void CheckCtrlBreak() -{ - if (TestBreakSignal()) - throw CCtrlBreakException(); -} - -CCtrlHandlerSetter::CCtrlHandlerSetter() -{ - memo_sig_int = signal(SIGINT,HandlerRoutine); // CTRL-C - if (memo_sig_int == SIG_ERR) - throw "SetConsoleCtrlHandler fails (SIGINT)"; - memo_sig_term = signal(SIGTERM,HandlerRoutine); // for kill -15 (before "kill -9") - if (memo_sig_term == SIG_ERR) - throw "SetConsoleCtrlHandler fails (SIGTERM)"; -} - -CCtrlHandlerSetter::~CCtrlHandlerSetter() -{ - signal(SIGINT,memo_sig_int); // CTRL-C - signal(SIGTERM,memo_sig_term); // kill {pid} -} - -} diff --git a/src/libs/7zip/unix/CPP/7zip/UI/Console/ConsoleClose.h b/src/libs/7zip/unix/CPP/7zip/UI/Console/ConsoleClose.h deleted file mode 100644 index 042aaf2d6..000000000 --- a/src/libs/7zip/unix/CPP/7zip/UI/Console/ConsoleClose.h +++ /dev/null @@ -1,26 +0,0 @@ -// ConsoleCloseUtils.h - -#ifndef __CONSOLECLOSEUTILS_H -#define __CONSOLECLOSEUTILS_H - -namespace NConsoleClose { - -bool TestBreakSignal(); - -class CCtrlHandlerSetter -{ - void (*memo_sig_int)(int); - void (*memo_sig_term)(int); -public: - CCtrlHandlerSetter(); - virtual ~CCtrlHandlerSetter(); -}; - -class CCtrlBreakException -{}; - -void CheckCtrlBreak(); - -} - -#endif diff --git a/src/libs/7zip/unix/CPP/7zip/UI/Console/ExtractCallbackConsole.cpp b/src/libs/7zip/unix/CPP/7zip/UI/Console/ExtractCallbackConsole.cpp deleted file mode 100644 index af65739c3..000000000 --- a/src/libs/7zip/unix/CPP/7zip/UI/Console/ExtractCallbackConsole.cpp +++ /dev/null @@ -1,228 +0,0 @@ -// ExtractCallbackConsole.h - -#include "StdAfx.h" - -#include "ExtractCallbackConsole.h" -#include "UserInputUtils.h" -#include "ConsoleClose.h" - -#include "Common/Wildcard.h" - -#include "Windows/FileDir.h" -#include "Windows/FileFind.h" -#include "Windows/Time.h" -#include "Windows/Defs.h" -#include "Windows/PropVariant.h" -#include "Windows/Error.h" -#include "Windows/PropVariantConversions.h" - -#include "../../Common/FilePathAutoRename.h" - -#include "../Common/ExtractingFilePath.h" - -using namespace NWindows; -using namespace NFile; -using namespace NDirectory; - -static const char *kTestString = "Testing "; -static const char *kExtractString = "Extracting "; -static const char *kSkipString = "Skipping "; - -// 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 *kError = "ERROR: "; -static const char *kMemoryExceptionMessage = "Can't allocate required memory!"; - -static const char *kProcessing = "Processing archive: "; -static const char *kEverythingIsOk = "Everything is Ok"; -static const char *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 *kUnknownError = "Unknown Error"; - -STDMETHODIMP CExtractCallbackConsole::SetTotal(UInt64) -{ - if (NConsoleClose::TestBreakSignal()) - return E_ABORT; - return S_OK; -} - -STDMETHODIMP CExtractCallbackConsole::SetCompleted(const UInt64 *) -{ - if (NConsoleClose::TestBreakSignal()) - return E_ABORT; - return S_OK; -} - -STDMETHODIMP CExtractCallbackConsole::AskOverwrite( - const wchar_t *existName, const FILETIME *, const UInt64 *, - const wchar_t *newName, const FILETIME *, const UInt64 *, - Int32 *answer) -{ - (*OutStream) << "file " << existName << - "\nalready exists. Overwrite with " << endl; - (*OutStream) << newName; - - NUserAnswerMode::EEnum overwriteAnswer = ScanUserYesNoAllQuit(OutStream); - - switch(overwriteAnswer) - { - case NUserAnswerMode::kQuit: return E_ABORT; - case NUserAnswerMode::kNo: *answer = NOverwriteAnswer::kNo; break; - case NUserAnswerMode::kNoAll: *answer = NOverwriteAnswer::kNoToAll; break; - case NUserAnswerMode::kYesAll: *answer = NOverwriteAnswer::kYesToAll; break; - case NUserAnswerMode::kYes: *answer = NOverwriteAnswer::kYes; break; - case NUserAnswerMode::kAutoRenameAll: *answer = NOverwriteAnswer::kAutoRename; break; - default: return E_FAIL; - } - return S_OK; -} - -STDMETHODIMP CExtractCallbackConsole::PrepareOperation(const wchar_t *name, bool /* isFolder */, Int32 askExtractMode, const UInt64 *position) -{ - switch (askExtractMode) - { - case NArchive::NExtract::NAskMode::kExtract: (*OutStream) << kExtractString; break; - case NArchive::NExtract::NAskMode::kTest: (*OutStream) << kTestString; break; - case NArchive::NExtract::NAskMode::kSkip: (*OutStream) << kSkipString; break; - }; - (*OutStream) << name; - if (position != 0) - (*OutStream) << " <" << *position << ">"; - return S_OK; -} - -STDMETHODIMP CExtractCallbackConsole::MessageError(const wchar_t *message) -{ - (*OutStream) << message << endl; - NumFileErrorsInCurrentArchive++; - NumFileErrors++; - return S_OK; -} - -STDMETHODIMP CExtractCallbackConsole::SetOperationResult(Int32 operationResult, bool encrypted) -{ - switch(operationResult) - { - case NArchive::NExtract::NOperationResult::kOK: - break; - default: - { - NumFileErrorsInCurrentArchive++; - NumFileErrors++; - (*OutStream) << " "; - switch(operationResult) - { - case NArchive::NExtract::NOperationResult::kUnSupportedMethod: - (*OutStream) << kUnsupportedMethod; - break; - case NArchive::NExtract::NOperationResult::kCRCError: - (*OutStream) << (encrypted ? kCrcFailedEncrypted: kCrcFailed); - break; - case NArchive::NExtract::NOperationResult::kDataError: - (*OutStream) << (encrypted ? kDataErrorEncrypted : kDataError); - break; - default: - (*OutStream) << kUnknownError; - } - } - } - (*OutStream) << endl; - return S_OK; -} - -#ifndef _NO_CRYPTO - -HRESULT CExtractCallbackConsole::SetPassword(const UString &password) -{ - PasswordIsDefined = true; - Password = password; - return S_OK; -} - -STDMETHODIMP CExtractCallbackConsole::CryptoGetTextPassword(BSTR *password) -{ - if (!PasswordIsDefined) - { - Password = GetPassword(OutStream); - PasswordIsDefined = true; - } - return StringToBstr(Password, password); -} - -#endif - -HRESULT CExtractCallbackConsole::BeforeOpen(const wchar_t *name) -{ - NumArchives++; - NumFileErrorsInCurrentArchive = 0; - (*OutStream) << endl << kProcessing << name << endl; - return S_OK; -} - -HRESULT CExtractCallbackConsole::OpenResult(const wchar_t * /* name */, HRESULT result, bool encrypted) -{ - (*OutStream) << endl; - if (result != S_OK) - { - (*OutStream) << "Error: "; - if (result == S_FALSE) - { - (*OutStream) << (encrypted ? - "Can not open encrypted archive. Wrong password?" : - "Can not open file as archive"); - } - else - { - if (result == E_OUTOFMEMORY) - (*OutStream) << "Can't allocate required memory"; - else - (*OutStream) << NError::MyFormatMessage(result); - } - (*OutStream) << endl; - NumArchiveErrors++; - } - return S_OK; -} - -HRESULT CExtractCallbackConsole::ThereAreNoFiles() -{ - (*OutStream) << endl << kNoFiles << endl; - return S_OK; -} - -HRESULT CExtractCallbackConsole::ExtractResult(HRESULT result) -{ - if (result == S_OK) - { - (*OutStream) << endl; - if (NumFileErrorsInCurrentArchive == 0) - (*OutStream) << kEverythingIsOk << endl; - else - { - NumArchiveErrors++; - (*OutStream) << "Sub items Errors: " << NumFileErrorsInCurrentArchive << endl; - } - } - if (result == S_OK) - return result; - NumArchiveErrors++; - if (result == E_ABORT || result == ERROR_DISK_FULL) - return result; - (*OutStream) << endl << kError; - if (result == E_OUTOFMEMORY) - (*OutStream) << kMemoryExceptionMessage; - else - { - UString message; - NError::MyFormatMessage(result, message); - (*OutStream) << message; - } - (*OutStream) << endl; - return S_OK; -} diff --git a/src/libs/7zip/unix/CPP/7zip/UI/Console/ExtractCallbackConsole.h b/src/libs/7zip/unix/CPP/7zip/UI/Console/ExtractCallbackConsole.h deleted file mode 100644 index e42ca6f40..000000000 --- a/src/libs/7zip/unix/CPP/7zip/UI/Console/ExtractCallbackConsole.h +++ /dev/null @@ -1,73 +0,0 @@ -// ExtractCallbackConsole.h - -#ifndef __EXTRACTCALLBACKCONSOLE_H -#define __EXTRACTCALLBACKCONSOLE_H - -#include "Common/MyString.h" -#include "Common/StdOutStream.h" -#include "../../Common/FileStreams.h" -#include "../../IPassword.h" -#include "../../Archive/IArchive.h" -#include "../Common/ArchiveExtractCallback.h" - -class CExtractCallbackConsole: - public IExtractCallbackUI, - #ifndef _NO_CRYPTO - public ICryptoGetTextPassword, - #endif - public CMyUnknownImp -{ -public: - MY_QUERYINTERFACE_BEGIN2(IFolderArchiveExtractCallback) - #ifndef _NO_CRYPTO - MY_QUERYINTERFACE_ENTRY(ICryptoGetTextPassword) - #endif - MY_QUERYINTERFACE_END - MY_ADDREF_RELEASE - - STDMETHOD(SetTotal)(UInt64 total); - STDMETHOD(SetCompleted)(const UInt64 *completeValue); - - // IFolderArchiveExtractCallback - STDMETHOD(AskOverwrite)( - const wchar_t *existName, const FILETIME *existTime, const UInt64 *existSize, - const wchar_t *newName, const FILETIME *newTime, const UInt64 *newSize, - Int32 *answer); - STDMETHOD (PrepareOperation)(const wchar_t *name, bool isFolder, Int32 askExtractMode, const UInt64 *position); - - STDMETHOD(MessageError)(const wchar_t *message); - STDMETHOD(SetOperationResult)(Int32 operationResult, bool encrypted); - - HRESULT BeforeOpen(const wchar_t *name); - HRESULT OpenResult(const wchar_t *name, HRESULT result, bool encrypted); - HRESULT ThereAreNoFiles(); - HRESULT ExtractResult(HRESULT result); - - - #ifndef _NO_CRYPTO - HRESULT SetPassword(const UString &password); - STDMETHOD(CryptoGetTextPassword)(BSTR *password); - - bool PasswordIsDefined; - UString Password; - - #endif - - UInt64 NumArchives; - UInt64 NumArchiveErrors; - UInt64 NumFileErrors; - UInt64 NumFileErrorsInCurrentArchive; - - CStdOutStream *OutStream; - - void Init() - { - NumArchives = 0; - NumArchiveErrors = 0; - NumFileErrors = 0; - NumFileErrorsInCurrentArchive = 0; - } - -}; - -#endif diff --git a/src/libs/7zip/unix/CPP/7zip/UI/Console/List.cpp b/src/libs/7zip/unix/CPP/7zip/UI/Console/List.cpp deleted file mode 100644 index f747cfda8..000000000 --- a/src/libs/7zip/unix/CPP/7zip/UI/Console/List.cpp +++ /dev/null @@ -1,654 +0,0 @@ -// List.cpp - -#include "StdAfx.h" - -#include "Common/IntToString.h" -#include "Common/MyCom.h" -#include "Common/StdOutStream.h" -#include "Common/StringConvert.h" - -#include "Windows/Error.h" -#include "Windows/FileDir.h" -#include "Windows/PropVariant.h" -#include "Windows/PropVariantConversions.h" - -#include "../../Archive/IArchive.h" - -#include "../Common/OpenArchive.h" -#include "../Common/PropIDUtils.h" - -#include "ConsoleClose.h" -#include "List.h" -#include "OpenCallbackConsole.h" - -using namespace NWindows; - -struct CPropIdToName -{ - PROPID PropID; - const wchar_t *Name; -}; - -static const CPropIdToName kPropIdToName[] = -{ - { kpidPath, L"Path" }, - { kpidName, L"Name" }, - { kpidIsDir, L"Folder" }, - { kpidSize, L"Size" }, - { kpidPackSize, L"Packed Size" }, - { kpidAttrib, L"Attributes" }, - { kpidCTime, L"Created" }, - { kpidATime, L"Accessed" }, - { kpidMTime, L"Modified" }, - { kpidSolid, L"Solid" }, - { kpidCommented, L"Commented" }, - { kpidEncrypted, L"Encrypted" }, - { kpidSplitBefore, L"Split Before" }, - { kpidSplitAfter, L"Split After" }, - { kpidDictionarySize, L"Dictionary Size" }, - { kpidCRC, L"CRC" }, - { kpidType, L"Type" }, - { kpidIsAnti, L"Anti" }, - { kpidMethod, L"Method" }, - { kpidHostOS, L"Host OS" }, - { kpidFileSystem, L"File System" }, - { kpidUser, L"User" }, - { kpidGroup, L"Group" }, - { kpidBlock, L"Block" }, - { kpidComment, L"Comment" }, - { kpidPosition, L"Position" }, - { kpidPrefix, L"Prefix" }, - { kpidNumSubDirs, L"Folders" }, - { kpidNumSubFiles, L"Files" }, - { kpidUnpackVer, L"Version" }, - { kpidVolume, L"Volume" }, - { kpidIsVolume, L"Multivolume" }, - { kpidOffset, L"Offset" }, - { kpidLinks, L"Links" }, - { kpidNumBlocks, L"Blocks" }, - { kpidNumVolumes, L"Volumes" }, - - { kpidBit64, L"64-bit" }, - { kpidBigEndian, L"Big-endian" }, - { kpidCpu, L"CPU" }, - { kpidPhySize, L"Physical Size" }, - { kpidHeadersSize, L"Headers Size" }, - { kpidChecksum, L"Checksum" }, - { kpidCharacts, L"Characteristics" }, - { kpidVa, L"Virtual Address" }, - { kpidId, L"ID" }, - { kpidShortName, L"Short Name" }, - { kpidCreatorApp, L"Creator Application"}, - { kpidSectorSize, L"Sector Size" }, - { kpidPosixAttrib, L"Mode" }, - { kpidLink, L"Link" }, - { kpidError, L"Error" }, - - { kpidTotalSize, L"Total Size" }, - { kpidFreeSpace, L"Free Space" }, - { kpidClusterSize, L"Cluster Size" }, - { kpidVolumeName, L"Label" } -}; - -static const char kEmptyAttribChar = '.'; - -static const char *kListing = "Listing archive: "; -static const wchar_t *kFilesMessage = L"files"; -static const wchar_t *kDirsMessage = L"folders"; - -static void GetAttribString(DWORD wa, bool isDir, char *s) -{ - s[0] = ((wa & FILE_ATTRIBUTE_DIRECTORY) != 0 || isDir) ? 'D' : kEmptyAttribChar; - s[1] = ((wa & FILE_ATTRIBUTE_READONLY) != 0) ? 'R': kEmptyAttribChar; - s[2] = ((wa & FILE_ATTRIBUTE_HIDDEN) != 0) ? 'H': kEmptyAttribChar; - s[3] = ((wa & FILE_ATTRIBUTE_SYSTEM) != 0) ? 'S': kEmptyAttribChar; - s[4] = ((wa & FILE_ATTRIBUTE_ARCHIVE) != 0) ? 'A': kEmptyAttribChar; - s[5] = '\0'; -} - -enum EAdjustment -{ - kLeft, - kCenter, - kRight -}; - -struct CFieldInfo -{ - PROPID PropID; - UString Name; - EAdjustment TitleAdjustment; - EAdjustment TextAdjustment; - int PrefixSpacesWidth; - int Width; -}; - -struct CFieldInfoInit -{ - PROPID PropID; - const wchar_t *Name; - EAdjustment TitleAdjustment; - EAdjustment TextAdjustment; - int PrefixSpacesWidth; - int Width; -}; - -static CFieldInfoInit kStandardFieldTable[] = -{ - { kpidMTime, L" Date Time", kLeft, kLeft, 0, 19 }, - { kpidAttrib, L"Attr", kRight, kCenter, 1, 5 }, - { kpidSize, L"Size", kRight, kRight, 1, 12 }, - { kpidPackSize, L"Compressed", kRight, kRight, 1, 12 }, - { kpidPath, L"Name", kLeft, kLeft, 2, 24 } -}; - -static void PrintSpaces(int numSpaces) -{ - for (int i = 0; i < numSpaces; i++) - g_StdOut << ' '; -} - -static void PrintString(EAdjustment adjustment, int width, const UString &textString) -{ - const int numSpaces = width - textString.Length(); - int numLeftSpaces = 0; - switch (adjustment) - { - case kLeft: - numLeftSpaces = 0; - break; - case kCenter: - numLeftSpaces = numSpaces / 2; - break; - case kRight: - numLeftSpaces = numSpaces; - break; - } - PrintSpaces(numLeftSpaces); - g_StdOut << textString; - PrintSpaces(numSpaces - numLeftSpaces); -} - -class CFieldPrinter -{ - CObjectVector<CFieldInfo> _fields; -public: - void Clear() { _fields.Clear(); } - void Init(const CFieldInfoInit *standardFieldTable, int numItems); - HRESULT Init(IInArchive *archive); - void PrintTitle(); - void PrintTitleLines(); - HRESULT PrintItemInfo(const CArc &arc, UInt32 index, bool techMode); - HRESULT PrintSummaryInfo(UInt64 numFiles, UInt64 numDirs, - const UInt64 *size, const UInt64 *compressedSize); -}; - -void CFieldPrinter::Init(const CFieldInfoInit *standardFieldTable, int numItems) -{ - Clear(); - for (int i = 0; i < numItems; i++) - { - CFieldInfo fieldInfo; - const CFieldInfoInit &fieldInfoInit = standardFieldTable[i]; - fieldInfo.PropID = fieldInfoInit.PropID; - fieldInfo.Name = fieldInfoInit.Name; - fieldInfo.TitleAdjustment = fieldInfoInit.TitleAdjustment; - fieldInfo.TextAdjustment = fieldInfoInit.TextAdjustment; - fieldInfo.PrefixSpacesWidth = fieldInfoInit.PrefixSpacesWidth; - fieldInfo.Width = fieldInfoInit.Width; - _fields.Add(fieldInfo); - } -} - -static UString GetPropName(PROPID propID, BSTR name) -{ - for (int i = 0; i < sizeof(kPropIdToName) / sizeof(kPropIdToName[0]); i++) - { - const CPropIdToName &propIdToName = kPropIdToName[i]; - if (propIdToName.PropID == propID) - return propIdToName.Name; - } - if (name) - return name; - wchar_t s[16]; - ConvertUInt32ToString(propID, s); - return s; -} - -HRESULT CFieldPrinter::Init(IInArchive *archive) -{ - Clear(); - UInt32 numProps; - RINOK(archive->GetNumberOfProperties(&numProps)); - for (UInt32 i = 0; i < numProps; i++) - { - CMyComBSTR name; - PROPID propID; - VARTYPE vt; - RINOK(archive->GetPropertyInfo(i, &name, &propID, &vt)); - CFieldInfo fieldInfo; - fieldInfo.PropID = propID; - fieldInfo.Name = GetPropName(propID, name); - _fields.Add(fieldInfo); - } - return S_OK; -} - -void CFieldPrinter::PrintTitle() -{ - for (int i = 0; i < _fields.Size(); i++) - { - const CFieldInfo &fieldInfo = _fields[i]; - PrintSpaces(fieldInfo.PrefixSpacesWidth); - PrintString(fieldInfo.TitleAdjustment, - ((fieldInfo.PropID == kpidPath) ? 0: fieldInfo.Width), fieldInfo.Name); - } -} - -void CFieldPrinter::PrintTitleLines() -{ - for (int i = 0; i < _fields.Size(); i++) - { - const CFieldInfo &fieldInfo = _fields[i]; - PrintSpaces(fieldInfo.PrefixSpacesWidth); - for (int i = 0; i < fieldInfo.Width; i++) - g_StdOut << '-'; - } -} - - -static BOOL IsFileTimeZero(CONST FILETIME *lpFileTime) -{ - return (lpFileTime->dwLowDateTime == 0) && (lpFileTime->dwHighDateTime == 0); -} - -static const char *kEmptyTimeString = " "; -static void PrintTime(const NCOM::CPropVariant &prop) -{ - if (prop.vt != VT_FILETIME) - throw "incorrect item"; - if (IsFileTimeZero(&prop.filetime)) - g_StdOut << kEmptyTimeString; - else - { - FILETIME localFileTime; - if (!FileTimeToLocalFileTime(&prop.filetime, &localFileTime)) - throw "FileTimeToLocalFileTime error"; - char s[32]; - if (ConvertFileTimeToString(localFileTime, s, true, true)) - g_StdOut << s; - else - g_StdOut << kEmptyTimeString; - } -} - -HRESULT CFieldPrinter::PrintItemInfo(const CArc &arc, UInt32 index, bool techMode) -{ - /* - if (techMode) - { - g_StdOut << "Index = "; - g_StdOut << (UInt64)index; - g_StdOut << endl; - } - */ - for (int i = 0; i < _fields.Size(); i++) - { - const CFieldInfo &fieldInfo = _fields[i]; - if (!techMode) - PrintSpaces(fieldInfo.PrefixSpacesWidth); - - NCOM::CPropVariant prop; - if (fieldInfo.PropID == kpidPath) - { - UString s; - RINOK(arc.GetItemPath(index, s)); - prop = s; - } - else - { - RINOK(arc.Archive->GetProperty(index, fieldInfo.PropID, &prop)); - } - if (techMode) - { - g_StdOut << fieldInfo.Name << " = "; - } - int width = (fieldInfo.PropID == kpidPath) ? 0: fieldInfo.Width; - if (fieldInfo.PropID == kpidAttrib && (prop.vt == VT_EMPTY || prop.vt == VT_UI4)) - { - UInt32 attrib = (prop.vt == VT_EMPTY) ? 0 : prop.ulVal; - bool isFolder; - RINOK(IsArchiveItemFolder(arc.Archive, index, isFolder)); - char s[8]; - GetAttribString(attrib, isFolder, s); - g_StdOut << s; - } - else if (prop.vt == VT_EMPTY) - { - if (!techMode) - PrintSpaces(width); - } - else if (fieldInfo.PropID == kpidMTime) - { - PrintTime(prop); - } - else if (prop.vt == VT_BSTR) - { - if (techMode) - g_StdOut << prop.bstrVal; - else - PrintString(fieldInfo.TextAdjustment, width, prop.bstrVal); - } - else - { - UString s = ConvertPropertyToString(prop, fieldInfo.PropID); - s.Replace(wchar_t(0xA), L' '); - s.Replace(wchar_t(0xD), L' '); - - if (techMode) - g_StdOut << s; - else - PrintString(fieldInfo.TextAdjustment, width, s); - } - if (techMode) - g_StdOut << endl; - } - return S_OK; -} - -static void PrintNumberString(EAdjustment adjustment, int width, const UInt64 *value) -{ - wchar_t textString[32] = { 0 }; - if (value != NULL) - ConvertUInt64ToString(*value, textString); - PrintString(adjustment, width, textString); -} - - -HRESULT CFieldPrinter::PrintSummaryInfo(UInt64 numFiles, UInt64 numDirs, - const UInt64 *size, const UInt64 *compressedSize) -{ - for (int i = 0; i < _fields.Size(); i++) - { - const CFieldInfo &fieldInfo = _fields[i]; - PrintSpaces(fieldInfo.PrefixSpacesWidth); - NCOM::CPropVariant prop; - if (fieldInfo.PropID == kpidSize) - PrintNumberString(fieldInfo.TextAdjustment, fieldInfo.Width, size); - else if (fieldInfo.PropID == kpidPackSize) - PrintNumberString(fieldInfo.TextAdjustment, fieldInfo.Width, compressedSize); - else if (fieldInfo.PropID == kpidPath) - { - wchar_t textString[32]; - ConvertUInt64ToString(numFiles, textString); - UString temp = textString; - temp += L" "; - temp += kFilesMessage; - temp += L", "; - ConvertUInt64ToString(numDirs, textString); - temp += textString; - temp += L" "; - temp += kDirsMessage; - PrintString(fieldInfo.TextAdjustment, 0, temp); - } - else - PrintString(fieldInfo.TextAdjustment, fieldInfo.Width, L""); - } - return S_OK; -} - -bool GetUInt64Value(IInArchive *archive, UInt32 index, PROPID propID, UInt64 &value) -{ - NCOM::CPropVariant prop; - if (archive->GetProperty(index, propID, &prop) != S_OK) - throw "GetPropertyValue error"; - if (prop.vt == VT_EMPTY) - return false; - value = ConvertPropVariantToUInt64(prop); - return true; -} - -static void PrintPropPair(const wchar_t *name, const wchar_t *value) -{ - g_StdOut << name << " = " << value << endl; -} - -HRESULT ListArchives(CCodecs *codecs, const CIntVector &formatIndices, - bool stdInMode, - UStringVector &arcPaths, UStringVector &arcPathsFull, - const NWildcard::CCensorNode &wildcardCensor, - bool enableHeaders, bool techMode, - #ifndef _NO_CRYPTO - bool &passwordEnabled, UString &password, - #endif - UInt64 &numErrors) -{ - numErrors = 0; - CFieldPrinter fieldPrinter; - if (!techMode) - fieldPrinter.Init(kStandardFieldTable, sizeof(kStandardFieldTable) / sizeof(kStandardFieldTable[0])); - - UInt64 numFiles2 = 0, numDirs2 = 0, totalPackSize2 = 0, totalUnPackSize2 = 0; - UInt64 *totalPackSizePointer2 = 0, *totalUnPackSizePointer2 = 0; - int numArcs = /* stdInMode ? 1 : */ arcPaths.Size(); - for (int i = 0; i < numArcs; i++) - { - const UString &archiveName = arcPaths[i]; - UInt64 arcPackSize = 0; - if (!stdInMode) - { - NFile::NFind::CFileInfoW fi; - if (!fi.Find(archiveName) || fi.IsDir()) - { - g_StdOut << endl << "Error: " << archiveName << " is not file" << endl; - numErrors++; - continue; - } - arcPackSize = fi.Size; - } - - CArchiveLink archiveLink; - - COpenCallbackConsole openCallback; - openCallback.OutStream = &g_StdOut; - - #ifndef _NO_CRYPTO - - openCallback.PasswordIsDefined = passwordEnabled; - openCallback.Password = password; - - #endif - - HRESULT result = archiveLink.Open2(codecs, formatIndices, stdInMode, NULL, archiveName, &openCallback); - if (result != S_OK) - { - if (result == E_ABORT) - return result; - g_StdOut << endl << "Error: " << archiveName << ": "; - if (result == S_FALSE) - { - #ifndef _NO_CRYPTO - if (openCallback.Open_WasPasswordAsked()) - g_StdOut << "Can not open encrypted archive. Wrong password?"; - else - #endif - g_StdOut << "Can not open file as archive"; - } - else if (result == E_OUTOFMEMORY) - g_StdOut << "Can't allocate required memory"; - else - g_StdOut << NError::MyFormatMessage(result); - g_StdOut << endl; - numErrors++; - continue; - } - - if (!stdInMode) - for (int v = 0; v < archiveLink.VolumePaths.Size(); v++) - { - int index = arcPathsFull.FindInSorted(archiveLink.VolumePaths[v]); - if (index >= 0 && index > i) - { - arcPaths.Delete(index); - arcPathsFull.Delete(index); - numArcs = arcPaths.Size(); - } - } - - if (enableHeaders) - { - g_StdOut << endl << kListing << archiveName << endl << endl; - - for (int i = 0; i < archiveLink.Arcs.Size(); i++) - { - const CArc &arc = archiveLink.Arcs[i]; - - g_StdOut << "--\n"; - PrintPropPair(L"Path", arc.Path); - PrintPropPair(L"Type", codecs->Formats[arc.FormatIndex].Name); - if (!arc.ErrorMessage.IsEmpty()) - PrintPropPair(L"Error", arc.ErrorMessage); - UInt32 numProps; - IInArchive *archive = arc.Archive; - if (archive->GetNumberOfArchiveProperties(&numProps) == S_OK) - { - for (UInt32 j = 0; j < numProps; j++) - { - CMyComBSTR name; - PROPID propID; - VARTYPE vt; - RINOK(archive->GetArchivePropertyInfo(j, &name, &propID, &vt)); - NCOM::CPropVariant prop; - RINOK(archive->GetArchiveProperty(propID, &prop)); - UString s = ConvertPropertyToString(prop, propID); - if (!s.IsEmpty()) - PrintPropPair(GetPropName(propID, name), s); - } - } - if (i != archiveLink.Arcs.Size() - 1) - { - UInt32 numProps; - g_StdOut << "----\n"; - if (archive->GetNumberOfProperties(&numProps) == S_OK) - { - UInt32 mainIndex = archiveLink.Arcs[i + 1].SubfileIndex; - for (UInt32 j = 0; j < numProps; j++) - { - CMyComBSTR name; - PROPID propID; - VARTYPE vt; - RINOK(archive->GetPropertyInfo(j, &name, &propID, &vt)); - NCOM::CPropVariant prop; - RINOK(archive->GetProperty(mainIndex, propID, &prop)); - UString s = ConvertPropertyToString(prop, propID); - if (!s.IsEmpty()) - PrintPropPair(GetPropName(propID, name), s); - } - } - } - - } - g_StdOut << endl; - if (techMode) - g_StdOut << "----------\n"; - } - - if (enableHeaders && !techMode) - { - fieldPrinter.PrintTitle(); - g_StdOut << endl; - fieldPrinter.PrintTitleLines(); - g_StdOut << endl; - } - - const CArc &arc = archiveLink.Arcs.Back(); - IInArchive *archive = arc.Archive; - if (techMode) - { - RINOK(fieldPrinter.Init(archive)); - } - UInt64 numFiles = 0, numDirs = 0, totalPackSize = 0, totalUnPackSize = 0; - UInt64 *totalPackSizePointer = 0, *totalUnPackSizePointer = 0; - UInt32 numItems; - RINOK(archive->GetNumberOfItems(&numItems)); - for (UInt32 i = 0; i < numItems; i++) - { - if (NConsoleClose::TestBreakSignal()) - return E_ABORT; - - UString filePath; - HRESULT res = arc.GetItemPath(i, filePath); - if (stdInMode && res == E_INVALIDARG) - break; - RINOK(res); - - bool isFolder; - RINOK(IsArchiveItemFolder(archive, i, isFolder)); - if (!wildcardCensor.CheckPath(filePath, !isFolder)) - continue; - - fieldPrinter.PrintItemInfo(arc, i, techMode); - - UInt64 packSize, unpackSize; - if (!GetUInt64Value(archive, i, kpidSize, unpackSize)) - unpackSize = 0; - else - totalUnPackSizePointer = &totalUnPackSize; - if (!GetUInt64Value(archive, i, kpidPackSize, packSize)) - packSize = 0; - else - totalPackSizePointer = &totalPackSize; - - g_StdOut << endl; - - if (isFolder) - numDirs++; - else - numFiles++; - totalPackSize += packSize; - totalUnPackSize += unpackSize; - } - - if (!stdInMode && totalPackSizePointer == 0) - { - if (archiveLink.VolumePaths.Size() != 0) - arcPackSize += archiveLink.VolumesSize; - totalPackSize = (numFiles == 0) ? 0 : arcPackSize; - totalPackSizePointer = &totalPackSize; - } - if (totalUnPackSizePointer == 0 && numFiles == 0) - { - totalUnPackSize = 0; - totalUnPackSizePointer = &totalUnPackSize; - } - if (enableHeaders && !techMode) - { - fieldPrinter.PrintTitleLines(); - g_StdOut << endl; - fieldPrinter.PrintSummaryInfo(numFiles, numDirs, totalUnPackSizePointer, totalPackSizePointer); - g_StdOut << endl; - } - if (totalPackSizePointer != 0) - { - totalPackSizePointer2 = &totalPackSize2; - totalPackSize2 += totalPackSize; - } - if (totalUnPackSizePointer != 0) - { - totalUnPackSizePointer2 = &totalUnPackSize2; - totalUnPackSize2 += totalUnPackSize; - } - numFiles2 += numFiles; - numDirs2 += numDirs; - } - if (enableHeaders && !techMode && numArcs > 1) - { - g_StdOut << endl; - fieldPrinter.PrintTitleLines(); - g_StdOut << endl; - fieldPrinter.PrintSummaryInfo(numFiles2, numDirs2, totalUnPackSizePointer2, totalPackSizePointer2); - g_StdOut << endl; - g_StdOut << "Archives: " << numArcs << endl; - } - return S_OK; -} diff --git a/src/libs/7zip/unix/CPP/7zip/UI/Console/List.h b/src/libs/7zip/unix/CPP/7zip/UI/Console/List.h deleted file mode 100644 index 97d9fb15a..000000000 --- a/src/libs/7zip/unix/CPP/7zip/UI/Console/List.h +++ /dev/null @@ -1,20 +0,0 @@ -// List.h - -#ifndef __LIST_H -#define __LIST_H - -#include "Common/Wildcard.h" -#include "../Common/LoadCodecs.h" - -HRESULT ListArchives(CCodecs *codecs, const CIntVector &formatIndices, - bool stdInMode, - UStringVector &archivePaths, UStringVector &archivePathsFull, - const NWildcard::CCensorNode &wildcardCensor, - bool enableHeaders, bool techMode, - #ifndef _NO_CRYPTO - bool &passwordEnabled, UString &password, - #endif - UInt64 &errors); - -#endif - diff --git a/src/libs/7zip/unix/CPP/7zip/UI/Console/Main.cpp b/src/libs/7zip/unix/CPP/7zip/UI/Console/Main.cpp deleted file mode 100644 index cebfe2e42..000000000 --- a/src/libs/7zip/unix/CPP/7zip/UI/Console/Main.cpp +++ /dev/null @@ -1,628 +0,0 @@ -// Main.cpp - -#include "StdAfx.h" - -#if defined( _7ZIP_LARGE_PAGES) -#include "../../../../C/Alloc.h" -#endif - -#include "Common/MyInitGuid.h" - -#include "Common/CommandLineParser.h" -#include "Common/IntToString.h" -#include "Common/MyException.h" -#include "Common/StdOutStream.h" -#include "Common/StringConvert.h" -#include "Common/StringToInt.h" - -#include "Windows/Error.h" -#ifdef _WIN32 -#include "Windows/MemoryLock.h" -#endif - -#include "../Common/ArchiveCommandLine.h" -#include "../Common/ExitCode.h" -#include "../Common/Extract.h" -#ifdef EXTERNAL_CODECS -#include "../Common/LoadCodecs.h" -#endif - -#include "BenchCon.h" -#include "ExtractCallbackConsole.h" -#include "List.h" -#include "OpenCallbackConsole.h" -#include "UpdateCallbackConsole.h" - -#include "../../MyVersion.h" - -#include "myPrivate.h" -#include "Windows/System.h" - -using namespace NWindows; -using namespace NFile; -using namespace NCommandLineParser; - -// HINSTANCE g_hInstance = 0; -extern CStdOutStream *g_StdStream; - -static const char *kCopyrightString = "\n7-Zip" -#ifndef EXTERNAL_CODECS -" (A)" -#endif - -#ifdef _WIN64 -" [64]" -#endif - -" " MY_VERSION_COPYRIGHT_DATE "\n" -"p7zip Version " P7ZIP_VERSION ; - -static const char *kHelpString = - "\nUsage: 7z" -#ifdef _NO_CRYPTO - "r" -#else -#ifndef EXTERNAL_CODECS - "a" -#endif -#endif - " <command> [<switches>...] <archive_name> [<file_names>...]\n" - " [<@listfiles...>]\n" - "\n" - "<Commands>\n" - " a: Add files to archive\n" - " b: Benchmark\n" - " d: Delete files from archive\n" - " e: Extract files from archive (without using directory names)\n" - " l: List contents of archive\n" -// " l[a|t][f]: List contents of archive\n" -// " a - with Additional fields\n" -// " t - with all fields\n" -// " f - with Full pathnames\n" - " t: Test integrity of archive\n" - " u: Update files to archive\n" - " x: eXtract files with full paths\n" - "<Switches>\n" - " -ai[r[-|0]]{@listfile|!wildcard}: Include archives\n" - " -ax[r[-|0]]{@listfile|!wildcard}: eXclude archives\n" - " -bd: Disable percentage indicator\n" - " -i[r[-|0]]{@listfile|!wildcard}: Include filenames\n" - " -m{Parameters}: set compression Method\n" - " -o{Directory}: set Output directory\n" - #ifndef _NO_CRYPTO - " -p{Password}: set Password\n" - #endif - " -r[-|0]: Recurse subdirectories\n" - " -scs{UTF-8 | WIN | DOS}: set charset for list files\n" - " -sfx[{name}]: Create SFX archive\n" - " -si[{name}]: read data from stdin\n" - " -slt: show technical information for l (List) command\n" - " -so: write data to stdout\n" - " -ssc[-]: set sensitive case mode\n" - " -t{Type}: Set type of archive\n" - " -u[-][p#][q#][r#][x#][y#][z#][!newArchiveName]: Update options\n" - " -v{Size}[b|k|m|g]: Create volumes\n" - " -w[{path}]: assign Work directory. Empty path means a temporary directory\n" - " -x[r[-|0]]]{@listfile|!wildcard}: eXclude filenames\n" - " -y: assume Yes on all queries\n"; - -// --------------------------- -// exception messages - -static const char *kEverythingIsOk = "Everything is Ok"; -static const char *kUserErrorMessage = "Incorrect command line"; -static const char *kNoFormats = "7-Zip cannot find the code that works with archives."; -static const char *kUnsupportedArcTypeMessage = "Unsupported archive type"; - -static const wchar_t *kDefaultSfxModule = L"7zCon.sfx"; - -static void ShowMessageAndThrowException(CStdOutStream &s, LPCSTR message, NExitCode::EEnum code) -{ - s << message << endl; - throw code; -} - -static void PrintHelpAndExit(CStdOutStream &s) -{ - s << kHelpString; - ShowMessageAndThrowException(s, kUserErrorMessage, NExitCode::kUserError); -} - -#ifndef _WIN32 -static void GetArguments(int numArgs, const char *args[], UStringVector &parts) -{ - parts.Clear(); - for (int i = 0; i < numArgs; i++) - { - UString s = MultiByteToUnicodeString(args[i]); - parts.Add(s); - } -} -#endif - -static void ShowCopyrightAndHelp(CStdOutStream &s, bool needHelp) -{ - s << kCopyrightString << " (locale=" << my_getlocale() <<",Utf16="; - if (global_use_utf16_conversion) s << "on"; - else s << "off"; - s << ",HugeFiles="; - if (sizeof(off_t) >= 8) s << "on,"; - else s << "off,"; - int nbcpu = NWindows::NSystem::GetNumberOfProcessors(); - if (nbcpu > 1) s << nbcpu << " CPUs)\n"; - else s << nbcpu << " CPU)\n"; - - if (needHelp) - s << kHelpString; -} - -#ifdef EXTERNAL_CODECS -static void PrintString(CStdOutStream &stdStream, const AString &s, int size) -{ - int len = s.Length(); - stdStream << s; - for (int i = len; i < size; i++) - stdStream << ' '; -} -#endif - -static void PrintString(CStdOutStream &stdStream, const UString &s, int size) -{ - int len = s.Length(); - stdStream << s; - for (int i = len; i < size; i++) - stdStream << ' '; -} - -static inline char GetHex(Byte value) -{ - return (char)((value < 10) ? ('0' + value) : ('A' + (value - 10))); -} - -int Main2( - #ifndef _WIN32 - int numArgs, const char *args[] - #endif -) -{ - #if defined(_WIN32) && !defined(UNDER_CE) - SetFileApisToOEM(); - #endif - - UStringVector commandStrings; - #ifdef _WIN32 - NCommandLineParser::SplitCommandLine(GetCommandLineW(), commandStrings); - #else - // GetArguments(numArgs, args, commandStrings); - extern void mySplitCommandLine(int numArgs,const char *args[],UStringVector &parts); - mySplitCommandLine(numArgs,args,commandStrings); - #endif - - if (commandStrings.Size() == 1) - { - ShowCopyrightAndHelp(g_StdOut, true); - return 0; - } - commandStrings.Delete(0); - - CArchiveCommandLineOptions options; - - CArchiveCommandLineParser parser; - - parser.Parse1(commandStrings, options); - - if (options.HelpMode) - { - ShowCopyrightAndHelp(g_StdOut, true); - return 0; - } - - #if defined(_7ZIP_LARGE_PAGES) - if (options.LargePages) - { - SetLargePageSize(); -#ifdef _WIN32 - NSecurity::EnableLockMemoryPrivilege(); -#endif - } - #endif - - CStdOutStream &stdStream = options.StdOutMode ? g_StdErr : g_StdOut; - g_StdStream = &stdStream; - - if (options.EnableHeaders) - ShowCopyrightAndHelp(stdStream, false); - - parser.Parse2(options); - - CCodecs *codecs = new CCodecs; - CMyComPtr< - #ifdef EXTERNAL_CODECS - ICompressCodecsInfo - #else - IUnknown - #endif - > compressCodecsInfo = codecs; - HRESULT result = codecs->Load(); - if (result != S_OK) - throw CSystemException(result); - - bool isExtractGroupCommand = options.Command.IsFromExtractGroup(); - - if (codecs->Formats.Size() == 0 && - (isExtractGroupCommand || - options.Command.CommandType == NCommandType::kList || - options.Command.IsFromUpdateGroup())) - throw kNoFormats; - - CIntVector formatIndices; - if (!codecs->FindFormatForArchiveType(options.ArcType, formatIndices)) - throw kUnsupportedArcTypeMessage; - - if (options.Command.CommandType == NCommandType::kInfo) - { - stdStream << endl << "Formats:" << endl; - int i; - for (i = 0; i < codecs->Formats.Size(); i++) - { - const CArcInfoEx &arc = codecs->Formats[i]; - #ifdef EXTERNAL_CODECS - if (arc.LibIndex >= 0) - { - char s[16]; - ConvertUInt32ToString(arc.LibIndex, s); - PrintString(stdStream, s, 2); - } - else - #endif - stdStream << " "; - stdStream << ' '; - stdStream << (char)(arc.UpdateEnabled ? 'C' : ' '); - stdStream << (char)(arc.KeepName ? 'K' : ' '); - stdStream << " "; - PrintString(stdStream, arc.Name, 6); - stdStream << " "; - UString s; - for (int t = 0; t < arc.Exts.Size(); t++) - { - const CArcExtInfo &ext = arc.Exts[t]; - s += ext.Ext; - if (!ext.AddExt.IsEmpty()) - { - s += L" ("; - s += ext.AddExt; - s += L')'; - } - s += L' '; - } - PrintString(stdStream, s, 14); - stdStream << " "; - const CByteBuffer &sig = arc.StartSignature; - for (size_t j = 0; j < sig.GetCapacity(); j++) - { - Byte b = sig[j]; - if (b > 0x20 && b < 0x80) - { - stdStream << (char)b; - } - else - { - stdStream << GetHex((Byte)((b >> 4) & 0xF)); - stdStream << GetHex((Byte)(b & 0xF)); - } - stdStream << ' '; - } - stdStream << endl; - } - stdStream << endl << "Codecs:" << endl; - - #ifdef EXTERNAL_CODECS - UInt32 numMethods; - if (codecs->GetNumberOfMethods(&numMethods) == S_OK) - for (UInt32 j = 0; j < numMethods; j++) - { - int libIndex = codecs->GetCodecLibIndex(j); - if (libIndex >= 0) - { - char s[16]; - ConvertUInt32ToString(libIndex, s); - PrintString(stdStream, s, 2); - } - else - stdStream << " "; - stdStream << ' '; - stdStream << (char)(codecs->GetCodecEncoderIsAssigned(j) ? 'C' : ' '); - UInt64 id; - stdStream << " "; - HRESULT res = codecs->GetCodecId(j, id); - if (res != S_OK) - id = (UInt64)(Int64)-1; - char s[32]; - ConvertUInt64ToString(id, s, 16); - PrintString(stdStream, s, 8); - stdStream << " "; - PrintString(stdStream, codecs->GetCodecName(j), 11); - stdStream << endl; - /* - if (res != S_OK) - throw "incorrect Codec ID"; - */ - } - #endif - return S_OK; - } - else if (options.Command.CommandType == NCommandType::kBenchmark) - { - if (options.Method.CompareNoCase(L"CRC") == 0) - { - HRESULT res = CrcBenchCon((FILE *)stdStream, options.NumIterations, options.NumThreads, options.DictionarySize); - if (res != S_OK) - { - if (res == S_FALSE) - { - stdStream << "\nCRC Error\n"; - return NExitCode::kFatalError; - } - throw CSystemException(res); - } - } - else - { - HRESULT res; - #ifdef EXTERNAL_CODECS - CObjectVector<CCodecInfoEx> externalCodecs; - res = LoadExternalCodecs(compressCodecsInfo, externalCodecs); - if (res != S_OK) - throw CSystemException(res); - #endif - res = LzmaBenchCon( - #ifdef EXTERNAL_CODECS - compressCodecsInfo, &externalCodecs, - #endif - (FILE *)stdStream, options.NumIterations, options.NumThreads, options.DictionarySize); - if (res != S_OK) - { - if (res == S_FALSE) - { - stdStream << "\nDecoding Error\n"; - return NExitCode::kFatalError; - } - throw CSystemException(res); - } - } - } - else if (isExtractGroupCommand || options.Command.CommandType == NCommandType::kList) - { - if (isExtractGroupCommand) - { - CExtractCallbackConsole *ecs = new CExtractCallbackConsole; - CMyComPtr<IFolderArchiveExtractCallback> extractCallback = ecs; - - ecs->OutStream = &stdStream; - - #ifndef _NO_CRYPTO - ecs->PasswordIsDefined = options.PasswordEnabled; - ecs->Password = options.Password; - #endif - - ecs->Init(); - - COpenCallbackConsole openCallback; - openCallback.OutStream = &stdStream; - - #ifndef _NO_CRYPTO - openCallback.PasswordIsDefined = options.PasswordEnabled; - openCallback.Password = options.Password; - #endif - - CExtractOptions eo; - eo.StdInMode = options.StdInMode; - eo.StdOutMode = options.StdOutMode; - eo.PathMode = options.Command.GetPathMode(); - eo.TestMode = options.Command.IsTestMode(); - eo.OverwriteMode = options.OverwriteMode; - eo.OutputDir = options.OutputDir; - eo.YesToAll = options.YesToAll; - eo.CalcCrc = options.CalcCrc; - #if !defined(_7ZIP_ST) && !defined(_SFX) - eo.Properties = options.ExtractProperties; - #endif - UString errorMessage; - CDecompressStat stat; - HRESULT result = DecompressArchives( - codecs, - formatIndices, - options.ArchivePathsSorted, - options.ArchivePathsFullSorted, - options.WildcardCensor.Pairs.Front().Head, - eo, &openCallback, ecs, errorMessage, stat); - if (!errorMessage.IsEmpty()) - { - stdStream << endl << "Error: " << errorMessage; - if (result == S_OK) - result = E_FAIL; - } - - stdStream << endl; - if (ecs->NumArchives > 1) - stdStream << "Archives: " << ecs->NumArchives << endl; - if (ecs->NumArchiveErrors != 0 || ecs->NumFileErrors != 0) - { - if (ecs->NumArchives > 1) - { - stdStream << endl; - if (ecs->NumArchiveErrors != 0) - stdStream << "Archive Errors: " << ecs->NumArchiveErrors << endl; - if (ecs->NumFileErrors != 0) - stdStream << "Sub items Errors: " << ecs->NumFileErrors << endl; - } - if (result != S_OK) - throw CSystemException(result); - return NExitCode::kFatalError; - } - if (result != S_OK) - throw CSystemException(result); - if (stat.NumFolders != 0) - stdStream << "Folders: " << stat.NumFolders << endl; - if (stat.NumFiles != 1 || stat.NumFolders != 0) - stdStream << "Files: " << stat.NumFiles << endl; - stdStream - << "Size: " << stat.UnpackSize << endl - << "Compressed: " << stat.PackSize << endl; - if (options.CalcCrc) - { - char s[16]; - ConvertUInt32ToHexWithZeros(stat.CrcSum, s); - stdStream << "CRC: " << s << endl; - } - } - else - { - UInt64 numErrors = 0; - HRESULT result = ListArchives( - codecs, - formatIndices, - options.StdInMode, - options.ArchivePathsSorted, - options.ArchivePathsFullSorted, - options.WildcardCensor.Pairs.Front().Head, - options.EnableHeaders, - options.TechMode, - #ifndef _NO_CRYPTO - options.PasswordEnabled, - options.Password, - #endif - numErrors); - if (numErrors > 0) - { - g_StdOut << endl << "Errors: " << numErrors; - return NExitCode::kFatalError; - } - if (result != S_OK) - throw CSystemException(result); - } - } - else if (options.Command.IsFromUpdateGroup()) - { - CUpdateOptions &uo = options.UpdateOptions; - if (uo.SfxMode && uo.SfxModule.IsEmpty()) - uo.SfxModule = kDefaultSfxModule; - - COpenCallbackConsole openCallback; - openCallback.OutStream = &stdStream; - - #ifndef _NO_CRYPTO - bool passwordIsDefined = - options.PasswordEnabled && !options.Password.IsEmpty(); - openCallback.PasswordIsDefined = passwordIsDefined; - openCallback.Password = options.Password; - #endif - - CUpdateCallbackConsole callback; - callback.EnablePercents = options.EnablePercents; - - #ifndef _NO_CRYPTO - callback.PasswordIsDefined = passwordIsDefined; - callback.AskPassword = options.PasswordEnabled && options.Password.IsEmpty(); - callback.Password = options.Password; - #endif - callback.StdOutMode = uo.StdOutMode; - callback.Init(&stdStream); - - CUpdateErrorInfo errorInfo; - - if (!uo.Init(codecs, formatIndices, options.ArchiveName)) - throw kUnsupportedArcTypeMessage; - HRESULT result = UpdateArchive(codecs, - options.WildcardCensor, uo, - errorInfo, &openCallback, &callback); - -#ifdef ENV_UNIX - if (uo.SfxMode) - { - void myAddExeFlag(const UString &name); - for(int i = 0; i < uo.Commands.Size(); i++) - { - CUpdateArchiveCommand &command = uo.Commands[i]; - if (!uo.StdOutMode) - { - myAddExeFlag(command.ArchivePath.GetFinalPath()); - } - } - } -#endif - - int exitCode = NExitCode::kSuccess; - if (callback.CantFindFiles.Size() > 0) - { - stdStream << endl; - stdStream << "WARNINGS for files:" << endl << endl; - int numErrors = callback.CantFindFiles.Size(); - for (int i = 0; i < numErrors; i++) - { - stdStream << callback.CantFindFiles[i] << " : "; - stdStream << NError::MyFormatMessageW(callback.CantFindCodes[i]) << endl; - } - stdStream << "----------------" << endl; - stdStream << "WARNING: Cannot find " << numErrors << " file"; - if (numErrors > 1) - stdStream << "s"; - stdStream << endl; - exitCode = NExitCode::kWarning; - } - - if (result != S_OK) - { - UString message; - if (!errorInfo.Message.IsEmpty()) - { - message += errorInfo.Message; - message += L"\n"; - } - if (!errorInfo.FileName.IsEmpty()) - { - message += errorInfo.FileName; - message += L"\n"; - } - if (!errorInfo.FileName2.IsEmpty()) - { - message += errorInfo.FileName2; - message += L"\n"; - } - if (errorInfo.SystemError != 0) - { - message += NError::MyFormatMessageW(errorInfo.SystemError); - message += L"\n"; - } - if (!message.IsEmpty()) - stdStream << L"\nError:\n" << message; - throw CSystemException(result); - } - int numErrors = callback.FailedFiles.Size(); - if (numErrors == 0) - { - if (callback.CantFindFiles.Size() == 0) - stdStream << kEverythingIsOk << endl; - } - else - { - stdStream << endl; - stdStream << "WARNINGS for files:" << endl << endl; - for (int i = 0; i < numErrors; i++) - { - stdStream << callback.FailedFiles[i] << " : "; - stdStream << NError::MyFormatMessageW(callback.FailedCodes[i]) << endl; - } - stdStream << "----------------" << endl; - stdStream << "WARNING: Cannot open " << numErrors << " file"; - if (numErrors > 1) - stdStream << "s"; - stdStream << endl; - exitCode = NExitCode::kWarning; - } - return exitCode; - } - else - PrintHelpAndExit(stdStream); - return 0; -} diff --git a/src/libs/7zip/unix/CPP/7zip/UI/Console/MainAr.cpp b/src/libs/7zip/unix/CPP/7zip/UI/Console/MainAr.cpp deleted file mode 100644 index 68059575b..000000000 --- a/src/libs/7zip/unix/CPP/7zip/UI/Console/MainAr.cpp +++ /dev/null @@ -1,127 +0,0 @@ -// MainAr.cpp - -#include "StdAfx.h" - -#include "Common/NewHandler.h" // FIXME - -#include "Common/MyException.h" -#include "Common/StdOutStream.h" - -#include "Windows/Error.h" -#include "Windows/NtCheck.h" - -#include "../Common/ArchiveCommandLine.h" -#include "../Common/ExitCode.h" - -#include "ConsoleClose.h" - -using namespace NWindows; - -CStdOutStream *g_StdStream = 0; - -extern int Main2( - #ifndef _WIN32 - int numArgs, const char *args[] - #endif -); - -static const char *kExceptionErrorMessage = "\n\nError:\n"; -static const char *kUserBreak = "\nBreak signaled\n"; -static const char *kMemoryExceptionMessage = "\n\nERROR: Can't allocate required memory!\n"; -static const char *kUnknownExceptionMessage = "\n\nUnknown Error\n"; -static const char *kInternalExceptionMessage = "\n\nInternal Error #"; - -#define NT_CHECK_FAIL_ACTION (*g_StdStream) << "Unsupported Windows version"; return NExitCode::kFatalError; - -int MY_CDECL main -( - #ifndef _WIN32 - int numArgs, const char *args[] - #endif -) -{ - g_StdStream = &g_StdOut; - - NT_CHECK - - NConsoleClose::CCtrlHandlerSetter ctrlHandlerSetter; - int res = 0; - try - { - res = Main2( - #ifndef _WIN32 - numArgs, args - #endif - ); - } - catch(const CNewException &) - { - (*g_StdStream) << kMemoryExceptionMessage; - return (NExitCode::kMemoryError); - } - catch(const NConsoleClose::CCtrlBreakException &) - { - (*g_StdStream) << endl << kUserBreak; - return (NExitCode::kUserBreak); - } - catch(const CArchiveCommandLineException &e) - { - (*g_StdStream) << kExceptionErrorMessage << e << endl; - return (NExitCode::kUserError); - } - catch(const CSystemException &systemError) - { - if (systemError.ErrorCode == E_OUTOFMEMORY) - { - (*g_StdStream) << kMemoryExceptionMessage; - return (NExitCode::kMemoryError); - } - if (systemError.ErrorCode == E_ABORT) - { - (*g_StdStream) << endl << kUserBreak; - return (NExitCode::kUserBreak); - } - UString message; - NError::MyFormatMessage(systemError.ErrorCode, message); - (*g_StdStream) << endl << endl << "System error:" << endl << message << endl; - return (NExitCode::kFatalError); - } - catch(NExitCode::EEnum &exitCode) - { - (*g_StdStream) << kInternalExceptionMessage << exitCode << endl; - return (exitCode); - } - /* - catch(const NExitCode::CMultipleErrors &multipleErrors) - { - (*g_StdStream) << endl << multipleErrors.NumErrors << " errors" << endl; - return (NExitCode::kFatalError); - } - */ - catch(const UString &s) - { - (*g_StdStream) << kExceptionErrorMessage << s << endl; - return (NExitCode::kFatalError); - } - catch(const AString &s) - { - (*g_StdStream) << kExceptionErrorMessage << s << endl; - return (NExitCode::kFatalError); - } - catch(const char *s) - { - (*g_StdStream) << kExceptionErrorMessage << s << endl; - return (NExitCode::kFatalError); - } - catch(int t) - { - (*g_StdStream) << kInternalExceptionMessage << t << endl; - return (NExitCode::kFatalError); - } - catch(...) - { - (*g_StdStream) << kUnknownExceptionMessage; - return (NExitCode::kFatalError); - } - return res; -} diff --git a/src/libs/7zip/unix/CPP/7zip/UI/Console/OpenCallbackConsole.cpp b/src/libs/7zip/unix/CPP/7zip/UI/Console/OpenCallbackConsole.cpp deleted file mode 100644 index 7dba2ad5d..000000000 --- a/src/libs/7zip/unix/CPP/7zip/UI/Console/OpenCallbackConsole.cpp +++ /dev/null @@ -1,58 +0,0 @@ -// OpenCallbackConsole.cpp - -#include "StdAfx.h" - -#include "OpenCallbackConsole.h" - -#include "ConsoleClose.h" -#include "UserInputUtils.h" - -HRESULT COpenCallbackConsole::Open_CheckBreak() -{ - if (NConsoleClose::TestBreakSignal()) - return E_ABORT; - return S_OK; -} - -HRESULT COpenCallbackConsole::Open_SetTotal(const UInt64 *, const UInt64 *) -{ - return Open_CheckBreak(); -} - -HRESULT COpenCallbackConsole::Open_SetCompleted(const UInt64 *, const UInt64 *) -{ - return Open_CheckBreak(); -} - -#ifndef _NO_CRYPTO - -HRESULT COpenCallbackConsole::Open_CryptoGetTextPassword(BSTR *password) -{ - PasswordWasAsked = true; - RINOK(Open_CheckBreak()); - if (!PasswordIsDefined) - { - Password = GetPassword(OutStream); - PasswordIsDefined = true; - } - return StringToBstr(Password, password); -} - -HRESULT COpenCallbackConsole::Open_GetPasswordIfAny(UString &password) -{ - if (PasswordIsDefined) - password = Password; - return S_OK; -} - -bool COpenCallbackConsole::Open_WasPasswordAsked() -{ - return PasswordWasAsked; -} - -void COpenCallbackConsole::Open_ClearPasswordWasAskedFlag() -{ - PasswordWasAsked = false; -} - -#endif diff --git a/src/libs/7zip/unix/CPP/7zip/UI/Console/OpenCallbackConsole.h b/src/libs/7zip/unix/CPP/7zip/UI/Console/OpenCallbackConsole.h deleted file mode 100644 index c002e6a72..000000000 --- a/src/libs/7zip/unix/CPP/7zip/UI/Console/OpenCallbackConsole.h +++ /dev/null @@ -1,24 +0,0 @@ -// OpenCallbackConsole.h - -#ifndef __OPENCALLBACKCONSOLE_H -#define __OPENCALLBACKCONSOLE_H - -#include "Common/StdOutStream.h" -#include "../Common/ArchiveOpenCallback.h" - -class COpenCallbackConsole: public IOpenCallbackUI -{ -public: - INTERFACE_IOpenCallbackUI(;) - - CStdOutStream *OutStream; - - #ifndef _NO_CRYPTO - bool PasswordIsDefined; - bool PasswordWasAsked; - UString Password; - COpenCallbackConsole(): PasswordIsDefined(false), PasswordWasAsked(false) {} - #endif -}; - -#endif diff --git a/src/libs/7zip/unix/CPP/7zip/UI/Console/PercentPrinter.cpp b/src/libs/7zip/unix/CPP/7zip/UI/Console/PercentPrinter.cpp index 28452b177..f2889957a 100644 --- a/src/libs/7zip/unix/CPP/7zip/UI/Console/PercentPrinter.cpp +++ b/src/libs/7zip/unix/CPP/7zip/UI/Console/PercentPrinter.cpp @@ -2,18 +2,18 @@ #include "StdAfx.h" -#include "Common/IntToString.h" -#include "Common/MyString.h" +#include "../../../Common/Defs.h" +#include "../../../Common/IntToString.h" #include "PercentPrinter.h" -const int kPaddingSize = 2; -const int kPercentsSize = 4; -const int kMaxExtraSize = kPaddingSize + 32 + kPercentsSize; +static const unsigned kPaddingSize = 2; +static const unsigned kPercentsSize = 4; +static const unsigned kMaxExtraSize = kPaddingSize + 32 + kPercentsSize; -static void ClearPrev(char *p, int num) +static void ClearPrev(char *p, unsigned num) { - int i; + unsigned i; for (i = 0; i < num; i++) *p++ = '\b'; for (i = 0; i < num; i++) *p++ = ' '; for (i = 0; i < num; i++) *p++ = '\b'; @@ -51,18 +51,30 @@ void CPercentPrinter::PrintNewLine() void CPercentPrinter::RePrintRatio() { char s[32]; - ConvertUInt64ToString(((m_Total == 0) ? 0 : (m_CurValue * 100 / m_Total)), s); - int size = (int)strlen(s); - s[size++] = '%'; - s[size] = '\0'; + unsigned size; + { + char c = '%'; + UInt64 value = 0; + if (m_Total == (UInt64)(Int64)-1) + { + value = m_CurValue >> 20; + c = 'M'; + } + else if (m_Total != 0) + value = m_CurValue * 100 / m_Total; + ConvertUInt64ToString(value, s); + size = (unsigned)strlen(s); + s[size++] = c; + s[size] = '\0'; + } - int extraSize = kPaddingSize + MyMax(size, kPercentsSize); + unsigned extraSize = kPaddingSize + MyMax(size, kPercentsSize); if (extraSize < m_NumExtraChars) extraSize = m_NumExtraChars; char fullString[kMaxExtraSize * 3]; char *p = fullString; - int i; + unsigned i; if (m_NumExtraChars == 0) { for (i = 0; i < extraSize; i++) @@ -73,7 +85,7 @@ void CPercentPrinter::RePrintRatio() for (i = 0; i < m_NumExtraChars; i++) *p++ = '\b'; m_NumExtraChars = extraSize; - for (; size < m_NumExtraChars; size++) + for (; size < extraSize; size++) *p++ = ' '; MyStringCopy(p, s); (*OutStream) << fullString; diff --git a/src/libs/7zip/unix/CPP/7zip/UI/Console/PercentPrinter.h b/src/libs/7zip/unix/CPP/7zip/UI/Console/PercentPrinter.h index 97f2e6adb..509bab5fc 100644 --- a/src/libs/7zip/unix/CPP/7zip/UI/Console/PercentPrinter.h +++ b/src/libs/7zip/unix/CPP/7zip/UI/Console/PercentPrinter.h @@ -1,10 +1,9 @@ // PercentPrinter.h -#ifndef __PERCENTPRINTER_H -#define __PERCENTPRINTER_H +#ifndef __PERCENT_PRINTER_H +#define __PERCENT_PRINTER_H -#include "Common/Types.h" -#include "Common/StdOutStream.h" +#include "../../../Common/StdOutStream.h" class CPercentPrinter { @@ -12,12 +11,12 @@ class CPercentPrinter UInt64 m_PrevValue; UInt64 m_CurValue; UInt64 m_Total; - int m_NumExtraChars; + unsigned m_NumExtraChars; public: CStdOutStream *OutStream; CPercentPrinter(UInt64 minStepSize = 1): m_MinStepSize(minStepSize), - m_PrevValue(0), m_CurValue(0), m_Total(1), m_NumExtraChars(0) {} + m_PrevValue(0), m_CurValue(0), m_Total((UInt64)(Int64)-1), m_NumExtraChars(0) {} void SetTotal(UInt64 total) { m_Total = total; m_PrevValue = 0; } void SetRatio(UInt64 doneValue) { m_CurValue = doneValue; } void PrintString(const char *s); diff --git a/src/libs/7zip/unix/CPP/7zip/UI/Console/UpdateCallbackConsole.cpp b/src/libs/7zip/unix/CPP/7zip/UI/Console/UpdateCallbackConsole.cpp deleted file mode 100644 index e0eb4dec7..000000000 --- a/src/libs/7zip/unix/CPP/7zip/UI/Console/UpdateCallbackConsole.cpp +++ /dev/null @@ -1,261 +0,0 @@ -// UpdateCallbackConsole.cpp - -#include "StdAfx.h" - -#include "UpdateCallbackConsole.h" - -#include "Windows/Error.h" -#ifndef _7ZIP_ST -#include "Windows/Synchronization.h" -#endif - -#include "ConsoleClose.h" -#include "UserInputUtils.h" - -using namespace NWindows; - -#ifndef _7ZIP_ST -static NSynchronization::CCriticalSection g_CriticalSection; -#define MT_LOCK NSynchronization::CCriticalSectionLock lock(g_CriticalSection); -#else -#define MT_LOCK -#endif - -static const wchar_t *kEmptyFileAlias = L"[Content]"; - -static const char *kCreatingArchiveMessage = "Creating archive "; -static const char *kUpdatingArchiveMessage = "Updating archive "; -static const char *kScanningMessage = "Scanning"; - - -HRESULT CUpdateCallbackConsole::OpenResult(const wchar_t *name, HRESULT result) -{ - (*OutStream) << endl; - if (result != S_OK) - (*OutStream) << "Error: " << name << " is not supported archive" << endl; - return S_OK; -} - -HRESULT CUpdateCallbackConsole::StartScanning() -{ - (*OutStream) << kScanningMessage; - return S_OK; -} - -HRESULT CUpdateCallbackConsole::ScanProgress(UInt64 /* numFolders */, UInt64 /* numFiles */, const wchar_t * /* path */) -{ - return CheckBreak(); -} - -HRESULT CUpdateCallbackConsole::CanNotFindError(const wchar_t *name, DWORD systemError) -{ - CantFindFiles.Add(name); - CantFindCodes.Add(systemError); - // m_PercentPrinter.ClosePrint(); - if (!m_WarningsMode) - { - (*OutStream) << endl << endl; - m_PercentPrinter.PrintNewLine(); - m_WarningsMode = true; - } - m_PercentPrinter.PrintString(name); - m_PercentPrinter.PrintString(": WARNING: "); - m_PercentPrinter.PrintString(NError::MyFormatMessageW(systemError)); - m_PercentPrinter.PrintNewLine(); - return S_OK; -} - -HRESULT CUpdateCallbackConsole::FinishScanning() -{ - (*OutStream) << endl << endl; - return S_OK; -} - -HRESULT CUpdateCallbackConsole::StartArchive(const wchar_t *name, bool updating) -{ - if(updating) - (*OutStream) << kUpdatingArchiveMessage; - else - (*OutStream) << kCreatingArchiveMessage; - if (name != 0) - (*OutStream) << name; - else - (*OutStream) << "StdOut"; - (*OutStream) << endl << endl; - return S_OK; -} - -HRESULT CUpdateCallbackConsole::FinishArchive() -{ - (*OutStream) << endl; - return S_OK; -} - -HRESULT CUpdateCallbackConsole::CheckBreak() -{ - if (NConsoleClose::TestBreakSignal()) - return E_ABORT; - return S_OK; -} - -HRESULT CUpdateCallbackConsole::Finilize() -{ - MT_LOCK - if (m_NeedBeClosed) - { - if (EnablePercents) - { - m_PercentPrinter.ClosePrint(); - } - if (!StdOutMode && m_NeedNewLine) - { - m_PercentPrinter.PrintNewLine(); - m_NeedNewLine = false; - } - m_NeedBeClosed = false; - } - return S_OK; -} - -HRESULT CUpdateCallbackConsole::SetNumFiles(UInt64 /* numFiles */) -{ - return S_OK; -} - -HRESULT CUpdateCallbackConsole::SetTotal(UInt64 size) -{ - MT_LOCK - if (EnablePercents) - m_PercentPrinter.SetTotal(size); - return S_OK; -} - -HRESULT CUpdateCallbackConsole::SetCompleted(const UInt64 *completeValue) -{ - MT_LOCK - if (completeValue != NULL) - { - if (EnablePercents) - { - m_PercentPrinter.SetRatio(*completeValue); - m_PercentPrinter.PrintRatio(); - m_NeedBeClosed = true; - } - } - if (NConsoleClose::TestBreakSignal()) - return E_ABORT; - return S_OK; -} - -HRESULT CUpdateCallbackConsole::SetRatioInfo(const UInt64 * /* inSize */, const UInt64 * /* outSize */) -{ - if (NConsoleClose::TestBreakSignal()) - return E_ABORT; - return S_OK; -} - -HRESULT CUpdateCallbackConsole::GetStream(const wchar_t *name, bool isAnti) -{ - MT_LOCK - if (StdOutMode) - return S_OK; - if(isAnti) - m_PercentPrinter.PrintString("Anti item "); - else - m_PercentPrinter.PrintString("Compressing "); - if (name[0] == 0) - name = kEmptyFileAlias; - m_PercentPrinter.PrintString(name); - if (EnablePercents) - m_PercentPrinter.RePrintRatio(); - return S_OK; -} - -HRESULT CUpdateCallbackConsole::OpenFileError(const wchar_t *name, DWORD systemError) -{ - MT_LOCK - FailedCodes.Add(systemError); - FailedFiles.Add(name); - // if (systemError == ERROR_SHARING_VIOLATION) - { - m_PercentPrinter.ClosePrint(); - m_PercentPrinter.PrintNewLine(); - m_PercentPrinter.PrintString("WARNING: "); - m_PercentPrinter.PrintString(NError::MyFormatMessageW(systemError)); - return S_FALSE; - } - // return systemError; -} - -HRESULT CUpdateCallbackConsole::SetOperationResult(Int32 ) -{ - m_NeedBeClosed = true; - m_NeedNewLine = true; - return S_OK; -} - -HRESULT CUpdateCallbackConsole::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password) -{ - *password = NULL; - - #ifdef _NO_CRYPTO - - *passwordIsDefined = false; - return S_OK; - - #else - - if (!PasswordIsDefined) - { - if (AskPassword) - { - Password = GetPassword(OutStream,true); - PasswordIsDefined = true; - } - } - *passwordIsDefined = BoolToInt(PasswordIsDefined); - return StringToBstr(Password, password); - - #endif -} - -HRESULT CUpdateCallbackConsole::CryptoGetTextPassword(BSTR *password) -{ - *password = NULL; - - #ifdef _NO_CRYPTO - - return E_NOTIMPL; - - #else - - if (!PasswordIsDefined) - { - { - Password = GetPassword(OutStream); - PasswordIsDefined = true; - } - } - return StringToBstr(Password, password); - - #endif -} - -/* -HRESULT CUpdateCallbackConsole::ShowDeleteFile(const wchar_t *name) -{ - // MT_LOCK - if (StdOutMode) - return S_OK; - RINOK(Finilize()); - m_PercentPrinter.PrintString("Deleting "); - if (name[0] == 0) - name = kEmptyFileAlias; - m_PercentPrinter.PrintString(name); - if (EnablePercents) - m_PercentPrinter.RePrintRatio(); - m_NeedBeClosed = true; - m_NeedNewLine = true; - return S_OK; -} -*/ diff --git a/src/libs/7zip/unix/CPP/7zip/UI/Console/UpdateCallbackConsole.h b/src/libs/7zip/unix/CPP/7zip/UI/Console/UpdateCallbackConsole.h deleted file mode 100644 index 5ffe3eb7a..000000000 --- a/src/libs/7zip/unix/CPP/7zip/UI/Console/UpdateCallbackConsole.h +++ /dev/null @@ -1,62 +0,0 @@ -// UpdateCallbackConsole.h - -#ifndef __UPDATE_CALLBACK_CONSOLE_H -#define __UPDATE_CALLBACK_CONSOLE_H - -#include "Common/StdOutStream.h" - -#include "../Common/Update.h" - -#include "PercentPrinter.h" - -class CUpdateCallbackConsole: public IUpdateCallbackUI2 -{ - CPercentPrinter m_PercentPrinter; - bool m_NeedBeClosed; - bool m_NeedNewLine; - - bool m_WarningsMode; - - CStdOutStream *OutStream; -public: - bool EnablePercents; - bool StdOutMode; - - #ifndef _NO_CRYPTO - bool PasswordIsDefined; - UString Password; - bool AskPassword; - #endif - - CUpdateCallbackConsole(): - m_PercentPrinter(1 << 16), - #ifndef _NO_CRYPTO - PasswordIsDefined(false), - AskPassword(false), - #endif - StdOutMode(false), - EnablePercents(true), - m_WarningsMode(false) - {} - - ~CUpdateCallbackConsole() { Finilize(); } - void Init(CStdOutStream *outStream) - { - m_NeedBeClosed = false; - m_NeedNewLine = false; - FailedFiles.Clear(); - FailedCodes.Clear(); - OutStream = outStream; - m_PercentPrinter.OutStream = outStream; - } - - INTERFACE_IUpdateCallbackUI2(;) - - UStringVector FailedFiles; - CRecordVector<HRESULT> FailedCodes; - - UStringVector CantFindFiles; - CRecordVector<HRESULT> CantFindCodes; -}; - -#endif diff --git a/src/libs/7zip/unix/CPP/7zip/UI/Console/UserInputUtils.cpp b/src/libs/7zip/unix/CPP/7zip/UI/Console/UserInputUtils.cpp deleted file mode 100644 index 4733e4ffb..000000000 --- a/src/libs/7zip/unix/CPP/7zip/UI/Console/UserInputUtils.cpp +++ /dev/null @@ -1,96 +0,0 @@ -// UserInputUtils.cpp - -#include "StdAfx.h" - -#include "Common/StdInStream.h" -#include "Common/StringConvert.h" - -#include "UserInputUtils.h" - -#ifdef USE_FLTK -// the programs like file-roller or xarchiver do not support archives with password -// these programs freeze because p7zip is waiting for a password -// defining USE_FLTK allows p7zip to use a popup in order to ask the password. -#include <FL/Fl.H> -#include <FL/Fl_Window.H> -#include <FL/fl_ask.H> -#else -#ifdef ENV_HAVE_GETPASS -#include <pwd.h> -#include <unistd.h> -#include "Common/MyException.h" -#endif -#endif - -static const char kYes = 'Y'; -static const char kNo = 'N'; -static const char kYesAll = 'A'; -static const char kNoAll = 'S'; -static const char kAutoRenameAll = 'U'; -static const char kQuit = 'Q'; - -static const char *kFirstQuestionMessage = "?\n"; -static const char *kHelpQuestionMessage = - "(Y)es / (N)o / (A)lways / (S)kip all / A(u)to rename all / (Q)uit? "; - -// return true if pressed Quite; - -NUserAnswerMode::EEnum ScanUserYesNoAllQuit(CStdOutStream *outStream) -{ - (*outStream) << kFirstQuestionMessage; - for (;;) - { - (*outStream) << kHelpQuestionMessage; - outStream->Flush(); - AString scannedString = g_StdIn.ScanStringUntilNewLine(); - scannedString.Trim(); - if (!scannedString.IsEmpty()) - switch( - ::MyCharUpper( - #ifdef UNDER_CE - (wchar_t) - #endif - scannedString[0])) - { - case kYes: - return NUserAnswerMode::kYes; - case kNo: - return NUserAnswerMode::kNo; - case kYesAll: - return NUserAnswerMode::kYesAll; - case kNoAll: - return NUserAnswerMode::kNoAll; - case kAutoRenameAll: - return NUserAnswerMode::kAutoRenameAll; - case kQuit: - return NUserAnswerMode::kQuit; - } - } -} - -UString GetPassword(CStdOutStream *outStream,bool verify) -{ -#ifdef USE_FLTK - const char *r = fl_password("Enter password", 0); - AString oemPassword = ""; - if (r) oemPassword = r; -#else /* USE_FLTK */ -#ifdef ENV_HAVE_GETPASS - (*outStream) << "\nEnter password (will not be echoed) :"; - outStream->Flush(); - AString oemPassword = getpass(""); - if (verify) - { - (*outStream) << "Verify password (will not be echoed) :"; - outStream->Flush(); - AString oemPassword2 = getpass(""); - if (oemPassword != oemPassword2) throw "password verification failed"; - } -#else - (*outStream) << "\nEnter password:"; - outStream->Flush(); - AString oemPassword = g_StdIn.ScanStringUntilNewLine(); -#endif -#endif /* USE_FLTK */ - return MultiByteToUnicodeString(oemPassword, CP_OEMCP); -} diff --git a/src/libs/7zip/unix/CPP/7zip/UI/Console/UserInputUtils.h b/src/libs/7zip/unix/CPP/7zip/UI/Console/UserInputUtils.h deleted file mode 100644 index 8c575194d..000000000 --- a/src/libs/7zip/unix/CPP/7zip/UI/Console/UserInputUtils.h +++ /dev/null @@ -1,24 +0,0 @@ -// UserInputUtils.h - -#ifndef __USERINPUTUTILS_H -#define __USERINPUTUTILS_H - -#include "Common/StdOutStream.h" - -namespace NUserAnswerMode { - -enum EEnum -{ - kYes, - kNo, - kYesAll, - kNoAll, - kAutoRenameAll, - kQuit -}; -} - -NUserAnswerMode::EEnum ScanUserYesNoAllQuit(CStdOutStream *outStream); -UString GetPassword(CStdOutStream *outStream,bool verify = false); - -#endif |