diff options
Diffstat (limited to '3rdparty/lzma/CPP/7zip/Bundles/SFXCon/SfxCon.cpp')
-rw-r--r-- | 3rdparty/lzma/CPP/7zip/Bundles/SFXCon/SfxCon.cpp | 129 |
1 files changed, 86 insertions, 43 deletions
diff --git a/3rdparty/lzma/CPP/7zip/Bundles/SFXCon/SfxCon.cpp b/3rdparty/lzma/CPP/7zip/Bundles/SFXCon/SfxCon.cpp index d828922f314..cfce24d95f9 100644 --- a/3rdparty/lzma/CPP/7zip/Bundles/SFXCon/SfxCon.cpp +++ b/3rdparty/lzma/CPP/7zip/Bundles/SFXCon/SfxCon.cpp @@ -2,8 +2,10 @@ #include "StdAfx.h" -#include "../../../Common/MyWindows.h" +#include "../../../../C/CpuArch.h" +#include "../../../../C/DllSecur.h" +#include "../../../Common/MyWindows.h" #include "../../../Common/MyInitGuid.h" #include "../../../Common/CommandLineParser.h" @@ -11,8 +13,10 @@ #ifdef _WIN32 #include "../../../Windows/DLL.h" -#include "../../../Windows/FileDir.h" +#else +#include "../../../Common/StringConvert.h" #endif +#include "../../../Windows/FileDir.h" #include "../../../Windows/FileName.h" #include "../../UI/Common/ExitCode.h" @@ -24,7 +28,6 @@ #include "../../MyVersion.h" -#include "../../../../C/DllSecur.h" using namespace NWindows; using namespace NFile; @@ -32,13 +35,17 @@ using namespace NDir; using namespace NCommandLineParser; #ifdef _WIN32 -HINSTANCE g_hInstance = 0; +extern +HINSTANCE g_hInstance; +HINSTANCE g_hInstance = NULL; #endif +extern +int g_CodePage; int g_CodePage = -1; extern CStdOutStream *g_StdStream; -static const char *kCopyrightString = -"\n7-Zip SFX " MY_VERSION_COPYRIGHT_DATE "\n"; +static const char * const kCopyrightString = +"\n7-Zip SFX " MY_VERSION_CPU " : " MY_COPYRIGHT_DATE "\n"; static const int kNumSwitches = 6; @@ -65,7 +72,6 @@ enum EEnum } /* static const char kRecursedIDChar = 'R'; -static const wchar_t *kRecursedPostCharSet = L"0-"; namespace NRecursedPostCharIndex { enum EEnum @@ -81,14 +87,20 @@ static const char kImmediateNameID = '!'; static const char kSomeCludePostStringMinSize = 2; // at least <@|!><N>ame must be static const char kSomeCludeAfterRecursedPostStringMinSize = 2; // at least <@|!><N>ame must be */ + +#define SWFRM_3(t, mu, mi) t, mu, mi, NULL +#define SWFRM_1(t) SWFRM_3(t, false, 0) +#define SWFRM_SIMPLE SWFRM_1(NSwitchType::kSimple) +#define SWFRM_STRING_SINGL(mi) SWFRM_3(NSwitchType::kString, false, mi) + static const CSwitchForm kSwitchForms[kNumSwitches] = { - { "?", NSwitchType::kSimple }, - { "H", NSwitchType::kSimple }, - { "BD", NSwitchType::kSimple }, - { "Y", NSwitchType::kSimple }, - { "P", NSwitchType::kString, false, 1 }, - { "O", NSwitchType::kString, false, 1 }, + { "?", SWFRM_SIMPLE }, + { "H", SWFRM_SIMPLE }, + { "BD", SWFRM_SIMPLE }, + { "Y", SWFRM_SIMPLE }, + { "P", SWFRM_STRING_SINGL(1) }, + { "O", SWFRM_STRING_SINGL(1) }, }; static const int kNumCommandForms = 3; @@ -101,10 +113,9 @@ static const NRecursedType::EEnum kCommandRecursedDefault[kNumCommandForms] = // static const bool kTestExtractRecursedDefault = true; // static const bool kAddRecursedDefault = false; -static const wchar_t *kUniversalWildcard = L"*"; -static const int kCommandIndex = 0; +static const char * const kUniversalWildcard = "*"; -static const char *kHelpString = +static const char * const kHelpString = "\nUsage: 7zSFX [<command>] [<switches>...] [<file_name>...]\n" "\n" "<Commands>\n" @@ -121,16 +132,16 @@ static const char *kHelpString = // --------------------------- // exception messages -static const char *kUserErrorMessage = "Incorrect command line"; // NExitCode::kUserError -// static const char *kIncorrectListFile = "Incorrect wildcard in listfile"; -static const char *kIncorrectWildcardInCommandLine = "Incorrect wildcard in command line"; +static const char * const kUserErrorMessage = "Incorrect command line"; // NExitCode::kUserError +// static const char * const kIncorrectListFile = "Incorrect wildcard in listfile"; +static const char * const kIncorrectWildcardInCommandLine = "Incorrect wildcard in command line"; // static const CSysString kFileIsNotArchiveMessageBefore = "File \""; // static const CSysString kFileIsNotArchiveMessageAfter = "\" is not archive"; -// static const char *kProcessArchiveMessage = " archive: "; +// static const char * const kProcessArchiveMessage = " archive: "; -static const char *kCantFindSFX = " cannot find sfx"; +static const char * const kCantFindSFX = " cannot find sfx"; namespace NCommandType { @@ -151,7 +162,7 @@ struct CArchiveCommand NRecursedType::EEnum DefaultRecursedType() const; }; -bool ParseArchiveCommand(const UString &commandString, CArchiveCommand &command) +static bool ParseArchiveCommand(const UString &commandString, CArchiveCommand &command) { UString s = commandString; s.MakeLower_Ascii(); @@ -171,17 +182,19 @@ NRecursedType::EEnum CArchiveCommand::DefaultRecursedType() const return kCommandRecursedDefault[CommandType]; } -void PrintHelp(void) +static void PrintHelp(void) { g_StdOut << kHelpString; } +Z7_ATTR_NORETURN static void ShowMessageAndThrowException(const char *message, NExitCode::EEnum code) { g_StdOut << message << endl; throw code; } +Z7_ATTR_NORETURN static void PrintHelpAndExit() // yyy { PrintHelp(); @@ -198,7 +211,7 @@ static bool AddNameToCensor(NWildcard::CCensor &wildcardCensor, if (!IsWildcardFilePathLegal(name)) return false; */ - bool isWildcard = DoesNameContainWildcard(name); + const bool isWildcard = DoesNameContainWildcard(name); bool recursed = false; switch (type) @@ -213,11 +226,14 @@ static bool AddNameToCensor(NWildcard::CCensor &wildcardCensor, recursed = false; break; } - wildcardCensor.AddPreItem(include, name, recursed, true); + + NWildcard::CCensorPathProps props; + props.Recursive = recursed; + wildcardCensor.AddPreItem(include, name, props); return true; } -void AddCommandLineWildcardToCensor(NWildcard::CCensor &wildcardCensor, +static void AddCommandLineWildcardToCensor(NWildcard::CCensor &wildcardCensor, const UString &name, bool include, NRecursedType::EEnum type) { if (!AddNameToCensor(wildcardCensor, name, include, type)) @@ -226,7 +242,7 @@ void AddCommandLineWildcardToCensor(NWildcard::CCensor &wildcardCensor, #ifndef _WIN32 -static void GetArguments(int numArgs, const char *args[], UStringVector &parts) +static void GetArguments(int numArgs, char *args[], UStringVector &parts) { parts.Clear(); for (int i = 0; i < numArgs; i++) @@ -237,9 +253,15 @@ static void GetArguments(int numArgs, const char *args[], UStringVector &parts) } #endif + int Main2( #ifndef _WIN32 - int numArgs, const char *args[] + int numArgs, char *args[] + #endif +); +int Main2( + #ifndef _WIN32 + int numArgs, char *args[] #endif ) { @@ -252,6 +274,10 @@ int Main2( SetFileApisToOEM(); #endif + #ifdef ENV_HAVE_LOCALE + MY_SetLocale(); + #endif + g_StdOut << kCopyrightString; UStringVector commandStrings; @@ -276,17 +302,23 @@ int Main2( #else - UString arcPath = commandStrings.Front(); + if (commandStrings.IsEmpty()) + return NExitCode::kFatalError; + + const FString arcPath = us2fs(commandStrings.Front()); #endif - commandStrings.Delete(0); + #ifndef UNDER_CE + if (commandStrings.Size() > 0) + commandStrings.Delete(0); + #endif - NCommandLineParser::CParser parser(kNumSwitches); + NCommandLineParser::CParser parser; try { - if (!parser.ParseStrings(kSwitchForms, commandStrings)) + if (!parser.ParseStrings(kSwitchForms, kNumSwitches, commandStrings)) { g_StdOut << "Command line error:" << endl << parser.ErrorMessage << endl @@ -331,7 +363,7 @@ int Main2( { if (nonSwitchStrings.Size() == curCommandIndex) - AddCommandLineWildcardToCensor(wildcardCensor, kUniversalWildcard, true, recursedType); + AddCommandLineWildcardToCensor(wildcardCensor, (UString)kUniversalWildcard, true, recursedType); for (; curCommandIndex < nonSwitchStrings.Size(); curCommandIndex++) { const UString &s = nonSwitchStrings[curCommandIndex]; @@ -341,18 +373,18 @@ int Main2( } } - bool yesToAll = parser[NKey::kYes].ThereIs; + const bool yesToAll = parser[NKey::kYes].ThereIs; // NExtractMode::EEnum extractMode; // bool isExtractGroupCommand = command.IsFromExtractGroup(extractMode); - bool passwordEnabled = parser[NKey::kPassword].ThereIs; + const bool passwordEnabled = parser[NKey::kPassword].ThereIs; UString password; if (passwordEnabled) password = parser[NKey::kPassword].PostStrings[0]; - if (!NFind::DoesFileExist(arcPath)) + if (!NFind::DoesFileExist_FollowLink(arcPath)) throw kCantFindSFX; FString outputDir; @@ -374,7 +406,7 @@ int Main2( CCodecs *codecs = new CCodecs; CMyComPtr< - #ifdef EXTERNAL_CODECS + #ifdef Z7_EXTERNAL_CODECS ICompressCodecsInfo #else IUnknown @@ -392,7 +424,7 @@ int Main2( CMyComPtr<IFolderArchiveExtractCallback> extractCallback = ecs; ecs->Init(g_StdStream, &g_StdErr, g_StdStream); - #ifndef _NO_CRYPTO + #ifndef Z7_NO_CRYPTO ecs->PasswordIsDefined = passwordEnabled; ecs->Password = password; #endif @@ -401,7 +433,7 @@ int Main2( COpenCallbackConsole openCallback; openCallback.Init(g_StdStream, g_StdStream); - #ifndef _NO_CRYPTO + #ifndef Z7_NO_CRYPTO openCallback.PasswordIsDefined = passwordEnabled; openCallback.Password = password; #endif @@ -423,22 +455,33 @@ int Main2( codecs, CObjectVector<COpenType>(), CIntVector(), v1, v2, wildcardCensorHead, - eo, ecs, ecs, + eo, + ecs, ecs, ecs, // NULL, // hash errorMessage, stat); + + ecs->ClosePercents(); + if (!errorMessage.IsEmpty()) { - (*g_StdStream) << endl << "Error: " << errorMessage;; + (*g_StdStream) << endl << "Error: " << errorMessage; if (result == S_OK) result = E_FAIL; } - if (ecs->NumArcsWithError != 0 || ecs->NumFileErrors != 0) + if ( 0 != ecs->NumCantOpenArcs + || 0 != ecs->NumArcsWithError + || 0 != ecs->NumFileErrors + || 0 != ecs->NumOpenArcErrors) { + if (ecs->NumCantOpenArcs != 0) + (*g_StdStream) << endl << "Can't open as archive" << endl; if (ecs->NumArcsWithError != 0) (*g_StdStream) << endl << "Archive Errors" << endl; if (ecs->NumFileErrors != 0) (*g_StdStream) << endl << "Sub items Errors: " << ecs->NumFileErrors << endl; + if (ecs->NumOpenArcErrors != 0) + (*g_StdStream) << endl << "Open Errors: " << ecs->NumOpenArcErrors << endl; return NExitCode::kFatalError; } if (result != S_OK) @@ -460,7 +503,7 @@ int Main2( wildcardCensorHead, true, // enableHeaders false, // techMode - #ifndef _NO_CRYPTO + #ifndef Z7_NO_CRYPTO passwordEnabled, password, #endif numErrors, numWarnings); |