aboutsummaryrefslogtreecommitdiff
path: root/CPP/7zip/UI/Console/ExtractCallbackConsole.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'CPP/7zip/UI/Console/ExtractCallbackConsole.cpp')
-rw-r--r--[-rwxr-xr-x]CPP/7zip/UI/Console/ExtractCallbackConsole.cpp245
1 files changed, 200 insertions, 45 deletions
diff --git a/CPP/7zip/UI/Console/ExtractCallbackConsole.cpp b/CPP/7zip/UI/Console/ExtractCallbackConsole.cpp
index 278b069..0c6f806 100755..100644
--- a/CPP/7zip/UI/Console/ExtractCallbackConsole.cpp
+++ b/CPP/7zip/UI/Console/ExtractCallbackConsole.cpp
@@ -1,20 +1,21 @@
-// ExtractCallbackConsole.h
+// ExtractCallbackConsole.cpp
#include "StdAfx.h"
+// #undef sprintf
+
+#include "ConsoleClose.h"
#include "ExtractCallbackConsole.h"
#include "UserInputUtils.h"
-#include "ConsoleClose.h"
-#include "Common/Wildcard.h"
+#include "../../../Common/IntToString.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 "../../../Windows/FileDir.h"
+#include "../../../Windows/FileFind.h"
+#include "../../../Windows/TimeUtils.h"
+#include "../../../Windows/ErrorMsg.h"
+#include "../../../Windows/PropVariantConv.h"
#include "../../Common/FilePathAutoRename.h"
@@ -22,11 +23,11 @@
using namespace NWindows;
using namespace NFile;
-using namespace NDirectory;
+using namespace NDir;
static const char *kTestString = "Testing ";
static const char *kExtractString = "Extracting ";
-static const char *kSkipString = "Skipping ";
+static const char *kSkipString = "Skipping ";
// static const char *kCantAutoRename = "can not create file with auto name\n";
// static const char *kCantRenameFile = "can not rename existing file\n";
@@ -43,7 +44,27 @@ static const char *kCrcFailed = "CRC Failed";
static const char *kCrcFailedEncrypted = "CRC Failed in encrypted file. Wrong password?";
static const char *kDataError = "Data Error";
static const char *kDataErrorEncrypted = "Data Error in encrypted file. Wrong password?";
-static const char *kUnknownError = "Unknown Error";
+static const char *kUnavailableData = "Unavailable data";
+static const char *kUnexpectedEnd = "Unexpected end of data";
+static const char *kDataAfterEnd = "There are some data after the end of the payload data";
+static const char *kIsNotArc = "Is not archive";
+static const char *kHeadersError = "Headers Error";
+
+static const char *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"
+};
+
STDMETHODIMP CExtractCallbackConsole::SetTotal(UInt64)
{
@@ -64,13 +85,13 @@ STDMETHODIMP CExtractCallbackConsole::AskOverwrite(
const wchar_t *newName, const FILETIME *, const UInt64 *,
Int32 *answer)
{
- (*OutStream) << "file " << existName <<
- "\nalready exists. Overwrite with " << endl;
- (*OutStream) << newName;
+ (*OutStream) << "file " << existName << endl <<
+ "already exists. Overwrite with" << endl <<
+ newName;
NUserAnswerMode::EEnum overwriteAnswer = ScanUserYesNoAllQuit(OutStream);
- switch(overwriteAnswer)
+ switch (overwriteAnswer)
{
case NUserAnswerMode::kQuit: return E_ABORT;
case NUserAnswerMode::kNo: *answer = NOverwriteAnswer::kNo; break;
@@ -85,13 +106,15 @@ STDMETHODIMP CExtractCallbackConsole::AskOverwrite(
STDMETHODIMP CExtractCallbackConsole::PrepareOperation(const wchar_t *name, bool /* isFolder */, Int32 askExtractMode, const UInt64 *position)
{
+ const char *s;
switch (askExtractMode)
{
- case NArchive::NExtract::NAskMode::kExtract: (*OutStream) << kExtractString; break;
- case NArchive::NExtract::NAskMode::kTest: (*OutStream) << kTestString; break;
- case NArchive::NExtract::NAskMode::kSkip: (*OutStream) << kSkipString; break;
+ case NArchive::NExtract::NAskMode::kExtract: s = kExtractString; break;
+ case NArchive::NExtract::NAskMode::kTest: s = kTestString; break;
+ case NArchive::NExtract::NAskMode::kSkip: s = kSkipString; break;
+ default: s = ""; // return E_FAIL;
};
- (*OutStream) << name;
+ (*OutStream) << s << name;
if (position != 0)
(*OutStream) << " <" << *position << ">";
return S_OK;
@@ -100,35 +123,57 @@ STDMETHODIMP CExtractCallbackConsole::PrepareOperation(const wchar_t *name, bool
STDMETHODIMP CExtractCallbackConsole::MessageError(const wchar_t *message)
{
(*OutStream) << message << endl;
- NumFileErrorsInCurrentArchive++;
+ NumFileErrorsInCurrent++;
NumFileErrors++;
return S_OK;
}
STDMETHODIMP CExtractCallbackConsole::SetOperationResult(Int32 operationResult, bool encrypted)
{
- switch(operationResult)
+ switch (operationResult)
{
case NArchive::NExtract::NOperationResult::kOK:
break;
default:
{
- NumFileErrorsInCurrentArchive++;
+ NumFileErrorsInCurrent++;
NumFileErrors++;
- (*OutStream) << " ";
- switch(operationResult)
+ (*OutStream) << " : ";
+ const char *s = NULL;
+ switch (operationResult)
{
- case NArchive::NExtract::NOperationResult::kUnSupportedMethod:
- (*OutStream) << kUnsupportedMethod;
+ case NArchive::NExtract::NOperationResult::kUnsupportedMethod:
+ s = kUnsupportedMethod;
break;
case NArchive::NExtract::NOperationResult::kCRCError:
- (*OutStream) << (encrypted ? kCrcFailedEncrypted: kCrcFailed);
+ s = (encrypted ? kCrcFailedEncrypted : kCrcFailed);
break;
case NArchive::NExtract::NOperationResult::kDataError:
- (*OutStream) << (encrypted ? kDataErrorEncrypted : 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;
- default:
- (*OutStream) << kUnknownError;
+ case NArchive::NExtract::NOperationResult::kIsNotArc:
+ s = kIsNotArc;
+ break;
+ case NArchive::NExtract::NOperationResult::kHeadersError:
+ s = kHeadersError;
+ break;
+ }
+ if (s)
+ (*OutStream) << "Error : " << s;
+ else
+ {
+ char temp[16];
+ ConvertUInt32ToString(operationResult, temp);
+ (*OutStream) << "Error #" << temp;
}
}
}
@@ -159,8 +204,10 @@ STDMETHODIMP CExtractCallbackConsole::CryptoGetTextPassword(BSTR *password)
HRESULT CExtractCallbackConsole::BeforeOpen(const wchar_t *name)
{
- NumArchives++;
- NumFileErrorsInCurrentArchive = 0;
+ NumTryArcs++;
+ ThereIsErrorInCurrent = false;
+ ThereIsWarningInCurrent = false;
+ NumFileErrorsInCurrent = 0;
(*OutStream) << endl << kProcessing << name << endl;
return S_OK;
}
@@ -185,8 +232,90 @@ HRESULT CExtractCallbackConsole::OpenResult(const wchar_t * /* name */, HRESULT
(*OutStream) << NError::MyFormatMessage(result);
}
(*OutStream) << endl;
- NumArchiveErrors++;
+ NumCantOpenArcs++;
+ ThereIsErrorInCurrent = true;
+ }
+ return S_OK;
+}
+
+AString GetOpenArcErrorMessage(UInt32 errorFlags)
+{
+ AString s;
+ for (unsigned i = 0; i < ARRAY_SIZE(k_ErrorFlagsMessages); i++)
+ {
+ UInt32 f = (1 << i);
+ if ((errorFlags & f) == 0)
+ continue;
+ const char *m = k_ErrorFlagsMessages[i];
+ if (!s.IsEmpty())
+ s += '\n';
+ s += m;
+ errorFlags &= ~f;
+ }
+ if (errorFlags != 0)
+ {
+ char sz[16];
+ sz[0] = '0';
+ sz[1] = 'x';
+ ConvertUInt32ToHex(errorFlags, sz + 2);
+ if (!s.IsEmpty())
+ s += '\n';
+ s += sz;
+ }
+ return s;
+}
+
+
+HRESULT CExtractCallbackConsole::SetError(int level, const wchar_t *name,
+ UInt32 errorFlags, const wchar_t *errors,
+ UInt32 warningFlags, const wchar_t *warnings)
+{
+ if (level != 0)
+ {
+ (*OutStream) << name << endl;
+ }
+
+ if (errorFlags != 0)
+ {
+ (*OutStream) << "Errors: ";
+ (*OutStream) << endl;
+ (*OutStream) << GetOpenArcErrorMessage(errorFlags);
+ (*OutStream) << endl;
+ NumOpenArcErrors++;
+ ThereIsErrorInCurrent = true;
}
+
+ if (errors && wcslen(errors) != 0)
+ {
+ (*OutStream) << "Errors: ";
+ (*OutStream) << endl;
+ (*OutStream) << errors;
+ (*OutStream) << endl;
+ NumOpenArcErrors++;
+ ThereIsErrorInCurrent = true;
+ }
+
+ if (warningFlags != 0)
+ {
+ (*OutStream) << "Warnings: ";
+ (*OutStream) << endl;
+ (*OutStream) << GetOpenArcErrorMessage(warningFlags);
+ (*OutStream) << endl;
+ NumOpenArcWarnings++;
+ ThereIsWarningInCurrent = true;
+ }
+
+ if (warnings && wcslen(warnings) != 0)
+ {
+ (*OutStream) << "Warnings: ";
+ (*OutStream) << endl;
+ (*OutStream) << warnings;
+ (*OutStream) << endl;
+ NumOpenArcWarnings++;
+ ThereIsWarningInCurrent = true;
+ }
+
+ (*OutStream) << endl;
return S_OK;
}
@@ -201,28 +330,54 @@ HRESULT CExtractCallbackConsole::ExtractResult(HRESULT result)
if (result == S_OK)
{
(*OutStream) << endl;
- if (NumFileErrorsInCurrentArchive == 0)
+
+ if (NumFileErrorsInCurrent == 0 && !ThereIsErrorInCurrent)
+ {
+ if (ThereIsWarningInCurrent)
+ NumArcsWithWarnings++;
+ else
+ NumOkArcs++;
(*OutStream) << kEverythingIsOk << endl;
+ }
else
{
- NumArchiveErrors++;
- (*OutStream) << "Sub items Errors: " << NumFileErrorsInCurrentArchive << endl;
+ NumArcsWithError++;
+ if (NumFileErrorsInCurrent != 0)
+ (*OutStream) << "Sub items Errors: " << NumFileErrorsInCurrent << endl;
}
+ return S_OK;
}
- if (result == S_OK)
- return result;
- NumArchiveErrors++;
+
+ NumArcsWithError++;
if (result == E_ABORT || result == ERROR_DISK_FULL)
return result;
(*OutStream) << endl << kError;
if (result == E_OUTOFMEMORY)
(*OutStream) << kMemoryExceptionMessage;
else
+ (*OutStream) << NError::MyFormatMessage(result);
+ (*OutStream) << endl;
+ return S_OK;
+}
+
+HRESULT CExtractCallbackConsole::OpenTypeWarning(const wchar_t *name, const wchar_t *okType, const wchar_t *errorType)
+{
+ UString s = L"Warning:\n";
+ if (wcscmp(okType, errorType) == 0)
+ {
+ s += L"The archive is open with offset";
+ }
+ else
{
- UString message;
- NError::MyFormatMessage(result, message);
- (*OutStream) << message;
+ s += name;
+ s += L"\nCan not open the file as [";
+ s += errorType;
+ s += L"] archive\n";
+ s += L"The file is open as [";
+ s += okType;
+ s += L"] archive";
}
- (*OutStream) << endl;
+ (*OutStream) << s << endl << endl;
+ ThereIsWarningInCurrent = true;
return S_OK;
}