4.38 beta

This commit is contained in:
Igor Pavlov
2006-04-13 00:00:00 +00:00
committed by Kornel Lesiński
parent cb9eea7264
commit 83911c8529
54 changed files with 798 additions and 308 deletions

View File

@@ -40,7 +40,10 @@ static const char *kCopyrightString =
static const int kNumSwitches = 6;
const wchar_t *defaultExt = L".exe";
#ifdef _WIN32
static const wchar_t *kDefaultExt = L".exe";
static const int kDefaultExtLength = 4;
#endif
namespace NKey {
enum Enum
@@ -383,8 +386,10 @@ int Main2(
bool yesToAll = parser[NKey::kYes].ThereIs;
if (archiveName.Right(4).CompareNoCase(defaultExt) != 0)
archiveName += defaultExt;
#ifdef _WIN32
if (archiveName.Right(kDefaultExtLength).CompareNoCase(kDefaultExt) != 0)
archiveName += kDefaultExt;
#endif
// NExtractMode::EEnum extractMode;
// bool isExtractGroupCommand = command.IsFromExtractGroup(extractMode);

View File

@@ -23,9 +23,9 @@ static LPCWSTR kErrorTitle = L"7-Zip";
static LPCWSTR kCantDeleteFile = L"Can not delete output file";
static LPCWSTR kCantOpenFile = L"Can not open output file";
static LPCWSTR kUnsupportedMethod = L"Unsupported Method";
static LPCWSTR kCRCFailed = L"CRC Failed";
static LPCWSTR kDataError = L"Data Error";
// static LPCTSTR kUnknownError = TEXT("Unknown Error");
// static LPCWSTR kCRCFailed = L"CRC Failed";
// static LPCWSTR kDataError = L"Data Error";
// static LPCWSTR kUnknownError = L""Unknown Error";
void CExtractCallbackImp::Init(IInArchive *archiveHandler,
const UString &directoryPath,
@@ -33,7 +33,8 @@ void CExtractCallbackImp::Init(IInArchive *archiveHandler,
const FILETIME &utcLastWriteTimeDefault,
UInt32 attributesDefault)
{
_numErrors = 0;
_message.Empty();
_isCorrupt = false;
_itemDefaultName = itemDefaultName;
_utcLastWriteTimeDefault = utcLastWriteTimeDefault;
_attributesDefault = attributesDefault;
@@ -170,14 +171,8 @@ STDMETHODIMP CExtractCallbackImp::GetStream(UInt32 index,
{
if (!NDirectory::DeleteFileAlways(fullProcessedPath))
{
#ifdef _SILENT
_message = kCantDeleteFile;
#else
MessageBoxW(0, kCantDeleteFile, kErrorTitle, 0);
#endif
// g_StdOut << GetOemString(fullProcessedPath);
// return E_ABORT;
return E_ABORT;
return E_FAIL;
}
}
@@ -187,12 +182,8 @@ STDMETHODIMP CExtractCallbackImp::GetStream(UInt32 index,
CMyComPtr<ISequentialOutStream> outStreamLoc(_outFileStreamSpec);
if (!_outFileStreamSpec->Create(fullProcessedPath, true))
{
#ifdef _SILENT
_message = kCantOpenFile;
#else
MessageBoxW(0, kCantOpenFile, kErrorTitle, 0);
#endif
return E_ABORT;
return E_FAIL;
}
_outFileStream = outStreamLoc;
*outStream = outStreamLoc.Detach();
@@ -228,30 +219,23 @@ STDMETHODIMP CExtractCallbackImp::SetOperationResult(Int32 resultEOperationResul
}
default:
{
_numErrors++;
UString errorMessage;
_outFileStream.Release();
switch(resultEOperationResult)
{
case NArchive::NExtract::NOperationResult::kUnSupportedMethod:
errorMessage = kUnsupportedMethod;
_message = kUnsupportedMethod;
break;
case NArchive::NExtract::NOperationResult::kCRCError:
errorMessage = kCRCFailed;
_isCorrupt = true;
// _message = kCRCFailed;
break;
case NArchive::NExtract::NOperationResult::kDataError:
errorMessage = kDataError;
_isCorrupt = true;
// _message = kDataError;
break;
/*
default:
errorMessage = kUnknownError;
*/
_isCorrupt = true;
}
#ifdef _SILENT
_message = errorMessage;
#else
MessageBoxW(0, errorMessage, kErrorTitle, 0);
#endif
return E_FAIL;
}
}
@@ -263,4 +247,3 @@ STDMETHODIMP CExtractCallbackImp::SetOperationResult(Int32 resultEOperationResul
return S_OK;
}

View File

@@ -11,15 +11,12 @@
#include "../../Archive/IArchive.h"
#include "../../Common/FileStreams.h"
// #include "../../Common/ZipSettings.h"
#include "../../ICoder.h"
#ifndef _NO_PROGRESS
#include "../../FileManager/Resource/ProgressDialog/ProgressDialog.h"
#endif
// #include "../../Explorer/MyMessages.h"
class CExtractCallbackImp:
public IArchiveExtractCallback,
public CMyUnknownImp
@@ -67,9 +64,8 @@ public:
CProgressDialog ProgressDialog;
#endif
#ifdef _SILENT
bool _isCorrupt;
UString _message;
#endif
void Init(IInArchive *archiveHandler,
const UString &directoryPath,
@@ -77,8 +73,6 @@ public:
const FILETIME &utcLastWriteTimeDefault,
UInt32 attributesDefault);
UInt64 _numErrors;
#ifndef _NO_PROGRESS
HRESULT StartProgressDialog(const UString &title)
{
@@ -92,7 +86,6 @@ public:
}
ProgressDialog.Show(SW_SHOWNORMAL);
// _progressDialog.Start(m_ParentWindow, PROGDLG_MODAL | PROGDLG_AUTOTIME);
return S_OK;
}
virtual ~CExtractCallbackImp() { ProgressDialog.Destroy(); }

View File

@@ -1,4 +1,4 @@
// ExtractEngine.h
// ExtractEngine.cpp
#include "StdAfx.h"
@@ -21,7 +21,6 @@ using namespace NWindows;
struct CThreadExtracting
{
// CMyComPtr<IInArchive> ArchiveHandler;
CArchiveLink ArchiveLink;
CExtractCallbackImp *ExtractCallbackSpec;
@@ -29,12 +28,15 @@ struct CThreadExtracting
#ifndef _NO_PROGRESS
HRESULT Result;
HRESULT Extract()
{
return ArchiveLink.GetArchive()->Extract(0, (UInt32)-1 , BoolToInt(false), ExtractCallback);
}
DWORD Process()
{
ExtractCallbackSpec->ProgressDialog.WaitCreating();
Result = ArchiveLink.GetArchive()->Extract(0, (UInt32)-1 , BoolToInt(false),
ExtractCallback);
Result = Extract();
ExtractCallbackSpec->ProgressDialog.MyClose();
return 0;
}
@@ -45,26 +47,22 @@ struct CThreadExtracting
#endif
};
static const LPCTSTR kCantFindArchive = TEXT("Can not find archive file");
static const LPCTSTR kCantOpenArchive = TEXT("File is not correct archive");
static const LPCWSTR kCantFindArchive = L"Can not find archive file";
static const LPCWSTR kCantOpenArchive = L"File is not correct archive";
HRESULT ExtractArchive(
const UString &fileName,
const UString &folderName,
COpenCallbackGUI *openCallback
#ifdef _SILENT
, UString &resultMessage
#endif
)
COpenCallbackGUI *openCallback,
bool showProgress,
bool &isCorrupt,
UString &errorMessage)
{
isCorrupt = false;
NFile::NFind::CFileInfoW archiveFileInfo;
if (!NFile::NFind::FindFile(fileName, archiveFileInfo))
{
#ifndef _SILENT
MessageBox(0, kCantFindArchive, TEXT("7-Zip"), 0);
#else
resultMessage = kCantFindArchive;
#endif
errorMessage = kCantFindArchive;
return E_FAIL;
}
@@ -72,18 +70,10 @@ HRESULT ExtractArchive(
HRESULT result = MyOpenArchive(fileName, extracter.ArchiveLink, openCallback);
/*
CArchiverInfo archiverInfoResult;
int subExtIndex;
HRESULT result = OpenArchive(fileName, &extracter.ArchiveHandler,
archiverInfoResult, subExtIndex, NULL);
*/
if (result != S_OK)
{
#ifdef _SILENT
resultMessage = kCantOpenArchive;
#endif
return E_FAIL;
errorMessage = kCantOpenArchive;
return result;
}
UString directoryPath = folderName;
@@ -105,54 +95,45 @@ HRESULT ExtractArchive(
if(!NFile::NDirectory::CreateComplexDirectory(directoryPath))
{
#ifndef _SILENT
MyMessageBox(MyFormatNew(IDS_CANNOT_CREATE_FOLDER,
errorMessage = MyFormatNew(IDS_CANNOT_CREATE_FOLDER,
#ifdef LANG
0x02000603,
#endif
directoryPath));
#else
resultMessage = TEXT("Can not create output folder");
#endif
directoryPath);
return E_FAIL;
}
extracter.ExtractCallbackSpec = new CExtractCallbackImp;
extracter.ExtractCallback = extracter.ExtractCallbackSpec;
// anExtractCallBackSpec->StartProgressDialog();
// anExtractCallBackSpec->m_ProgressDialog.ShowWindow(SW_SHOWNORMAL);
extracter.ExtractCallbackSpec->Init(
extracter.ArchiveLink.GetArchive(),
directoryPath, L"Default", archiveFileInfo.LastWriteTime, 0);
#ifndef _NO_PROGRESS
CThread thread;
if (!thread.Create(CThreadExtracting::MyThreadFunction, &extracter))
throw 271824;
if (showProgress)
{
CThread thread;
if (!thread.Create(CThreadExtracting::MyThreadFunction, &extracter))
throw 271824;
UString title;
#ifdef LANG
title = LangLoadString(IDS_PROGRESS_EXTRACTING, 0x02000890);
#else
title = NWindows::MyLoadStringW(IDS_PROGRESS_EXTRACTING);
#endif
extracter.ExtractCallbackSpec->StartProgressDialog(title);
result = extracter.Result;
}
else
UString title;
#ifdef LANG
title = LangLoadString(IDS_PROGRESS_EXTRACTING, 0x02000890);
#else
title = NWindows::MyLoadStringW(IDS_PROGRESS_EXTRACTING);
#endif
extracter.ExtractCallbackSpec->StartProgressDialog(title);
return extracter.Result;
#else
result = extracter.ArchiveHandler->Extract(0, (UInt32)-1,
BoolToInt(false), extracter.ExtractCallback);
#ifdef _SILENT
resultMessage = extracter.ExtractCallbackSpec->_message;
#endif
{
result = extracter.Extract();
}
errorMessage = extracter.ExtractCallbackSpec->_message;
isCorrupt = extracter.ExtractCallbackSpec->_isCorrupt;
return result;
#endif
}

View File

@@ -9,11 +9,9 @@
HRESULT ExtractArchive(
const UString &fileName,
const UString &folderName,
COpenCallbackGUI *openCallback
#ifdef _SILENT
, UString &resultMessage
#endif
);
COpenCallbackGUI *openCallback,
bool showProgress,
bool &isCorrupt,
UString &errorMessage);
#endif

View File

@@ -14,6 +14,7 @@
#include "Windows/FileFind.h"
#include "Windows/FileName.h"
#include "Windows/DLL.h"
#include "Windows/ResourceString.h"
#include "../../IPassword.h"
#include "../../ICoder.h"
@@ -24,13 +25,16 @@
#include "ExtractEngine.h"
HINSTANCE g_hInstance;
#include "resource.h"
using namespace NWindows;
HINSTANCE g_hInstance;
static LPCTSTR kTempDirPrefix = TEXT("7zS");
#define _SHELL_EXECUTE
static bool ReadDataString(LPCWSTR fileName, LPCSTR startID,
LPCSTR endID, AString &stringResult)
{
@@ -143,17 +147,14 @@ int APIENTRY WinMain(
InitCommonControls();
UString archiveName, switches;
#ifdef _SHELL_EXECUTE
UString executeFile, executeParameters;
#endif
NCommandLineParser::SplitCommandLine(GetCommandLineW(), archiveName, switches);
UString fullPath;
NDLL::MyGetModuleFileName(g_hInstance, fullPath);
AString config;
if (!ReadDataString(fullPath, kStartID, kEndID, config))
{
MyMessageBox(L"Can't load config info");
return 1;
}
switches.Trim();
bool assumeYes = false;
if (switches.Left(2).CompareNoCase(UString(L"-y")) == 0)
@@ -163,21 +164,34 @@ int APIENTRY WinMain(
switches.Trim();
}
#ifdef _SHELL_EXECUTE
bool executeMode = false;
#endif
AString config;
if (!ReadDataString(fullPath, kStartID, kEndID, config))
{
if (!assumeYes)
MyMessageBox(L"Can't load config info");
return 1;
}
UString dirPrefix = L".\\";
UString appLaunched;
bool showProgress = true;
if (!config.IsEmpty())
{
CObjectVector<CTextConfigPair> pairs;
if (!GetTextConfig(config, pairs))
{
MyMessageBox(L"Config failed");
if (!assumeYes)
MyMessageBox(L"Config failed");
return 1;
}
UString friendlyName = GetTextConfigValue(pairs, L"Title");
UString installPrompt = GetTextConfigValue(pairs, L"BeginPrompt");
UString progress = GetTextConfigValue(pairs, L"Progress");
if (progress.CompareNoCase(L"no") == 0)
showProgress = false;
int index = FindTextConfigItem(pairs, L"Directory");
if (index >= 0)
dirPrefix = pairs[index].String;
if (!installPrompt.IsEmpty() && !assumeYes)
{
if (MessageBoxW(0, installPrompt, friendlyName, MB_YESNO |
@@ -185,33 +199,41 @@ int APIENTRY WinMain(
return 0;
}
appLaunched = GetTextConfigValue(pairs, L"RunProgram");
#ifdef _SHELL_EXECUTE
if (appLaunched.IsEmpty())
{
executeMode = true;
appLaunched = GetTextConfigValue(pairs, L"Execute");
}
#endif
#ifdef _SHELL_EXECUTE
executeFile = GetTextConfigValue(pairs, L"ExecuteFile");
executeParameters = GetTextConfigValue(pairs, L"ExecuteParameters") + switches;
#endif
}
NFile::NDirectory::CTempDirectory tempDir;
if (!tempDir.Create(kTempDirPrefix))
{
MyMessageBox(L"Can not create temp folder archive");
if (!assumeYes)
MyMessageBox(L"Can not create temp folder archive");
return 1;
}
COpenCallbackGUI openCallback;
UString tempDirPath = GetUnicodeString(tempDir.GetPath());
HRESULT result = ExtractArchive(fullPath, tempDirPath, &openCallback);
bool isCorrupt = false;
UString errorMessage;
HRESULT result = ExtractArchive(fullPath, tempDirPath, &openCallback, showProgress,
isCorrupt, errorMessage);
if (result != S_OK)
{
if (result == S_FALSE)
MyMessageBox(L"Can not open archive");
else if (result != E_ABORT)
ShowErrorMessage(result);
if (!assumeYes)
{
if (result == S_FALSE || isCorrupt)
{
errorMessage = NWindows::MyLoadStringW(IDS_EXTRACTION_ERROR_MESSAGE);
result = E_FAIL;
}
if (result != E_ABORT && !errorMessage.IsEmpty())
::MessageBoxW(0, errorMessage, NWindows::MyLoadStringW(IDS_EXTRACTION_ERROR_TITLE), MB_ICONERROR);
}
return 1;
}
@@ -220,30 +242,11 @@ int APIENTRY WinMain(
if (!SetCurrentDirectory(tempDir.GetPath()))
return 1;
if (appLaunched.IsEmpty())
{
appLaunched = L"setup.exe";
if (!NFile::NFind::DoesFileExist(GetSystemString(appLaunched)))
{
MyMessageBox(L"Can not find setup.exe");
return 1;
}
}
{
UString s2 = tempDirPath;
NFile::NName::NormalizeDirPathPrefix(s2);
appLaunched.Replace(L"%%T\\", s2);
}
appLaunched.Replace(L"%%T", tempDirPath);
HANDLE hProcess = 0;
#ifdef _SHELL_EXECUTE
if (executeMode)
if (!executeFile.IsEmpty())
{
CSysString filePath = GetSystemString(appLaunched);
CSysString filePath = GetSystemString(executeFile);
SHELLEXECUTEINFO execInfo;
execInfo.cbSize = sizeof(execInfo);
execInfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_DDEWAIT;
@@ -251,11 +254,14 @@ int APIENTRY WinMain(
execInfo.lpVerb = NULL;
execInfo.lpFile = filePath;
CSysString switchesSys = GetSystemString(switches);
if (switchesSys.IsEmpty())
if (!switches.IsEmpty())
executeParameters += switches;
CSysString parametersSys = GetSystemString(executeParameters);
if (parametersSys.IsEmpty())
execInfo.lpParameters = NULL;
else
execInfo.lpParameters = switchesSys;
execInfo.lpParameters = parametersSys;
execInfo.lpDirectory = NULL;
execInfo.nShow = SW_SHOWNORMAL;
@@ -264,7 +270,8 @@ int APIENTRY WinMain(
result = (UINT32)execInfo.hInstApp;
if(result <= 32)
{
MyMessageBox(L"Can not open file");
if (!assumeYes)
MyMessageBox(L"Can not open file");
return 1;
}
hProcess = execInfo.hProcess;
@@ -272,6 +279,25 @@ int APIENTRY WinMain(
else
#endif
{
if (appLaunched.IsEmpty())
{
appLaunched = L"setup.exe";
if (!NFile::NFind::DoesFileExist(GetSystemString(appLaunched)))
{
if (!assumeYes)
MyMessageBox(L"Can not find setup.exe");
return 1;
}
}
{
UString s2 = tempDirPath;
NFile::NName::NormalizeDirPathPrefix(s2);
appLaunched.Replace(L"%%T\\", s2);
}
appLaunched.Replace(L"%%T", tempDirPath);
if (!switches.IsEmpty())
{
appLaunched += L' ';
@@ -288,14 +314,15 @@ int APIENTRY WinMain(
PROCESS_INFORMATION processInformation;
CSysString appLaunchedSys = CSysString(TEXT(".\\")) + GetSystemString(appLaunched);
CSysString appLaunchedSys = GetSystemString(dirPrefix + appLaunched);
BOOL createResult = CreateProcess(NULL, (LPTSTR)(LPCTSTR)appLaunchedSys,
NULL, NULL, FALSE, 0, NULL, NULL /*tempDir.GetPath() */,
&startupInfo, &processInformation);
if (createResult == 0)
{
ShowLastErrorMessage();
if (!assumeYes)
ShowLastErrorMessage();
return 1;
}
::CloseHandle(processInformation.hThread);

View File

@@ -1,4 +1,6 @@
#define IDI_ICON3 159
#define IDS_EXTRACTION_ERROR_TITLE 7
#define IDS_EXTRACTION_ERROR_MESSAGE 8
#define IDS_CANNOT_CREATE_FOLDER 9
#define IDS_PROGRESS_EXTRACTING 69

View File

@@ -7,6 +7,8 @@ IDI_ICON3 ICON "setup.ico"
STRINGTABLE
BEGIN
IDS_EXTRACTION_ERROR_TITLE "Extraction Failed"
IDS_EXTRACTION_ERROR_MESSAGE "File is corrupt"
IDS_CANNOT_CREATE_FOLDER "Cannot create folder '{0}'"
IDS_PROGRESS_EXTRACTING "Extracting"
END