mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-11 16:07:10 -06:00
4.20
This commit is contained in:
committed by
Kornel Lesiński
parent
8c1b5c7b7e
commit
3c510ba80b
227
7zip/UI/Console/ExtractCallbackConsole.cpp
Executable file
227
7zip/UI/Console/ExtractCallbackConsole.cpp
Executable file
@@ -0,0 +1,227 @@
|
||||
// ExtractCallbackConsole.h
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "ExtractCallbackConsole.h"
|
||||
#include "UserInputUtils.h"
|
||||
#include "ConsoleClose.h"
|
||||
|
||||
#include "Common/Wildcard.h"
|
||||
|
||||
#include "Windows/FileDir.h"
|
||||
#include "Windows/FileFind.h"
|
||||
#include "Windows/Time.h"
|
||||
#include "Windows/Defs.h"
|
||||
#include "Windows/PropVariant.h"
|
||||
#include "Windows/Error.h"
|
||||
#include "Windows/PropVariantConversions.h"
|
||||
|
||||
#include "../../Common/FilePathAutoRename.h"
|
||||
|
||||
#include "../Common/ExtractingFilePath.h"
|
||||
|
||||
using namespace NWindows;
|
||||
using namespace NFile;
|
||||
using namespace NDirectory;
|
||||
|
||||
static const char *kTestingString = "Testing ";
|
||||
static const char *kExtractingString = "Extracting ";
|
||||
static const char *kSkippingString = "Skipping ";
|
||||
|
||||
static const char *kCantAutoRename = "can not create file with auto name\n";
|
||||
static const char *kCantRenameFile = "can not rename existing file\n";
|
||||
static const char *kCantDeleteOutputFile = "can not delete output file ";
|
||||
static const char *kError = "ERROR: ";
|
||||
static const char *kMemoryExceptionMessage = "Can't allocate required memory!";
|
||||
|
||||
static const char *kProcessing = "Processing archive: ";
|
||||
static const char *kEverythingIsOk = "Everything is Ok";
|
||||
static const char *kNoFiles = "No files to process";
|
||||
|
||||
static const char *kUnsupportedMethod = "Unsupported Method";
|
||||
static const char *kCRCFailed = "CRC Failed";
|
||||
static const char *kDataError = "Data Error";
|
||||
static const char *kUnknownError = "Unknown Error";
|
||||
|
||||
STDMETHODIMP CExtractCallbackConsole::SetTotal(UInt64 size)
|
||||
{
|
||||
if (NConsoleClose::TestBreakSignal())
|
||||
return E_ABORT;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CExtractCallbackConsole::SetCompleted(const UInt64 *completeValue)
|
||||
{
|
||||
if (NConsoleClose::TestBreakSignal())
|
||||
return E_ABORT;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CExtractCallbackConsole::AskOverwrite(
|
||||
const wchar_t *existName, const FILETIME *existTime, const UInt64 *existSize,
|
||||
const wchar_t *newName, const FILETIME *newTime, const UInt64 *newSize,
|
||||
Int32 *answer)
|
||||
{
|
||||
(*OutStream) << "file " << existName <<
|
||||
"\nalready exists. Overwrite with " << endl;
|
||||
(*OutStream) << newName;
|
||||
|
||||
NUserAnswerMode::EEnum overwriteAnswer = ScanUserYesNoAllQuit(OutStream);
|
||||
|
||||
switch(overwriteAnswer)
|
||||
{
|
||||
case NUserAnswerMode::kQuit:
|
||||
return E_ABORT;
|
||||
case NUserAnswerMode::kNo:
|
||||
*answer = NOverwriteAnswer::kNo;
|
||||
break;
|
||||
case NUserAnswerMode::kNoAll:
|
||||
*answer = NOverwriteAnswer::kNoToAll;
|
||||
break;
|
||||
case NUserAnswerMode::kYesAll:
|
||||
*answer = NOverwriteAnswer::kYesToAll;
|
||||
break;
|
||||
case NUserAnswerMode::kYes:
|
||||
*answer = NOverwriteAnswer::kYes;
|
||||
break;
|
||||
case NUserAnswerMode::kAutoRename:
|
||||
*answer = NOverwriteAnswer::kAutoRename;
|
||||
break;
|
||||
default:
|
||||
return E_FAIL;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CExtractCallbackConsole::PrepareOperation(const wchar_t *name, Int32 askExtractMode, const UInt64 *position)
|
||||
{
|
||||
switch (askExtractMode)
|
||||
{
|
||||
case NArchive::NExtract::NAskMode::kExtract:
|
||||
(*OutStream) << kExtractingString;
|
||||
break;
|
||||
case NArchive::NExtract::NAskMode::kTest:
|
||||
(*OutStream) << kTestingString;
|
||||
break;
|
||||
case NArchive::NExtract::NAskMode::kSkip:
|
||||
(*OutStream) << kSkippingString;
|
||||
break;
|
||||
};
|
||||
(*OutStream) << name;
|
||||
if (position != 0)
|
||||
(*OutStream) << " <" << *position << ">";
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CExtractCallbackConsole::MessageError(const wchar_t *message)
|
||||
{
|
||||
(*OutStream) << message << endl;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CExtractCallbackConsole::SetOperationResult(Int32 operationResult)
|
||||
{
|
||||
switch(operationResult)
|
||||
{
|
||||
case NArchive::NExtract::NOperationResult::kOK:
|
||||
break;
|
||||
default:
|
||||
{
|
||||
NumFileErrorsInCurrentArchive++;
|
||||
NumFileErrors++;
|
||||
(*OutStream) << " ";
|
||||
switch(operationResult)
|
||||
{
|
||||
case NArchive::NExtract::NOperationResult::kUnSupportedMethod:
|
||||
(*OutStream) << kUnsupportedMethod;
|
||||
break;
|
||||
case NArchive::NExtract::NOperationResult::kCRCError:
|
||||
(*OutStream) << kCRCFailed;
|
||||
break;
|
||||
case NArchive::NExtract::NOperationResult::kDataError:
|
||||
(*OutStream) << kDataError;
|
||||
break;
|
||||
default:
|
||||
(*OutStream) << kUnknownError;
|
||||
}
|
||||
}
|
||||
}
|
||||
(*OutStream) << endl;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CExtractCallbackConsole::CryptoGetTextPassword(BSTR *password)
|
||||
{
|
||||
if (!PasswordIsDefined)
|
||||
{
|
||||
Password = GetPassword(OutStream);
|
||||
PasswordIsDefined = true;
|
||||
}
|
||||
CMyComBSTR tempName(Password);
|
||||
*password = tempName.Detach();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CExtractCallbackConsole::BeforeOpen(const wchar_t *name)
|
||||
{
|
||||
NumArchives++;
|
||||
NumFileErrorsInCurrentArchive = 0;
|
||||
(*OutStream) << endl << kProcessing << name << endl;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CExtractCallbackConsole::OpenResult(const wchar_t *name, HRESULT result)
|
||||
{
|
||||
(*OutStream) << endl;
|
||||
if (result != S_OK)
|
||||
{
|
||||
(*OutStream) << "Error: " << name << " is not supported archive" << endl;
|
||||
NumArchiveErrors++;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CExtractCallbackConsole::ThereAreNoFiles()
|
||||
{
|
||||
(*OutStream) << endl << kNoFiles << endl;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CExtractCallbackConsole::ExtractResult(HRESULT result)
|
||||
{
|
||||
if (result == S_OK)
|
||||
{
|
||||
(*OutStream) << endl;
|
||||
if (NumFileErrorsInCurrentArchive == 0)
|
||||
(*OutStream) << kEverythingIsOk << endl;
|
||||
else
|
||||
{
|
||||
NumArchiveErrors++;
|
||||
(*OutStream) << "Sub items Errors: " << NumFileErrorsInCurrentArchive << endl;
|
||||
}
|
||||
}
|
||||
if (result == S_OK)
|
||||
return result;
|
||||
if (result == E_ABORT)
|
||||
return result;
|
||||
(*OutStream) << endl << kError;
|
||||
if (result == E_OUTOFMEMORY)
|
||||
(*OutStream) << kMemoryExceptionMessage;
|
||||
else
|
||||
{
|
||||
UString message;
|
||||
NError::MyFormatMessage(result, message);
|
||||
(*OutStream) << message;
|
||||
}
|
||||
(*OutStream) << endl;
|
||||
|
||||
NumArchiveErrors++;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CExtractCallbackConsole::SetPassword(const UString &password)
|
||||
{
|
||||
PasswordIsDefined = true;
|
||||
Password = password;
|
||||
return S_OK;
|
||||
}
|
||||
Reference in New Issue
Block a user