chore: initial commit (extracted from Launchers monorepo)
Plugin: ns7zip v2.0.0 Architectures: x86-ansi, x86-unicode, amd64-unicode License: LGPL-2.1-or-later
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
// BenchCon.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "../Common/Bench.h"
|
||||
|
||||
#include "BenchCon.h"
|
||||
#include "ConsoleClose.h"
|
||||
|
||||
struct CPrintBenchCallback Z7_final: public IBenchPrintCallback
|
||||
{
|
||||
FILE *_file;
|
||||
|
||||
void Print(const char *s) Z7_override;
|
||||
void NewLine() Z7_override;
|
||||
HRESULT CheckBreak() Z7_override;
|
||||
};
|
||||
|
||||
void CPrintBenchCallback::Print(const char *s)
|
||||
{
|
||||
fputs(s, _file);
|
||||
}
|
||||
|
||||
void CPrintBenchCallback::NewLine()
|
||||
{
|
||||
fputc('\n', _file);
|
||||
}
|
||||
|
||||
HRESULT CPrintBenchCallback::CheckBreak()
|
||||
{
|
||||
return NConsoleClose::TestBreakSignal() ? E_ABORT: S_OK;
|
||||
}
|
||||
|
||||
HRESULT BenchCon(DECL_EXTERNAL_CODECS_LOC_VARS
|
||||
const CObjectVector<CProperty> &props, UInt32 numIterations, FILE *f)
|
||||
{
|
||||
CPrintBenchCallback callback;
|
||||
callback._file = f;
|
||||
return Bench(EXTERNAL_CODECS_LOC_VARS
|
||||
&callback, NULL, props, numIterations, true);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// BenchCon.h
|
||||
|
||||
#ifndef ZIP7_INC_BENCH_CON_H
|
||||
#define ZIP7_INC_BENCH_CON_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../../Common/CreateCoder.h"
|
||||
#include "../../UI/Common/Property.h"
|
||||
|
||||
HRESULT BenchCon(DECL_EXTERNAL_CODECS_LOC_VARS
|
||||
const CObjectVector<CProperty> &props, UInt32 numIterations, FILE *f);
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,29 @@
|
||||
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "Console"=".\Console.dsp" - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
MY_CONSOLE = 1
|
||||
|
||||
!IFNDEF UNDER_CE
|
||||
CFLAGS = $(CFLAGS) -DZ7_DEVICE_FILE
|
||||
# -DZ7_LONG_PATH -DZ7_LARGE_PAGES
|
||||
!ENDIF
|
||||
|
||||
CONSOLE_OBJS = \
|
||||
$O\BenchCon.obj \
|
||||
$O\ConsoleClose.obj \
|
||||
$O\ExtractCallbackConsole.obj \
|
||||
$O\HashCon.obj \
|
||||
$O\List.obj \
|
||||
$O\Main.obj \
|
||||
$O\MainAr.obj \
|
||||
$O\OpenCallbackConsole.obj \
|
||||
$O\PercentPrinter.obj \
|
||||
$O\UpdateCallbackConsole.obj \
|
||||
$O\UserInputUtils.obj \
|
||||
|
||||
UI_COMMON_OBJS = \
|
||||
$O\ArchiveCommandLine.obj \
|
||||
$O\ArchiveExtractCallback.obj \
|
||||
$O\ArchiveOpenCallback.obj \
|
||||
$O\Bench.obj \
|
||||
$O\DefaultName.obj \
|
||||
$O\EnumDirItems.obj \
|
||||
$O\Extract.obj \
|
||||
$O\ExtractingFilePath.obj \
|
||||
$O\HashCalc.obj \
|
||||
$O\LoadCodecs.obj \
|
||||
$O\OpenArchive.obj \
|
||||
$O\PropIDUtils.obj \
|
||||
$O\SetProperties.obj \
|
||||
$O\SortUtils.obj \
|
||||
$O\TempFiles.obj \
|
||||
$O\Update.obj \
|
||||
$O\UpdateAction.obj \
|
||||
$O\UpdateCallback.obj \
|
||||
$O\UpdatePair.obj \
|
||||
$O\UpdateProduce.obj \
|
||||
|
||||
C_OBJS = $(C_OBJS) \
|
||||
$O\DllSecur.obj \
|
||||
|
||||
# we need empty line after last line above
|
||||
@@ -0,0 +1,16 @@
|
||||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||
<assemblyIdentity version="1.0.0.0" processorArchitecture="*" name="7z" type="win32"></assemblyIdentity>
|
||||
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
|
||||
<security><requestedPrivileges><requestedExecutionLevel level="asInvoker" uiAccess="false">
|
||||
</requestedExecutionLevel></requestedPrivileges></security></trustInfo>
|
||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"><application>
|
||||
<!-- Vista --> <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
|
||||
<!-- Win 7 --> <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
|
||||
<!-- Win 8 --> <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
|
||||
<!-- Win 8.1 --> <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
|
||||
<!-- Win 10 --> <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
|
||||
</application></compatibility>
|
||||
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
|
||||
<ws2:longPathAware>true</ws2:longPathAware></windowsSettings></application>
|
||||
</assembly>
|
||||
@@ -0,0 +1,98 @@
|
||||
// ConsoleClose.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "ConsoleClose.h"
|
||||
|
||||
#ifndef UNDER_CE
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "../../../Common/MyWindows.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
namespace NConsoleClose {
|
||||
|
||||
unsigned g_BreakCounter = 0;
|
||||
static const unsigned kBreakAbortThreshold = 3;
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
static BOOL WINAPI HandlerRoutine(DWORD ctrlType)
|
||||
{
|
||||
if (ctrlType == CTRL_LOGOFF_EVENT)
|
||||
{
|
||||
// printf("\nCTRL_LOGOFF_EVENT\n");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (++g_BreakCounter < kBreakAbortThreshold)
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
/*
|
||||
switch (ctrlType)
|
||||
{
|
||||
case CTRL_C_EVENT:
|
||||
case CTRL_BREAK_EVENT:
|
||||
if (g_BreakCounter < kBreakAbortThreshold)
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
*/
|
||||
}
|
||||
|
||||
CCtrlHandlerSetter::CCtrlHandlerSetter()
|
||||
{
|
||||
if (!SetConsoleCtrlHandler(HandlerRoutine, TRUE))
|
||||
throw 1019; // "SetConsoleCtrlHandler fails";
|
||||
}
|
||||
|
||||
CCtrlHandlerSetter::~CCtrlHandlerSetter()
|
||||
{
|
||||
if (!SetConsoleCtrlHandler(HandlerRoutine, FALSE))
|
||||
{
|
||||
// warning for throw in destructor.
|
||||
// throw "SetConsoleCtrlHandler fails";
|
||||
}
|
||||
}
|
||||
|
||||
#else // _WIN32
|
||||
|
||||
static void HandlerRoutine(int)
|
||||
{
|
||||
if (++g_BreakCounter < kBreakAbortThreshold)
|
||||
return;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
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}
|
||||
}
|
||||
|
||||
#endif // _WIN32
|
||||
|
||||
/*
|
||||
void CheckCtrlBreak()
|
||||
{
|
||||
if (TestBreakSignal())
|
||||
throw CCtrlBreakException();
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,39 @@
|
||||
// ConsoleClose.h
|
||||
|
||||
#ifndef ZIP7_INC_CONSOLE_CLOSE_H
|
||||
#define ZIP7_INC_CONSOLE_CLOSE_H
|
||||
|
||||
namespace NConsoleClose {
|
||||
|
||||
// class CCtrlBreakException {};
|
||||
|
||||
#ifdef UNDER_CE
|
||||
|
||||
inline bool TestBreakSignal() { return false; }
|
||||
struct CCtrlHandlerSetter {};
|
||||
|
||||
#else
|
||||
|
||||
extern unsigned g_BreakCounter;
|
||||
|
||||
inline bool TestBreakSignal()
|
||||
{
|
||||
return (g_BreakCounter != 0);
|
||||
}
|
||||
|
||||
class CCtrlHandlerSetter Z7_final
|
||||
{
|
||||
#ifndef _WIN32
|
||||
void (*memo_sig_int)(int);
|
||||
void (*memo_sig_term)(int);
|
||||
#endif
|
||||
public:
|
||||
CCtrlHandlerSetter();
|
||||
~CCtrlHandlerSetter();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,946 @@
|
||||
// ExtractCallbackConsole.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "../../../Common/IntToString.h"
|
||||
#include "../../../Common/Wildcard.h"
|
||||
|
||||
#include "../../../Windows/FileDir.h"
|
||||
#include "../../../Windows/FileFind.h"
|
||||
#include "../../../Windows/TimeUtils.h"
|
||||
#include "../../../Windows/ErrorMsg.h"
|
||||
#include "../../../Windows/PropVariantConv.h"
|
||||
|
||||
#ifndef Z7_ST
|
||||
#include "../../../Windows/Synchronization.h"
|
||||
#endif
|
||||
|
||||
#include "../../Common/FilePathAutoRename.h"
|
||||
|
||||
#include "../Common/ExtractingFilePath.h"
|
||||
|
||||
#include "ConsoleClose.h"
|
||||
#include "ExtractCallbackConsole.h"
|
||||
#include "UserInputUtils.h"
|
||||
|
||||
using namespace NWindows;
|
||||
using namespace NFile;
|
||||
using namespace NDir;
|
||||
|
||||
static HRESULT CheckBreak2()
|
||||
{
|
||||
return NConsoleClose::TestBreakSignal() ? E_ABORT : S_OK;
|
||||
}
|
||||
|
||||
static const char * const kError = "ERROR: ";
|
||||
|
||||
|
||||
void CExtractScanConsole::StartScanning()
|
||||
{
|
||||
if (NeedPercents())
|
||||
_percent.Command = "Scan";
|
||||
}
|
||||
|
||||
HRESULT CExtractScanConsole::ScanProgress(const CDirItemsStat &st, const FString &path, bool /* isDir */)
|
||||
{
|
||||
if (NeedPercents())
|
||||
{
|
||||
_percent.Files = st.NumDirs + st.NumFiles;
|
||||
_percent.Completed = st.GetTotalBytes();
|
||||
_percent.FileName = fs2us(path);
|
||||
_percent.Print();
|
||||
}
|
||||
|
||||
return CheckBreak2();
|
||||
}
|
||||
|
||||
HRESULT CExtractScanConsole::ScanError(const FString &path, DWORD systemError)
|
||||
{
|
||||
// 22.00:
|
||||
// ScanErrors.AddError(path, systemError);
|
||||
|
||||
ClosePercentsAndFlush();
|
||||
|
||||
if (_se)
|
||||
{
|
||||
*_se << endl << kError << NError::MyFormatMessage(systemError) << endl;
|
||||
_se->NormalizePrint_UString_Path(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];
|
||||
ConvertUInt64ToString(val, temp);
|
||||
s += temp;
|
||||
s.Add_Space();
|
||||
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");
|
||||
|
||||
if (val == 0)
|
||||
return;
|
||||
|
||||
unsigned numBits = 10;
|
||||
char c = 'K';
|
||||
char temp[4] = { 'K', 'i', 'B', 0 };
|
||||
if (val >= ((UInt64)10 << 30)) { numBits = 30; c = 'G'; }
|
||||
else if (val >= ((UInt64)10 << 20)) { numBits = 20; c = 'M'; }
|
||||
temp[0] = c;
|
||||
s += " (";
|
||||
Print_UInt64_and_String(s, ((val + ((UInt64)1 << numBits) - 1) >> numBits), temp);
|
||||
s.Add_Char(')');
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
Print_UInt64_and_String(s, st.NumDirs, st.NumDirs == 1 ? "folder" : "folders");
|
||||
s += ", ";
|
||||
}
|
||||
Print_UInt64_and_String(s, st.NumFiles, st.NumFiles == 1 ? "file" : "files");
|
||||
PrintSize_bytes_Smart_comma(s, st.FilesSize);
|
||||
if (st.NumAltStreams != 0)
|
||||
{
|
||||
s.Add_LF();
|
||||
Print_UInt64_and_String(s, st.NumAltStreams, "alternate streams");
|
||||
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)
|
||||
{
|
||||
AString s;
|
||||
Print_DirItemsStat(s, st);
|
||||
*_so << s << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef Z7_ST
|
||||
static NSynchronization::CCriticalSection g_CriticalSection;
|
||||
#define MT_LOCK NSynchronization::CCriticalSectionLock lock(g_CriticalSection);
|
||||
#else
|
||||
#define MT_LOCK
|
||||
#endif
|
||||
|
||||
|
||||
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 * 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 * const kMemoryExceptionMessage = "Can't allocate required memory!";
|
||||
|
||||
static const char * const kExtracting = "Extracting archive: ";
|
||||
static const char * const kTesting = "Testing archive: ";
|
||||
|
||||
static const char * const kEverythingIsOk = "Everything is Ok";
|
||||
static const char * const kNoFiles = "No files to process";
|
||||
|
||||
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[] =
|
||||
{
|
||||
"Is not archive"
|
||||
, "Headers Error"
|
||||
, "Headers Error in encrypted archive. Wrong password?"
|
||||
, "Unavailable start of archive"
|
||||
, "Unconfirmed start of archive"
|
||||
, "Unexpected end of archive"
|
||||
, "There are data after the end of archive"
|
||||
, "Unsupported method"
|
||||
, "Unsupported feature"
|
||||
, "Data Error"
|
||||
, "CRC Error"
|
||||
};
|
||||
|
||||
Z7_COM7F_IMF(CExtractCallbackConsole::SetTotal(UInt64 size))
|
||||
{
|
||||
MT_LOCK
|
||||
|
||||
if (NeedPercents())
|
||||
{
|
||||
_percent.Total = size;
|
||||
_percent.Print();
|
||||
}
|
||||
return CheckBreak2();
|
||||
}
|
||||
|
||||
Z7_COM7F_IMF(CExtractCallbackConsole::SetCompleted(const UInt64 *completeValue))
|
||||
{
|
||||
MT_LOCK
|
||||
|
||||
if (NeedPercents())
|
||||
{
|
||||
if (completeValue)
|
||||
_percent.Completed = *completeValue;
|
||||
_percent.Print();
|
||||
}
|
||||
return CheckBreak2();
|
||||
}
|
||||
|
||||
static const char * const kTab = " ";
|
||||
|
||||
static void PrintFileInfo(CStdOutStream *_so, const wchar_t *path, const FILETIME *ft, const UInt64 *size)
|
||||
{
|
||||
*_so << kTab << "Path: ";
|
||||
_so->NormalizePrint_wstr_Path(path);
|
||||
*_so << endl;
|
||||
if (size && *size != (UInt64)(Int64)-1)
|
||||
{
|
||||
AString s;
|
||||
PrintSize_bytes_Smart(s, *size);
|
||||
*_so << kTab << "Size: " << s << endl;
|
||||
}
|
||||
if (ft)
|
||||
{
|
||||
char temp[64];
|
||||
if (ConvertUtcFileTimeToString(*ft, temp, kTimestampPrintLevel_SEC))
|
||||
*_so << kTab << "Modified: " << temp << endl;
|
||||
}
|
||||
}
|
||||
|
||||
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))
|
||||
{
|
||||
MT_LOCK
|
||||
|
||||
RINOK(CheckBreak2())
|
||||
|
||||
ClosePercentsAndFlush();
|
||||
|
||||
if (_so)
|
||||
{
|
||||
*_so << endl << "Would you like to replace the existing file:\n";
|
||||
PrintFileInfo(_so, existName, existTime, existSize);
|
||||
*_so << "with the file from archive:\n";
|
||||
PrintFileInfo(_so, newName, newTime, newSize);
|
||||
}
|
||||
|
||||
NUserAnswerMode::EEnum overwriteAnswer = ScanUserYesNoAllQuit(_so);
|
||||
|
||||
switch ((int)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;
|
||||
case NUserAnswerMode::kEof: return E_ABORT;
|
||||
case NUserAnswerMode::kError: return E_FAIL;
|
||||
default: return E_FAIL;
|
||||
}
|
||||
|
||||
if (_so)
|
||||
{
|
||||
*_so << endl;
|
||||
if (NeedFlush)
|
||||
_so->Flush();
|
||||
}
|
||||
|
||||
return CheckBreak2();
|
||||
}
|
||||
|
||||
Z7_COM7F_IMF(CExtractCallbackConsole::PrepareOperation(const wchar_t *name, Int32 isFolder, Int32 askExtractMode, const UInt64 *position))
|
||||
{
|
||||
MT_LOCK
|
||||
|
||||
_currentName = name;
|
||||
|
||||
const char *s;
|
||||
unsigned requiredLevel = 1;
|
||||
|
||||
switch (askExtractMode)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
const bool show2 = (LogLevel >= requiredLevel && _so);
|
||||
|
||||
if (show2)
|
||||
{
|
||||
ClosePercents_for_so();
|
||||
|
||||
_tempA = s;
|
||||
if (name)
|
||||
_tempA.Add_Space();
|
||||
*_so << _tempA;
|
||||
|
||||
_tempU.Empty();
|
||||
if (name)
|
||||
{
|
||||
_tempU = name;
|
||||
_so->Normalize_UString_Path(_tempU);
|
||||
// 21.04
|
||||
if (isFolder)
|
||||
{
|
||||
if (!_tempU.IsEmpty() && _tempU.Back() != WCHAR_PATH_SEPARATOR)
|
||||
_tempU.Add_PathSepar();
|
||||
}
|
||||
}
|
||||
_so->PrintUString(_tempU, _tempA);
|
||||
if (position)
|
||||
*_so << " <" << *position << ">";
|
||||
*_so << endl;
|
||||
|
||||
if (NeedFlush)
|
||||
_so->Flush();
|
||||
// _so->Flush(); // for debug only
|
||||
}
|
||||
|
||||
if (NeedPercents())
|
||||
{
|
||||
if (PercentsNameLevel >= 1)
|
||||
{
|
||||
_percent.FileName.Empty();
|
||||
_percent.Command.Empty();
|
||||
if (PercentsNameLevel > 1 || !show2)
|
||||
{
|
||||
_percent.Command = s;
|
||||
if (name)
|
||||
_percent.FileName = name;
|
||||
}
|
||||
}
|
||||
_percent.Print();
|
||||
}
|
||||
|
||||
return CheckBreak2();
|
||||
}
|
||||
|
||||
Z7_COM7F_IMF(CExtractCallbackConsole::MessageError(const wchar_t *message))
|
||||
{
|
||||
MT_LOCK
|
||||
|
||||
RINOK(CheckBreak2())
|
||||
|
||||
NumFileErrors_in_Current++;
|
||||
NumFileErrors++;
|
||||
|
||||
ClosePercentsAndFlush();
|
||||
if (_se)
|
||||
{
|
||||
*_se << kError << message << endl;
|
||||
_se->Flush();
|
||||
}
|
||||
|
||||
return CheckBreak2();
|
||||
}
|
||||
|
||||
void SetExtractErrorMessage(Int32 opRes, Int32 encrypted, AString &dest);
|
||||
void SetExtractErrorMessage(Int32 opRes, Int32 encrypted, AString &dest)
|
||||
{
|
||||
dest.Empty();
|
||||
const char *s = NULL;
|
||||
|
||||
switch (opRes)
|
||||
{
|
||||
case NArchive::NExtract::NOperationResult::kUnsupportedMethod:
|
||||
s = kUnsupportedMethod;
|
||||
break;
|
||||
case NArchive::NExtract::NOperationResult::kCRCError:
|
||||
s = (encrypted ? kCrcFailedEncrypted : kCrcFailed);
|
||||
break;
|
||||
case NArchive::NExtract::NOperationResult::kDataError:
|
||||
s = (encrypted ? kDataErrorEncrypted : kDataError);
|
||||
break;
|
||||
case NArchive::NExtract::NOperationResult::kUnavailable:
|
||||
s = kUnavailableData;
|
||||
break;
|
||||
case NArchive::NExtract::NOperationResult::kUnexpectedEnd:
|
||||
s = kUnexpectedEnd;
|
||||
break;
|
||||
case NArchive::NExtract::NOperationResult::kDataAfterEnd:
|
||||
s = kDataAfterEnd;
|
||||
break;
|
||||
case NArchive::NExtract::NOperationResult::kIsNotArc:
|
||||
s = kIsNotArc;
|
||||
break;
|
||||
case NArchive::NExtract::NOperationResult::kHeadersError:
|
||||
s = kHeadersError;
|
||||
break;
|
||||
case NArchive::NExtract::NOperationResult::kWrongPassword:
|
||||
s = kWrongPassword;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
dest += kError;
|
||||
if (s)
|
||||
dest += s;
|
||||
else
|
||||
{
|
||||
dest += "Error #";
|
||||
dest.Add_UInt32((UInt32)opRes);
|
||||
}
|
||||
}
|
||||
|
||||
Z7_COM7F_IMF(CExtractCallbackConsole::SetOperationResult(Int32 opRes, Int32 encrypted))
|
||||
{
|
||||
MT_LOCK
|
||||
|
||||
if (opRes == NArchive::NExtract::NOperationResult::kOK)
|
||||
{
|
||||
if (NeedPercents())
|
||||
{
|
||||
_percent.Command.Empty();
|
||||
_percent.FileName.Empty();
|
||||
_percent.Files++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NumFileErrors_in_Current++;
|
||||
NumFileErrors++;
|
||||
|
||||
if (_se)
|
||||
{
|
||||
ClosePercentsAndFlush();
|
||||
|
||||
AString s;
|
||||
SetExtractErrorMessage(opRes, encrypted, s);
|
||||
|
||||
*_se << s;
|
||||
if (!_currentName.IsEmpty())
|
||||
{
|
||||
*_se << " : ";
|
||||
_se->NormalizePrint_UString_Path(_currentName);
|
||||
}
|
||||
*_se << endl;
|
||||
_se->Flush();
|
||||
}
|
||||
}
|
||||
|
||||
return CheckBreak2();
|
||||
}
|
||||
|
||||
Z7_COM7F_IMF(CExtractCallbackConsole::ReportExtractResult(Int32 opRes, Int32 encrypted, const wchar_t *name))
|
||||
{
|
||||
if (opRes != NArchive::NExtract::NOperationResult::kOK)
|
||||
{
|
||||
_currentName = name;
|
||||
return SetOperationResult(opRes, encrypted);
|
||||
}
|
||||
|
||||
return CheckBreak2();
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifndef Z7_NO_CRYPTO
|
||||
|
||||
HRESULT CExtractCallbackConsole::SetPassword(const UString &password)
|
||||
{
|
||||
PasswordIsDefined = true;
|
||||
Password = password;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
Z7_COM7F_IMF(CExtractCallbackConsole::CryptoGetTextPassword(BSTR *password))
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
MT_LOCK
|
||||
return Open_CryptoGetTextPassword(password);
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef Z7_SFX
|
||||
|
||||
void CExtractCallbackConsole::PrintTo_se_Path_WithTitle(const UString &path, const char *title)
|
||||
{
|
||||
*_se << title;
|
||||
_se->NormalizePrint_UString_Path(path);
|
||||
*_se << endl;
|
||||
}
|
||||
|
||||
void CExtractCallbackConsole::Add_ArchiveName_Error()
|
||||
{
|
||||
if (_needWriteArchivePath)
|
||||
{
|
||||
PrintTo_se_Path_WithTitle(_currentArchivePath, "Archive: ");
|
||||
_needWriteArchivePath = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Z7_COM7F_IMF(CExtractCallbackConsole::RequestMemoryUse(
|
||||
UInt32 flags, UInt32 /* indexType */, UInt32 /* index */, const wchar_t *path,
|
||||
UInt64 requiredSize, UInt64 *allowedSize, UInt32 *answerFlags))
|
||||
{
|
||||
if ((flags & NRequestMemoryUseFlags::k_IsReport) == 0
|
||||
&& requiredSize <= *allowedSize)
|
||||
{
|
||||
#if 0
|
||||
// it's expected, that *answerFlags was set to NRequestMemoryAnswerFlags::k_Allow already,
|
||||
// because it's default answer for (requiredSize <= *allowedSize) case.
|
||||
// optional code:
|
||||
*answerFlags = NRequestMemoryAnswerFlags::k_Allow;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((flags & NRequestMemoryUseFlags::k_NoErrorMessage) == 0)
|
||||
if (_se)
|
||||
{
|
||||
const UInt64 num_GB_allowed = (*allowedSize + ((1u << 30) - 1)) >> 30;
|
||||
const UInt64 num_GB_required = (requiredSize + ((1u << 30) - 1)) >> 30;
|
||||
ClosePercentsAndFlush();
|
||||
Add_ArchiveName_Error();
|
||||
if (path)
|
||||
PrintTo_se_Path_WithTitle(path, "File: ");
|
||||
*_se << "The extraction operation requires big amount memory (RAM):" << endl
|
||||
<< " " << num_GB_required << " GB : required memory usage size" << endl
|
||||
<< " " << num_GB_allowed << " GB : allowed memory usage limit" << endl
|
||||
<< " Use -smemx{size}g switch to set allowed memory usage limit for extraction." << endl;
|
||||
*_se << "ERROR: Memory usage limit was exceeded." << endl;
|
||||
const char *m = NULL;
|
||||
// if (indexType == NArchive::NEventIndexType::kNoIndex)
|
||||
if ((flags & NRequestMemoryUseFlags::k_SkipArc_IsExpected) ||
|
||||
(flags & NRequestMemoryUseFlags::k_Report_SkipArc))
|
||||
m = "Archive unpacking was skipped.";
|
||||
/*
|
||||
else if ((flags & NRequestMemoryUseFlags::k_SkipBigFiles_IsExpected) ||
|
||||
(flags & NRequestMemoryUseFlags::k_Report_SkipBigFiles))
|
||||
m = "Extraction for some files will be skipped.";
|
||||
else if ((flags & NRequestMemoryUseFlags::k_SkipBigFile_IsExpected) ||
|
||||
(flags & NRequestMemoryUseFlags::k_Report_SkipBigFile))
|
||||
m = "File extraction was skipped.";
|
||||
*/
|
||||
if (m)
|
||||
*_se << m;
|
||||
_se->Flush();
|
||||
}
|
||||
|
||||
if ((flags & NRequestMemoryUseFlags::k_IsReport) == 0)
|
||||
{
|
||||
// default answer can be k_Allow, if limit was not forced,
|
||||
// so we change answer to non-allowed here.
|
||||
*answerFlags = NRequestMemoryAnswerFlags::k_Limit_Exceeded;
|
||||
if (flags & NRequestMemoryUseFlags::k_SkipArc_IsExpected)
|
||||
*answerFlags |= NRequestMemoryAnswerFlags::k_SkipArc;
|
||||
/*
|
||||
else if (flags & NRequestMemoryUseFlags::k_SkipBigFile_IsExpected)
|
||||
*answerFlags |= NRequestMemoryAnswerFlags::k_SkipBigFile;
|
||||
else if (flags & NRequestMemoryUseFlags::k_SkipBigFiles_IsExpected)
|
||||
*answerFlags |= NRequestMemoryAnswerFlags::k_SkipBigFiles;
|
||||
*/
|
||||
}
|
||||
}
|
||||
return CheckBreak2();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
HRESULT CExtractCallbackConsole::BeforeOpen(const wchar_t *name, bool testMode)
|
||||
{
|
||||
_currentArchivePath = name;
|
||||
_needWriteArchivePath = true;
|
||||
|
||||
RINOK(CheckBreak2())
|
||||
|
||||
NumTryArcs++;
|
||||
ThereIsError_in_Current = false;
|
||||
ThereIsWarning_in_Current = false;
|
||||
NumFileErrors_in_Current = 0;
|
||||
|
||||
ClosePercents_for_so();
|
||||
if (_so)
|
||||
{
|
||||
*_so << endl << (testMode ? kTesting : kExtracting);
|
||||
_so->NormalizePrint_wstr_Path(name);
|
||||
*_so << endl;
|
||||
}
|
||||
|
||||
if (NeedPercents())
|
||||
_percent.Command = "Open";
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT Print_OpenArchive_Props(CStdOutStream &so, const CCodecs *codecs, const CArchiveLink &arcLink);
|
||||
HRESULT Print_OpenArchive_Error(CStdOutStream &so, const CCodecs *codecs, const CArchiveLink &arcLink);
|
||||
|
||||
static AString GetOpenArcErrorMessage(UInt32 errorFlags)
|
||||
{
|
||||
AString s;
|
||||
|
||||
for (unsigned i = 0; i < Z7_ARRAY_SIZE(k_ErrorFlagsMessages); i++)
|
||||
{
|
||||
UInt32 f = (1 << i);
|
||||
if ((errorFlags & f) == 0)
|
||||
continue;
|
||||
const char *m = k_ErrorFlagsMessages[i];
|
||||
if (!s.IsEmpty())
|
||||
s.Add_LF();
|
||||
s += m;
|
||||
errorFlags &= ~f;
|
||||
}
|
||||
|
||||
if (errorFlags != 0)
|
||||
{
|
||||
char sz[16];
|
||||
sz[0] = '0';
|
||||
sz[1] = 'x';
|
||||
ConvertUInt32ToHex(errorFlags, sz + 2);
|
||||
if (!s.IsEmpty())
|
||||
s.Add_LF();
|
||||
s += sz;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
void PrintErrorFlags(CStdOutStream &so, const char *s, UInt32 errorFlags);
|
||||
void PrintErrorFlags(CStdOutStream &so, const char *s, UInt32 errorFlags)
|
||||
{
|
||||
if (errorFlags == 0)
|
||||
return;
|
||||
so << s << endl << GetOpenArcErrorMessage(errorFlags) << endl;
|
||||
}
|
||||
|
||||
static void Add_Messsage_Pre_ArcType(UString &s, const char *pre, const wchar_t *arcType)
|
||||
{
|
||||
s.Add_LF();
|
||||
s += pre;
|
||||
s += " as [";
|
||||
s += arcType;
|
||||
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;
|
||||
|
||||
*_so << "WARNING:\n";
|
||||
_so->NormalizePrint_UString_Path(arc.Path);
|
||||
UString s;
|
||||
if (arc.FormatIndex == er.ErrorFormatIndex)
|
||||
{
|
||||
s.Add_LF();
|
||||
s += "The archive is open with offset";
|
||||
}
|
||||
else
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
*_so << s << endl << endl;
|
||||
}
|
||||
|
||||
|
||||
HRESULT CExtractCallbackConsole::OpenResult(
|
||||
const CCodecs *codecs, const CArchiveLink &arcLink,
|
||||
const wchar_t *name, HRESULT result)
|
||||
{
|
||||
_currentArchivePath = name;
|
||||
_needWriteArchivePath = true;
|
||||
|
||||
ClosePercents();
|
||||
|
||||
if (NeedPercents())
|
||||
{
|
||||
_percent.Files = 0;
|
||||
_percent.Command.Empty();
|
||||
_percent.FileName.Empty();
|
||||
}
|
||||
|
||||
|
||||
ClosePercentsAndFlush();
|
||||
|
||||
FOR_VECTOR (level, arcLink.Arcs)
|
||||
{
|
||||
const CArc &arc = arcLink.Arcs[level];
|
||||
const CArcErrorInfo &er = arc.ErrorInfo;
|
||||
|
||||
UInt32 errorFlags = er.GetErrorFlags();
|
||||
|
||||
if (errorFlags != 0 || !er.ErrorMessage.IsEmpty())
|
||||
{
|
||||
if (_se)
|
||||
{
|
||||
*_se << endl;
|
||||
if (level != 0)
|
||||
{
|
||||
_se->NormalizePrint_UString_Path(arc.Path);
|
||||
*_se << endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (errorFlags != 0)
|
||||
{
|
||||
if (_se)
|
||||
PrintErrorFlags(*_se, "ERRORS:", errorFlags);
|
||||
NumOpenArcErrors++;
|
||||
ThereIsError_in_Current = true;
|
||||
}
|
||||
|
||||
if (!er.ErrorMessage.IsEmpty())
|
||||
{
|
||||
if (_se)
|
||||
*_se << "ERRORS:" << endl << er.ErrorMessage << endl;
|
||||
NumOpenArcErrors++;
|
||||
ThereIsError_in_Current = true;
|
||||
}
|
||||
|
||||
if (_se)
|
||||
{
|
||||
*_se << endl;
|
||||
_se->Flush();
|
||||
}
|
||||
}
|
||||
|
||||
UInt32 warningFlags = er.GetWarningFlags();
|
||||
|
||||
if (warningFlags != 0 || !er.WarningMessage.IsEmpty())
|
||||
{
|
||||
if (_so)
|
||||
{
|
||||
*_so << endl;
|
||||
if (level != 0)
|
||||
{
|
||||
_so->NormalizePrint_UString_Path(arc.Path);
|
||||
*_so << endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (warningFlags != 0)
|
||||
{
|
||||
if (_so)
|
||||
PrintErrorFlags(*_so, "WARNINGS:", warningFlags);
|
||||
NumOpenArcWarnings++;
|
||||
ThereIsWarning_in_Current = true;
|
||||
}
|
||||
|
||||
if (!er.WarningMessage.IsEmpty())
|
||||
{
|
||||
if (_so)
|
||||
*_so << "WARNINGS:" << endl << er.WarningMessage << endl;
|
||||
NumOpenArcWarnings++;
|
||||
ThereIsWarning_in_Current = true;
|
||||
}
|
||||
|
||||
if (_so)
|
||||
{
|
||||
*_so << endl;
|
||||
if (NeedFlush)
|
||||
_so->Flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (er.ErrorFormatIndex >= 0)
|
||||
{
|
||||
if (_so)
|
||||
{
|
||||
Print_ErrorFormatIndex_Warning(_so, codecs, arc);
|
||||
if (NeedFlush)
|
||||
_so->Flush();
|
||||
}
|
||||
ThereIsWarning_in_Current = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (result == S_OK)
|
||||
{
|
||||
if (_so)
|
||||
{
|
||||
RINOK(Print_OpenArchive_Props(*_so, codecs, arcLink))
|
||||
*_so << endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NumCantOpenArcs++;
|
||||
if (_so)
|
||||
_so->Flush();
|
||||
if (_se)
|
||||
{
|
||||
*_se << kError;
|
||||
_se->NormalizePrint_wstr_Path(name);
|
||||
*_se << endl;
|
||||
const HRESULT res = Print_OpenArchive_Error(*_se, codecs, arcLink);
|
||||
RINOK(res)
|
||||
if (result == S_FALSE)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
if (result == E_OUTOFMEMORY)
|
||||
*_se << "Can't allocate required memory";
|
||||
else
|
||||
*_se << NError::MyFormatMessage(result);
|
||||
*_se << endl;
|
||||
}
|
||||
_se->Flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return CheckBreak2();
|
||||
}
|
||||
|
||||
HRESULT CExtractCallbackConsole::ThereAreNoFiles()
|
||||
{
|
||||
ClosePercents_for_so();
|
||||
|
||||
if (_so)
|
||||
{
|
||||
*_so << endl << kNoFiles << endl;
|
||||
if (NeedFlush)
|
||||
_so->Flush();
|
||||
}
|
||||
return CheckBreak2();
|
||||
}
|
||||
|
||||
HRESULT CExtractCallbackConsole::ExtractResult(HRESULT result)
|
||||
{
|
||||
MT_LOCK
|
||||
|
||||
if (NeedPercents())
|
||||
{
|
||||
_percent.ClosePrint(true);
|
||||
_percent.Command.Empty();
|
||||
_percent.FileName.Empty();
|
||||
}
|
||||
|
||||
if (_so)
|
||||
_so->Flush();
|
||||
|
||||
if (result == S_OK)
|
||||
{
|
||||
if (NumFileErrors_in_Current == 0 && !ThereIsError_in_Current)
|
||||
{
|
||||
if (ThereIsWarning_in_Current)
|
||||
NumArcsWithWarnings++;
|
||||
else
|
||||
NumOkArcs++;
|
||||
if (_so)
|
||||
*_so << kEverythingIsOk << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
NumArcsWithError++;
|
||||
if (_so)
|
||||
{
|
||||
*_so << endl;
|
||||
if (NumFileErrors_in_Current != 0)
|
||||
*_so << "Sub items Errors: " << NumFileErrors_in_Current << endl;
|
||||
}
|
||||
}
|
||||
if (_so && NeedFlush)
|
||||
_so->Flush();
|
||||
}
|
||||
else
|
||||
{
|
||||
// we don't update NumArcsWithError, if error is not related to archive data.
|
||||
if (result == E_ABORT
|
||||
|| result == HRESULT_FROM_WIN32(ERROR_DISK_FULL))
|
||||
return result;
|
||||
NumArcsWithError++;
|
||||
|
||||
if (_se)
|
||||
{
|
||||
*_se << endl << kError;
|
||||
if (result == E_OUTOFMEMORY)
|
||||
*_se << kMemoryExceptionMessage;
|
||||
else
|
||||
*_se << NError::MyFormatMessage(result);
|
||||
*_se << endl;
|
||||
_se->Flush();
|
||||
}
|
||||
}
|
||||
|
||||
return CheckBreak2();
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
// ExtractCallbackConsole.h
|
||||
|
||||
#ifndef ZIP7_INC_EXTRACT_CALLBACK_CONSOLE_H
|
||||
#define ZIP7_INC_EXTRACT_CALLBACK_CONSOLE_H
|
||||
|
||||
#include "../../../Common/StdOutStream.h"
|
||||
|
||||
#include "../../IPassword.h"
|
||||
|
||||
#include "../../Archive/IArchive.h"
|
||||
|
||||
#include "../Common/ArchiveExtractCallback.h"
|
||||
|
||||
#include "PercentPrinter.h"
|
||||
|
||||
#include "OpenCallbackConsole.h"
|
||||
|
||||
/*
|
||||
struct CErrorPathCodes2
|
||||
{
|
||||
FStringVector Paths;
|
||||
CRecordVector<DWORD> Codes;
|
||||
|
||||
void AddError(const FString &path, DWORD systemError)
|
||||
{
|
||||
Paths.Add(path);
|
||||
Codes.Add(systemError);
|
||||
}
|
||||
void Clear()
|
||||
{
|
||||
Paths.Clear();
|
||||
Codes.Clear();
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
||||
class CExtractScanConsole Z7_final: public IDirItemsCallback
|
||||
{
|
||||
Z7_IFACE_IMP(IDirItemsCallback)
|
||||
|
||||
CStdOutStream *_so;
|
||||
CStdOutStream *_se;
|
||||
CPercentPrinter _percent;
|
||||
|
||||
// CErrorPathCodes2 ScanErrors;
|
||||
|
||||
bool NeedPercents() const { return _percent._so && !_percent.DisablePrint; }
|
||||
|
||||
void ClosePercentsAndFlush()
|
||||
{
|
||||
if (NeedPercents())
|
||||
_percent.ClosePrint(true);
|
||||
if (_so)
|
||||
_so->Flush();
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
void Init(
|
||||
CStdOutStream *outStream,
|
||||
CStdOutStream *errorStream,
|
||||
CStdOutStream *percentStream,
|
||||
bool disablePercents)
|
||||
{
|
||||
_so = outStream;
|
||||
_se = errorStream;
|
||||
_percent._so = percentStream;
|
||||
_percent.DisablePrint = disablePercents;
|
||||
}
|
||||
|
||||
void SetWindowWidth(unsigned width) { _percent.MaxLen = width - 1; }
|
||||
|
||||
void StartScanning();
|
||||
|
||||
void CloseScanning()
|
||||
{
|
||||
if (NeedPercents())
|
||||
_percent.ClosePrint(true);
|
||||
}
|
||||
|
||||
void PrintStat(const CDirItemsStat &st);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class CExtractCallbackConsole Z7_final:
|
||||
public IFolderArchiveExtractCallback,
|
||||
public IExtractCallbackUI,
|
||||
// public IArchiveExtractCallbackMessage,
|
||||
public IFolderArchiveExtractCallback2,
|
||||
#ifndef Z7_NO_CRYPTO
|
||||
public ICryptoGetTextPassword,
|
||||
#endif
|
||||
#ifndef Z7_SFX
|
||||
public IArchiveRequestMemoryUseCallback,
|
||||
#endif
|
||||
|
||||
public COpenCallbackConsole,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
Z7_COM_QI_BEGIN2(IFolderArchiveExtractCallback)
|
||||
// Z7_COM_QI_ENTRY(IArchiveExtractCallbackMessage)
|
||||
Z7_COM_QI_ENTRY(IFolderArchiveExtractCallback2)
|
||||
#ifndef Z7_NO_CRYPTO
|
||||
Z7_COM_QI_ENTRY(ICryptoGetTextPassword)
|
||||
#endif
|
||||
#ifndef Z7_SFX
|
||||
Z7_COM_QI_ENTRY(IArchiveRequestMemoryUseCallback)
|
||||
#endif
|
||||
|
||||
Z7_COM_QI_END
|
||||
Z7_COM_ADDREF_RELEASE
|
||||
|
||||
Z7_IFACE_COM7_IMP(IProgress)
|
||||
Z7_IFACE_COM7_IMP(IFolderArchiveExtractCallback)
|
||||
Z7_IFACE_IMP(IExtractCallbackUI)
|
||||
// Z7_IFACE_COM7_IMP(IArchiveExtractCallbackMessage)
|
||||
Z7_IFACE_COM7_IMP(IFolderArchiveExtractCallback2)
|
||||
#ifndef Z7_NO_CRYPTO
|
||||
Z7_IFACE_COM7_IMP(ICryptoGetTextPassword)
|
||||
#endif
|
||||
#ifndef Z7_SFX
|
||||
Z7_IFACE_COM7_IMP(IArchiveRequestMemoryUseCallback)
|
||||
#endif
|
||||
|
||||
bool _needWriteArchivePath;
|
||||
|
||||
public:
|
||||
bool ThereIsError_in_Current;
|
||||
bool ThereIsWarning_in_Current;
|
||||
bool NeedFlush;
|
||||
|
||||
private:
|
||||
AString _tempA;
|
||||
UString _tempU;
|
||||
|
||||
UString _currentArchivePath;
|
||||
UString _currentName;
|
||||
|
||||
#ifndef Z7_SFX
|
||||
void PrintTo_se_Path_WithTitle(const UString &path, const char *title);
|
||||
void Add_ArchiveName_Error();
|
||||
#endif
|
||||
|
||||
void ClosePercents_for_so()
|
||||
{
|
||||
if (NeedPercents() && _so == _percent._so)
|
||||
_percent.ClosePrint(false);
|
||||
}
|
||||
|
||||
void ClosePercentsAndFlush()
|
||||
{
|
||||
if (NeedPercents())
|
||||
_percent.ClosePrint(true);
|
||||
if (_so)
|
||||
_so->Flush();
|
||||
}
|
||||
public:
|
||||
UInt64 NumTryArcs;
|
||||
|
||||
UInt64 NumOkArcs;
|
||||
UInt64 NumCantOpenArcs;
|
||||
UInt64 NumArcsWithError;
|
||||
UInt64 NumArcsWithWarnings;
|
||||
|
||||
UInt64 NumOpenArcErrors;
|
||||
UInt64 NumOpenArcWarnings;
|
||||
|
||||
UInt64 NumFileErrors;
|
||||
UInt64 NumFileErrors_in_Current;
|
||||
|
||||
unsigned PercentsNameLevel;
|
||||
unsigned LogLevel;
|
||||
|
||||
CExtractCallbackConsole():
|
||||
_needWriteArchivePath(true),
|
||||
NeedFlush(false),
|
||||
PercentsNameLevel(1),
|
||||
LogLevel(0)
|
||||
{}
|
||||
|
||||
void SetWindowWidth(unsigned width) { _percent.MaxLen = width - 1; }
|
||||
|
||||
void Init(
|
||||
CStdOutStream *outStream,
|
||||
CStdOutStream *errorStream,
|
||||
CStdOutStream *percentStream,
|
||||
bool disablePercents)
|
||||
{
|
||||
COpenCallbackConsole::Init(outStream, errorStream, percentStream, disablePercents);
|
||||
|
||||
NumTryArcs = 0;
|
||||
|
||||
ThereIsError_in_Current = false;
|
||||
ThereIsWarning_in_Current = false;
|
||||
|
||||
NumOkArcs = 0;
|
||||
NumCantOpenArcs = 0;
|
||||
NumArcsWithError = 0;
|
||||
NumArcsWithWarnings = 0;
|
||||
|
||||
NumOpenArcErrors = 0;
|
||||
NumOpenArcWarnings = 0;
|
||||
|
||||
NumFileErrors = 0;
|
||||
NumFileErrors_in_Current = 0;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,426 @@
|
||||
// HashCon.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "../../../Common/IntToString.h"
|
||||
|
||||
#include "../../../Windows/FileName.h"
|
||||
|
||||
#include "ConsoleClose.h"
|
||||
#include "HashCon.h"
|
||||
|
||||
static const char * const kEmptyFileAlias = "[Content]";
|
||||
|
||||
static const char * const kScanningMessage = "Scanning";
|
||||
|
||||
static HRESULT CheckBreak2()
|
||||
{
|
||||
return NConsoleClose::TestBreakSignal() ? E_ABORT : S_OK;
|
||||
}
|
||||
|
||||
HRESULT CHashCallbackConsole::CheckBreak()
|
||||
{
|
||||
return CheckBreak2();
|
||||
}
|
||||
|
||||
HRESULT CHashCallbackConsole::StartScanning()
|
||||
{
|
||||
if (PrintHeaders && _so)
|
||||
*_so << kScanningMessage << endl;
|
||||
if (NeedPercents())
|
||||
{
|
||||
_percent.ClearCurState();
|
||||
_percent.Command = "Scan";
|
||||
}
|
||||
return CheckBreak2();
|
||||
}
|
||||
|
||||
HRESULT CHashCallbackConsole::ScanProgress(const CDirItemsStat &st, const FString &path, bool isDir)
|
||||
{
|
||||
if (NeedPercents())
|
||||
{
|
||||
_percent.Files = st.NumDirs + st.NumFiles + st.NumAltStreams;
|
||||
_percent.Completed = st.GetTotalBytes();
|
||||
_percent.FileName = fs2us(path);
|
||||
if (isDir)
|
||||
NWindows::NFile::NName::NormalizeDirPathPrefix(_percent.FileName);
|
||||
_percent.Print();
|
||||
}
|
||||
return CheckBreak2();
|
||||
}
|
||||
|
||||
HRESULT CHashCallbackConsole::ScanError(const FString &path, DWORD systemError)
|
||||
{
|
||||
return ScanError_Base(path, systemError);
|
||||
}
|
||||
|
||||
void Print_DirItemsStat(AString &s, const CDirItemsStat &st);
|
||||
|
||||
HRESULT CHashCallbackConsole::FinishScanning(const CDirItemsStat &st)
|
||||
{
|
||||
if (NeedPercents())
|
||||
{
|
||||
_percent.ClosePrint(true);
|
||||
_percent.ClearCurState();
|
||||
}
|
||||
if (PrintHeaders && _so)
|
||||
{
|
||||
Print_DirItemsStat(_s, st);
|
||||
*_so << _s << endl << endl;
|
||||
}
|
||||
return CheckBreak2();
|
||||
}
|
||||
|
||||
HRESULT CHashCallbackConsole::SetNumFiles(UInt64 /* numFiles */)
|
||||
{
|
||||
return CheckBreak2();
|
||||
}
|
||||
|
||||
HRESULT CHashCallbackConsole::SetTotal(UInt64 size)
|
||||
{
|
||||
if (NeedPercents())
|
||||
{
|
||||
_percent.Total = size;
|
||||
_percent.Print();
|
||||
}
|
||||
return CheckBreak2();
|
||||
}
|
||||
|
||||
HRESULT CHashCallbackConsole::SetCompleted(const UInt64 *completeValue)
|
||||
{
|
||||
if (completeValue && NeedPercents())
|
||||
{
|
||||
_percent.Completed = *completeValue;
|
||||
_percent.Print();
|
||||
}
|
||||
return CheckBreak2();
|
||||
}
|
||||
|
||||
static void AddMinuses(AString &s, unsigned num)
|
||||
{
|
||||
for (unsigned i = 0; i < num; i++)
|
||||
s.Add_Minus();
|
||||
}
|
||||
|
||||
static void AddSpaces_if_Positive(AString &s, int num)
|
||||
{
|
||||
for (int i = 0; i < num; i++)
|
||||
s.Add_Space();
|
||||
}
|
||||
|
||||
static void SetSpacesAndNul(char *s, unsigned num)
|
||||
{
|
||||
for (unsigned i = 0; i < num; i++)
|
||||
s[i] = ' ';
|
||||
s[num] = 0;
|
||||
}
|
||||
|
||||
static void SetSpacesAndNul_if_Positive(char *s, int num)
|
||||
{
|
||||
if (num < 0)
|
||||
return;
|
||||
for (int i = 0; i < num; i++)
|
||||
s[i] = ' ';
|
||||
s[num] = 0;
|
||||
}
|
||||
|
||||
static const unsigned kSizeField_Len = 13;
|
||||
static const unsigned kNameField_Len = 12;
|
||||
|
||||
static const unsigned kHashColumnWidth_Min = 4 * 2;
|
||||
|
||||
static unsigned GetColumnWidth(unsigned digestSize)
|
||||
{
|
||||
unsigned width = digestSize * 2;
|
||||
return width < kHashColumnWidth_Min ? kHashColumnWidth_Min: width;
|
||||
}
|
||||
|
||||
|
||||
AString CHashCallbackConsole::GetFields() const
|
||||
{
|
||||
AString s (PrintFields);
|
||||
if (s.IsEmpty())
|
||||
s = "hsn";
|
||||
s.MakeLower_Ascii();
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
void CHashCallbackConsole::PrintSeparatorLine(const CObjectVector<CHasherState> &hashers)
|
||||
{
|
||||
_s.Empty();
|
||||
const AString fields = GetFields();
|
||||
for (unsigned pos = 0; pos < fields.Len(); pos++)
|
||||
{
|
||||
const char c = fields[pos];
|
||||
if (c == 'h')
|
||||
{
|
||||
for (unsigned i = 0; i < hashers.Size(); i++)
|
||||
{
|
||||
AddSpace();
|
||||
const CHasherState &h = hashers[i];
|
||||
AddMinuses(_s, GetColumnWidth(h.DigestSize));
|
||||
}
|
||||
}
|
||||
else if (c == 's')
|
||||
{
|
||||
AddSpace();
|
||||
AddMinuses(_s, kSizeField_Len);
|
||||
}
|
||||
else if (c == 'n')
|
||||
{
|
||||
AddSpacesBeforeName();
|
||||
AddMinuses(_s, kNameField_Len);
|
||||
}
|
||||
}
|
||||
|
||||
*_so << _s << endl;
|
||||
}
|
||||
|
||||
|
||||
HRESULT CHashCallbackConsole::BeforeFirstFile(const CHashBundle &hb)
|
||||
{
|
||||
if (PrintHeaders && _so)
|
||||
{
|
||||
_s.Empty();
|
||||
ClosePercents_for_so();
|
||||
|
||||
const AString fields = GetFields();
|
||||
for (unsigned pos = 0; pos < fields.Len(); pos++)
|
||||
{
|
||||
const char c = fields[pos];
|
||||
if (c == 'h')
|
||||
{
|
||||
FOR_VECTOR (i, hb.Hashers)
|
||||
{
|
||||
AddSpace();
|
||||
const CHasherState &h = hb.Hashers[i];
|
||||
_s += h.Name;
|
||||
AddSpaces_if_Positive(_s, (int)GetColumnWidth(h.DigestSize) - (int)h.Name.Len());
|
||||
}
|
||||
}
|
||||
|
||||
else if (c == 's')
|
||||
{
|
||||
AddSpace();
|
||||
const AString s2 ("Size");
|
||||
AddSpaces_if_Positive(_s, (int)kSizeField_Len - (int)s2.Len());
|
||||
_s += s2;
|
||||
}
|
||||
else if (c == 'n')
|
||||
{
|
||||
AddSpacesBeforeName();
|
||||
_s += "Name";
|
||||
}
|
||||
}
|
||||
|
||||
*_so << _s << endl;
|
||||
PrintSeparatorLine(hb.Hashers);
|
||||
}
|
||||
|
||||
return CheckBreak2();
|
||||
}
|
||||
|
||||
HRESULT CHashCallbackConsole::OpenFileError(const FString &path, DWORD systemError)
|
||||
{
|
||||
return OpenFileError_Base(path, systemError);
|
||||
}
|
||||
|
||||
HRESULT CHashCallbackConsole::GetStream(const wchar_t *name, bool isDir)
|
||||
{
|
||||
_fileName = name;
|
||||
if (isDir)
|
||||
NWindows::NFile::NName::NormalizeDirPathPrefix(_fileName);
|
||||
|
||||
if (NeedPercents())
|
||||
{
|
||||
if (PrintNameInPercents)
|
||||
{
|
||||
_percent.FileName.Empty();
|
||||
if (name)
|
||||
_percent.FileName = name;
|
||||
}
|
||||
_percent.Print();
|
||||
}
|
||||
return CheckBreak2();
|
||||
}
|
||||
|
||||
|
||||
static const unsigned k_DigestStringSize = k_HashCalc_DigestSize_Max * 2 + k_HashCalc_ExtraSize * 2 + 16;
|
||||
|
||||
|
||||
|
||||
void CHashCallbackConsole::PrintResultLine(UInt64 fileSize,
|
||||
const CObjectVector<CHasherState> &hashers, unsigned digestIndex, bool showHash,
|
||||
const AString &path)
|
||||
{
|
||||
ClosePercents_for_so();
|
||||
|
||||
_s.Empty();
|
||||
const AString fields = GetFields();
|
||||
|
||||
for (unsigned pos = 0; pos < fields.Len(); pos++)
|
||||
{
|
||||
const char c = fields[pos];
|
||||
if (c == 'h')
|
||||
{
|
||||
FOR_VECTOR (i, hashers)
|
||||
{
|
||||
AddSpace();
|
||||
const CHasherState &h = hashers[i];
|
||||
char s[k_DigestStringSize];
|
||||
s[0] = 0;
|
||||
if (showHash)
|
||||
h.WriteToString(digestIndex, s);
|
||||
const unsigned len = (unsigned)strlen(s);
|
||||
SetSpacesAndNul_if_Positive(s + len, (int)GetColumnWidth(h.DigestSize) - (int)len);
|
||||
_s += s;
|
||||
}
|
||||
}
|
||||
else if (c == 's')
|
||||
{
|
||||
AddSpace();
|
||||
char s[kSizeField_Len + 32];
|
||||
char *p = s;
|
||||
SetSpacesAndNul(s, kSizeField_Len);
|
||||
if (showHash)
|
||||
{
|
||||
p = s + kSizeField_Len;
|
||||
ConvertUInt64ToString(fileSize, p);
|
||||
const int numSpaces = (int)kSizeField_Len - (int)strlen(p);
|
||||
if (numSpaces > 0)
|
||||
p -= (unsigned)numSpaces;
|
||||
}
|
||||
_s += p;
|
||||
}
|
||||
else if (c == 'n')
|
||||
{
|
||||
AddSpacesBeforeName();
|
||||
_s += path;
|
||||
}
|
||||
}
|
||||
|
||||
*_so << _s;
|
||||
}
|
||||
|
||||
|
||||
HRESULT CHashCallbackConsole::SetOperationResult(UInt64 fileSize, const CHashBundle &hb, bool showHash)
|
||||
{
|
||||
if (_so)
|
||||
{
|
||||
AString s;
|
||||
if (_fileName.IsEmpty())
|
||||
s = kEmptyFileAlias;
|
||||
else
|
||||
{
|
||||
UString temp (_fileName);
|
||||
_so->Normalize_UString_Path(temp);
|
||||
_so->Convert_UString_to_AString(temp, s);
|
||||
}
|
||||
PrintResultLine(fileSize, hb.Hashers, k_HashCalc_Index_Current, showHash, s);
|
||||
|
||||
/*
|
||||
PrintResultLine(fileSize, hb.Hashers, k_HashCalc_Index_Current, showHash);
|
||||
if (PrintName)
|
||||
{
|
||||
if (_fileName.IsEmpty())
|
||||
*_so << kEmptyFileAlias;
|
||||
else
|
||||
_so->NormalizePrint_UString(_fileName);
|
||||
}
|
||||
*/
|
||||
// if (PrintNewLine)
|
||||
*_so << endl;
|
||||
}
|
||||
|
||||
if (NeedPercents())
|
||||
{
|
||||
_percent.Files++;
|
||||
_percent.Print();
|
||||
}
|
||||
|
||||
return CheckBreak2();
|
||||
}
|
||||
|
||||
static const char * const k_DigestTitles[] =
|
||||
{
|
||||
" : "
|
||||
, " for data: "
|
||||
, " for data and names: "
|
||||
, " for streams and names: "
|
||||
};
|
||||
|
||||
static void PrintSum(CStdOutStream &so, const CHasherState &h, unsigned digestIndex)
|
||||
{
|
||||
so << h.Name;
|
||||
|
||||
{
|
||||
AString temp;
|
||||
AddSpaces_if_Positive(temp, 6 - (int)h.Name.Len());
|
||||
so << temp;
|
||||
}
|
||||
|
||||
so << k_DigestTitles[digestIndex];
|
||||
|
||||
char s[k_DigestStringSize];
|
||||
// s[0] = 0;
|
||||
h.WriteToString(digestIndex, s);
|
||||
so << s << endl;
|
||||
}
|
||||
|
||||
void PrintHashStat(CStdOutStream &so, const CHashBundle &hb)
|
||||
{
|
||||
FOR_VECTOR (i, hb.Hashers)
|
||||
{
|
||||
const CHasherState &h = hb.Hashers[i];
|
||||
PrintSum(so, h, k_HashCalc_Index_DataSum);
|
||||
if (hb.NumFiles != 1 || hb.NumDirs != 0)
|
||||
PrintSum(so, h, k_HashCalc_Index_NamesSum);
|
||||
if (hb.NumAltStreams != 0)
|
||||
PrintSum(so, h, k_HashCalc_Index_StreamsSum);
|
||||
so << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void CHashCallbackConsole::PrintProperty(const char *name, UInt64 value)
|
||||
{
|
||||
char s[32];
|
||||
s[0] = ':';
|
||||
s[1] = ' ';
|
||||
ConvertUInt64ToString(value, s + 2);
|
||||
*_so << name << s << endl;
|
||||
}
|
||||
|
||||
HRESULT CHashCallbackConsole::AfterLastFile(CHashBundle &hb)
|
||||
{
|
||||
ClosePercents2();
|
||||
|
||||
if (PrintHeaders && _so)
|
||||
{
|
||||
PrintSeparatorLine(hb.Hashers);
|
||||
|
||||
PrintResultLine(hb.FilesSize, hb.Hashers, k_HashCalc_Index_DataSum, true, AString());
|
||||
|
||||
*_so << endl << endl;
|
||||
|
||||
if (hb.NumFiles != 1 || hb.NumDirs != 0)
|
||||
{
|
||||
if (hb.NumDirs != 0)
|
||||
PrintProperty("Folders", hb.NumDirs);
|
||||
PrintProperty("Files", hb.NumFiles);
|
||||
}
|
||||
|
||||
PrintProperty("Size", hb.FilesSize);
|
||||
|
||||
if (hb.NumAltStreams != 0)
|
||||
{
|
||||
PrintProperty("Alternate streams", hb.NumAltStreams);
|
||||
PrintProperty("Alternate streams size", hb.AltStreamsSize);
|
||||
}
|
||||
|
||||
*_so << endl;
|
||||
PrintHashStat(*_so, hb);
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// HashCon.h
|
||||
|
||||
#ifndef ZIP7_INC_HASH_CON_H
|
||||
#define ZIP7_INC_HASH_CON_H
|
||||
|
||||
#include "../Common/HashCalc.h"
|
||||
|
||||
#include "UpdateCallbackConsole.h"
|
||||
|
||||
class CHashCallbackConsole Z7_final:
|
||||
public IHashCallbackUI,
|
||||
public CCallbackConsoleBase
|
||||
{
|
||||
Z7_IFACE_IMP(IDirItemsCallback)
|
||||
Z7_IFACE_IMP(IHashCallbackUI)
|
||||
|
||||
UString _fileName;
|
||||
AString _s;
|
||||
|
||||
void AddSpace()
|
||||
{
|
||||
_s.Add_Space_if_NotEmpty();
|
||||
}
|
||||
|
||||
void AddSpacesBeforeName()
|
||||
{
|
||||
if (!_s.IsEmpty())
|
||||
{
|
||||
_s.Add_Space();
|
||||
_s.Add_Space();
|
||||
}
|
||||
}
|
||||
|
||||
void PrintSeparatorLine(const CObjectVector<CHasherState> &hashers);
|
||||
void PrintResultLine(UInt64 fileSize,
|
||||
const CObjectVector<CHasherState> &hashers, unsigned digestIndex, bool showHash, const AString &path);
|
||||
void PrintProperty(const char *name, UInt64 value);
|
||||
|
||||
public:
|
||||
bool PrintNameInPercents;
|
||||
bool PrintHeaders;
|
||||
// bool PrintSize;
|
||||
// bool PrintNewLine; // set it too (false), if you need only hash for single file without LF char.
|
||||
AString PrintFields;
|
||||
|
||||
AString GetFields() const;
|
||||
|
||||
CHashCallbackConsole():
|
||||
PrintNameInPercents(true),
|
||||
PrintHeaders(false)
|
||||
// , PrintSize(true),
|
||||
// , PrintNewLine(true)
|
||||
{}
|
||||
};
|
||||
|
||||
void PrintHashStat(CStdOutStream &so, const CHashBundle &hb);
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,42 @@
|
||||
// List.h
|
||||
|
||||
#ifndef ZIP7_INC_LIST_H
|
||||
#define ZIP7_INC_LIST_H
|
||||
|
||||
#include "../../../Common/Wildcard.h"
|
||||
|
||||
#include "../Common/LoadCodecs.h"
|
||||
|
||||
struct CListOptions
|
||||
{
|
||||
bool ExcludeDirItems;
|
||||
bool ExcludeFileItems;
|
||||
bool DisablePercents;
|
||||
|
||||
CListOptions():
|
||||
ExcludeDirItems(false),
|
||||
ExcludeFileItems(false),
|
||||
DisablePercents(false)
|
||||
{}
|
||||
};
|
||||
|
||||
HRESULT ListArchives(
|
||||
const CListOptions &listOptions,
|
||||
CCodecs *codecs,
|
||||
const CObjectVector<COpenType> &types,
|
||||
const CIntVector &excludedFormats,
|
||||
bool stdInMode,
|
||||
UStringVector &archivePaths, UStringVector &archivePathsFull,
|
||||
bool processAltStreams, bool showAltStreams,
|
||||
const NWildcard::CCensorNode &wildcardCensor,
|
||||
bool enableHeaders, bool techMode,
|
||||
#ifndef Z7_NO_CRYPTO
|
||||
bool &passwordEnabled, UString &password,
|
||||
#endif
|
||||
#ifndef Z7_SFX
|
||||
const CObjectVector<CProperty> *props,
|
||||
#endif
|
||||
UInt64 &errors,
|
||||
UInt64 &numWarnings);
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,235 @@
|
||||
// MainAr.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "../../../../C/DllSecur.h"
|
||||
#endif
|
||||
#include "../../../../C/CpuArch.h"
|
||||
|
||||
#include "../../../Common/MyException.h"
|
||||
#include "../../../Common/StdOutStream.h"
|
||||
|
||||
#include "../../../Windows/ErrorMsg.h"
|
||||
#include "../../../Windows/NtCheck.h"
|
||||
|
||||
#include "../Common/ArchiveCommandLine.h"
|
||||
#include "../Common/ExitCode.h"
|
||||
|
||||
#include "ConsoleClose.h"
|
||||
|
||||
using namespace NWindows;
|
||||
|
||||
extern
|
||||
CStdOutStream *g_StdStream;
|
||||
CStdOutStream *g_StdStream = NULL;
|
||||
extern
|
||||
CStdOutStream *g_ErrStream;
|
||||
CStdOutStream *g_ErrStream = NULL;
|
||||
|
||||
extern int Main2(
|
||||
#ifndef _WIN32
|
||||
int numArgs, char *args[]
|
||||
#endif
|
||||
);
|
||||
|
||||
static const char * const kException_CmdLine_Error_Message = "Command Line Error:";
|
||||
static const char * const kExceptionErrorMessage = "ERROR:";
|
||||
static const char * const kUserBreakMessage = "Break signaled";
|
||||
static const char * const kMemoryExceptionMessage = "ERROR: Can't allocate required memory!";
|
||||
static const char * const kUnknownExceptionMessage = "Unknown Error";
|
||||
static const char * const kInternalExceptionMessage = "\n\nInternal Error #";
|
||||
|
||||
static void FlushStreams()
|
||||
{
|
||||
if (g_StdStream)
|
||||
g_StdStream->Flush();
|
||||
}
|
||||
|
||||
static void PrintError(const char *message)
|
||||
{
|
||||
FlushStreams();
|
||||
if (g_ErrStream)
|
||||
*g_ErrStream << "\n\n" << message << endl;
|
||||
}
|
||||
|
||||
#if defined(_WIN32) && defined(_UNICODE) && !defined(_WIN64) && !defined(UNDER_CE)
|
||||
#define NT_CHECK_FAIL_ACTION *g_StdStream << "Unsupported Windows version"; return NExitCode::kFatalError;
|
||||
#endif
|
||||
|
||||
static inline bool CheckIsa()
|
||||
{
|
||||
// __try
|
||||
{
|
||||
// some compilers (e2k) support SSE/AVX, but cpuid() can be unavailable or return lower isa support
|
||||
#ifdef MY_CPU_X86_OR_AMD64
|
||||
#if 0 && (defined(__AVX512F__) && defined(__AVX512VL__))
|
||||
if (!CPU_IsSupported_AVX512F_AVX512VL())
|
||||
return false;
|
||||
#elif defined(__AVX2__)
|
||||
if (!CPU_IsSupported_AVX2())
|
||||
return false;
|
||||
#elif defined(__AVX__)
|
||||
if (!CPU_IsSupported_AVX())
|
||||
return false;
|
||||
#elif defined(__SSE2__) && !defined(MY_CPU_AMD64) || defined(_M_IX86_FP) && (_M_IX86_FP >= 2)
|
||||
if (!CPU_IsSupported_SSE2())
|
||||
return false;
|
||||
#elif defined(__SSE__) && !defined(MY_CPU_AMD64) || defined(_M_IX86_FP) && (_M_IX86_FP >= 1)
|
||||
if (!CPU_IsSupported_SSE() ||
|
||||
!CPU_IsSupported_CMOV())
|
||||
return false;
|
||||
#endif
|
||||
#endif
|
||||
/*
|
||||
__asm
|
||||
{
|
||||
_emit 0fH
|
||||
_emit 038H
|
||||
_emit 0cbH
|
||||
_emit (0c0H + 0 * 8 + 0)
|
||||
}
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
__except (EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
int Z7_CDECL main
|
||||
(
|
||||
#ifndef _WIN32
|
||||
int numArgs, char *args[]
|
||||
#endif
|
||||
)
|
||||
{
|
||||
g_ErrStream = &g_StdErr;
|
||||
g_StdStream = &g_StdOut;
|
||||
|
||||
// #if (defined(_MSC_VER) && defined(_M_IX86))
|
||||
if (!CheckIsa())
|
||||
{
|
||||
PrintError("ERROR: processor doesn't support required ISA extension");
|
||||
return NExitCode::kFatalError;
|
||||
}
|
||||
// #endif
|
||||
|
||||
NT_CHECK
|
||||
|
||||
NConsoleClose::CCtrlHandlerSetter ctrlHandlerSetter;
|
||||
int res = 0;
|
||||
|
||||
try
|
||||
{
|
||||
#ifdef _WIN32
|
||||
My_SetDefaultDllDirectories();
|
||||
#endif
|
||||
|
||||
res = Main2(
|
||||
#ifndef _WIN32
|
||||
numArgs, args
|
||||
#endif
|
||||
);
|
||||
}
|
||||
catch(const CNewException &)
|
||||
{
|
||||
PrintError(kMemoryExceptionMessage);
|
||||
return (NExitCode::kMemoryError);
|
||||
}
|
||||
/*
|
||||
catch(const NConsoleClose::CCtrlBreakException &)
|
||||
{
|
||||
PrintError(kUserBreakMessage);
|
||||
return (NExitCode::kUserBreak);
|
||||
}
|
||||
*/
|
||||
catch(const CMessagePathException &e)
|
||||
{
|
||||
PrintError(kException_CmdLine_Error_Message);
|
||||
if (g_ErrStream)
|
||||
*g_ErrStream << e << endl;
|
||||
return (NExitCode::kUserError);
|
||||
}
|
||||
catch(const CSystemException &systemError)
|
||||
{
|
||||
if (systemError.ErrorCode == E_OUTOFMEMORY)
|
||||
{
|
||||
PrintError(kMemoryExceptionMessage);
|
||||
return (NExitCode::kMemoryError);
|
||||
}
|
||||
if (systemError.ErrorCode == E_ABORT)
|
||||
{
|
||||
PrintError(kUserBreakMessage);
|
||||
return (NExitCode::kUserBreak);
|
||||
}
|
||||
if (g_ErrStream)
|
||||
{
|
||||
PrintError("System ERROR:");
|
||||
*g_ErrStream << NError::MyFormatMessage(systemError.ErrorCode) << endl;
|
||||
}
|
||||
return (NExitCode::kFatalError);
|
||||
}
|
||||
catch(NExitCode::EEnum exitCode)
|
||||
{
|
||||
FlushStreams();
|
||||
if (g_ErrStream)
|
||||
*g_ErrStream << kInternalExceptionMessage << exitCode << endl;
|
||||
return (exitCode);
|
||||
}
|
||||
catch(const UString &s)
|
||||
{
|
||||
if (g_ErrStream)
|
||||
{
|
||||
PrintError(kExceptionErrorMessage);
|
||||
*g_ErrStream << s << endl;
|
||||
}
|
||||
return (NExitCode::kFatalError);
|
||||
}
|
||||
catch(const AString &s)
|
||||
{
|
||||
if (g_ErrStream)
|
||||
{
|
||||
PrintError(kExceptionErrorMessage);
|
||||
*g_ErrStream << s << endl;
|
||||
}
|
||||
return (NExitCode::kFatalError);
|
||||
}
|
||||
catch(const char *s)
|
||||
{
|
||||
if (g_ErrStream)
|
||||
{
|
||||
PrintError(kExceptionErrorMessage);
|
||||
*g_ErrStream << s << endl;
|
||||
}
|
||||
return (NExitCode::kFatalError);
|
||||
}
|
||||
catch(const wchar_t *s)
|
||||
{
|
||||
if (g_ErrStream)
|
||||
{
|
||||
PrintError(kExceptionErrorMessage);
|
||||
*g_ErrStream << s << endl;
|
||||
}
|
||||
return (NExitCode::kFatalError);
|
||||
}
|
||||
catch(int t)
|
||||
{
|
||||
if (g_ErrStream)
|
||||
{
|
||||
FlushStreams();
|
||||
*g_ErrStream << kInternalExceptionMessage << t << endl;
|
||||
return (NExitCode::kFatalError);
|
||||
}
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
PrintError(kUnknownExceptionMessage);
|
||||
return (NExitCode::kFatalError);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
// OpenCallbackConsole.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "OpenCallbackConsole.h"
|
||||
|
||||
#include "ConsoleClose.h"
|
||||
#include "UserInputUtils.h"
|
||||
|
||||
static HRESULT CheckBreak2()
|
||||
{
|
||||
return NConsoleClose::TestBreakSignal() ? E_ABORT : S_OK;
|
||||
}
|
||||
|
||||
HRESULT COpenCallbackConsole::Open_CheckBreak()
|
||||
{
|
||||
return CheckBreak2();
|
||||
}
|
||||
|
||||
HRESULT COpenCallbackConsole::Open_SetTotal(const UInt64 *files, const UInt64 *bytes)
|
||||
{
|
||||
if (!MultiArcMode && NeedPercents())
|
||||
{
|
||||
if (files)
|
||||
{
|
||||
_totalFilesDefined = true;
|
||||
// _totalFiles = *files;
|
||||
_percent.Total = *files;
|
||||
}
|
||||
else
|
||||
_totalFilesDefined = false;
|
||||
|
||||
if (bytes)
|
||||
{
|
||||
// _totalBytesDefined = true;
|
||||
_totalBytes = *bytes;
|
||||
if (!files)
|
||||
_percent.Total = *bytes;
|
||||
}
|
||||
else
|
||||
{
|
||||
// _totalBytesDefined = false;
|
||||
if (!files)
|
||||
_percent.Total = _totalBytes;
|
||||
}
|
||||
}
|
||||
|
||||
return CheckBreak2();
|
||||
}
|
||||
|
||||
HRESULT COpenCallbackConsole::Open_SetCompleted(const UInt64 *files, const UInt64 *bytes)
|
||||
{
|
||||
if (!MultiArcMode && NeedPercents())
|
||||
{
|
||||
if (files)
|
||||
{
|
||||
_percent.Files = *files;
|
||||
if (_totalFilesDefined)
|
||||
_percent.Completed = *files;
|
||||
}
|
||||
|
||||
if (bytes)
|
||||
{
|
||||
if (!_totalFilesDefined)
|
||||
_percent.Completed = *bytes;
|
||||
}
|
||||
_percent.Print();
|
||||
}
|
||||
|
||||
return CheckBreak2();
|
||||
}
|
||||
|
||||
HRESULT COpenCallbackConsole::Open_Finished()
|
||||
{
|
||||
ClosePercents();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
#ifndef Z7_NO_CRYPTO
|
||||
|
||||
HRESULT COpenCallbackConsole::Open_CryptoGetTextPassword(BSTR *password)
|
||||
{
|
||||
*password = NULL;
|
||||
RINOK(CheckBreak2())
|
||||
|
||||
if (!PasswordIsDefined)
|
||||
{
|
||||
ClosePercents();
|
||||
RINOK(GetPassword_HRESULT(_so, Password))
|
||||
PasswordIsDefined = true;
|
||||
}
|
||||
return StringToBstr(Password, password);
|
||||
}
|
||||
|
||||
/*
|
||||
HRESULT COpenCallbackConsole::Open_GetPasswordIfAny(bool &passwordIsDefined, UString &password)
|
||||
{
|
||||
passwordIsDefined = PasswordIsDefined;
|
||||
password = Password;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
bool COpenCallbackConsole::Open_WasPasswordAsked()
|
||||
{
|
||||
return PasswordWasAsked;
|
||||
}
|
||||
|
||||
void COpenCallbackConsole::Open_Clear_PasswordWasAsked_Flag ()
|
||||
{
|
||||
PasswordWasAsked = false;
|
||||
}
|
||||
*/
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,73 @@
|
||||
// OpenCallbackConsole.h
|
||||
|
||||
#ifndef ZIP7_INC_OPEN_CALLBACK_CONSOLE_H
|
||||
#define ZIP7_INC_OPEN_CALLBACK_CONSOLE_H
|
||||
|
||||
#include "../../../Common/StdOutStream.h"
|
||||
|
||||
#include "../Common/ArchiveOpenCallback.h"
|
||||
|
||||
#include "PercentPrinter.h"
|
||||
|
||||
class COpenCallbackConsole: public IOpenCallbackUI
|
||||
{
|
||||
protected:
|
||||
CPercentPrinter _percent;
|
||||
|
||||
CStdOutStream *_so;
|
||||
CStdOutStream *_se;
|
||||
|
||||
// UInt64 _totalFiles;
|
||||
UInt64 _totalBytes;
|
||||
bool _totalFilesDefined;
|
||||
// bool _totalBytesDefined;
|
||||
|
||||
bool NeedPercents() const { return _percent._so && !_percent.DisablePrint; }
|
||||
|
||||
public:
|
||||
|
||||
bool MultiArcMode;
|
||||
|
||||
void ClosePercents()
|
||||
{
|
||||
if (NeedPercents())
|
||||
_percent.ClosePrint(true);
|
||||
}
|
||||
|
||||
COpenCallbackConsole():
|
||||
_totalBytes(0),
|
||||
_totalFilesDefined(false),
|
||||
// _totalBytesDefined(false),
|
||||
MultiArcMode(false)
|
||||
|
||||
#ifndef Z7_NO_CRYPTO
|
||||
, PasswordIsDefined(false)
|
||||
// , PasswordWasAsked(false)
|
||||
#endif
|
||||
|
||||
{}
|
||||
|
||||
virtual ~COpenCallbackConsole() {}
|
||||
|
||||
void Init(
|
||||
CStdOutStream *outStream,
|
||||
CStdOutStream *errorStream,
|
||||
CStdOutStream *percentStream,
|
||||
bool disablePercents)
|
||||
{
|
||||
_so = outStream;
|
||||
_se = errorStream;
|
||||
_percent._so = percentStream;
|
||||
_percent.DisablePrint = disablePercents;
|
||||
}
|
||||
|
||||
Z7_IFACE_IMP(IOpenCallbackUI)
|
||||
|
||||
#ifndef Z7_NO_CRYPTO
|
||||
bool PasswordIsDefined;
|
||||
// bool PasswordWasAsked;
|
||||
UString Password;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,186 @@
|
||||
// PercentPrinter.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "../../../Common/IntToString.h"
|
||||
|
||||
#include "PercentPrinter.h"
|
||||
|
||||
static const unsigned kPercentsSize = 4;
|
||||
|
||||
CPercentPrinter::~CPercentPrinter()
|
||||
{
|
||||
ClosePrint(false);
|
||||
}
|
||||
|
||||
void CPercentPrinterState::ClearCurState()
|
||||
{
|
||||
Completed = 0;
|
||||
Total = ((UInt64)(Int64)-1);
|
||||
Files = 0;
|
||||
Command.Empty();
|
||||
FileName.Empty();
|
||||
}
|
||||
|
||||
void CPercentPrinter::ClosePrint(bool needFlush)
|
||||
{
|
||||
unsigned num = _printedString.Len();
|
||||
if (num != 0)
|
||||
{
|
||||
|
||||
unsigned i;
|
||||
|
||||
/* '\r' in old MAC OS means "new line".
|
||||
So we can't use '\r' in some systems */
|
||||
|
||||
#ifdef _WIN32
|
||||
char *start = _temp.GetBuf(num + 2);
|
||||
char *p = start;
|
||||
*p++ = '\r';
|
||||
for (i = 0; i < num; i++) *p++ = ' ';
|
||||
*p++ = '\r';
|
||||
#else
|
||||
char *start = _temp.GetBuf(num * 3);
|
||||
char *p = start;
|
||||
for (i = 0; i < num; i++) *p++ = '\b';
|
||||
for (i = 0; i < num; i++) *p++ = ' ';
|
||||
for (i = 0; i < num; i++) *p++ = '\b';
|
||||
#endif
|
||||
|
||||
*p = 0;
|
||||
_temp.ReleaseBuf_SetLen((unsigned)(p - start));
|
||||
*_so << _temp;
|
||||
}
|
||||
if (needFlush)
|
||||
_so->Flush();
|
||||
_printedString.Empty();
|
||||
}
|
||||
|
||||
void CPercentPrinter::GetPercents()
|
||||
{
|
||||
char s[32];
|
||||
unsigned size;
|
||||
{
|
||||
char c = '%';
|
||||
UInt64 val = 0;
|
||||
if (Total == (UInt64)(Int64)-1 ||
|
||||
(Total == 0 && Completed != 0))
|
||||
{
|
||||
val = Completed >> 20;
|
||||
c = 'M';
|
||||
}
|
||||
else if (Total != 0)
|
||||
val = Completed * 100 / Total;
|
||||
ConvertUInt64ToString(val, s);
|
||||
size = (unsigned)strlen(s);
|
||||
s[size++] = c;
|
||||
s[size] = 0;
|
||||
}
|
||||
|
||||
while (size < kPercentsSize)
|
||||
{
|
||||
_s.Add_Space();
|
||||
size++;
|
||||
}
|
||||
|
||||
_s += s;
|
||||
}
|
||||
|
||||
void CPercentPrinter::Print()
|
||||
{
|
||||
if (DisablePrint)
|
||||
return;
|
||||
DWORD tick = 0;
|
||||
if (_tickStep != 0)
|
||||
tick = GetTickCount();
|
||||
|
||||
bool onlyPercentsChanged = false;
|
||||
|
||||
if (!_printedString.IsEmpty())
|
||||
{
|
||||
if (_tickStep != 0 && (UInt32)(tick - _prevTick) < _tickStep)
|
||||
return;
|
||||
|
||||
CPercentPrinterState &st = *this;
|
||||
if (_printedState.Command == st.Command
|
||||
&& _printedState.FileName == st.FileName
|
||||
&& _printedState.Files == st.Files)
|
||||
{
|
||||
if (_printedState.Total == st.Total
|
||||
&& _printedState.Completed == st.Completed)
|
||||
return;
|
||||
onlyPercentsChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
_s.Empty();
|
||||
|
||||
GetPercents();
|
||||
|
||||
if (onlyPercentsChanged && _s == _printedPercents)
|
||||
return;
|
||||
|
||||
_printedPercents = _s;
|
||||
|
||||
if (Files != 0)
|
||||
{
|
||||
char s[32];
|
||||
ConvertUInt64ToString(Files, s);
|
||||
// unsigned size = (unsigned)strlen(s);
|
||||
// for (; size < 3; size++) _s.Add_Space();
|
||||
_s.Add_Space();
|
||||
_s += s;
|
||||
// _s += "f";
|
||||
}
|
||||
|
||||
|
||||
if (!Command.IsEmpty())
|
||||
{
|
||||
_s.Add_Space();
|
||||
_s += Command;
|
||||
}
|
||||
|
||||
if (!FileName.IsEmpty() && _s.Len() < MaxLen)
|
||||
{
|
||||
_s.Add_Space();
|
||||
|
||||
_tempU = FileName;
|
||||
_so->Normalize_UString_Path(_tempU);
|
||||
_so->Convert_UString_to_AString(_tempU, _temp);
|
||||
if (_s.Len() + _temp.Len() > MaxLen)
|
||||
{
|
||||
unsigned len = FileName.Len();
|
||||
for (; len != 0;)
|
||||
{
|
||||
unsigned delta = len / 8;
|
||||
if (delta == 0)
|
||||
delta = 1;
|
||||
len -= delta;
|
||||
_tempU = FileName;
|
||||
_tempU.Delete(len / 2, _tempU.Len() - len);
|
||||
_tempU.Insert(len / 2, L" . ");
|
||||
_so->Normalize_UString_Path(_tempU);
|
||||
_so->Convert_UString_to_AString(_tempU, _temp);
|
||||
if (_s.Len() + _temp.Len() <= MaxLen)
|
||||
break;
|
||||
}
|
||||
if (len == 0)
|
||||
_temp.Empty();
|
||||
}
|
||||
_s += _temp;
|
||||
}
|
||||
|
||||
if (_printedString != _s)
|
||||
{
|
||||
ClosePrint(false);
|
||||
*_so << _s;
|
||||
if (NeedFlush)
|
||||
_so->Flush();
|
||||
_printedString = _s;
|
||||
}
|
||||
|
||||
_printedState = *this;
|
||||
|
||||
if (_tickStep != 0)
|
||||
_prevTick = tick;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
// PercentPrinter.h
|
||||
|
||||
#ifndef ZIP7_INC_PERCENT_PRINTER_H
|
||||
#define ZIP7_INC_PERCENT_PRINTER_H
|
||||
|
||||
#include "../../../Common/StdOutStream.h"
|
||||
|
||||
struct CPercentPrinterState
|
||||
{
|
||||
UInt64 Completed;
|
||||
UInt64 Total;
|
||||
|
||||
UInt64 Files;
|
||||
|
||||
AString Command;
|
||||
UString FileName;
|
||||
|
||||
void ClearCurState();
|
||||
|
||||
CPercentPrinterState():
|
||||
Completed(0),
|
||||
Total((UInt64)(Int64)-1),
|
||||
Files(0)
|
||||
{}
|
||||
};
|
||||
|
||||
class CPercentPrinter: public CPercentPrinterState
|
||||
{
|
||||
public:
|
||||
CStdOutStream *_so;
|
||||
bool DisablePrint;
|
||||
bool NeedFlush;
|
||||
unsigned MaxLen;
|
||||
|
||||
private:
|
||||
UInt32 _tickStep;
|
||||
DWORD _prevTick;
|
||||
|
||||
AString _s;
|
||||
|
||||
AString _printedString;
|
||||
AString _temp;
|
||||
UString _tempU;
|
||||
|
||||
CPercentPrinterState _printedState;
|
||||
AString _printedPercents;
|
||||
|
||||
void GetPercents();
|
||||
|
||||
public:
|
||||
|
||||
CPercentPrinter(UInt32 tickStep = 200):
|
||||
DisablePrint(false),
|
||||
NeedFlush(true),
|
||||
MaxLen(80 - 1),
|
||||
_tickStep(tickStep),
|
||||
_prevTick(0)
|
||||
{}
|
||||
|
||||
~CPercentPrinter();
|
||||
|
||||
void ClosePrint(bool needFlush);
|
||||
void Print();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,3 @@
|
||||
// StdAfx.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
@@ -0,0 +1,11 @@
|
||||
// StdAfx.h
|
||||
|
||||
#ifndef ZIP7_INC_STDAFX_H
|
||||
#define ZIP7_INC_STDAFX_H
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1800
|
||||
#pragma warning(disable : 4464) // relative include path contains '..'
|
||||
#endif
|
||||
#include "../../../Common/Common.h"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,998 @@
|
||||
// UpdateCallbackConsole.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "../../../Common/IntToString.h"
|
||||
|
||||
#include "../../../Windows/ErrorMsg.h"
|
||||
#include "../../../Windows/FileName.h"
|
||||
|
||||
#ifndef Z7_ST
|
||||
#include "../../../Windows/Synchronization.h"
|
||||
#endif
|
||||
|
||||
// #include "../Common/PropIDUtils.h"
|
||||
|
||||
#include "ConsoleClose.h"
|
||||
#include "UserInputUtils.h"
|
||||
#include "UpdateCallbackConsole.h"
|
||||
|
||||
using namespace NWindows;
|
||||
|
||||
#ifndef Z7_ST
|
||||
static NSynchronization::CCriticalSection g_CriticalSection;
|
||||
#define MT_LOCK NSynchronization::CCriticalSectionLock lock(g_CriticalSection);
|
||||
#else
|
||||
#define MT_LOCK
|
||||
#endif
|
||||
|
||||
static const wchar_t * const kEmptyFileAlias = L"[Content]";
|
||||
|
||||
static const char * const kOpenArchiveMessage = "Open archive: ";
|
||||
static const char * const kCreatingArchiveMessage = "Creating archive: ";
|
||||
static const char * const kUpdatingArchiveMessage = "Updating archive: ";
|
||||
static const char * const kScanningMessage = "Scanning the drive:";
|
||||
|
||||
static const char * const kError = "ERROR: ";
|
||||
static const char * const kWarning = "WARNING: ";
|
||||
|
||||
static HRESULT CheckBreak2()
|
||||
{
|
||||
return NConsoleClose::TestBreakSignal() ? E_ABORT : S_OK;
|
||||
}
|
||||
|
||||
HRESULT Print_OpenArchive_Props(CStdOutStream &so, const CCodecs *codecs, const CArchiveLink &arcLink);
|
||||
HRESULT Print_OpenArchive_Error(CStdOutStream &so, const CCodecs *codecs, const CArchiveLink &arcLink);
|
||||
|
||||
void PrintErrorFlags(CStdOutStream &so, const char *s, UInt32 errorFlags);
|
||||
|
||||
void Print_ErrorFormatIndex_Warning(CStdOutStream *_so, const CCodecs *codecs, const CArc &arc);
|
||||
|
||||
HRESULT CUpdateCallbackConsole::OpenResult(
|
||||
const CCodecs *codecs, const CArchiveLink &arcLink,
|
||||
const wchar_t *name, HRESULT result)
|
||||
{
|
||||
ClosePercents2();
|
||||
|
||||
FOR_VECTOR (level, arcLink.Arcs)
|
||||
{
|
||||
const CArc &arc = arcLink.Arcs[level];
|
||||
const CArcErrorInfo &er = arc.ErrorInfo;
|
||||
|
||||
UInt32 errorFlags = er.GetErrorFlags();
|
||||
|
||||
if (errorFlags != 0 || !er.ErrorMessage.IsEmpty())
|
||||
{
|
||||
if (_se)
|
||||
{
|
||||
*_se << endl;
|
||||
if (level != 0)
|
||||
*_se << arc.Path << endl;
|
||||
}
|
||||
|
||||
if (errorFlags != 0)
|
||||
{
|
||||
if (_se)
|
||||
PrintErrorFlags(*_se, "ERRORS:", errorFlags);
|
||||
}
|
||||
|
||||
if (!er.ErrorMessage.IsEmpty())
|
||||
{
|
||||
if (_se)
|
||||
*_se << "ERRORS:" << endl << er.ErrorMessage << endl;
|
||||
}
|
||||
|
||||
if (_se)
|
||||
{
|
||||
*_se << endl;
|
||||
_se->Flush();
|
||||
}
|
||||
}
|
||||
|
||||
UInt32 warningFlags = er.GetWarningFlags();
|
||||
|
||||
if (warningFlags != 0 || !er.WarningMessage.IsEmpty())
|
||||
{
|
||||
if (_so)
|
||||
{
|
||||
*_so << endl;
|
||||
if (level != 0)
|
||||
*_so << arc.Path << endl;
|
||||
}
|
||||
|
||||
if (warningFlags != 0)
|
||||
{
|
||||
if (_so)
|
||||
PrintErrorFlags(*_so, "WARNINGS:", warningFlags);
|
||||
}
|
||||
|
||||
if (!er.WarningMessage.IsEmpty())
|
||||
{
|
||||
if (_so)
|
||||
*_so << "WARNINGS:" << endl << er.WarningMessage << endl;
|
||||
}
|
||||
|
||||
if (_so)
|
||||
{
|
||||
*_so << endl;
|
||||
if (NeedFlush)
|
||||
_so->Flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (er.ErrorFormatIndex >= 0)
|
||||
{
|
||||
if (_so)
|
||||
{
|
||||
Print_ErrorFormatIndex_Warning(_so, codecs, arc);
|
||||
if (NeedFlush)
|
||||
_so->Flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (result == S_OK)
|
||||
{
|
||||
if (_so)
|
||||
{
|
||||
RINOK(Print_OpenArchive_Props(*_so, codecs, arcLink))
|
||||
*_so << endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_so)
|
||||
_so->Flush();
|
||||
if (_se)
|
||||
{
|
||||
*_se << kError;
|
||||
_se->NormalizePrint_wstr_Path(name);
|
||||
*_se << endl;
|
||||
HRESULT res = Print_OpenArchive_Error(*_se, codecs, arcLink);
|
||||
RINOK(res)
|
||||
_se->Flush();
|
||||
}
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CUpdateCallbackConsole::StartScanning()
|
||||
{
|
||||
if (_so)
|
||||
*_so << kScanningMessage << endl;
|
||||
_percent.Command = "Scan ";
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CUpdateCallbackConsole::ScanProgress(const CDirItemsStat &st, const FString &path, bool /* isDir */)
|
||||
{
|
||||
if (NeedPercents())
|
||||
{
|
||||
_percent.Files = st.NumDirs + st.NumFiles + st.NumAltStreams;
|
||||
_percent.Completed = st.GetTotalBytes();
|
||||
_percent.FileName = fs2us(path);
|
||||
_percent.Print();
|
||||
}
|
||||
|
||||
return CheckBreak();
|
||||
}
|
||||
|
||||
void CCallbackConsoleBase::CommonError(const FString &path, DWORD systemError, bool isWarning)
|
||||
{
|
||||
ClosePercents2();
|
||||
|
||||
if (_se)
|
||||
{
|
||||
if (_so)
|
||||
_so->Flush();
|
||||
|
||||
*_se << endl << (isWarning ? kWarning : kError)
|
||||
<< NError::MyFormatMessage(systemError)
|
||||
<< endl;
|
||||
_se->NormalizePrint_UString_Path(fs2us(path));
|
||||
*_se << endl << endl;
|
||||
_se->Flush();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void CCallbackConsoleBase::CommonError(const char *message)
|
||||
{
|
||||
ClosePercents2();
|
||||
|
||||
if (_se)
|
||||
{
|
||||
if (_so)
|
||||
_so->Flush();
|
||||
|
||||
*_se << endl << kError << message << endl;
|
||||
_se->Flush();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
HRESULT CCallbackConsoleBase::ScanError_Base(const FString &path, DWORD systemError)
|
||||
{
|
||||
MT_LOCK
|
||||
|
||||
ScanErrors.AddError(path, systemError);
|
||||
CommonError(path, systemError, true);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CCallbackConsoleBase::OpenFileError_Base(const FString &path, DWORD systemError)
|
||||
{
|
||||
MT_LOCK
|
||||
FailedFiles.AddError(path, systemError);
|
||||
NumNonOpenFiles++;
|
||||
/*
|
||||
if (systemError == ERROR_SHARING_VIOLATION)
|
||||
{
|
||||
*/
|
||||
CommonError(path, systemError, true);
|
||||
return S_FALSE;
|
||||
/*
|
||||
}
|
||||
return systemError;
|
||||
*/
|
||||
}
|
||||
|
||||
HRESULT CCallbackConsoleBase::ReadingFileError_Base(const FString &path, DWORD systemError)
|
||||
{
|
||||
MT_LOCK
|
||||
CommonError(path, systemError, false);
|
||||
return HRESULT_FROM_WIN32(systemError);
|
||||
}
|
||||
|
||||
HRESULT CUpdateCallbackConsole::ScanError(const FString &path, DWORD systemError)
|
||||
{
|
||||
return ScanError_Base(path, systemError);
|
||||
}
|
||||
|
||||
|
||||
static void PrintPropPair(AString &s, const char *name, UInt64 val)
|
||||
{
|
||||
char temp[32];
|
||||
ConvertUInt64ToString(val, temp);
|
||||
s += name;
|
||||
s += ": ";
|
||||
s += temp;
|
||||
}
|
||||
|
||||
void PrintSize_bytes_Smart(AString &s, UInt64 val);
|
||||
void Print_DirItemsStat(AString &s, const CDirItemsStat &st);
|
||||
void Print_DirItemsStat2(AString &s, const CDirItemsStat2 &st);
|
||||
|
||||
HRESULT CUpdateCallbackConsole::FinishScanning(const CDirItemsStat &st)
|
||||
{
|
||||
if (NeedPercents())
|
||||
{
|
||||
_percent.ClosePrint(true);
|
||||
_percent.ClearCurState();
|
||||
}
|
||||
|
||||
if (_so)
|
||||
{
|
||||
AString s;
|
||||
Print_DirItemsStat(s, st);
|
||||
*_so << s << endl << endl;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static const char * const k_StdOut_ArcName = "StdOut";
|
||||
|
||||
HRESULT CUpdateCallbackConsole::StartOpenArchive(const wchar_t *name)
|
||||
{
|
||||
if (_so)
|
||||
{
|
||||
*_so << kOpenArchiveMessage;
|
||||
if (name)
|
||||
*_so << name;
|
||||
else
|
||||
*_so << k_StdOut_ArcName;
|
||||
*_so << endl;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CUpdateCallbackConsole::StartArchive(const wchar_t *name, bool updating)
|
||||
{
|
||||
if (NeedPercents())
|
||||
_percent.ClosePrint(true);
|
||||
|
||||
_percent.ClearCurState();
|
||||
NumNonOpenFiles = 0;
|
||||
|
||||
if (_so)
|
||||
{
|
||||
*_so << (updating ? kUpdatingArchiveMessage : kCreatingArchiveMessage);
|
||||
if (name)
|
||||
_so->NormalizePrint_wstr_Path(name);
|
||||
else
|
||||
*_so << k_StdOut_ArcName;
|
||||
*_so << endl << endl;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CUpdateCallbackConsole::FinishArchive(const CFinishArchiveStat &st)
|
||||
{
|
||||
ClosePercents2();
|
||||
|
||||
if (_so)
|
||||
{
|
||||
AString s;
|
||||
// Print_UInt64_and_String(s, _percent.Files == 1 ? "file" : "files", _percent.Files);
|
||||
PrintPropPair(s, "Files read from disk", _percent.Files - NumNonOpenFiles);
|
||||
s.Add_LF();
|
||||
s += "Archive size: ";
|
||||
PrintSize_bytes_Smart(s, st.OutArcFileSize);
|
||||
s.Add_LF();
|
||||
if (st.IsMultiVolMode)
|
||||
{
|
||||
s += "Volumes: ";
|
||||
s.Add_UInt32(st.NumVolumes);
|
||||
s.Add_LF();
|
||||
}
|
||||
*_so << endl;
|
||||
*_so << s;
|
||||
// *_so << endl;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CUpdateCallbackConsole::WriteSfx(const wchar_t *name, UInt64 size)
|
||||
{
|
||||
if (_so)
|
||||
{
|
||||
*_so << "Write SFX: ";
|
||||
*_so << name;
|
||||
AString s (" : ");
|
||||
PrintSize_bytes_Smart(s, size);
|
||||
*_so << s << endl;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
HRESULT CUpdateCallbackConsole::MoveArc_UpdateStatus()
|
||||
{
|
||||
if (NeedPercents())
|
||||
{
|
||||
AString &s = _percent.Command;
|
||||
s = " : ";
|
||||
s.Add_UInt64(_arcMoving_percents);
|
||||
s.Add_Char('%');
|
||||
const bool totalDefined = (_arcMoving_total != 0 && _arcMoving_total != (UInt64)(Int64)-1);
|
||||
if (_arcMoving_current != 0 || totalDefined)
|
||||
{
|
||||
s += " : ";
|
||||
s.Add_UInt64(_arcMoving_current >> 20);
|
||||
s += " MiB";
|
||||
}
|
||||
if (totalDefined)
|
||||
{
|
||||
s += " / ";
|
||||
s.Add_UInt64((_arcMoving_total + ((1 << 20) - 1)) >> 20);
|
||||
s += " MiB";
|
||||
}
|
||||
s += " : temporary archive moving ...";
|
||||
_percent.Print();
|
||||
}
|
||||
|
||||
// we ignore single Ctrl-C, if (_arcMoving_updateMode) mode
|
||||
// because we want to get good final archive instead of temp archive.
|
||||
if (NConsoleClose::g_BreakCounter == 1 && _arcMoving_updateMode)
|
||||
return S_OK;
|
||||
return CheckBreak();
|
||||
}
|
||||
|
||||
|
||||
HRESULT CUpdateCallbackConsole::MoveArc_Start(
|
||||
const wchar_t *srcTempPath, const wchar_t *destFinalPath,
|
||||
UInt64 size, Int32 updateMode)
|
||||
{
|
||||
#if 0 // 1 : for debug
|
||||
if (LogLevel > 0 && _so)
|
||||
{
|
||||
ClosePercents_for_so();
|
||||
*_so << "Temporary archive moving:" << endl;
|
||||
_tempU = srcTempPath;
|
||||
_so->Normalize_UString_Path(_tempU);
|
||||
_so->PrintUString(_tempU, _tempA);
|
||||
*_so << endl;
|
||||
_tempU = destFinalPath;
|
||||
_so->Normalize_UString_Path(_tempU);
|
||||
_so->PrintUString(_tempU, _tempA);
|
||||
*_so << endl;
|
||||
}
|
||||
#else
|
||||
UNUSED_VAR(srcTempPath)
|
||||
UNUSED_VAR(destFinalPath)
|
||||
#endif
|
||||
|
||||
_arcMoving_updateMode = updateMode;
|
||||
_arcMoving_total = size;
|
||||
_arcMoving_current = 0;
|
||||
_arcMoving_percents = 0;
|
||||
return MoveArc_UpdateStatus();
|
||||
}
|
||||
|
||||
|
||||
HRESULT CUpdateCallbackConsole::MoveArc_Progress(UInt64 totalSize, UInt64 currentSize)
|
||||
{
|
||||
#if 0 // 1 : for debug
|
||||
if (_so)
|
||||
{
|
||||
ClosePercents_for_so();
|
||||
*_so << totalSize << " : " << currentSize << endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
UInt64 percents = 0;
|
||||
if (totalSize != 0)
|
||||
{
|
||||
if (totalSize < ((UInt64)1 << 57))
|
||||
percents = currentSize * 100 / totalSize;
|
||||
else
|
||||
percents = currentSize / (totalSize / 100);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
// Sleep(300); // for debug
|
||||
#endif
|
||||
// totalSize = (UInt64)(Int64)-1; // for debug
|
||||
|
||||
if (percents == _arcMoving_percents)
|
||||
return CheckBreak();
|
||||
_arcMoving_current = currentSize;
|
||||
_arcMoving_total = totalSize;
|
||||
_arcMoving_percents = percents;
|
||||
return MoveArc_UpdateStatus();
|
||||
}
|
||||
|
||||
|
||||
HRESULT CUpdateCallbackConsole::MoveArc_Finish()
|
||||
{
|
||||
// _arcMoving_percents = 0;
|
||||
if (NeedPercents())
|
||||
{
|
||||
_percent.Command.Empty();
|
||||
_percent.Print();
|
||||
}
|
||||
// it can return delayed user break (E_ABORT) status,
|
||||
// if it ignored single CTRL+C in MoveArc_Progress().
|
||||
return CheckBreak();
|
||||
}
|
||||
|
||||
|
||||
|
||||
HRESULT CUpdateCallbackConsole::DeletingAfterArchiving(const FString &path, bool /* isDir */)
|
||||
{
|
||||
if (LogLevel > 0 && _so)
|
||||
{
|
||||
ClosePercents_for_so();
|
||||
|
||||
if (!DeleteMessageWasShown)
|
||||
{
|
||||
if (_so)
|
||||
*_so << endl << ": Removing files after including to archive" << endl;
|
||||
}
|
||||
|
||||
{
|
||||
{
|
||||
_tempA = "Removing";
|
||||
_tempA.Add_Space();
|
||||
*_so << _tempA;
|
||||
_tempU = fs2us(path);
|
||||
_so->Normalize_UString_Path(_tempU);
|
||||
_so->PrintUString(_tempU, _tempA);
|
||||
*_so << endl;
|
||||
if (NeedFlush)
|
||||
_so->Flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!DeleteMessageWasShown)
|
||||
{
|
||||
if (NeedPercents())
|
||||
{
|
||||
_percent.ClearCurState();
|
||||
}
|
||||
DeleteMessageWasShown = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_percent.Files++;
|
||||
}
|
||||
|
||||
if (NeedPercents())
|
||||
{
|
||||
// if (!FullLog)
|
||||
{
|
||||
_percent.Command = "Removing";
|
||||
_percent.FileName = fs2us(path);
|
||||
}
|
||||
_percent.Print();
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
HRESULT CUpdateCallbackConsole::FinishDeletingAfterArchiving()
|
||||
{
|
||||
ClosePercents2();
|
||||
if (_so && DeleteMessageWasShown)
|
||||
*_so << endl;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CUpdateCallbackConsole::CheckBreak()
|
||||
{
|
||||
return CheckBreak2();
|
||||
}
|
||||
|
||||
/*
|
||||
HRESULT CUpdateCallbackConsole::Finalize()
|
||||
{
|
||||
// MT_LOCK
|
||||
return S_OK;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
void static PrintToDoStat(CStdOutStream *_so, const CDirItemsStat2 &stat, const char *name)
|
||||
{
|
||||
AString s;
|
||||
Print_DirItemsStat2(s, stat);
|
||||
*_so << name << ": " << s << endl;
|
||||
}
|
||||
|
||||
HRESULT CUpdateCallbackConsole::SetNumItems(const CArcToDoStat &stat)
|
||||
{
|
||||
if (_so)
|
||||
{
|
||||
ClosePercents_for_so();
|
||||
if (!stat.DeleteData.IsEmpty())
|
||||
{
|
||||
*_so << endl;
|
||||
PrintToDoStat(_so, stat.DeleteData, "Delete data from archive");
|
||||
}
|
||||
if (!stat.OldData.IsEmpty())
|
||||
PrintToDoStat(_so, stat.OldData, "Keep old data in archive");
|
||||
// if (!stat.NewData.IsEmpty())
|
||||
{
|
||||
PrintToDoStat(_so, stat.NewData, "Add new data to archive");
|
||||
}
|
||||
*_so << endl;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CUpdateCallbackConsole::SetTotal(UInt64 size)
|
||||
{
|
||||
MT_LOCK
|
||||
if (NeedPercents())
|
||||
{
|
||||
_percent.Total = size;
|
||||
_percent.Print();
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CUpdateCallbackConsole::SetCompleted(const UInt64 *completeValue)
|
||||
{
|
||||
MT_LOCK
|
||||
if (completeValue)
|
||||
{
|
||||
if (NeedPercents())
|
||||
{
|
||||
_percent.Completed = *completeValue;
|
||||
_percent.Print();
|
||||
}
|
||||
}
|
||||
return CheckBreak2();
|
||||
}
|
||||
|
||||
HRESULT CUpdateCallbackConsole::SetRatioInfo(const UInt64 * /* inSize */, const UInt64 * /* outSize */)
|
||||
{
|
||||
return CheckBreak2();
|
||||
}
|
||||
|
||||
HRESULT CCallbackConsoleBase::PrintProgress(const wchar_t *name, bool isDir, const char *command, bool showInLog)
|
||||
{
|
||||
MT_LOCK
|
||||
|
||||
bool show2 = (showInLog && _so);
|
||||
|
||||
if (show2)
|
||||
{
|
||||
ClosePercents_for_so();
|
||||
|
||||
_tempA = command;
|
||||
if (name)
|
||||
_tempA.Add_Space();
|
||||
*_so << _tempA;
|
||||
|
||||
_tempU.Empty();
|
||||
if (name)
|
||||
{
|
||||
_tempU = name;
|
||||
if (isDir)
|
||||
NWindows::NFile::NName::NormalizeDirPathPrefix(_tempU);
|
||||
_so->Normalize_UString_Path(_tempU);
|
||||
}
|
||||
_so->PrintUString(_tempU, _tempA);
|
||||
*_so << endl;
|
||||
if (NeedFlush)
|
||||
_so->Flush();
|
||||
}
|
||||
|
||||
if (NeedPercents())
|
||||
{
|
||||
if (PercentsNameLevel >= 1)
|
||||
{
|
||||
_percent.FileName.Empty();
|
||||
_percent.Command.Empty();
|
||||
if (PercentsNameLevel > 1 || !show2)
|
||||
{
|
||||
_percent.Command = command;
|
||||
if (name)
|
||||
_percent.FileName = name;
|
||||
}
|
||||
}
|
||||
_percent.Print();
|
||||
}
|
||||
|
||||
return CheckBreak2();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
void CCallbackConsoleBase::PrintInfoLine(const UString &s)
|
||||
{
|
||||
if (LogLevel < 1000)
|
||||
return;
|
||||
|
||||
MT_LOCK
|
||||
|
||||
const bool show2 = (_so != NULL);
|
||||
|
||||
if (show2)
|
||||
{
|
||||
ClosePercents_for_so();
|
||||
_so->PrintUString(s, _tempA);
|
||||
*_so << endl;
|
||||
if (NeedFlush)
|
||||
_so->Flush();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
HRESULT CUpdateCallbackConsole::GetStream(const wchar_t *name, bool isDir, bool isAnti, UInt32 mode)
|
||||
{
|
||||
if (StdOutMode)
|
||||
return S_OK;
|
||||
|
||||
if (!name || name[0] == 0)
|
||||
name = kEmptyFileAlias;
|
||||
|
||||
unsigned requiredLevel = 1;
|
||||
|
||||
const char *s;
|
||||
if (mode == NUpdateNotifyOp::kAdd ||
|
||||
mode == NUpdateNotifyOp::kUpdate)
|
||||
{
|
||||
if (isAnti)
|
||||
s = "Anti";
|
||||
else if (mode == NUpdateNotifyOp::kAdd)
|
||||
s = "+";
|
||||
else
|
||||
s = "U";
|
||||
}
|
||||
else
|
||||
{
|
||||
requiredLevel = 3;
|
||||
if (mode == NUpdateNotifyOp::kAnalyze)
|
||||
s = "A";
|
||||
else
|
||||
s = "Reading";
|
||||
}
|
||||
|
||||
return PrintProgress(name, isDir, s, LogLevel >= requiredLevel);
|
||||
}
|
||||
|
||||
HRESULT CUpdateCallbackConsole::OpenFileError(const FString &path, DWORD systemError)
|
||||
{
|
||||
return OpenFileError_Base(path, systemError);
|
||||
}
|
||||
|
||||
HRESULT CUpdateCallbackConsole::ReadingFileError(const FString &path, DWORD systemError)
|
||||
{
|
||||
return ReadingFileError_Base(path, systemError);
|
||||
}
|
||||
|
||||
HRESULT CUpdateCallbackConsole::SetOperationResult(Int32 /* opRes */)
|
||||
{
|
||||
MT_LOCK
|
||||
_percent.Files++;
|
||||
/*
|
||||
if (opRes != NArchive::NUpdate::NOperationResult::kOK)
|
||||
{
|
||||
if (opRes == NArchive::NUpdate::NOperationResult::kError_FileChanged)
|
||||
{
|
||||
CommonError("Input file changed");
|
||||
}
|
||||
}
|
||||
*/
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void SetExtractErrorMessage(Int32 opRes, Int32 encrypted, AString &dest);
|
||||
|
||||
HRESULT CUpdateCallbackConsole::ReportExtractResult(Int32 opRes, Int32 isEncrypted, const wchar_t *name)
|
||||
{
|
||||
// if (StdOutMode) return S_OK;
|
||||
|
||||
if (opRes != NArchive::NExtract::NOperationResult::kOK)
|
||||
{
|
||||
ClosePercents2();
|
||||
|
||||
if (_se)
|
||||
{
|
||||
if (_so)
|
||||
_so->Flush();
|
||||
|
||||
AString s;
|
||||
SetExtractErrorMessage(opRes, isEncrypted, s);
|
||||
*_se << s << " : " << endl;
|
||||
_se->NormalizePrint_wstr_Path(name);
|
||||
*_se << endl << endl;
|
||||
_se->Flush();
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
HRESULT CUpdateCallbackConsole::ReportUpdateOperation(UInt32 op, const wchar_t *name, bool isDir)
|
||||
{
|
||||
// if (StdOutMode) return S_OK;
|
||||
|
||||
char temp[16];
|
||||
const char *s;
|
||||
|
||||
unsigned requiredLevel = 1;
|
||||
|
||||
switch (op)
|
||||
{
|
||||
case NUpdateNotifyOp::kAdd: s = "+"; break;
|
||||
case NUpdateNotifyOp::kUpdate: s = "U"; break;
|
||||
case NUpdateNotifyOp::kAnalyze: s = "A"; requiredLevel = 3; break;
|
||||
case NUpdateNotifyOp::kReplicate: s = "="; requiredLevel = 3; break;
|
||||
case NUpdateNotifyOp::kRepack: s = "R"; requiredLevel = 2; break;
|
||||
case NUpdateNotifyOp::kSkip: s = "."; requiredLevel = 2; break;
|
||||
case NUpdateNotifyOp::kDelete: s = "D"; requiredLevel = 3; break;
|
||||
case NUpdateNotifyOp::kHeader: s = "Header creation"; requiredLevel = 100; break;
|
||||
case NUpdateNotifyOp::kInFileChanged: s = "Size of input file was changed:"; requiredLevel = 10; break;
|
||||
// case NUpdateNotifyOp::kOpFinished: s = "Finished"; requiredLevel = 100; break;
|
||||
default:
|
||||
{
|
||||
temp[0] = 'o';
|
||||
temp[1] = 'p';
|
||||
ConvertUInt64ToString(op, temp + 2);
|
||||
s = temp;
|
||||
}
|
||||
}
|
||||
|
||||
return PrintProgress(name, isDir, s, LogLevel >= requiredLevel);
|
||||
}
|
||||
|
||||
/*
|
||||
HRESULT CUpdateCallbackConsole::SetPassword(const UString &
|
||||
#ifndef Z7_NO_CRYPTO
|
||||
password
|
||||
#endif
|
||||
)
|
||||
{
|
||||
#ifndef Z7_NO_CRYPTO
|
||||
PasswordIsDefined = true;
|
||||
Password = password;
|
||||
#endif
|
||||
return S_OK;
|
||||
}
|
||||
*/
|
||||
|
||||
HRESULT CUpdateCallbackConsole::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
|
||||
*password = NULL;
|
||||
|
||||
#ifdef Z7_NO_CRYPTO
|
||||
|
||||
*passwordIsDefined = false;
|
||||
return S_OK;
|
||||
|
||||
#else
|
||||
|
||||
if (!PasswordIsDefined)
|
||||
{
|
||||
if (AskPassword)
|
||||
{
|
||||
RINOK(GetPassword_HRESULT(_so, Password))
|
||||
PasswordIsDefined = true;
|
||||
}
|
||||
}
|
||||
*passwordIsDefined = BoolToInt(PasswordIsDefined);
|
||||
return StringToBstr(Password, password);
|
||||
|
||||
#endif
|
||||
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
HRESULT CUpdateCallbackConsole::CryptoGetTextPassword(BSTR *password)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
|
||||
*password = NULL;
|
||||
|
||||
#ifdef Z7_NO_CRYPTO
|
||||
|
||||
return E_NOTIMPL;
|
||||
|
||||
#else
|
||||
|
||||
if (!PasswordIsDefined)
|
||||
{
|
||||
{
|
||||
RINOK(GetPassword_HRESULT(_so, Password))
|
||||
PasswordIsDefined = true;
|
||||
}
|
||||
}
|
||||
return StringToBstr(Password, password);
|
||||
|
||||
#endif
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
HRESULT CUpdateCallbackConsole::ShowDeleteFile(const wchar_t *name, bool isDir)
|
||||
{
|
||||
if (StdOutMode)
|
||||
return S_OK;
|
||||
|
||||
if (LogLevel > 7)
|
||||
{
|
||||
if (!name || name[0] == 0)
|
||||
name = kEmptyFileAlias;
|
||||
return PrintProgress(name, isDir, "D", true);
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
void GetPropName(PROPID propID, const wchar_t *name, AString &nameA, UString &nameU);
|
||||
|
||||
static void GetPropName(PROPID propID, UString &nameU)
|
||||
{
|
||||
AString nameA;
|
||||
GetPropName(propID, NULL, nameA, nameU);
|
||||
// if (!nameA.IsEmpty())
|
||||
nameU = nameA;
|
||||
}
|
||||
|
||||
|
||||
static void AddPropNamePrefix(UString &s, PROPID propID)
|
||||
{
|
||||
UString name;
|
||||
GetPropName(propID, name);
|
||||
s += name;
|
||||
s += " = ";
|
||||
}
|
||||
|
||||
void CCallbackConsoleBase::PrintPropInfo(UString &s, PROPID propID, const PROPVARIANT *value)
|
||||
{
|
||||
AddPropNamePrefix(s, propID);
|
||||
{
|
||||
UString dest;
|
||||
const int level = 9; // we show up to ns precision level
|
||||
ConvertPropertyToString2(dest, *value, propID, level);
|
||||
s += dest;
|
||||
}
|
||||
PrintInfoLine(s);
|
||||
}
|
||||
|
||||
static void Add_IndexType_Index(UString &s, UInt32 indexType, UInt32 index)
|
||||
{
|
||||
if (indexType == NArchive::NEventIndexType::kArcProp)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
if (indexType == NArchive::NEventIndexType::kBlockIndex)
|
||||
{
|
||||
s += "#";
|
||||
}
|
||||
else if (indexType == NArchive::NEventIndexType::kOutArcIndex)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
s += "indexType_";
|
||||
s.Add_UInt32(indexType);
|
||||
s.Add_Space();
|
||||
}
|
||||
s.Add_UInt32(index);
|
||||
}
|
||||
s += ": ";
|
||||
}
|
||||
|
||||
HRESULT CUpdateCallbackConsole::ReportProp(UInt32 indexType, UInt32 index, PROPID propID, const PROPVARIANT *value)
|
||||
{
|
||||
UString s;
|
||||
Add_IndexType_Index(s, indexType, index);
|
||||
PrintPropInfo(s, propID, value);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static inline char GetHex(Byte value)
|
||||
{
|
||||
return (char)((value < 10) ? ('0' + value) : ('a' + (value - 10)));
|
||||
}
|
||||
|
||||
static void AddHexToString(UString &dest, const Byte *data, UInt32 size)
|
||||
{
|
||||
for (UInt32 i = 0; i < size; i++)
|
||||
{
|
||||
Byte b = data[i];
|
||||
dest += GetHex((Byte)((b >> 4) & 0xF));
|
||||
dest += GetHex((Byte)(b & 0xF));
|
||||
}
|
||||
}
|
||||
|
||||
void HashHexToString(char *dest, const Byte *data, UInt32 size);
|
||||
|
||||
HRESULT CUpdateCallbackConsole::ReportRawProp(UInt32 indexType, UInt32 index,
|
||||
PROPID propID, const void *data, UInt32 dataSize, UInt32 propType)
|
||||
{
|
||||
UString s;
|
||||
propType = propType;
|
||||
Add_IndexType_Index(s, indexType, index);
|
||||
AddPropNamePrefix(s, propID);
|
||||
if (propID == kpidChecksum)
|
||||
{
|
||||
char temp[k_HashCalc_DigestSize_Max + 8];
|
||||
HashHexToString(temp, (const Byte *)data, dataSize);
|
||||
s += temp;
|
||||
}
|
||||
else
|
||||
AddHexToString(s, (const Byte *)data, dataSize);
|
||||
PrintInfoLine(s);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CUpdateCallbackConsole::ReportFinished(UInt32 indexType, UInt32 index, Int32 opRes)
|
||||
{
|
||||
UString s;
|
||||
Add_IndexType_Index(s, indexType, index);
|
||||
s += "finished";
|
||||
if (opRes != NArchive::NUpdate::NOperationResult::kOK)
|
||||
{
|
||||
s += ": ";
|
||||
s.Add_UInt32(opRes);
|
||||
}
|
||||
PrintInfoLine(s);
|
||||
return S_OK;
|
||||
}
|
||||
*/
|
||||
@@ -0,0 +1,148 @@
|
||||
// UpdateCallbackConsole.h
|
||||
|
||||
#ifndef ZIP7_INC_UPDATE_CALLBACK_CONSOLE_H
|
||||
#define ZIP7_INC_UPDATE_CALLBACK_CONSOLE_H
|
||||
|
||||
#include "../../../Common/StdOutStream.h"
|
||||
|
||||
#include "../Common/Update.h"
|
||||
|
||||
#include "PercentPrinter.h"
|
||||
|
||||
struct CErrorPathCodes
|
||||
{
|
||||
FStringVector Paths;
|
||||
CRecordVector<DWORD> Codes;
|
||||
|
||||
void AddError(const FString &path, DWORD systemError)
|
||||
{
|
||||
Paths.Add(path);
|
||||
Codes.Add(systemError);
|
||||
}
|
||||
void Clear()
|
||||
{
|
||||
Paths.Clear();
|
||||
Codes.Clear();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class CCallbackConsoleBase
|
||||
{
|
||||
void CommonError(const FString &path, DWORD systemError, bool isWarning);
|
||||
|
||||
protected:
|
||||
CStdOutStream *_so;
|
||||
CStdOutStream *_se;
|
||||
|
||||
HRESULT ScanError_Base(const FString &path, DWORD systemError);
|
||||
HRESULT OpenFileError_Base(const FString &name, DWORD systemError);
|
||||
HRESULT ReadingFileError_Base(const FString &name, DWORD systemError);
|
||||
|
||||
public:
|
||||
bool StdOutMode;
|
||||
bool NeedFlush;
|
||||
unsigned PercentsNameLevel;
|
||||
unsigned LogLevel;
|
||||
|
||||
protected:
|
||||
AString _tempA;
|
||||
UString _tempU;
|
||||
CPercentPrinter _percent;
|
||||
|
||||
public:
|
||||
CErrorPathCodes FailedFiles;
|
||||
CErrorPathCodes ScanErrors;
|
||||
UInt64 NumNonOpenFiles;
|
||||
|
||||
CCallbackConsoleBase():
|
||||
StdOutMode(false),
|
||||
NeedFlush(false),
|
||||
PercentsNameLevel(1),
|
||||
LogLevel(0),
|
||||
NumNonOpenFiles(0)
|
||||
{}
|
||||
|
||||
bool NeedPercents() const { return _percent._so != NULL; }
|
||||
void SetWindowWidth(unsigned width) { _percent.MaxLen = width - 1; }
|
||||
|
||||
void Init(
|
||||
CStdOutStream *outStream,
|
||||
CStdOutStream *errorStream,
|
||||
CStdOutStream *percentStream,
|
||||
bool disablePercents)
|
||||
{
|
||||
FailedFiles.Clear();
|
||||
|
||||
_so = outStream;
|
||||
_se = errorStream;
|
||||
_percent._so = percentStream;
|
||||
_percent.DisablePrint = disablePercents;
|
||||
}
|
||||
|
||||
void ClosePercents2()
|
||||
{
|
||||
if (NeedPercents())
|
||||
_percent.ClosePrint(true);
|
||||
}
|
||||
|
||||
void ClosePercents_for_so()
|
||||
{
|
||||
if (NeedPercents() && _so == _percent._so)
|
||||
_percent.ClosePrint(false);
|
||||
}
|
||||
|
||||
HRESULT PrintProgress(const wchar_t *name, bool isDir, const char *command, bool showInLog);
|
||||
|
||||
// void PrintInfoLine(const UString &s);
|
||||
// void PrintPropInfo(UString &s, PROPID propID, const PROPVARIANT *value);
|
||||
};
|
||||
|
||||
|
||||
class CUpdateCallbackConsole Z7_final:
|
||||
public IUpdateCallbackUI2,
|
||||
public CCallbackConsoleBase
|
||||
{
|
||||
// void PrintPropPair(const char *name, const wchar_t *val);
|
||||
Z7_IFACE_IMP(IUpdateCallbackUI)
|
||||
Z7_IFACE_IMP(IDirItemsCallback)
|
||||
Z7_IFACE_IMP(IUpdateCallbackUI2)
|
||||
|
||||
HRESULT MoveArc_UpdateStatus();
|
||||
|
||||
UInt64 _arcMoving_total;
|
||||
UInt64 _arcMoving_current;
|
||||
UInt64 _arcMoving_percents;
|
||||
Int32 _arcMoving_updateMode;
|
||||
|
||||
public:
|
||||
bool DeleteMessageWasShown;
|
||||
|
||||
#ifndef Z7_NO_CRYPTO
|
||||
bool PasswordIsDefined;
|
||||
bool AskPassword;
|
||||
UString Password;
|
||||
#endif
|
||||
|
||||
CUpdateCallbackConsole():
|
||||
_arcMoving_total(0)
|
||||
, _arcMoving_current(0)
|
||||
, _arcMoving_percents(0)
|
||||
, _arcMoving_updateMode(0)
|
||||
, DeleteMessageWasShown(false)
|
||||
#ifndef Z7_NO_CRYPTO
|
||||
, PasswordIsDefined(false)
|
||||
, AskPassword(false)
|
||||
#endif
|
||||
{}
|
||||
|
||||
/*
|
||||
void Init(CStdOutStream *outStream)
|
||||
{
|
||||
CCallbackConsoleBase::Init(outStream);
|
||||
}
|
||||
*/
|
||||
// ~CUpdateCallbackConsole() { if (NeedPercents()) _percent.ClosePrint(); }
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,118 @@
|
||||
// UserInputUtils.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "../../../Common/StdInStream.h"
|
||||
#include "../../../Common/StringConvert.h"
|
||||
|
||||
#include "UserInputUtils.h"
|
||||
|
||||
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 * const kFirstQuestionMessage = "? ";
|
||||
static const char * const 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)
|
||||
{
|
||||
if (outStream)
|
||||
*outStream << kFirstQuestionMessage;
|
||||
for (;;)
|
||||
{
|
||||
if (outStream)
|
||||
{
|
||||
*outStream << kHelpQuestionMessage;
|
||||
outStream->Flush();
|
||||
}
|
||||
AString scannedString;
|
||||
if (!g_StdIn.ScanAStringUntilNewLine(scannedString))
|
||||
return NUserAnswerMode::kError;
|
||||
if (g_StdIn.Error())
|
||||
return NUserAnswerMode::kError;
|
||||
scannedString.Trim();
|
||||
if (scannedString.IsEmpty() && g_StdIn.Eof())
|
||||
return NUserAnswerMode::kEof;
|
||||
|
||||
if (scannedString.Len() == 1)
|
||||
switch (::MyCharLower_Ascii(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;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef UNDER_CE
|
||||
#define MY_DISABLE_ECHO
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static bool GetPassword(CStdOutStream *outStream, UString &psw)
|
||||
{
|
||||
if (outStream)
|
||||
{
|
||||
*outStream << "\nEnter password"
|
||||
#ifdef MY_DISABLE_ECHO
|
||||
" (will not be echoed)"
|
||||
#endif
|
||||
":";
|
||||
outStream->Flush();
|
||||
}
|
||||
|
||||
#ifdef MY_DISABLE_ECHO
|
||||
|
||||
const HANDLE console = GetStdHandle(STD_INPUT_HANDLE);
|
||||
|
||||
/*
|
||||
GetStdHandle() returns
|
||||
INVALID_HANDLE_VALUE: If the function fails.
|
||||
NULL : If an application does not have associated standard handles,
|
||||
such as a service running on an interactive desktop,
|
||||
and has not redirected them. */
|
||||
bool wasChanged = false;
|
||||
DWORD mode = 0;
|
||||
if (console != INVALID_HANDLE_VALUE && console != NULL)
|
||||
if (GetConsoleMode(console, &mode))
|
||||
wasChanged = (SetConsoleMode(console, mode & ~(DWORD)ENABLE_ECHO_INPUT) != 0);
|
||||
const bool res = g_StdIn.ScanUStringUntilNewLine(psw);
|
||||
if (wasChanged)
|
||||
SetConsoleMode(console, mode);
|
||||
|
||||
#else
|
||||
|
||||
const bool res = g_StdIn.ScanUStringUntilNewLine(psw);
|
||||
|
||||
#endif
|
||||
|
||||
if (outStream)
|
||||
{
|
||||
*outStream << endl;
|
||||
outStream->Flush();
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
HRESULT GetPassword_HRESULT(CStdOutStream *outStream, UString &psw)
|
||||
{
|
||||
if (!GetPassword(outStream, psw))
|
||||
return E_INVALIDARG;
|
||||
if (g_StdIn.Error())
|
||||
return E_FAIL;
|
||||
if (g_StdIn.Eof() && psw.IsEmpty())
|
||||
return E_ABORT;
|
||||
return S_OK;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// UserInputUtils.h
|
||||
|
||||
#ifndef ZIP7_INC_USER_INPUT_UTILS_H
|
||||
#define ZIP7_INC_USER_INPUT_UTILS_H
|
||||
|
||||
#include "../../../Common/StdOutStream.h"
|
||||
|
||||
namespace NUserAnswerMode {
|
||||
|
||||
enum EEnum
|
||||
{
|
||||
kYes,
|
||||
kNo,
|
||||
kYesAll,
|
||||
kNoAll,
|
||||
kAutoRenameAll,
|
||||
kQuit,
|
||||
kEof,
|
||||
kError
|
||||
};
|
||||
}
|
||||
|
||||
NUserAnswerMode::EEnum ScanUserYesNoAllQuit(CStdOutStream *outStream);
|
||||
// bool GetPassword(CStdOutStream *outStream, UString &psw);
|
||||
HRESULT GetPassword_HRESULT(CStdOutStream *outStream, UString &psw);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,68 @@
|
||||
PROG = 7z.exe
|
||||
CFLAGS = $(CFLAGS) \
|
||||
-DZ7_EXTERNAL_CODECS \
|
||||
|
||||
COMMON_OBJS = \
|
||||
$O\CommandLineParser.obj \
|
||||
$O\CRC.obj \
|
||||
$O\DynLimBuf.obj \
|
||||
$O\IntToString.obj \
|
||||
$O\ListFileUtils.obj \
|
||||
$O\NewHandler.obj \
|
||||
$O\StdInStream.obj \
|
||||
$O\StdOutStream.obj \
|
||||
$O\MyString.obj \
|
||||
$O\StringConvert.obj \
|
||||
$O\StringToInt.obj \
|
||||
$O\UTFConvert.obj \
|
||||
$O\MyVector.obj \
|
||||
$O\Wildcard.obj \
|
||||
|
||||
WIN_OBJS = \
|
||||
$O\DLL.obj \
|
||||
$O\ErrorMsg.obj \
|
||||
$O\FileDir.obj \
|
||||
$O\FileFind.obj \
|
||||
$O\FileIO.obj \
|
||||
$O\FileLink.obj \
|
||||
$O\FileName.obj \
|
||||
$O\FileSystem.obj \
|
||||
$O\MemoryLock.obj \
|
||||
$O\PropVariant.obj \
|
||||
$O\PropVariantConv.obj \
|
||||
$O\Registry.obj \
|
||||
$O\System.obj \
|
||||
$O\SystemInfo.obj \
|
||||
$O\TimeUtils.obj \
|
||||
|
||||
7ZIP_COMMON_OBJS = \
|
||||
$O\CreateCoder.obj \
|
||||
$O\FilePathAutoRename.obj \
|
||||
$O\FileStreams.obj \
|
||||
$O\FilterCoder.obj \
|
||||
$O\LimitedStreams.obj \
|
||||
$O\MethodProps.obj \
|
||||
$O\MultiOutStream.obj \
|
||||
$O\ProgressUtils.obj \
|
||||
$O\PropId.obj \
|
||||
$O\StreamObjects.obj \
|
||||
$O\StreamUtils.obj \
|
||||
$O\UniqBlocks.obj \
|
||||
|
||||
AR_COMMON_OBJS = \
|
||||
$O\ItemNameUtils.obj \
|
||||
$O\OutStreamWithCRC.obj \
|
||||
|
||||
COMPRESS_OBJS = \
|
||||
$O\CopyCoder.obj \
|
||||
|
||||
C_OBJS = $(C_OBJS) \
|
||||
$O\Alloc.obj \
|
||||
$O\CpuArch.obj \
|
||||
$O\Threads.obj \
|
||||
|
||||
!include "../../Crc.mak"
|
||||
!include "../../Sort.mak"
|
||||
!include "Console.mak"
|
||||
|
||||
!include "../../7zip.mak"
|
||||
@@ -0,0 +1,187 @@
|
||||
PROG = 7z
|
||||
IS_NOT_STANDALONE = 1
|
||||
|
||||
# IS_X64 = 1
|
||||
# USE_ASM = 1
|
||||
# ST_MODE = 1
|
||||
|
||||
|
||||
LOCAL_FLAGS_ST =
|
||||
MT_OBJS =
|
||||
|
||||
ifdef SystemDrive
|
||||
IS_MINGW = 1
|
||||
else
|
||||
ifdef SYSTEMDRIVE
|
||||
# ifdef OS
|
||||
IS_MINGW = 1
|
||||
endif
|
||||
endif
|
||||
|
||||
ifdef ST_MODE
|
||||
|
||||
LOCAL_FLAGS_ST = -DZ7_ST
|
||||
|
||||
ifdef IS_MINGW
|
||||
MT_OBJS = \
|
||||
$O/Threads.o \
|
||||
|
||||
endif
|
||||
|
||||
else
|
||||
|
||||
MT_OBJS = \
|
||||
$O/Synchronization.o \
|
||||
$O/Threads.o \
|
||||
|
||||
endif
|
||||
|
||||
|
||||
|
||||
LOCAL_FLAGS_SYS=
|
||||
|
||||
ifdef IS_MINGW
|
||||
|
||||
LOCAL_FLAGS_SYS = \
|
||||
-DZ7_DEVICE_FILE \
|
||||
|
||||
# -DZ7_LARGE_PAGES
|
||||
# -DZ7_LONG_PATH
|
||||
|
||||
SYS_OBJS = \
|
||||
$O/FileSystem.o \
|
||||
$O/Registry.o \
|
||||
$O/MemoryLock.o \
|
||||
$O/DllSecur.o \
|
||||
$O/resource.o \
|
||||
|
||||
else
|
||||
|
||||
SYS_OBJS = \
|
||||
$O/MyWindows.o \
|
||||
|
||||
endif
|
||||
|
||||
|
||||
|
||||
LOCAL_FLAGS = \
|
||||
$(LOCAL_FLAGS_SYS) \
|
||||
$(LOCAL_FLAGS_ST) \
|
||||
-DZ7_EXTERNAL_CODECS \
|
||||
|
||||
|
||||
|
||||
CONSOLE_OBJS = \
|
||||
$O/BenchCon.o \
|
||||
$O/ConsoleClose.o \
|
||||
$O/ExtractCallbackConsole.o \
|
||||
$O/HashCon.o \
|
||||
$O/List.o \
|
||||
$O/Main.o \
|
||||
$O/MainAr.o \
|
||||
$O/OpenCallbackConsole.o \
|
||||
$O/PercentPrinter.o \
|
||||
$O/UpdateCallbackConsole.o \
|
||||
$O/UserInputUtils.o \
|
||||
|
||||
UI_COMMON_OBJS = \
|
||||
$O/ArchiveCommandLine.o \
|
||||
$O/ArchiveExtractCallback.o \
|
||||
$O/ArchiveOpenCallback.o \
|
||||
$O/Bench.o \
|
||||
$O/DefaultName.o \
|
||||
$O/EnumDirItems.o \
|
||||
$O/Extract.o \
|
||||
$O/ExtractingFilePath.o \
|
||||
$O/HashCalc.o \
|
||||
$O/LoadCodecs.o \
|
||||
$O/OpenArchive.o \
|
||||
$O/PropIDUtils.o \
|
||||
$O/SetProperties.o \
|
||||
$O/SortUtils.o \
|
||||
$O/TempFiles.o \
|
||||
$O/Update.o \
|
||||
$O/UpdateAction.o \
|
||||
$O/UpdateCallback.o \
|
||||
$O/UpdatePair.o \
|
||||
$O/UpdateProduce.o \
|
||||
|
||||
COMMON_OBJS = \
|
||||
$O/CommandLineParser.o \
|
||||
$O/CRC.o \
|
||||
$O/CrcReg.o \
|
||||
$O/DynLimBuf.o \
|
||||
$O/IntToString.o \
|
||||
$O/ListFileUtils.o \
|
||||
$O/NewHandler.o \
|
||||
$O/StdInStream.o \
|
||||
$O/StdOutStream.o \
|
||||
$O/MyString.o \
|
||||
$O/StringConvert.o \
|
||||
$O/StringToInt.o \
|
||||
$O/UTFConvert.o \
|
||||
$O/MyVector.o \
|
||||
$O/Wildcard.o \
|
||||
|
||||
WIN_OBJS = \
|
||||
$O/DLL.o \
|
||||
$O/ErrorMsg.o \
|
||||
$O/FileDir.o \
|
||||
$O/FileFind.o \
|
||||
$O/FileIO.o \
|
||||
$O/FileLink.o \
|
||||
$O/FileName.o \
|
||||
$O/PropVariant.o \
|
||||
$O/PropVariantConv.o \
|
||||
$O/System.o \
|
||||
$O/SystemInfo.o \
|
||||
$O/TimeUtils.o \
|
||||
|
||||
7ZIP_COMMON_OBJS = \
|
||||
$O/CreateCoder.o \
|
||||
$O/CWrappers.o \
|
||||
$O/FilePathAutoRename.o \
|
||||
$O/FileStreams.o \
|
||||
$O/InBuffer.o \
|
||||
$O/InOutTempBuffer.o \
|
||||
$O/FilterCoder.o \
|
||||
$O/LimitedStreams.o \
|
||||
$O/MethodId.o \
|
||||
$O/MethodProps.o \
|
||||
$O/MultiOutStream.o \
|
||||
$O/OffsetStream.o \
|
||||
$O/OutBuffer.o \
|
||||
$O/ProgressUtils.o \
|
||||
$O/PropId.o \
|
||||
$O/StreamObjects.o \
|
||||
$O/StreamUtils.o \
|
||||
$O/UniqBlocks.o \
|
||||
|
||||
COMPRESS_OBJS = \
|
||||
$O/CopyCoder.o \
|
||||
|
||||
AR_COMMON_OBJS = \
|
||||
$O/ItemNameUtils.o \
|
||||
|
||||
C_OBJS = \
|
||||
$O/Alloc.o \
|
||||
$O/CpuArch.o \
|
||||
$O/Sort.o \
|
||||
$O/7zCrc.o \
|
||||
$O/7zCrcOpt.o \
|
||||
|
||||
|
||||
OBJS = \
|
||||
$(C_OBJS) \
|
||||
$(MT_OBJS) \
|
||||
$(COMMON_OBJS) \
|
||||
$(WIN_OBJS) \
|
||||
$(SYS_OBJS) \
|
||||
$(COMPRESS_OBJS) \
|
||||
$(AR_COMMON_OBJS) \
|
||||
$(7ZIP_COMMON_OBJS) \
|
||||
$(UI_COMMON_OBJS) \
|
||||
$(CONSOLE_OBJS) \
|
||||
|
||||
|
||||
include ../../7zip_gcc.mak
|
||||
@@ -0,0 +1,7 @@
|
||||
#include "../../MyVersionInfo.rc"
|
||||
|
||||
MY_VERSION_INFO_APP("7-Zip Console" , "7z")
|
||||
|
||||
#ifndef UNDER_CE
|
||||
1 24 MOVEABLE PURE "Console.manifest"
|
||||
#endif
|
||||
Reference in New Issue
Block a user