This commit is contained in:
Igor Pavlov
2005-05-30 00:00:00 +00:00
committed by Kornel Lesiński
parent 8c1b5c7b7e
commit 3c510ba80b
926 changed files with 40559 additions and 23519 deletions

View File

@@ -2,13 +2,14 @@
#include "StdAfx.h"
#include <initguid.h>
#include "Common/MyInitGuid.h"
#include "Common/CommandLineParser.h"
#include "Common/StdOutStream.h"
#include "Common/Wildcard.h"
#include "Common/StringConvert.h"
#include "Common/MyCom.h"
#include "Common/Exception.h"
#include "Windows/FileDir.h"
#include "Windows/FileName.h"
@@ -18,19 +19,22 @@
#include "../../ICoder.h"
#include "../../UI/Common/OpenArchive.h"
#include "../../UI/Common/ZipRegistry.h"
#include "../../UI/Common/DefaultName.h"
#include "../../UI/Common/ExitCode.h"
#include "../../UI/Common/Extract.h"
#include "../../UI/Console/Extract.h"
#include "../../UI/Console/ArError.h"
#include "../../UI/Console/List.h"
#include "../../UI/Console/OpenCallbackConsole.h"
#include "../../UI/Console/ExtractCallbackConsole.h"
using namespace NWindows;
using namespace NFile;
using namespace NCommandLineParser;
extern CStdOutStream *g_StdStream;
static const char *kCopyrightString =
"\n7-Zip SFX 3.12 Copyright (c) 1999-2003 Igor Pavlov 2003-12-10\n";
"\n7-Zip SFX 4.20 Copyright (c) 1999-2005 Igor Pavlov 2005-05-30\n";
static const int kNumSwitches = 6;
@@ -140,11 +144,13 @@ static const char *kUserErrorMessage = "Incorrect command line"; // NExitCode::
static const char *kIncorrectListFile = "Incorrect wildcard in listfile";
static const char *kIncorrectWildCardInCommandLine = "Incorrect wildcard in command line";
static const CSysString kFileIsNotArchiveMessageBefore = "File \"";
static const CSysString kFileIsNotArchiveMessageAfter = "\" is not archive";
// static const CSysString kFileIsNotArchiveMessageBefore = "File \"";
// static const CSysString kFileIsNotArchiveMessageAfter = "\" is not archive";
static const char *kProcessArchiveMessage = " archive: ";
static const char *kCantFindSFX = " cannot find sfx";
// ---------------------------
@@ -156,10 +162,7 @@ static const CSysString kDefaultWorkingDirectory = ""; // test it maybemust be
struct CArchiveCommand
{
NCommandType::EEnum CommandType;
// NListMode::EEnum ListMode;
// bool ListFullPathes;
NRecursedType::EEnum DefaultRecursedType() const;
bool IsFromExtractGroup(NExtractMode::EEnum &extractMode) const;
};
NRecursedType::EEnum CArchiveCommand::DefaultRecursedType() const
@@ -167,26 +170,6 @@ NRecursedType::EEnum CArchiveCommand::DefaultRecursedType() const
return kCommandRecursedDefault[CommandType];
}
bool CArchiveCommand::IsFromExtractGroup(NExtractMode::EEnum &extractMode) const
{
switch(CommandType)
{
case NCommandType::kTest:
extractMode = NExtractMode::kTest;
return true;
/*
case NCommandType::kExtract:
extractMode = NExtractMode::kExtractToOne;
return true;
*/
case NCommandType::kFullExtract:
extractMode = NExtractMode::kFullPath;
return true;
default:
return false;
}
}
static NRecursedType::EEnum GetRecursedTypeFromIndex(int index)
{
switch (index)
@@ -261,7 +244,7 @@ static bool AddNameToCensor(NWildcard::CCensor &wildcardCensor,
recursed = false;
break;
}
wildcardCensor.AddItem(name, include, recursed, isWildCard);
wildcardCensor.AddItem(name, include, recursed);
return true;
}
@@ -284,6 +267,7 @@ void AddToCensorFromNonSwitchesStrings(NWildcard::CCensor &wildcardCensor,
AddCommandLineWildCardToCensr(wildcardCensor, kUniversalWildcard, true, type);
}
/*
void AddSwitchWildCardsToCensor(NWildcard::CCensor &wildcardCensor,
const UStringVector &strings, bool include, NRecursedType::EEnum commonRecursedType)
{
@@ -314,42 +298,48 @@ void AddSwitchWildCardsToCensor(NWildcard::CCensor &wildcardCensor,
PrintHelpAndExit();
}
}
*/
// ------------------------------------------------------------------
/*
static void ThrowPrintFileIsNotArchiveException(const CSysString &fileName)
{
CSysString message;
message = kFileIsNotArchiveMessageBefore + fileName + kFileIsNotArchiveMessageAfter;
ShowMessageAndThrowException(message, NExitCode::kFileIsNotArchive);
}
*/
void MyOpenArhive(const UString &archiveName,
const NFind::CFileInfoW &archiveFileInfo,
IInArchive **archiveHandler,
UString &defaultItemName)
#ifndef _WIN32
static void GetArguments(int numArguments, const char *arguments[], UStringVector &parts)
{
CArchiverInfo archiverInfo;
int subExtIndex;
HRESULT result = OpenArchive(archiveName, archiveHandler,
archiverInfo, subExtIndex, 0);
if (result == S_FALSE)
throw "file is not supported archive";
if (result != S_OK)
throw "error";
defaultItemName = GetDefaultName(archiveName,
archiverInfo.Extensions[subExtIndex].Extension,
archiverInfo.Extensions[subExtIndex].AddExtension);
parts.Clear();
for(int i = 0; i < numArguments; i++)
{
UString s = MultiByteToUnicodeString(arguments[i]);
parts.Add(s);
}
}
#endif
// int Main2(int numArguments, const char *arguments[])
int Main2()
int Main2(
#ifndef _WIN32
int numArguments, const char *arguments[]
#endif
)
{
#ifdef _WIN32
SetFileApisToOEM();
#endif
g_StdOut << kCopyrightString;
UStringVector commandStrings;
SplitCommandLine(GetCommandLineW(), commandStrings);
#ifdef _WIN32
NCommandLineParser::SplitCommandLine(GetCommandLineW(), commandStrings);
#else
GetArguments(numArguments, arguments, commandStrings);
#endif
UString archiveName = commandStrings.Front();
@@ -401,9 +391,8 @@ int Main2()
if (archiveName.Right(4).CompareNoCase(defaultExt) != 0)
archiveName += defaultExt;
NExtractMode::EEnum extractMode;
bool isExtractGroupCommand = command.IsFromExtractGroup(extractMode);
// NExtractMode::EEnum extractMode;
// bool isExtractGroupCommand = command.IsFromExtractGroup(extractMode);
bool passwordEnabled = parser[NKey::kPassword].ThereIs;
@@ -411,49 +400,76 @@ int Main2()
if(passwordEnabled)
password = parser[NKey::kPassword].PostStrings[0];
if(isExtractGroupCommand || command.CommandType == NCommandType::kList)
NFind::CFileInfoW archiveFileInfo;
if (!NFind::FindFile(archiveName, archiveFileInfo))
throw kCantFindSFX;
if (archiveFileInfo.IsDirectory())
throw kCantFindSFX;
UString outputDir;
if(parser[NKey::kOutputDir].ThereIs)
{
NFind::CFileInfoW archiveFileInfo;
if (!NFind::FindFile(archiveName, archiveFileInfo) || archiveFileInfo.IsDirectory())
throw "there is no such archive";
outputDir = parser[NKey::kOutputDir].PostStrings[0];
NName::NormalizeDirPathPrefix(outputDir);
}
if (archiveFileInfo.IsDirectory())
throw "there is no such archive";
UString defaultItemName;
CMyComPtr<IInArchive> archiveHandler;
CArchiverInfo archiverInfo;
MyOpenArhive(archiveName, archiveFileInfo, &archiveHandler, defaultItemName);
if(isExtractGroupCommand)
{
UStringVector v1, v2;
v1.Add(archiveName);
v2.Add(archiveName);
const NWildcard::CCensorNode &wildcardCensorHead =
wildcardCensor.Pairs.Front().Head;
if(command.CommandType != NCommandType::kList)
{
PrintProcessTitle(kExtractGroupProcessMessage, archiveName);
UString outputDir;
if(parser[NKey::kOutputDir].ThereIs)
CExtractCallbackConsole *ecs = new CExtractCallbackConsole;
CMyComPtr<IFolderArchiveExtractCallback> extractCallback = ecs;
ecs->OutStream = g_StdStream;
ecs->PasswordIsDefined = passwordEnabled;
ecs->Password = password;
ecs->Init();
COpenCallbackConsole openCallback;
openCallback.OutStream = g_StdStream;
openCallback.PasswordIsDefined = passwordEnabled;
openCallback.Password = password;
CExtractOptions eo;
eo.StdOutMode = false;
eo.PathMode = NExtract::NPathMode::kFullPathnames;
eo.TestMode = command.CommandType == NCommandType::kTest;
eo.OverwriteMode = yesToAll ?
NExtract::NOverwriteMode::kWithoutPrompt :
NExtract::NOverwriteMode::kAskBefore;
eo.OutputDir = outputDir;
eo.YesToAll = yesToAll;
HRESULT result = DecompressArchives(
v1, v2,
wildcardCensorHead,
eo, &openCallback, ecs);
if (ecs->NumArchiveErrors != 0 || ecs->NumFileErrors != 0)
{
outputDir = parser[NKey::kOutputDir].PostStrings[0];
NName::NormalizeDirPathPrefix(outputDir);
if (ecs->NumArchiveErrors != 0)
(*g_StdStream) << endl << "Archive Errors: " << ecs->NumArchiveErrors << endl;
if (ecs->NumFileErrors != 0)
(*g_StdStream) << endl << "Sub items Errors: " << ecs->NumFileErrors << endl;
return NExitCode::kFatalError;
}
NExtraction::NOverwriteMode::EEnum overwriteMode =
NExtraction::NOverwriteMode::kAskBefore;
CExtractOptions options(extractMode, outputDir, yesToAll,
passwordEnabled, password, overwriteMode);
options.DefaultItemName = defaultItemName;
options.ArchiveFileInfo = archiveFileInfo;
// options.ArchiveFileInfo = archiveFileInfo;
HRESULT result = DeCompressArchiveSTD(archiveHandler, wildcardCensor, options);
if (result != S_OK)
{
return NExitCode::kErrorsDuringDecompression;
}
throw CSystemException(result);
}
else
{
PrintProcessTitle(kListingProcessMessage, archiveName);
ListArchive(archiveHandler, defaultItemName, archiveFileInfo,
wildcardCensor/*, command.ListFullPathes, command.ListMode*/);
HRESULT result = ListArchives(
v1, v2,
wildcardCensorHead,
true,
passwordEnabled,
password);
if (result != S_OK)
throw CSystemException(result);
}
}
else
PrintHelpAndExit();
return 0;
}