From d9666cf046a8453b33b3e2fbf4d82295a9f87df3 Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Sat, 20 Jan 2007 00:00:00 +0000 Subject: 4.44 beta --- CPP/7zip/UI/GUI/7zG.exe.manifest | 1 + CPP/7zip/UI/GUI/CompressDialog.cpp | 1373 +++++++++++++++++++++++++++++++++ CPP/7zip/UI/GUI/CompressDialog.h | 171 ++++ CPP/7zip/UI/GUI/ExtractDialog.cpp | 371 +++++++++ CPP/7zip/UI/GUI/ExtractDialog.h | 77 ++ CPP/7zip/UI/GUI/ExtractGUI.cpp | 172 +++++ CPP/7zip/UI/GUI/ExtractGUI.h | 20 + CPP/7zip/UI/GUI/FM.ico | Bin 0 -> 4846 bytes CPP/7zip/UI/GUI/GUI.cpp | 260 +++++++ CPP/7zip/UI/GUI/GUI.dsp | 904 ++++++++++++++++++++++ CPP/7zip/UI/GUI/GUI.dsw | 29 + CPP/7zip/UI/GUI/OpenCallbackGUI.cpp | 65 ++ CPP/7zip/UI/GUI/OpenCallbackGUI.h | 35 + CPP/7zip/UI/GUI/StdAfx.cpp | 3 + CPP/7zip/UI/GUI/StdAfx.h | 13 + CPP/7zip/UI/GUI/UpdateCallbackGUI.cpp | 167 ++++ CPP/7zip/UI/GUI/UpdateCallbackGUI.h | 63 ++ CPP/7zip/UI/GUI/UpdateGUI.cpp | 397 ++++++++++ CPP/7zip/UI/GUI/UpdateGUI.h | 20 + CPP/7zip/UI/GUI/makefile | 135 ++++ CPP/7zip/UI/GUI/resource.h | 45 ++ CPP/7zip/UI/GUI/resource.rc | 57 ++ 22 files changed, 4378 insertions(+) create mode 100755 CPP/7zip/UI/GUI/7zG.exe.manifest create mode 100755 CPP/7zip/UI/GUI/CompressDialog.cpp create mode 100755 CPP/7zip/UI/GUI/CompressDialog.h create mode 100755 CPP/7zip/UI/GUI/ExtractDialog.cpp create mode 100755 CPP/7zip/UI/GUI/ExtractDialog.h create mode 100755 CPP/7zip/UI/GUI/ExtractGUI.cpp create mode 100755 CPP/7zip/UI/GUI/ExtractGUI.h create mode 100755 CPP/7zip/UI/GUI/FM.ico create mode 100755 CPP/7zip/UI/GUI/GUI.cpp create mode 100755 CPP/7zip/UI/GUI/GUI.dsp create mode 100755 CPP/7zip/UI/GUI/GUI.dsw create mode 100755 CPP/7zip/UI/GUI/OpenCallbackGUI.cpp create mode 100755 CPP/7zip/UI/GUI/OpenCallbackGUI.h create mode 100755 CPP/7zip/UI/GUI/StdAfx.cpp create mode 100755 CPP/7zip/UI/GUI/StdAfx.h create mode 100755 CPP/7zip/UI/GUI/UpdateCallbackGUI.cpp create mode 100755 CPP/7zip/UI/GUI/UpdateCallbackGUI.h create mode 100755 CPP/7zip/UI/GUI/UpdateGUI.cpp create mode 100755 CPP/7zip/UI/GUI/UpdateGUI.h create mode 100755 CPP/7zip/UI/GUI/makefile create mode 100755 CPP/7zip/UI/GUI/resource.h create mode 100755 CPP/7zip/UI/GUI/resource.rc (limited to 'CPP/7zip/UI/GUI') diff --git a/CPP/7zip/UI/GUI/7zG.exe.manifest b/CPP/7zip/UI/GUI/7zG.exe.manifest new file mode 100755 index 00000000..c6ef90e8 --- /dev/null +++ b/CPP/7zip/UI/GUI/7zG.exe.manifest @@ -0,0 +1 @@ +7-Zip GUI. diff --git a/CPP/7zip/UI/GUI/CompressDialog.cpp b/CPP/7zip/UI/GUI/CompressDialog.cpp new file mode 100755 index 00000000..f49bb078 --- /dev/null +++ b/CPP/7zip/UI/GUI/CompressDialog.cpp @@ -0,0 +1,1373 @@ +// CompressDialog.cpp + +#include "StdAfx.h" + +#include "resource.h" +#include "Common/Defs.h" +#include "Common/StringConvert.h" +#include "Common/IntToString.h" +#include "Windows/CommonDialog.h" +#include "Windows/FileDir.h" +#include "Windows/FileName.h" +#include "Windows/ResourceString.h" +#include "Windows/System.h" + +#include "../../FileManager/HelpUtils.h" +#include "../../FileManager/SplitUtils.h" +#include "../../FileManager/FormatUtils.h" + +#include "../Explorer/MyMessages.h" + +#include "../Common/ZipRegistry.h" + +#include "CompressDialog.h" + +#ifndef _UNICODE +extern bool g_IsNT; +#endif + +#ifdef LANG +#include "../../FileManager/LangUtils.h" +#endif + +#include "../Resource/CompressDialog/resource.h" + +#define MY_SIZE_OF_ARRAY(x) (sizeof(x) / sizeof(x[0])) + +#ifdef LANG +static CIDLangPair kIDLangPairs[] = +{ + { IDC_STATIC_COMPRESS_ARCHIVE, 0x02000D01 }, + { IDC_STATIC_COMPRESS_FORMAT, 0x02000D03 }, + { IDC_STATIC_COMPRESS_LEVEL, 0x02000D0B }, + { IDC_STATIC_COMPRESS_METHOD, 0x02000D04 }, + { IDC_STATIC_COMPRESS_DICTIONARY, 0x02000D0C }, + { IDC_STATIC_COMPRESS_ORDER, 0x02000D0D }, + { IDC_STATIC_COMPRESS_MEMORY, 0x02000D0E }, + { IDC_STATIC_COMPRESS_MEMORY_DE, 0x02000D0F }, + { IDC_COMPRESS_SOLID, 0x02000D05 }, + { IDC_COMPRESS_MULTI_THREAD, 0x02000D09 }, + { IDC_STATIC_COMPRESS_VOLUME, 0x02000D40 }, + { IDC_STATIC_COMPRESS_PARAMETERS, 0x02000D06 }, + + { IDC_STATIC_COMPRESS_UPDATE_MODE, 0x02000D02 }, + { IDC_STATIC_COMPRESS_OPTIONS, 0x02000D07 }, + { IDC_COMPRESS_SFX, 0x02000D08 }, + + { IDC_COMPRESS_ENCRYPTION, 0x02000D10 }, + { IDC_STATIC_COMPRESS_PASSWORD1, 0x02000B01 }, + { IDC_STATIC_COMPRESS_PASSWORD2, 0x02000B03 }, + { IDC_COMPRESS_CHECK_SHOW_PASSWORD, 0x02000B02 }, + { IDC_STATIC_COMPRESS_ENCRYPTION_METHOD, 0x02000D11 }, + { IDC_COMPRESS_CHECK_ENCRYPT_FILE_NAMES, 0x02000D0A }, + + { IDOK, 0x02000702 }, + { IDCANCEL, 0x02000710 }, + { IDHELP, 0x02000720 } +}; +#endif + +using namespace NWindows; +using namespace NFile; +using namespace NName; +using namespace NDirectory; + +static const int kHistorySize = 8; + +static LPCWSTR kExeExt = L".exe"; +static LPCWSTR k7zFormat = L"7z"; + +struct CLevelInfo +{ + UInt32 ResourceID; + UInt32 LangID; +}; + +enum ELevel +{ + kStore = 0, + kFastest = 1, + kFast = 3, + kNormal = 5, + kMaximum = 7, + kUltra = 9 +}; + +static const CLevelInfo g_Levels[] = +{ + { IDS_METHOD_STORE, 0x02000D81 }, + { IDS_METHOD_FASTEST, 0x02000D85 }, + { 0, 0 }, + { IDS_METHOD_FAST, 0x02000D84 }, + { 0, 0 }, + { IDS_METHOD_NORMAL, 0x02000D82 }, + { 0, 0 }, + { IDS_METHOD_MAXIMUM, 0x02000D83 }, + { 0, 0 }, + { IDS_METHOD_ULTRA, 0x02000D86 } +}; + +enum EMethodID +{ + kCopy, + kLZMA, + kPPMd, + kBZip2, + kDeflate, + kDeflate64 +}; + +static const LPCWSTR kMethodsNames[] = +{ + L"Copy", + L"LZMA", + L"PPMd", + L"BZip2", + L"Deflate", + L"Deflate64" +}; + +static const EMethodID g_7zMethods[] = +{ + kLZMA, + kPPMd, + kBZip2 +}; + +static const EMethodID g_7zSfxMethods[] = +{ + kCopy, + kLZMA, + kPPMd +}; + +static EMethodID g_ZipMethods[] = +{ + kDeflate, + kDeflate64, + kBZip2 +}; + +static EMethodID g_GZipMethods[] = +{ + kDeflate +}; + +static EMethodID g_BZip2Methods[] = +{ + kBZip2 +}; + +struct CFormatInfo +{ + LPCWSTR Name; + UInt32 LevelsMask; + const EMethodID *MathodIDs; + int NumMethods; + bool Filter; + bool Solid; + bool MultiThread; + bool SFX; + bool Encrypt; + bool EncryptFileNames; +}; + +static const CFormatInfo g_Formats[] = +{ + { + L"", + (1 << 0) | (1 << 1) | (1 << 3) | (1 << 5) | (1 << 7) | (1 << 9), + 0, 0, + false, false, false, false, false, false + }, + { + k7zFormat, + (1 << 0) | (1 << 1) | (1 << 3) | (1 << 5) | (1 << 7) | (1 << 9), + g_7zMethods, MY_SIZE_OF_ARRAY(g_7zMethods), + true, true, true, true, true, true + }, + { + L"Zip", + (1 << 0) | (1 << 1) | (1 << 3) | (1 << 5) | (1 << 7) | (1 << 9), + g_ZipMethods, MY_SIZE_OF_ARRAY(g_ZipMethods) , + false, false, true, false, true, false + }, + { + L"GZip", + (1 << 5) | (1 << 7) | (1 << 9), + g_GZipMethods, MY_SIZE_OF_ARRAY(g_GZipMethods), + false, false, false, false, false, false + }, + { + L"BZip2", + (1 << 1) | (1 << 3) | (1 << 5) | (1 << 7) | (1 << 9), + g_BZip2Methods, + MY_SIZE_OF_ARRAY(g_BZip2Methods), + false, false, true, false, false + }, + { + L"Tar", + (1 << 0), + 0, 0, + false, false, false, false, false, false + } +}; + +static bool IsMethodSupportedBySfx(int methodID) +{ + for (int i = 0; i < MY_SIZE_OF_ARRAY(g_7zSfxMethods); i++) + if (methodID == g_7zSfxMethods[i]) + return true; + return false; +}; + +#ifndef _WIN64 +typedef BOOL (WINAPI *GlobalMemoryStatusExP)(LPMEMORYSTATUSEX lpBuffer); +#endif + +static UInt64 GetPhysicalRamSize() +{ + MEMORYSTATUSEX stat; + stat.dwLength = sizeof(stat); + // return (128 << 20); + #ifdef _WIN64 + if (!::GlobalMemoryStatusEx(&stat)) + return 0; + return stat.ullTotalPhys; + #else + GlobalMemoryStatusExP globalMemoryStatusEx = (GlobalMemoryStatusExP) + ::GetProcAddress(::GetModuleHandle(TEXT("kernel32.dll")), + "GlobalMemoryStatusEx"); + if (globalMemoryStatusEx != 0) + if (globalMemoryStatusEx(&stat)) + return stat.ullTotalPhys; + { + MEMORYSTATUS stat; + stat.dwLength = sizeof(stat); + GlobalMemoryStatus(&stat); + return stat.dwTotalPhys; + } + #endif +} + +static UInt64 GetMaxRamSizeForProgram() +{ + UInt64 physSize = GetPhysicalRamSize(); + const UInt64 kMinSysSize = (1 << 24); + if (physSize <= kMinSysSize) + physSize = 0; + else + physSize -= kMinSysSize; + const UInt64 kMinUseSize = (1 << 25); + if (physSize < kMinUseSize) + physSize = kMinUseSize; + return physSize; +} + +bool CCompressDialog::OnInit() +{ + #ifdef LANG + LangSetWindowText(HWND(*this), 0x02000D00); + LangSetDlgItemsText(HWND(*this), kIDLangPairs, MY_SIZE_OF_ARRAY(kIDLangPairs) ); + #endif + _password1Control.Attach(GetItem(IDC_COMPRESS_EDIT_PASSWORD1)); + _password2Control.Attach(GetItem(IDC_COMPRESS_EDIT_PASSWORD2)); + _password1Control.SetText(Info.Password); + _password2Control.SetText(Info.Password); + _encryptionMethod.Attach(GetItem(IDC_COMPRESS_COMBO_ENCRYPTION_METHOD)); + + m_ArchivePath.Attach(GetItem(IDC_COMPRESS_COMBO_ARCHIVE)); + m_Format.Attach(GetItem(IDC_COMPRESS_COMBO_FORMAT)); + m_Level.Attach(GetItem(IDC_COMPRESS_COMBO_LEVEL)); + m_Method.Attach(GetItem(IDC_COMPRESS_COMBO_METHOD)); + m_Dictionary.Attach(GetItem(IDC_COMPRESS_COMBO_DICTIONARY)); + m_Order.Attach(GetItem(IDC_COMPRESS_COMBO_ORDER)); + + m_UpdateMode.Attach(GetItem(IDC_COMPRESS_COMBO_UPDATE_MODE)); + m_Volume.Attach(GetItem(IDC_COMPRESS_COMBO_VOLUME)); + m_Params.Attach(GetItem(IDC_COMPRESS_EDIT_PARAMETERS)); + + AddVolumeItems(m_Volume); + + ReadCompressionInfo(m_RegistryInfo); + CheckButton(IDC_COMPRESS_CHECK_SHOW_PASSWORD, m_RegistryInfo.ShowPassword); + CheckButton(IDC_COMPRESS_CHECK_ENCRYPT_FILE_NAMES, m_RegistryInfo.EncryptHeaders); + + UpdatePasswordControl(); + + Info.ArchiverInfoIndex = 0; + int i; + for(i = 0; i < m_ArchiverInfoList.Size(); i++) + { + const CArchiverInfo &ai = m_ArchiverInfoList[i]; + m_Format.AddString(ai.Name); + if (ai.Name.CompareNoCase(m_RegistryInfo.ArchiveType) == 0) + Info.ArchiverInfoIndex = i; + } + m_Format.SetCurSel(Info.ArchiverInfoIndex); + + SetArchiveName(Info.ArchiveName); + SetLevel(); + SetParams(); + + for(i = 0; i < m_RegistryInfo.HistoryArchives.Size() && i < kHistorySize; i++) + m_ArchivePath.AddString(m_RegistryInfo.HistoryArchives[i]); + + m_UpdateMode.AddString(LangString(IDS_COMPRESS_UPDATE_MODE_ADD, 0x02000DA1)); + m_UpdateMode.AddString(LangString(IDS_COMPRESS_UPDATE_MODE_UPDATE, 0x02000DA2)); + m_UpdateMode.AddString(LangString(IDS_COMPRESS_UPDATE_MODE_FRESH, 0x02000DA3)); + m_UpdateMode.AddString(LangString(IDS_COMPRESS_UPDATE_MODE_SYNCHRONIZE, 0x02000DA4)); + + m_UpdateMode.SetCurSel(0); + + Info.Solid = m_RegistryInfo.Solid; + Info.MultiThread = m_RegistryInfo.MultiThread; + + CheckButton(IDC_COMPRESS_SOLID, Info.Solid); + CheckButton(IDC_COMPRESS_MULTI_THREAD, Info.MultiThread); + CheckButton(IDC_COMPRESS_SFX, Info.SFXMode); + + CheckControlsEnable(); + + OnButtonSFX(); + + SetEncryptionMethod(); + return CModalDialog::OnInit(); +} + +namespace NCompressDialog +{ + bool CInfo::GetFullPathName(UString &result) const + { + NDirectory::MySetCurrentDirectory(CurrentDirPrefix); + return MyGetFullPathName(ArchiveName, result); + } +} + +void CCompressDialog::UpdatePasswordControl() +{ + bool showPassword = IsShowPasswordChecked(); + TCHAR c = showPassword ? 0: TEXT('*'); + _password1Control.SetPasswordChar(c); + _password2Control.SetPasswordChar(c); + UString password; + _password1Control.GetText(password); + _password1Control.SetText(password); + _password2Control.GetText(password); + _password2Control.SetText(password); + + int cmdShow = showPassword ? SW_HIDE : SW_SHOW; + ShowItem(IDC_STATIC_COMPRESS_PASSWORD2, cmdShow); + _password2Control.Show(cmdShow); +} + +bool CCompressDialog::OnButtonClicked(int buttonID, HWND buttonHWND) +{ + switch(buttonID) + { + case IDC_COMPRESS_BUTTON_SET_ARCHIVE: + { + OnButtonSetArchive(); + return true; + } + case IDC_COMPRESS_SFX: + { + OnButtonSFX(); + return true; + } + case IDC_COMPRESS_CHECK_SHOW_PASSWORD: + { + UpdatePasswordControl(); + return true; + } + case IDC_COMPRESS_MULTI_THREAD: + { + SetMemoryUsage(); + return true; + } + } + return CModalDialog::OnButtonClicked(buttonID, buttonHWND); +} + +static bool IsMultiProcessor() +{ + return NSystem::GetNumberOfProcessors() > 1; +} + +void CCompressDialog::CheckSFXControlsEnable() +{ + const CFormatInfo &fi = g_Formats[GetStaticFormatIndex()]; + bool enable = fi.SFX; + if (enable) + { + int methodID = GetMethodID(); + enable = (methodID == -1 || IsMethodSupportedBySfx(methodID)); + } + if (!enable) + CheckButton(IDC_COMPRESS_SFX, false); + EnableItem(IDC_COMPRESS_SFX, enable); +} + +void CCompressDialog::CheckVolumeEnable() +{ + bool isSFX = IsSFX(); + m_Volume.Enable(!isSFX); + if (isSFX) + m_Volume.SetText(TEXT("")); +} + +void CCompressDialog::CheckControlsEnable() +{ + const CFormatInfo &fi = g_Formats[GetStaticFormatIndex()]; + Info.SolidIsAllowed = fi.Solid; + bool multiThreadEnable = fi.MultiThread & IsMultiProcessor(); + Info.MultiThreadIsAllowed = multiThreadEnable; + Info.EncryptHeadersIsAllowed = fi.EncryptFileNames; + + EnableItem(IDC_COMPRESS_SOLID, fi.Solid); + EnableItem(IDC_COMPRESS_MULTI_THREAD, multiThreadEnable); + CheckSFXControlsEnable(); + CheckVolumeEnable(); + + EnableItem(IDC_COMPRESS_ENCRYPTION, fi.Encrypt); + + EnableItem(IDC_STATIC_COMPRESS_PASSWORD1, fi.Encrypt); + EnableItem(IDC_STATIC_COMPRESS_PASSWORD2, fi.Encrypt); + EnableItem(IDC_COMPRESS_EDIT_PASSWORD1, fi.Encrypt); + EnableItem(IDC_COMPRESS_EDIT_PASSWORD2, fi.Encrypt); + EnableItem(IDC_COMPRESS_CHECK_SHOW_PASSWORD, fi.Encrypt); + + EnableItem(IDC_STATIC_COMPRESS_ENCRYPTION_METHOD, fi.Encrypt); + EnableItem(IDC_COMPRESS_COMBO_ENCRYPTION_METHOD, fi.Encrypt); + EnableItem(IDC_COMPRESS_CHECK_ENCRYPT_FILE_NAMES, fi.EncryptFileNames); +} + +bool CCompressDialog::IsSFX() +{ + CWindow sfxButton = GetItem(IDC_COMPRESS_SFX); + return sfxButton.IsEnabled() && IsButtonCheckedBool(IDC_COMPRESS_SFX); +} + +void CCompressDialog::OnButtonSFX() +{ + SetMethod(); + + UString fileName; + m_ArchivePath.GetText(fileName); + int dotPos = fileName.ReverseFind(L'.'); + int slashPos = fileName.ReverseFind(L'\\'); + if (dotPos < 0 || dotPos <= slashPos) + dotPos = -1; + bool isSFX = IsSFX(); + if (isSFX) + { + if (dotPos >= 0) + fileName = fileName.Left(dotPos); + fileName += kExeExt; + m_ArchivePath.SetText(fileName); + } + else + { + if (dotPos >= 0) + { + UString ext = fileName.Mid(dotPos); + if (ext.CompareNoCase(kExeExt) == 0) + { + fileName = fileName.Left(dotPos); + m_ArchivePath.SetText(fileName); + } + } + SetArchiveName2(false); // it's for OnInit + } + + CheckVolumeEnable(); +} + +void CCompressDialog::OnButtonSetArchive() +{ + UString fileName; + m_ArchivePath.GetText(fileName); + fileName.Trim(); + Info.ArchiveName = fileName; + UString fullFileName; + if (!Info.GetFullPathName(fullFileName)) + { + fullFileName = Info.ArchiveName; + return; + } + UString title = LangString(IDS_COMPRESS_SET_ARCHIVE_DIALOG_TITLE, 0x02000D90); + UString s = LangString(IDS_OPEN_TYPE_ALL_FILES, 0x02000DB1); + s += L" (*.*)"; + UString resPath; + if (!MyGetOpenFileName(HWND(*this), title, fullFileName, s, resPath)) + return; + m_ArchivePath.SetText(resPath); +} + +// in ExtractDialog.cpp +extern void AddUniqueString(UStringVector &strings, const UString &srcString); + +static bool IsAsciiString(const UString &s) +{ + for (int i = 0; i < s.Length(); i++) + { + wchar_t c = s[i]; + if (c < 0x20 || c > 0x7F) + return false; + } + return true; +} + +void CCompressDialog::OnOK() +{ + _password1Control.GetText(Info.Password); + if (IsZipFormat()) + { + if (!IsAsciiString(Info.Password)) + { + MyMessageBoxResource(*this, IDS_PASSWORD_USE_ASCII, 0x02000B11); + return; + } + UString method = GetEncryptionMethodSpec(); + method.MakeUpper(); + if (method.Find(L"AES") == 0) + { + if (Info.Password.Length() > 99) + { + MyMessageBoxResource(*this, IDS_PASSWORD_IS_TOO_LONG, 0x02000B12); + return; + } + } + } + if (!IsShowPasswordChecked()) + { + UString password2; + _password2Control.GetText(password2); + if (password2 != Info.Password) + { + MyMessageBoxResource(*this, IDS_PASSWORD_PASSWORDS_DO_NOT_MATCH, 0x02000B10); + return; + } + } + + SaveOptionsInMem(); + UString s; + m_ArchivePath.GetText(s); + s.Trim(); + m_RegistryInfo.HistoryArchives.Clear(); + AddUniqueString(m_RegistryInfo.HistoryArchives, s); + Info.ArchiveName = s; + Info.UpdateMode = NCompressDialog::NUpdateMode::EEnum(m_UpdateMode.GetCurSel()); + + Info.Level = GetLevelSpec(); + Info.Dictionary = GetDictionarySpec(); + Info.Order = GetOrderSpec(); + Info.OrderMode = GetOrderMode(); + Info.Method = GetMethodSpec(); + Info.EncryptionMethod = GetEncryptionMethodSpec(); + + Info.ArchiverInfoIndex = m_Format.GetCurSel(); + + Info.SFXMode = IsSFX(); + m_RegistryInfo.Solid = Info.Solid = IsButtonCheckedBool(IDC_COMPRESS_SOLID); + m_RegistryInfo.MultiThread = Info.MultiThread = IsMultiThread(); + m_RegistryInfo.EncryptHeaders = Info.EncryptHeaders = IsButtonCheckedBool(IDC_COMPRESS_CHECK_ENCRYPT_FILE_NAMES); + + m_Params.GetText(Info.Options); + UString volumeString; + m_Volume.GetText(volumeString); + volumeString.Trim(); + Info.VolumeSizes.Clear(); + if (!volumeString.IsEmpty()) + { + if (!ParseVolumeSizes(volumeString, Info.VolumeSizes)) + { + MyMessageBoxResource(*this, IDS_COMPRESS_INCORRECT_VOLUME_SIZE, 0x02000D41); + return; + } + if (!Info.VolumeSizes.IsEmpty()) + { + const UInt64 volumeSize = Info.VolumeSizes.Back(); + if (volumeSize < (100 << 10)) + { + wchar_t s[32]; + ConvertUInt64ToString(volumeSize, s); + if (::MessageBoxW(*this, MyFormatNew(IDS_COMPRESS_SPLIT_CONFIRM_MESSAGE, 0x02000D42, s), + L"7-Zip", MB_YESNOCANCEL | MB_ICONQUESTION | MB_TASKMODAL) != IDYES) + return; + } + } + } + + for(int i = 0; i < m_ArchivePath.GetCount(); i++) + { + UString sTemp; + m_ArchivePath.GetLBText(i, sTemp); + sTemp.Trim(); + AddUniqueString(m_RegistryInfo.HistoryArchives, sTemp); + } + if (m_RegistryInfo.HistoryArchives.Size() > kHistorySize) + m_RegistryInfo.HistoryArchives.DeleteBack(); + + //////////////////// + // Method + + m_RegistryInfo.Level = Info.Level; + m_RegistryInfo.ArchiveType = m_ArchiverInfoList[Info.ArchiverInfoIndex].Name; + + m_RegistryInfo.ShowPassword = IsShowPasswordChecked(); + + SaveCompressionInfo(m_RegistryInfo); + + CModalDialog::OnOK(); +} + +static LPCWSTR kHelpTopic = L"fm/plugins/7-zip/add.htm"; + +void CCompressDialog::OnHelp() +{ + ShowHelpWindow(NULL, kHelpTopic); +} + +bool CCompressDialog::OnCommand(int code, int itemID, LPARAM lParam) +{ + if (code == CBN_SELCHANGE) + { + switch(itemID) + { + case IDC_COMPRESS_COMBO_FORMAT: + { + OnChangeFormat(); + return true; + } + case IDC_COMPRESS_COMBO_LEVEL: + { + const CArchiverInfo &ai = m_ArchiverInfoList[m_Format.GetCurSel()]; + int index = FindRegistryFormatAlways(ai.Name); + NCompression::CFormatOptions &fo = m_RegistryInfo.FormatOptionsVector[index]; + fo.ResetForLevelChange(); + SetMethod(); + CheckSFXNameChange(); + return true; + } + case IDC_COMPRESS_COMBO_METHOD: + { + SetDictionary(); + SetOrder(); + CheckSFXNameChange(); + return true; + } + case IDC_COMPRESS_COMBO_DICTIONARY: + case IDC_COMPRESS_COMBO_ORDER: + { + SetMemoryUsage(); + return true; + } + } + } + return CModalDialog::OnCommand(code, itemID, lParam); +} + +void CCompressDialog::CheckSFXNameChange() +{ + bool isSFX = IsSFX(); + CheckSFXControlsEnable(); + if (isSFX != IsSFX()) + SetArchiveName2(isSFX); +} + +void CCompressDialog::SetArchiveName2(bool prevWasSFX) +{ + UString fileName; + m_ArchivePath.GetText(fileName); + const CArchiverInfo &prevArchiverInfo = m_ArchiverInfoList[m_PrevFormat]; + if (prevArchiverInfo.KeepName || Info.KeepName) + { + UString prevExtension = prevArchiverInfo.GetMainExtension(); + if (prevWasSFX) + prevExtension = kExeExt; + else + prevExtension = UString('.') + prevExtension; + const int prevExtensionLen = prevExtension.Length(); + if (fileName.Length() >= prevExtensionLen) + if (fileName.Right(prevExtensionLen).CompareNoCase(prevExtension) == 0) + fileName = fileName.Left(fileName.Length() - prevExtensionLen); + } + SetArchiveName(fileName); +} + +void CCompressDialog::OnChangeFormat() +{ + bool isSFX = IsSFX(); + SaveOptionsInMem(); + SetLevel(); + SetParams(); + CheckControlsEnable(); + SetArchiveName2(isSFX); + SetEncryptionMethod(); +} + +// if type.KeepName then use OriginalFileName +// else if !KeepName remove extension +// add new extension + +void CCompressDialog::SetArchiveName(const UString &name) +{ + UString fileName = name; + Info.ArchiverInfoIndex = m_Format.GetCurSel(); + const CArchiverInfo &ai = m_ArchiverInfoList[Info.ArchiverInfoIndex]; + m_PrevFormat = Info.ArchiverInfoIndex; + if (ai.KeepName) + { + fileName = OriginalFileName; + } + else + { + if (!Info.KeepName) + { + int dotPos = fileName.ReverseFind('.'); + int slashPos = MyMax(fileName.ReverseFind('\\'), fileName.ReverseFind('/')); + if (dotPos >= 0 && dotPos > slashPos + 1) + fileName = fileName.Left(dotPos); + } + } + + if (IsSFX()) + fileName += kExeExt; + else + { + fileName += L'.'; + fileName += ai.GetMainExtension(); + } + m_ArchivePath.SetText(fileName); +} + +int CCompressDialog::FindRegistryFormat(const UString &name) +{ + for (int i = 0; i < m_RegistryInfo.FormatOptionsVector.Size(); i++) + { + const NCompression::CFormatOptions &fo = m_RegistryInfo.FormatOptionsVector[i]; + if (GetUnicodeString(fo.FormatID) == name) + return i; + } + return -1; +} + +int CCompressDialog::FindRegistryFormatAlways(const UString &name) +{ + int index = FindRegistryFormat(name); + if (index < 0) + { + NCompression::CFormatOptions fo; + fo.FormatID = GetSystemString(name); + index = m_RegistryInfo.FormatOptionsVector.Add(fo); + } + return index; +} + +int CCompressDialog::GetStaticFormatIndex() +{ + int formatIndex = m_Format.GetCurSel(); + const CArchiverInfo &ai = m_ArchiverInfoList[formatIndex]; + for (int i = 0; i < MY_SIZE_OF_ARRAY(g_Formats); i++) + if (ai.Name.CompareNoCase(g_Formats[i].Name) == 0) + return i; + return 0; // -1; +} + +void CCompressDialog::SetNearestSelectComboBox( + NControl::CComboBox &comboBox, UInt32 value) +{ + for (int i = comboBox.GetCount() - 1; i >= 0; i--) + if ((UInt32)comboBox.GetItemData(i) <= value) + { + comboBox.SetCurSel(i); + return; + } + if (comboBox.GetCount() > 0) + comboBox.SetCurSel(0); +} + +void CCompressDialog::SetLevel() +{ + m_Level.ResetContent(); + const CFormatInfo &fi = g_Formats[GetStaticFormatIndex()]; + const CArchiverInfo &ai = m_ArchiverInfoList[m_Format.GetCurSel()]; + int index = FindRegistryFormat(ai.Name); + UInt32 level = kNormal; + if (index >= 0) + { + const NCompression::CFormatOptions &fo = m_RegistryInfo.FormatOptionsVector[index]; + if (fo.Level <= kUltra) + level = fo.Level; + else + level = kUltra; + } + int i; + for (i = 0; i <= kUltra; i++) + { + if ((fi.LevelsMask & (1 << i)) != 0) + { + const CLevelInfo &levelInfo = g_Levels[i]; + int index = (int)m_Level.AddString(LangString(levelInfo.ResourceID, levelInfo.LangID)); + m_Level.SetItemData(index, i); + } + } + SetNearestSelectComboBox(m_Level, level); + SetMethod(); +} + +int CCompressDialog::GetLevel() +{ + if (m_Level.GetCount() <= 0) + return -1; + return (int)m_Level.GetItemData(m_Level.GetCurSel()); +} + +int CCompressDialog::GetLevelSpec() +{ + if (m_Level.GetCount() <= 1) + return -1; + return GetLevel(); +} + +int CCompressDialog::GetLevel2() +{ + int level = GetLevel(); + if (level < 0) + level = 5; + return level; +} + +bool CCompressDialog::IsMultiThread() +{ + /* + const CFormatInfo &fi = g_Formats[GetStaticFormatIndex()]; + bool multiThreadEnable = fi.MultiThread & IsMultiProcessor(); + if (!multiThreadEnable) + return false; + */ + return IsButtonCheckedBool(IDC_COMPRESS_MULTI_THREAD); +} + +void CCompressDialog::SetMethod() +{ + m_Method.ResetContent(); + if (GetLevel() <= 0) + { + SetDictionary(); + SetOrder(); + return; + } + const CFormatInfo &fi = g_Formats[GetStaticFormatIndex()]; + const CArchiverInfo &ai = m_ArchiverInfoList[m_Format.GetCurSel()]; + int index = FindRegistryFormat(ai.Name); + UString defaultMethod; + if (index >= 0) + { + const NCompression::CFormatOptions &fo = m_RegistryInfo.FormatOptionsVector[index]; + defaultMethod = fo.Method; + } + bool isSfx = IsSFX(); + for(int m = 0; m < fi.NumMethods; m++) + { + EMethodID methodID = fi.MathodIDs[m]; + if (isSfx) + if (!IsMethodSupportedBySfx(methodID)) + continue; + const LPCWSTR method = kMethodsNames[methodID]; + int itemIndex = (int)m_Method.AddString(GetSystemString(method)); + if (defaultMethod.CompareNoCase(method) == 0 || m == 0) + m_Method.SetCurSel(itemIndex); + } + SetDictionary(); + SetOrder(); +} + +bool CCompressDialog::IsZipFormat() +{ + const CArchiverInfo &ai = m_ArchiverInfoList[m_Format.GetCurSel()]; + return (ai.Name.CompareNoCase(L"zip") == 0); +} + +void CCompressDialog::SetEncryptionMethod() +{ + _encryptionMethod.ResetContent(); + const CArchiverInfo &ai = m_ArchiverInfoList[m_Format.GetCurSel()]; + if (ai.Name.CompareNoCase(L"7z") == 0) + { + _encryptionMethod.AddString(TEXT("AES-256")); + _encryptionMethod.SetCurSel(0); + } + else if (ai.Name.CompareNoCase(L"zip") == 0) + { + int index = FindRegistryFormat(ai.Name); + UString encryptionMethod; + if (index >= 0) + { + const NCompression::CFormatOptions &fo = m_RegistryInfo.FormatOptionsVector[index]; + encryptionMethod = fo.EncryptionMethod; + } + _encryptionMethod.AddString(TEXT("ZipCrypto")); + _encryptionMethod.AddString(TEXT("AES-256")); + _encryptionMethod.SetCurSel(encryptionMethod.Find(L"AES") == 0 ? 1 : 0); + } +} + +int CCompressDialog::GetMethodID() +{ + UString methodName; + m_Method.GetText(methodName); + for (int i = 0; i < MY_SIZE_OF_ARRAY(kMethodsNames); i++) + if (methodName.CompareNoCase(kMethodsNames[i]) == 0) + return i; + return -1; +} + +UString CCompressDialog::GetMethodSpec() +{ + if (m_Method.GetCount() <= 1) + return UString(); + UString result; + m_Method.GetText(result); + return result; +} + +UString CCompressDialog::GetEncryptionMethodSpec() +{ + if (m_Method.GetCount() <= 1) + return UString(); + if (_encryptionMethod.GetCurSel() <= 0) + return UString(); + UString result; + _encryptionMethod.GetText(result); + result.Replace(L"-", L""); + return result; +} + +int CCompressDialog::AddDictionarySize(UInt32 size, bool kilo, bool maga) +{ + UInt32 sizePrint = size; + if (kilo) + sizePrint >>= 10; + else if (maga) + sizePrint >>= 20; + TCHAR s[40]; + ConvertUInt64ToString(sizePrint, s); + if (kilo) + lstrcat(s, TEXT(" K")); + else if (maga) + lstrcat(s, TEXT(" M")); + else + lstrcat(s, TEXT(" ")); + lstrcat(s, TEXT("B")); + int index = (int)m_Dictionary.AddString(s); + m_Dictionary.SetItemData(index, size); + return index; +} + +int CCompressDialog::AddDictionarySize(UInt32 size) +{ + if (size > 0) + { + if ((size & 0xFFFFF) == 0) + return AddDictionarySize(size, false, true); + if ((size & 0x3FF) == 0) + return AddDictionarySize(size, true, false); + } + return AddDictionarySize(size, false, false); +} + +void CCompressDialog::SetDictionary() +{ + m_Dictionary.ResetContent(); + const CArchiverInfo &ai = m_ArchiverInfoList[m_Format.GetCurSel()]; + int index = FindRegistryFormat(ai.Name); + UInt32 defaultDictionary = UInt32(-1); + if (index >= 0) + { + const NCompression::CFormatOptions &fo = m_RegistryInfo.FormatOptionsVector[index]; + if (fo.Method.CompareNoCase(GetMethodSpec()) == 0) + defaultDictionary = fo.Dictionary; + } + int methodID = GetMethodID(); + int level = GetLevel2(); + if (methodID < 0) + { + SetMemoryUsage(); + return; + } + const UInt64 maxRamSize = GetMaxRamSizeForProgram(); + switch (methodID) + { + case kLZMA: + { + static const UInt32 kMinDicSize = (1 << 16); + if (defaultDictionary == UInt32(-1)) + { + if (level >= 9) + defaultDictionary = (1 << 26); + else if (level >= 7) + defaultDictionary = (1 << 24); + else if (level >= 5) + defaultDictionary = (1 << 22); + else if (level >= 3) + defaultDictionary = (1 << 20); + else + defaultDictionary = (kMinDicSize); + } + int i; + AddDictionarySize(kMinDicSize); + m_Dictionary.SetCurSel(0); + for (i = 20; i <= 30; i++) + for (int j = 0; j < 2; j++) + { + if (i == 20 && j > 0) + continue; + UInt32 dictionary = (1 << i) + (j << (i - 1)); + if (dictionary > + #ifdef _WIN64 + (1 << 30) + #else + (1 << 27) + #endif + ) + continue; + AddDictionarySize(dictionary); + UInt64 decomprSize; + UInt64 requiredComprSize = GetMemoryUsage(dictionary, false, decomprSize); + if (dictionary <= defaultDictionary && requiredComprSize <= maxRamSize) + m_Dictionary.SetCurSel(m_Dictionary.GetCount() - 1); + } + + // SetNearestSelectComboBox(m_Dictionary, defaultDictionary); + break; + } + case kPPMd: + { + if (defaultDictionary == UInt32(-1)) + { + if (level >= 9) + defaultDictionary = (192 << 20); + else if (level >= 7) + defaultDictionary = (64 << 20); + else if (level >= 5) + defaultDictionary = (16 << 20); + else + defaultDictionary = (4 << 20); + } + int i; + for (i = 20; i < 31; i++) + for (int j = 0; j < 2; j++) + { + if (i == 20 && j > 0) + continue; + UInt32 dictionary = (1 << i) + (j << (i - 1)); + if (dictionary >= (1 << 31)) + continue; + AddDictionarySize(dictionary); + UInt64 decomprSize; + UInt64 requiredComprSize = GetMemoryUsage(dictionary, false, decomprSize); + if (dictionary <= defaultDictionary && requiredComprSize <= maxRamSize || m_Dictionary.GetCount() == 0) + m_Dictionary.SetCurSel(m_Dictionary.GetCount() - 1); + } + SetNearestSelectComboBox(m_Dictionary, defaultDictionary); + break; + } + case kDeflate: + { + AddDictionarySize(32 << 10); + m_Dictionary.SetCurSel(0); + break; + } + case kDeflate64: + { + AddDictionarySize(64 << 10); + m_Dictionary.SetCurSel(0); + break; + } + case kBZip2: + { + UInt32 defaultDictionary; + if (level >= 5) + defaultDictionary = (900 << 10); + else if (level >= 3) + defaultDictionary = (500 << 10); + else + defaultDictionary = (100 << 10); + for (int i = 1; i <= 9; i++) + { + UInt32 dictionary = (i * 100) << 10; + AddDictionarySize(dictionary); + if (dictionary <= defaultDictionary || m_Dictionary.GetCount() == 0) + m_Dictionary.SetCurSel(m_Dictionary.GetCount() - 1); + } + break; + } + } + SetMemoryUsage(); +} + +UInt32 CCompressDialog::GetDictionary() +{ + if (m_Dictionary.GetCount() <= 0) + return (UInt32)-1; + return (UInt32)m_Dictionary.GetItemData(m_Dictionary.GetCurSel()); +} + +UInt32 CCompressDialog::GetDictionarySpec() +{ + if (m_Dictionary.GetCount() <= 1) + return (UInt32)-1; + return GetDictionary(); +} + +int CCompressDialog::AddOrder(UInt32 size) +{ + TCHAR s[40]; + ConvertUInt64ToString(size, s); + int index = (int)m_Order.AddString(s); + m_Order.SetItemData(index, size); + return index; +} + +void CCompressDialog::SetOrder() +{ + m_Order.ResetContent(); + const CArchiverInfo &ai = m_ArchiverInfoList[m_Format.GetCurSel()]; + int index = FindRegistryFormat(ai.Name); + UInt32 defaultOrder = UInt32(-1); + if (index >= 0) + { + const NCompression::CFormatOptions &fo = m_RegistryInfo.FormatOptionsVector[index]; + if (fo.Method.CompareNoCase(GetMethodSpec()) == 0) + defaultOrder = fo.Order; + } + int methodID = GetMethodID(); + int level = GetLevel2(); + if (methodID < 0) + { + SetMemoryUsage(); + return; + } + switch (methodID) + { + case kLZMA: + { + if (defaultOrder == UInt32(-1)) + defaultOrder = (level >= 7) ? 64 : 32; + for (int i = 3; i <= 8; i++) + for (int j = 0; j < 2; j++) + { + UInt32 order = (1 << i) + (j << (i - 1)); + if (order <= 256) + AddOrder(order); + } + AddOrder(273); + SetNearestSelectComboBox(m_Order, defaultOrder); + break; + } + case kPPMd: + { + if (defaultOrder == UInt32(-1)) + { + if (level >= 9) + defaultOrder = 32; + else if (level >= 7) + defaultOrder = 16; + else if (level >= 5) + defaultOrder = 6; + else + defaultOrder = 4; + } + int i; + AddOrder(2); + AddOrder(3); + for (i = 2; i < 8; i++) + for (int j = 0; j < 4; j++) + { + UInt32 order = (1 << i) + (j << (i - 2)); + if (order < 32) + AddOrder(order); + } + AddOrder(32); + SetNearestSelectComboBox(m_Order, defaultOrder); + break; + } + case kDeflate: + case kDeflate64: + { + if (defaultOrder == UInt32(-1)) + { + if (level >= 9) + defaultOrder = 128; + else if (level >= 7) + defaultOrder = 64; + else + defaultOrder = 32; + } + int i; + for (i = 3; i <= 8; i++) + for (int j = 0; j < 2; j++) + { + UInt32 order = (1 << i) + (j << (i - 1)); + if (order <= 256) + AddOrder(order); + } + AddOrder(methodID == kDeflate64 ? 257 : 258); + SetNearestSelectComboBox(m_Order, defaultOrder); + break; + } + case kBZip2: + { + break; + } + } + SetMemoryUsage(); +} + +bool CCompressDialog::GetOrderMode() +{ + switch (GetMethodID()) + { + case kPPMd: + return true; + } + return false; +} + +UInt32 CCompressDialog::GetOrder() +{ + if (m_Order.GetCount() <= 0) + return (UInt32)-1; + return (UInt32)m_Order.GetItemData(m_Order.GetCurSel()); +} + +UInt32 CCompressDialog::GetOrderSpec() +{ + if (m_Order.GetCount() <= 1) + return (UInt32)-1; + return GetOrder(); +} + +UInt64 CCompressDialog::GetMemoryUsage(UInt32 dictionary, bool isMultiThread, UInt64 &decompressMemory) +{ + decompressMemory = UInt64(Int64(-1)); + int level = GetLevel2(); + if (level == 0) + { + decompressMemory = (1 << 20); + return decompressMemory; + } + UInt64 size = 0; + + const CFormatInfo &fi = g_Formats[GetStaticFormatIndex()]; + if (fi.Filter && level >= 9) + size += (12 << 20) * 2 + (5 << 20); + switch (GetMethodID()) + { + case kLZMA: + { + UInt32 hs = dictionary - 1; + hs |= (hs >> 1); + hs |= (hs >> 2); + hs |= (hs >> 4); + hs |= (hs >> 8); + hs >>= 1; + hs |= 0xFFFF; + if (hs > (1 << 24)) + hs >>= 1; + hs++; + size += hs * 4; + size += (UInt64)dictionary * 11 / 2; + if (level >= 5) + size += dictionary * 4; + size += (2 << 20); + if (isMultiThread && level >= 5) + size += (2 << 20) + (4 << 20); + + decompressMemory = dictionary + (2 << 20); + return size; + } + case kPPMd: + { + decompressMemory = dictionary + (2 << 20); + return size + decompressMemory; + } + case kDeflate: + case kDeflate64: + { + UInt32 order = GetOrder(); + if (order == UInt32(-1)) + order = 32; + if (level >= 7) + size += (1 << 20); + size += 3 << 20; + decompressMemory = (2 << 20); + return size; + } + case kBZip2: + { + decompressMemory = (7 << 20); + UInt64 memForOneThread = (10 << 20); + if (isMultiThread) + memForOneThread *= NSystem::GetNumberOfProcessors(); + return size + (10 << 20); + } + } + return UInt64(Int64(-1)); +} + +UInt64 CCompressDialog::GetMemoryUsage(UInt64 &decompressMemory) +{ + return GetMemoryUsage(GetDictionary(), IsMultiThread(), decompressMemory); +} + +void CCompressDialog::PrintMemUsage(UINT res, UInt64 value) +{ + if (value == (UInt64)Int64(-1)) + { + SetItemText(res, TEXT("?")); + return; + } + value = (value + (1 << 20) - 1) >> 20; + TCHAR s[40]; + ConvertUInt64ToString(value, s); + lstrcat(s, TEXT(" MB")); + SetItemText(res, s); +} + +void CCompressDialog::SetMemoryUsage() +{ + UInt64 decompressMem; + UInt64 memUsage = GetMemoryUsage(decompressMem); + PrintMemUsage(IDC_STATIC_COMPRESS_MEMORY_VALUE, memUsage); + PrintMemUsage(IDC_STATIC_COMPRESS_MEMORY_DE_VALUE, decompressMem); +} + +void CCompressDialog::SetParams() +{ + const CArchiverInfo &ai = m_ArchiverInfoList[m_Format.GetCurSel()]; + m_Params.SetText(TEXT("")); + int index = FindRegistryFormat(ai.Name); + if (index >= 0) + { + const NCompression::CFormatOptions &fo = m_RegistryInfo.FormatOptionsVector[index]; + m_Params.SetText(fo.Options); + } +} + +void CCompressDialog::SaveOptionsInMem() +{ + const CArchiverInfo &ai = m_ArchiverInfoList[Info.ArchiverInfoIndex]; + int index = FindRegistryFormatAlways(ai.Name); + m_Params.GetText(Info.Options); + Info.Options.Trim(); + NCompression::CFormatOptions &fo = m_RegistryInfo.FormatOptionsVector[index]; + fo.Options = Info.Options; + fo.Level = GetLevelSpec(); + fo.Dictionary = GetDictionarySpec(); + fo.Order = GetOrderSpec(); + fo.Method = GetMethodSpec(); + fo.EncryptionMethod = GetEncryptionMethodSpec(); +} diff --git a/CPP/7zip/UI/GUI/CompressDialog.h b/CPP/7zip/UI/GUI/CompressDialog.h new file mode 100755 index 00000000..87cf5d79 --- /dev/null +++ b/CPP/7zip/UI/GUI/CompressDialog.h @@ -0,0 +1,171 @@ +// CompressDialog.h + +#ifndef __COMPRESSDIALOG_H +#define __COMPRESSDIALOG_H + +#include "../Common/ZipRegistry.h" +#include "../Common/ArchiverInfo.h" +#include "../Resource/CompressDialog/resource.h" + +#include "Windows/Control/Dialog.h" +#include "Windows/Control/Edit.h" +#include "Windows/Control/ComboBox.h" + +namespace NCompressDialog +{ + namespace NUpdateMode + { + enum EEnum + { + kAdd, + kUpdate, + kFresh, + kSynchronize, + }; + } + struct CInfo + { + NUpdateMode::EEnum UpdateMode; + bool SolidIsAllowed; + bool Solid; + + bool MultiThreadIsAllowed; + bool MultiThread; + + CRecordVector VolumeSizes; + + UInt32 Level; + UString Method; + UInt32 Dictionary; + bool OrderMode; + UInt32 Order; + UString Options; + + UString EncryptionMethod; + + bool SFXMode; + + UString ArchiveName; // in: Relative for ; out: abs + UString CurrentDirPrefix; + bool KeepName; + + bool GetFullPathName(UString &result) const; + + int ArchiverInfoIndex; + + UString Password; + bool EncryptHeadersIsAllowed; + bool EncryptHeaders; + + void Init() + { + Level = Dictionary = Order = UInt32(-1); + OrderMode = false; + Method.Empty(); + Options.Empty(); + EncryptionMethod.Empty(); + } + CInfo() + { + Init(); + } + }; +} + +class CCompressDialog: public NWindows::NControl::CModalDialog +{ + NWindows::NControl::CComboBox m_ArchivePath; + NWindows::NControl::CComboBox m_Format; + NWindows::NControl::CComboBox m_Level; + NWindows::NControl::CComboBox m_Method; + NWindows::NControl::CComboBox m_Dictionary; + NWindows::NControl::CComboBox m_Order; + NWindows::NControl::CComboBox m_UpdateMode; + NWindows::NControl::CComboBox m_Volume; + NWindows::NControl::CDialogChildControl m_Params; + + NWindows::NControl::CEdit _password1Control; + NWindows::NControl::CEdit _password2Control; + NWindows::NControl::CComboBox _encryptionMethod; + + NCompression::CInfo m_RegistryInfo; + + int m_PrevFormat; + void SetArchiveName(const UString &name); + int FindRegistryFormat(const UString &name); + int FindRegistryFormatAlways(const UString &name); + + void OnChangeFormat(); + void CheckSFXNameChange(); + void SetArchiveName2(bool prevWasSFX); + + int GetStaticFormatIndex(); + + void SetNearestSelectComboBox(NWindows::NControl::CComboBox &comboBox, UInt32 value); + + void SetLevel(); + int GetLevel(); + int GetLevelSpec(); + int GetLevel2(); + bool IsMultiThread(); + + void SetMethod(); + int GetMethodID(); + UString GetMethodSpec(); + UString GetEncryptionMethodSpec(); + + bool IsZipFormat(); + + void SetEncryptionMethod(); + + int AddDictionarySize(UInt32 size, bool kilo, bool maga); + int AddDictionarySize(UInt32 size); + + void SetDictionary(); + UInt32 GetDictionary(); + UInt32 GetDictionarySpec(); + + int AddOrder(UInt32 size); + void SetOrder(); + bool GetOrderMode(); + UInt32 GetOrder(); + UInt32 GetOrderSpec(); + + UInt64 GetMemoryUsage(UInt32 dictionary, bool isMultiThread, UInt64 &decompressMemory); + UInt64 GetMemoryUsage(UInt64 &decompressMemory); + void PrintMemUsage(UINT res, UInt64 value); + void SetMemoryUsage(); + void SetParams(); + void SaveOptionsInMem(); + + void UpdatePasswordControl(); + bool IsShowPasswordChecked() const + { return IsButtonChecked(IDC_COMPRESS_CHECK_SHOW_PASSWORD) == BST_CHECKED; } +public: + CObjectVector m_ArchiverInfoList; + + NCompressDialog::CInfo Info; + UString OriginalFileName; // for bzip2, gzip2 + + INT_PTR Create(HWND wndParent = 0) + { return CModalDialog::Create(IDD_DIALOG_COMPRESS, wndParent); } + +protected: + + void CheckSFXControlsEnable(); + void CheckVolumeEnable(); + void CheckControlsEnable(); + + void OnButtonSetArchive(); + bool IsSFX(); + void OnButtonSFX(); + + virtual bool OnInit(); + virtual bool OnCommand(int code, int itemID, LPARAM lParam); + virtual bool OnButtonClicked(int buttonID, HWND buttonHWND); + virtual void OnOK(); + virtual void OnHelp(); + +}; + +#endif diff --git a/CPP/7zip/UI/GUI/ExtractDialog.cpp b/CPP/7zip/UI/GUI/ExtractDialog.cpp new file mode 100755 index 00000000..55c871ad --- /dev/null +++ b/CPP/7zip/UI/GUI/ExtractDialog.cpp @@ -0,0 +1,371 @@ +// ExtractDialog.cpp + +#include "StdAfx.h" + +// #include + +#include "ExtractDialog.h" + +#include "Common/StringConvert.h" +#include "Windows/Shell.h" +#include "Windows/FileName.h" +#include "Windows/FileDir.h" +#include "Windows/ResourceString.h" + +#ifndef NO_REGISTRY +#include "../../FileManager/HelpUtils.h" +#endif + +#include "../Common/ZipRegistry.h" + +#include "../../FileManager/LangUtils.h" + +#include "../Resource/Extract/resource.h" +#include "../Resource/ExtractDialog/resource.h" + +// #include "Help/Context/Extract.h" + +using namespace NWindows; +using namespace NFile; +using namespace NName; + +static const int kPathModeButtons[] = +{ + IDC_EXTRACT_RADIO_FULL_PATHNAMES, + IDC_EXTRACT_RADIO_CURRENT_PATHNAMES, + IDC_EXTRACT_RADIO_NO_PATHNAMES +}; + +static const NExtract::NPathMode::EEnum kPathModeButtonsVals[] = +{ + NExtract::NPathMode::kFullPathnames, + NExtract::NPathMode::kCurrentPathnames, + NExtract::NPathMode::kNoPathnames +}; + +static const int kNumPathnamesButtons = sizeof(kPathModeButtons) / sizeof(kPathModeButtons[0]); + +static const int kOverwriteButtons[] = +{ + IDC_EXTRACT_RADIO_ASK_BEFORE_OVERWRITE, + IDC_EXTRACT_RADIO_OVERWRITE_WITHOUT_PROMPT, + IDC_EXTRACT_RADIO_SKIP_EXISTING_FILES, + IDC_EXTRACT_RADIO_AUTO_RENAME, + IDC_EXTRACT_RADIO_AUTO_RENAME_EXISTING, +}; + +static const NExtract::NOverwriteMode::EEnum kOverwriteButtonsVals[] = +{ + NExtract::NOverwriteMode::kAskBefore, + NExtract::NOverwriteMode::kWithoutPrompt, + NExtract::NOverwriteMode::kSkipExisting, + NExtract::NOverwriteMode::kAutoRename, + NExtract::NOverwriteMode::kAutoRenameExisting +}; + +static const int kNumOverwriteButtons = sizeof(kOverwriteButtons) / sizeof(kOverwriteButtons[0]); + +/* +static const int kFilesButtons[] = +{ + IDC_EXTRACT_RADIO_SELECTED_FILES, + IDC_EXTRACT_RADIO_ALL_FILES +}; +static const int kNumFilesButtons = sizeof(kFilesButtons) / sizeof(kFilesButtons[0]); +*/ + +#ifndef _SFX +void CExtractDialog::GetPathMode() +{ + for (int i = 0; i < kNumPathnamesButtons; i++) + if(IsButtonCheckedBool(kPathModeButtons[i])) + { + PathMode = kPathModeButtonsVals[i]; + return; + } + throw 1; +} + +void CExtractDialog::SetPathMode() +{ + for (int j = 0; j < 2; j++) + { + for (int i = 0; i < kNumPathnamesButtons; i++) + if(PathMode == kPathModeButtonsVals[i]) + { + CheckRadioButton(kPathModeButtons[0], kPathModeButtons[kNumPathnamesButtons - 1], + kPathModeButtons[i]); + return; + } + PathMode = kPathModeButtonsVals[0]; + } + throw 1; +} + +void CExtractDialog::GetOverwriteMode() +{ + for (int i = 0; i < kNumOverwriteButtons; i++) + if(IsButtonCheckedBool(kOverwriteButtons[i])) + { + OverwriteMode = kOverwriteButtonsVals[i]; + return; + } + throw 0; +} + +void CExtractDialog::SetOverwriteMode() +{ + for (int j = 0; j < 2; j++) + { + for (int i = 0; i < kNumOverwriteButtons; i++) + if(OverwriteMode == kOverwriteButtonsVals[i]) + { + CheckRadioButton(kOverwriteButtons[0], kOverwriteButtons[kNumOverwriteButtons - 1], + kOverwriteButtons[i]); + return; + } + OverwriteMode = kOverwriteButtonsVals[0]; + } + throw 1; +} + +/* +int CExtractDialog::GetFilesMode() const +{ + for (int i = 0; i < kNumFilesButtons; i++) + if(IsButtonCheckedBool(kFilesButtons[i])) + return i; + throw 0; +} +*/ + +#endif + +#ifdef LANG +static CIDLangPair kIDLangPairs[] = +{ + { IDC_STATIC_EXTRACT_EXTRACT_TO, 0x02000801 }, + { IDC_EXTRACT_PATH_MODE, 0x02000810 }, + { IDC_EXTRACT_RADIO_FULL_PATHNAMES, 0x02000811 }, + { IDC_EXTRACT_RADIO_CURRENT_PATHNAMES, 0x02000812 }, + { IDC_EXTRACT_RADIO_NO_PATHNAMES, 0x02000813 }, + { IDC_EXTRACT_OVERWRITE_MODE, 0x02000820 }, + { IDC_EXTRACT_RADIO_ASK_BEFORE_OVERWRITE, 0x02000821 }, + { IDC_EXTRACT_RADIO_OVERWRITE_WITHOUT_PROMPT, 0x02000822 }, + { IDC_EXTRACT_RADIO_SKIP_EXISTING_FILES, 0x02000823 }, + { IDC_EXTRACT_RADIO_AUTO_RENAME, 0x02000824 }, + { IDC_EXTRACT_RADIO_AUTO_RENAME_EXISTING, 0x02000825 }, + { IDC_EXTRACT_FILES, 0x02000830 }, + { IDC_EXTRACT_RADIO_SELECTED_FILES, 0x02000831 }, + { IDC_EXTRACT_RADIO_ALL_FILES, 0x02000832 }, + { IDC_EXTRACT_PASSWORD, 0x02000802 }, + { IDC_EXTRACT_CHECK_SHOW_PASSWORD, 0x02000B02 }, + { IDOK, 0x02000702 }, + { IDCANCEL, 0x02000710 }, + { IDHELP, 0x02000720 } + +}; +#endif + +// static const int kWildcardsButtonIndex = 2; + +static const int kHistorySize = 8; + +bool CExtractDialog::OnInit() +{ + #ifdef LANG + LangSetWindowText(HWND(*this), 0x02000800); + LangSetDlgItemsText(HWND(*this), kIDLangPairs, sizeof(kIDLangPairs) / sizeof(kIDLangPairs[0])); + #endif + #ifndef _SFX + _passwordControl.Attach(GetItem(IDC_EXTRACT_EDIT_PASSWORD)); + _passwordControl.SetText(Password); + _passwordControl.SetPasswordChar(TEXT('*')); + #endif + + NExtract::CInfo extractionInfo; + + #ifdef NO_REGISTRY + PathMode = NExtract::NPathMode::kFullPathnames; + OverwriteMode = NExtract::NOverwriteMode::kAskBefore; + // extractionInfo.Paths = NExtract::NPathMode::kFullPathnames; + #else + ReadExtractionInfo(extractionInfo); + CheckButton(IDC_EXTRACT_CHECK_SHOW_PASSWORD, extractionInfo.ShowPassword); + UpdatePasswordControl(); + PathMode = extractionInfo.PathMode; + OverwriteMode = extractionInfo.OverwriteMode; + #endif + + _path.Attach(GetItem(IDC_EXTRACT_COMBO_PATH)); + + _path.SetText(DirectoryPath); + + #ifndef NO_REGISTRY + for(int i = 0; i < extractionInfo.Paths.Size() && i < kHistorySize; i++) + _path.AddString(extractionInfo.Paths[i]); + #endif + + /* + if(extractionInfo.Paths.Size() > 0) + _path.SetCurSel(0); + else + _path.SetCurSel(-1); + */ + + + + #ifndef _SFX + SetPathMode(); + SetOverwriteMode(); + + /* + CheckRadioButton(kFilesButtons[0], kFilesButtons[kNumFilesButtons - 1], + kFilesButtons[_filesMode]); + */ + + // CWindow selectedFilesWindow = GetItem(IDC_EXTRACT_RADIO_SELECTED_FILES); + // selectedFilesWindow.Enable(_enableSelectedFilesButton); + + + #endif + + + // CWindow filesWindow = GetItem(IDC_EXTRACT_RADIO_FILES); + // filesWindow.Enable(_enableFilesButton); + + // UpdateWildCardState(); + return CModalDialog::OnInit(); +} + +#ifndef _SFX +void CExtractDialog::UpdatePasswordControl() +{ + _passwordControl.SetPasswordChar((IsButtonChecked( + IDC_EXTRACT_CHECK_SHOW_PASSWORD) == BST_CHECKED) ? 0: TEXT('*')); + UString password; + _passwordControl.GetText(password); + _passwordControl.SetText(password); +} +#endif + +bool CExtractDialog::OnButtonClicked(int buttonID, HWND buttonHWND) +{ + /* + for (int i = 0; i < kNumFilesButtons; i++) + if (buttonID == kFilesButtons[i]) + { + UpdateWildCardState(); + return true; + } + */ + switch(buttonID) + { + case IDC_EXTRACT_BUTTON_SET_PATH: + OnButtonSetPath(); + return true; + #ifndef _SFX + case IDC_EXTRACT_CHECK_SHOW_PASSWORD: + { + UpdatePasswordControl(); + return true; + } + #endif + } + return CModalDialog::OnButtonClicked(buttonID, buttonHWND); +} + +void CExtractDialog::OnButtonSetPath() +{ + UString currentPath; + _path.GetText(currentPath); + UString title = LangStringSpec(IDS_EXTRACT_SET_FOLDER, 0x02000881); + UString resultPath; + if (!NShell::BrowseForFolder(HWND(*this), title, currentPath, resultPath)) + return; + #ifndef NO_REGISTRY + _path.SetCurSel(-1); + #endif + _path.SetText(resultPath); +} + +void AddUniqueString(UStringVector &list, const UString &s) +{ + for(int i = 0; i < list.Size(); i++) + if (s.CompareNoCase(list[i]) == 0) + return; + list.Add(s); +} + +void CExtractDialog::OnOK() +{ + #ifndef _SFX + GetPathMode(); + GetOverwriteMode(); + // _filesMode = (NExtractionDialog::NFilesMode::EEnum)GetFilesMode(); + + _passwordControl.GetText(Password); + #endif + + NExtract::CInfo extractionInfo; + extractionInfo.PathMode = PathMode; + extractionInfo.OverwriteMode = OverwriteMode; + extractionInfo.ShowPassword = (IsButtonChecked( + IDC_EXTRACT_CHECK_SHOW_PASSWORD) == BST_CHECKED); + + UString s; + + #ifdef NO_REGISTRY + + _path.GetText(s); + + #else + + int currentItem = _path.GetCurSel(); + if(currentItem == CB_ERR) + { + _path.GetText(s); + if(_path.GetCount() >= kHistorySize) + currentItem = _path.GetCount() - 1; + } + else + _path.GetLBText(currentItem, s); + + #endif + + s.Trim(); + #ifndef _SFX + AddUniqueString(extractionInfo.Paths, s); + #endif + DirectoryPath = s; + #ifndef NO_REGISTRY + for(int i = 0; i < _path.GetCount(); i++) + if(i != currentItem) + { + UString sTemp; + _path.GetLBText(i, sTemp); + sTemp.Trim(); + AddUniqueString(extractionInfo.Paths, sTemp); + } + SaveExtractionInfo(extractionInfo); + #endif + CModalDialog::OnOK(); +} + +/* +void CExtractDialog::UpdateWildCardState() +{ + // UpdateData(TRUE); + // m_Wildcards.EnableWindow(BoolToBOOL(m_Files == kWildcardsButtonIndex)); +} +*/ + +#ifndef NO_REGISTRY +static LPCWSTR kHelpTopic = L"fm/plugins/7-zip/extract.htm"; +void CExtractDialog::OnHelp() +{ + ShowHelpWindow(NULL, kHelpTopic); + CModalDialog::OnHelp(); +} +#endif + diff --git a/CPP/7zip/UI/GUI/ExtractDialog.h b/CPP/7zip/UI/GUI/ExtractDialog.h new file mode 100755 index 00000000..0020c693 --- /dev/null +++ b/CPP/7zip/UI/GUI/ExtractDialog.h @@ -0,0 +1,77 @@ +// ExtractDialog.h + +#ifndef __EXTRACTDIALOG_H +#define __EXTRACTDIALOG_H + +#include "resource.h" + +#include "Windows/Control/Dialog.h" +#include "Windows/Control/Edit.h" +#include "Windows/Control/ComboBox.h" + +#ifndef NO_REGISTRY +#include "../Common/ZipRegistry.h" +#endif +#include "../Common/ExtractMode.h" + +namespace NExtractionDialog +{ + /* + namespace NFilesMode + { + enum EEnum + { + kSelected, + kAll, + kSpecified + }; + } + */ +} + +class CExtractDialog: public NWindows::NControl::CModalDialog +{ + #ifdef NO_REGISTRY + NWindows::NControl::CDialogChildControl _path; + #else + NWindows::NControl::CComboBox _path; + #endif + + #ifndef _SFX + NWindows::NControl::CEdit _passwordControl; + #endif + + #ifndef _SFX + void GetPathMode(); + void SetPathMode(); + void GetOverwriteMode(); + void SetOverwriteMode(); + // int GetFilesMode() const; + void UpdatePasswordControl(); + #endif + + void OnButtonSetPath(); + + virtual bool OnInit(); + virtual bool OnButtonClicked(int buttonID, HWND buttonHWND); + virtual void OnOK(); + #ifndef NO_REGISTRY + virtual void OnHelp(); + #endif +public: + // bool _enableSelectedFilesButton; + // bool _enableFilesButton; + // NExtractionDialog::NFilesMode::EEnum FilesMode; + + UString DirectoryPath; + #ifndef _SFX + UString Password; + #endif + NExtract::NPathMode::EEnum PathMode; + NExtract::NOverwriteMode::EEnum OverwriteMode; + + INT_PTR Create(HWND aWndParent = 0) + { return CModalDialog::Create(IDD_DIALOG_EXTRACT, aWndParent); } +}; + +#endif diff --git a/CPP/7zip/UI/GUI/ExtractGUI.cpp b/CPP/7zip/UI/GUI/ExtractGUI.cpp new file mode 100755 index 00000000..395df5a9 --- /dev/null +++ b/CPP/7zip/UI/GUI/ExtractGUI.cpp @@ -0,0 +1,172 @@ +// ExtractGUI.cpp + +#include "StdAfx.h" + +#include "ExtractGUI.h" + +#include "Common/StringConvert.h" + +#include "Windows/FileDir.h" +#include "Windows/Error.h" +#include "Windows/FileFind.h" +#include "Windows/Thread.h" + +#include "../../FileManager/FormatUtils.h" +#include "../../FileManager/ExtractCallback.h" +#include "../../FileManager/LangUtils.h" + +#include "../Common/ArchiveExtractCallback.h" +#include "../Explorer/MyMessages.h" +#include "../Resource/Extract/resource.h" + +#include "OpenCallbackGUI.h" +#include "ExtractDialog.h" + +using namespace NWindows; + +static const wchar_t *kIncorrectOutDir = L"Incorrect output directory path"; + +struct CThreadExtracting +{ + CExtractCallbackImp *ExtractCallbackSpec; + + UStringVector *ArchivePaths; + UStringVector *ArchivePathsFull; + const NWildcard::CCensorNode *WildcardCensor; + const CExtractOptions *Options; + COpenCallbackGUI *OpenCallback; + CMyComPtr ExtractCallback; + + UString ErrorMessage; + HRESULT Result; + + DWORD Process() + { + ExtractCallbackSpec->ProgressDialog.WaitCreating(); + try + { + Result = DecompressArchives(*ArchivePaths, *ArchivePathsFull, + *WildcardCensor, *Options, OpenCallback, ExtractCallback, ErrorMessage); + } + catch(const UString &s) + { + ErrorMessage = s; + Result = E_FAIL; + } + catch(const wchar_t *s) + { + ErrorMessage = s; + Result = E_FAIL; + } + catch(const char *s) + { + ErrorMessage = GetUnicodeString(s); + Result = E_FAIL; + } + catch(...) + { + Result = E_FAIL; + } + ExtractCallbackSpec->ProgressDialog.MyClose(); + return 0; + } + static DWORD WINAPI MyThreadFunction(void *param) + { + return ((CThreadExtracting *)param)->Process(); + } +}; + +HRESULT ExtractGUI( + UStringVector &archivePaths, + UStringVector &archivePathsFull, + const NWildcard::CCensorNode &wildcardCensor, + CExtractOptions &options, + bool showDialog, + COpenCallbackGUI *openCallback, + CExtractCallbackImp *extractCallback) +{ + CThreadExtracting extracter; + + if (!options.TestMode) + { + UString outputDir = options.OutputDir; + if (outputDir.IsEmpty()) + NFile::NDirectory::MyGetCurrentDirectory(outputDir); + if (showDialog) + { + CExtractDialog dialog; + if (!NFile::NDirectory::MyGetFullPathName(outputDir, dialog.DirectoryPath)) + { + MyMessageBox(kIncorrectOutDir); + return E_FAIL; + } + NFile::NName::NormalizeDirPathPrefix(dialog.DirectoryPath); + + // dialog.OverwriteMode = options.OverwriteMode; + // dialog.PathMode = options.PathMode; + + if(dialog.Create(0) != IDOK) + return E_ABORT; + outputDir = dialog.DirectoryPath; + options.OverwriteMode = dialog.OverwriteMode; + options.PathMode = dialog.PathMode; + #ifndef _SFX + openCallback->Password = dialog.Password; + openCallback->PasswordIsDefined = !dialog.Password.IsEmpty(); + #endif + } + if (!NFile::NDirectory::MyGetFullPathName(outputDir, options.OutputDir)) + { + MyMessageBox(kIncorrectOutDir); + return E_FAIL; + } + NFile::NName::NormalizeDirPathPrefix(options.OutputDir); + + /* + if(!NFile::NDirectory::CreateComplexDirectory(options.OutputDir)) + { + UString s = GetUnicodeString(NError::MyFormatMessage(GetLastError())); + UString s2 = MyFormatNew(IDS_CANNOT_CREATE_FOLDER, + #ifdef LANG + 0x02000603, + #endif + options.OutputDir); + MyMessageBox(s2 + UString(L"\n") + s); + return E_FAIL; + } + */ + } + + UString title = LangStringSpec(options.TestMode ? IDS_PROGRESS_TESTING : IDS_PROGRESS_EXTRACTING, + options.TestMode ? 0x02000F90: 0x02000890); + + extracter.ExtractCallbackSpec = extractCallback; + extracter.ExtractCallback = extractCallback; + extracter.ExtractCallbackSpec->Init(); + + extracter.ArchivePaths = &archivePaths; + extracter.ArchivePathsFull = &archivePathsFull; + extracter.WildcardCensor = &wildcardCensor; + extracter.Options = &options; + extracter.OpenCallback = openCallback; + + CThread thread; + if (!thread.Create(CThreadExtracting::MyThreadFunction, &extracter)) + throw 271824; + extracter.ExtractCallbackSpec->StartProgressDialog(title); + if (extracter.Result == S_OK && options.TestMode && + extracter.ExtractCallbackSpec->Messages.IsEmpty() && + extracter.ExtractCallbackSpec->NumArchiveErrors == 0) + { + #ifndef _SFX + MessageBoxW(0, LangString(IDS_MESSAGE_NO_ERRORS, 0x02000608), + LangString(IDS_PROGRESS_TESTING, 0x02000F90), 0); + #endif + } + if (extracter.Result != S_OK) + if (!extracter.ErrorMessage.IsEmpty()) + throw extracter.ErrorMessage; + return extracter.Result; +} + + diff --git a/CPP/7zip/UI/GUI/ExtractGUI.h b/CPP/7zip/UI/GUI/ExtractGUI.h new file mode 100755 index 00000000..5a0b157d --- /dev/null +++ b/CPP/7zip/UI/GUI/ExtractGUI.h @@ -0,0 +1,20 @@ +// GUI/ExtractGUI.h + +#ifndef __EXTRACT_GUI_H +#define __EXTRACT_GUI_H + +#include "../Common/Extract.h" +#include "OpenCallbackGUI.h" + +#include "../../FileManager/ExtractCallback.h" + +HRESULT ExtractGUI( + UStringVector &archivePaths, + UStringVector &archivePathsFull, + const NWildcard::CCensorNode &wildcardCensor, + CExtractOptions &options, + bool showDialog, + COpenCallbackGUI *openCallback, + CExtractCallbackImp *extractCallback); + +#endif diff --git a/CPP/7zip/UI/GUI/FM.ico b/CPP/7zip/UI/GUI/FM.ico new file mode 100755 index 00000000..3a0a34da Binary files /dev/null and b/CPP/7zip/UI/GUI/FM.ico differ diff --git a/CPP/7zip/UI/GUI/GUI.cpp b/CPP/7zip/UI/GUI/GUI.cpp new file mode 100755 index 00000000..fe956dbd --- /dev/null +++ b/CPP/7zip/UI/GUI/GUI.cpp @@ -0,0 +1,260 @@ +// GUI.cpp + +#include "StdAfx.h" + +#include + +#include "Common/NewHandler.h" +#include "Common/StringConvert.h" +#include "Common/CommandLineParser.h" +#include "Common/Exception.h" + +#include "Windows/COM.h" +#include "Windows/FileMapping.h" +#include "Windows/FileDir.h" +#include "Windows/Synchronization.h" +#include "Windows/Error.h" +#include "Windows/FileName.h" +#ifdef _WIN32 +#include "Windows/MemoryLock.h" +#include "Common/Alloc.h" +#endif + +#include "../../IStream.h" +#include "../../IPassword.h" + +#include "../../FileManager/StringUtils.h" + +#include "../Common/ExitCode.h" +#include "../Common/ArchiveCommandLine.h" + +#include "../Resource/Extract/resource.h" +#include "../Explorer/MyMessages.h" + +#include "ExtractGUI.h" +#include "UpdateGUI.h" + +using namespace NWindows; + +HINSTANCE g_hInstance; +#ifndef _UNICODE +bool g_IsNT = false; +#endif + +static const wchar_t *kExceptionErrorMessage = L"Error:"; +static const wchar_t *kUserBreak = L"Break signaled"; + +static const wchar_t *kMemoryExceptionMessage = L"ERROR: Can't allocate required memory!"; +static const wchar_t *kUnknownExceptionMessage = L"Unknown Error"; +static const wchar_t *kInternalExceptionMessage = L"Internal Error #"; + +static const wchar_t *kIncorrectCommandMessage = L"Incorrect command"; + +static void ErrorMessage(const wchar_t *message) +{ + MessageBoxW(0, message, L"7-Zip GUI", MB_ICONERROR); +} + +int Main2() +{ + /* + TCHAR t[512]; + GetCurrentDirectory(512, t); + ErrorMessage(t); + return 0; + */ + + UStringVector commandStrings; + NCommandLineParser::SplitCommandLine(GetCommandLineW(), commandStrings); + if(commandStrings.Size() <= 1) + { + MessageBoxW(0, L"Specify command", L"7-Zip", 0); + return 0; + } + commandStrings.Delete(0); + + CArchiveCommandLineOptions options; + CArchiveCommandLineParser parser; + + parser.Parse1(commandStrings, options); + parser.Parse2(options); + + #ifdef _WIN32 + if (options.LargePages) + NSecurity::EnableLockMemoryPrivilege(); + #endif + + bool isExtractGroupCommand = options.Command.IsFromExtractGroup(); + + if (isExtractGroupCommand) + { + CExtractCallbackImp *ecs = new CExtractCallbackImp; + CMyComPtr extractCallback = ecs; + ecs->PasswordIsDefined = options.PasswordEnabled; + ecs->Password = options.Password; + ecs->Init(); + + COpenCallbackGUI openCallback; + openCallback.PasswordIsDefined = options.PasswordEnabled; + openCallback.Password = options.Password; + + CExtractOptions eo; + eo.StdOutMode = options.StdOutMode; + eo.OutputDir = options.OutputDir; + eo.YesToAll = options.YesToAll; + eo.OverwriteMode = options.OverwriteMode; + eo.PathMode = options.Command.GetPathMode(); + eo.TestMode = options.Command.IsTestMode(); + #ifdef COMPRESS_MT + eo.Properties = options.ExtractProperties; + #endif + + HRESULT result = ExtractGUI( + options.ArchivePathsSorted, + options.ArchivePathsFullSorted, + options.WildcardCensor.Pairs.Front().Head, + eo, options.ShowDialog, &openCallback, ecs); + if (result != S_OK) + throw CSystemException(result); + if (ecs->Messages.Size() > 0 || ecs->NumArchiveErrors != 0) + return NExitCode::kFatalError; + } + else if (options.Command.IsFromUpdateGroup()) + { + bool passwordIsDefined = + options.PasswordEnabled && !options.Password.IsEmpty(); + + COpenCallbackGUI openCallback; + openCallback.PasswordIsDefined = passwordIsDefined; + openCallback.Password = options.Password; + + CUpdateCallbackGUI callback; + // callback.EnablePercents = options.EnablePercents; + callback.PasswordIsDefined = passwordIsDefined; + callback.AskPassword = options.PasswordEnabled && options.Password.IsEmpty(); + callback.Password = options.Password; + // callback.StdOutMode = options.UpdateOptions.StdOutMode; + callback.Init(); + + CUpdateErrorInfo errorInfo; + + HRESULT result = UpdateGUI( + options.WildcardCensor, options.UpdateOptions, + options.ShowDialog, + errorInfo, &openCallback, &callback); + + if (result != S_OK) + { + if (!errorInfo.Message.IsEmpty()) + ErrorMessage(errorInfo.Message); + throw CSystemException(result); + } + if (callback.FailedFiles.Size() > 0) + return NExitCode::kWarning; + } + else + { + ErrorMessage(L"Use correct command"); + return 0; + } + return 0; +} + +static bool inline IsItWindowsNT() +{ + OSVERSIONINFO versionInfo; + versionInfo.dwOSVersionInfoSize = sizeof(versionInfo); + if (!::GetVersionEx(&versionInfo)) + return false; + return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT); +} + +int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */, LPSTR /* lpCmdLine */, int /* nCmdShow */) +{ + g_hInstance = hInstance; + #ifdef _UNICODE + if (!IsItWindowsNT()) + { + MyMessageBox(L"This program requires Windows NT/2000/XP/2003"); + return NExitCode::kFatalError; + } + #else + g_IsNT = IsItWindowsNT(); + #endif + + #ifdef _WIN32 + SetLargePageSize(); + #endif + + InitCommonControls(); + + ReloadLang(); + + // setlocale(LC_COLLATE, ".ACP"); + try + { + return Main2(); + } + catch(const CNewException &) + { + MyMessageBox(kMemoryExceptionMessage); + return (NExitCode::kMemoryError); + } + catch(const CArchiveCommandLineException &e) + { + MyMessageBox(GetUnicodeString(e)); + return (NExitCode::kUserError); + } + catch(const CSystemException &systemError) + { + if (systemError.ErrorCode == E_OUTOFMEMORY) + { + MyMessageBox(kMemoryExceptionMessage); + return (NExitCode::kMemoryError); + } + if (systemError.ErrorCode == E_ABORT) + { + // MyMessageBox(kUserBreak); + return (NExitCode::kUserBreak); + } + UString message; + NError::MyFormatMessage(systemError.ErrorCode, message); + MyMessageBox(message); + return (NExitCode::kFatalError); + } + /* + catch(NExitCode::EEnum &exitCode) + { + g_StdErr << kInternalExceptionMessage << exitCode << endl; + return (exitCode); + } + */ + catch(const UString &s) + { + MyMessageBox(s); + return (NExitCode::kFatalError); + } + catch(const AString &s) + { + MyMessageBox(GetUnicodeString(s)); + return (NExitCode::kFatalError); + } + catch(const char *s) + { + MyMessageBox(GetUnicodeString(s)); + return (NExitCode::kFatalError); + } + /* + catch(int t) + { + g_StdErr << kInternalExceptionMessage << t << endl; + return (NExitCode::kFatalError); + } + */ + catch(...) + { + MyMessageBox(kUnknownExceptionMessage); + return (NExitCode::kFatalError); + } +} + diff --git a/CPP/7zip/UI/GUI/GUI.dsp b/CPP/7zip/UI/GUI/GUI.dsp new file mode 100755 index 00000000..dadb9648 --- /dev/null +++ b/CPP/7zip/UI/GUI/GUI.dsp @@ -0,0 +1,904 @@ +# Microsoft Developer Studio Project File - Name="GUI" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Application" 0x0101 + +CFG=GUI - Win32 DebugU +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "GUI.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "GUI.mak" CFG="GUI - Win32 DebugU" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "GUI - Win32 Release" (based on "Win32 (x86) Application") +!MESSAGE "GUI - Win32 Debug" (based on "Win32 (x86) Application") +!MESSAGE "GUI - Win32 ReleaseU" (based on "Win32 (x86) Application") +!MESSAGE "GUI - Win32 DebugU" (based on "Win32 (x86) Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "GUI - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /Yu"stdafx.h" /FD /c +# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "..\..\..\\" /D "NDEBUG" /D "_MBCS" /D "WIN32" /D "_WINDOWS" /D "LANG" /D "COMPRESS_MT" /D "WIN_LONG_PATH" /Yu"stdafx.h" /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x419 /d "NDEBUG" +# ADD RSC /l 0x419 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib htmlhelp.lib /nologo /subsystem:windows /machine:I386 /out:"C:\Program Files\7-Zip\7zg.exe" /opt:NOWIN98 +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "GUI - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c +# ADD CPP /nologo /Gz /MDd /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "_DEBUG" /D "_MBCS" /D "WIN32" /D "_WINDOWS" /D "LANG" /D "COMPRESS_MT" /D "WIN_LONG_PATH" /Yu"stdafx.h" /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x419 /d "_DEBUG" +# ADD RSC /l 0x419 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib htmlhelp.lib /nologo /subsystem:windows /debug /machine:I386 /out:"C:\Program Files\7-Zip\7zg.exe" /pdbtype:sept + +!ELSEIF "$(CFG)" == "GUI - Win32 ReleaseU" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "ReleaseU" +# PROP BASE Intermediate_Dir "ReleaseU" +# PROP BASE Ignore_Export_Lib 0 +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "ReleaseU" +# PROP Intermediate_Dir "ReleaseU" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /Yu"stdafx.h" /FD /c +# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "..\..\..\\" /D "NDEBUG" /D "_UNICODE" /D "UNICODE" /D "WIN32" /D "_WINDOWS" /D "LANG" /D "COMPRESS_MT" /D "WIN_LONG_PATH" /Yu"stdafx.h" /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x419 /d "NDEBUG" +# ADD RSC /l 0x419 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 /out:"C:\UTIL\7zg.exe" +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib htmlhelp.lib /nologo /subsystem:windows /machine:I386 /out:"C:\Program Files\7-Zip\7zgn.exe" /opt:NOWIN98 +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "GUI - Win32 DebugU" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "DebugU" +# PROP BASE Intermediate_Dir "DebugU" +# PROP BASE Ignore_Export_Lib 0 +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "DebugU" +# PROP Intermediate_Dir "DebugU" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c +# ADD CPP /nologo /Gz /MDd /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "_DEBUG" /D "_UNICODE" /D "UNICODE" /D "WIN32" /D "_WINDOWS" /D "LANG" /D "COMPRESS_MT" /D "WIN_LONG_PATH" /Yu"stdafx.h" /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x419 /d "_DEBUG" +# ADD RSC /l 0x419 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /out:"C:\UTIL\7zg.exe" /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib htmlhelp.lib /nologo /subsystem:windows /debug /machine:I386 /out:"C:\Program Files\7-Zip\7zgn.exe" /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "GUI - Win32 Release" +# Name "GUI - Win32 Debug" +# Name "GUI - Win32 ReleaseU" +# Name "GUI - Win32 DebugU" +# Begin Group "Spec" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\7zG.exe.manifest +# End Source File +# Begin Source File + +SOURCE=.\FM.ico +# End Source File +# Begin Source File + +SOURCE=.\resource.h +# End Source File +# Begin Source File + +SOURCE=.\resource.rc +# End Source File +# Begin Source File + +SOURCE=.\StdAfx.cpp +# ADD CPP /Yc"stdafx.h" +# End Source File +# Begin Source File + +SOURCE=.\StdAfx.h +# End Source File +# End Group +# Begin Group "SDK" + +# PROP Default_Filter "" +# Begin Group "Common" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\..\Common\Alloc.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\Alloc.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\CommandLineParser.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\CommandLineParser.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\IntToString.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\IntToString.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\Lang.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\Lang.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\ListFileUtils.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\ListFileUtils.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\NewHandler.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\NewHandler.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\StdInStream.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\StdInStream.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\String.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\String.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\StringConvert.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\StringConvert.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\StringToInt.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\StringToInt.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\TextConfig.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\TextConfig.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\UTFConvert.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\UTFConvert.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\Vector.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\Vector.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\Wildcard.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\Wildcard.h +# End Source File +# End Group +# Begin Group "Windows" + +# PROP Default_Filter "" +# Begin Group "Control" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\..\Windows\Control\ComboBox.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\Control\ComboBox.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\Control\Dialog.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\Control\Dialog.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\Control\Edit.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\Control\ListView.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\Control\ListView.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\Control\ProgressBar.h +# End Source File +# End Group +# Begin Source File + +SOURCE=..\..\..\Windows\CommonDialog.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\CommonDialog.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\DLL.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\DLL.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\Error.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\Error.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\FileDir.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\FileDir.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\FileFind.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\FileFind.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\FileIO.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\FileIO.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\FileName.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\FileName.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\MemoryLock.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\MemoryLock.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\PropVariant.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\PropVariant.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\PropVariantConversions.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\PropVariantConversions.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\Registry.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\Registry.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\ResourceString.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\ResourceString.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\Shell.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\Shell.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\Synchronization.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\Synchronization.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\Window.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\Window.h +# End Source File +# End Group +# End Group +# Begin Group "UI Common" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\Common\ArchiveCommandLine.cpp +# End Source File +# Begin Source File + +SOURCE=..\Common\ArchiveCommandLine.h +# End Source File +# Begin Source File + +SOURCE=..\Common\ArchiveExtractCallback.cpp +# End Source File +# Begin Source File + +SOURCE=..\Common\ArchiveExtractCallback.h +# End Source File +# Begin Source File + +SOURCE=..\Common\ArchiveOpenCallback.cpp +# End Source File +# Begin Source File + +SOURCE=..\Common\ArchiveOpenCallback.h +# End Source File +# Begin Source File + +SOURCE=..\Common\ArchiverInfo.cpp +# End Source File +# Begin Source File + +SOURCE=..\Common\ArchiverInfo.h +# End Source File +# Begin Source File + +SOURCE=..\Common\DefaultName.cpp +# End Source File +# Begin Source File + +SOURCE=..\Common\DefaultName.h +# End Source File +# Begin Source File + +SOURCE=..\Common\DirItem.h +# End Source File +# Begin Source File + +SOURCE=..\Common\EnumDirItems.cpp +# End Source File +# Begin Source File + +SOURCE=..\Common\EnumDirItems.h +# End Source File +# Begin Source File + +SOURCE=..\Common\ExitCode.h +# End Source File +# Begin Source File + +SOURCE=..\Common\Extract.cpp +# End Source File +# Begin Source File + +SOURCE=..\Common\Extract.h +# End Source File +# Begin Source File + +SOURCE=..\Common\ExtractingFilePath.cpp +# End Source File +# Begin Source File + +SOURCE=..\Common\ExtractingFilePath.h +# End Source File +# Begin Source File + +SOURCE=..\Common\ExtractMode.h +# End Source File +# Begin Source File + +SOURCE=..\Common\HandlerLoader.h +# End Source File +# Begin Source File + +SOURCE=..\Common\IFileExtractCallback.h +# End Source File +# Begin Source File + +SOURCE=..\Common\OpenArchive.cpp +# End Source File +# Begin Source File + +SOURCE=..\Common\OpenArchive.h +# End Source File +# Begin Source File + +SOURCE=..\Common\Property.h +# End Source File +# Begin Source File + +SOURCE=..\Common\PropIDUtils.cpp +# End Source File +# Begin Source File + +SOURCE=..\Common\PropIDUtils.h +# End Source File +# Begin Source File + +SOURCE=..\Common\SetProperties.cpp +# End Source File +# Begin Source File + +SOURCE=..\Common\SetProperties.h +# End Source File +# Begin Source File + +SOURCE=..\Common\SortUtils.cpp +# End Source File +# Begin Source File + +SOURCE=..\Common\SortUtils.h +# End Source File +# Begin Source File + +SOURCE=..\Common\TempFiles.cpp +# End Source File +# Begin Source File + +SOURCE=..\Common\TempFiles.h +# End Source File +# Begin Source File + +SOURCE=..\Common\Update.cpp +# End Source File +# Begin Source File + +SOURCE=..\Common\Update.h +# End Source File +# Begin Source File + +SOURCE=..\Common\UpdateAction.cpp +# End Source File +# Begin Source File + +SOURCE=..\Common\UpdateAction.h +# End Source File +# Begin Source File + +SOURCE=..\Common\UpdateCallback.cpp +# End Source File +# Begin Source File + +SOURCE=..\Common\UpdateCallback.h +# End Source File +# Begin Source File + +SOURCE=..\Common\UpdatePair.cpp +# End Source File +# Begin Source File + +SOURCE=..\Common\UpdatePair.h +# End Source File +# Begin Source File + +SOURCE=..\Common\UpdateProduce.cpp +# End Source File +# Begin Source File + +SOURCE=..\Common\UpdateProduce.h +# End Source File +# Begin Source File + +SOURCE=..\Common\WorkDir.cpp +# End Source File +# Begin Source File + +SOURCE=..\Common\WorkDir.h +# End Source File +# Begin Source File + +SOURCE=..\Common\ZipRegistry.cpp +# End Source File +# Begin Source File + +SOURCE=..\Common\ZipRegistry.h +# End Source File +# End Group +# Begin Group "Explorer" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\Explorer\MyMessages.cpp +# End Source File +# Begin Source File + +SOURCE=..\Explorer\MyMessages.h +# End Source File +# End Group +# Begin Group "Dialogs" + +# PROP Default_Filter "" +# Begin Group "Progress" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\FileManager\Resource\ProgressDialog2\ProgressDialog.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\FileManager\Resource\ProgressDialog2\ProgressDialog.h +# End Source File +# End Group +# Begin Group "Messages" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\FileManager\Resource\MessagesDialog\MessagesDialog.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\FileManager\Resource\MessagesDialog\MessagesDialog.h +# End Source File +# End Group +# Begin Group "Overwtite" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\FileManager\Resource\OverwriteDialog\OverwriteDialog.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\FileManager\Resource\OverwriteDialog\OverwriteDialog.h +# End Source File +# End Group +# Begin Group "Password" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\FileManager\Resource\PasswordDialog\PasswordDialog.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\FileManager\Resource\PasswordDialog\PasswordDialog.h +# End Source File +# End Group +# Begin Group "Compress Dialog" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\CompressDialog.cpp +# End Source File +# Begin Source File + +SOURCE=.\CompressDialog.h +# End Source File +# End Group +# Begin Group "Extract Dialog" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\ExtractDialog.cpp +# End Source File +# Begin Source File + +SOURCE=.\ExtractDialog.h +# End Source File +# End Group +# End Group +# Begin Group "FM Common" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\FileManager\ExtractCallback.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\FileManager\ExtractCallback.h +# End Source File +# Begin Source File + +SOURCE=..\..\FileManager\FolderInterface.h +# End Source File +# Begin Source File + +SOURCE=..\..\FileManager\FormatUtils.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\FileManager\FormatUtils.h +# End Source File +# Begin Source File + +SOURCE=..\..\FileManager\HelpUtils.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\FileManager\HelpUtils.h +# End Source File +# Begin Source File + +SOURCE=..\..\FileManager\LangUtils.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\FileManager\LangUtils.h +# End Source File +# Begin Source File + +SOURCE=..\..\FileManager\OpenCallback.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\FileManager\OpenCallback.h +# End Source File +# Begin Source File + +SOURCE=..\..\FileManager\ProgramLocation.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\FileManager\ProgramLocation.h +# End Source File +# Begin Source File + +SOURCE=..\..\FileManager\RegistryUtils.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\FileManager\RegistryUtils.h +# End Source File +# Begin Source File + +SOURCE=..\..\FileManager\SplitUtils.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\FileManager\SplitUtils.h +# End Source File +# Begin Source File + +SOURCE=..\..\FileManager\StringUtils.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\FileManager\StringUtils.h +# End Source File +# Begin Source File + +SOURCE=..\..\FileManager\UpdateCallback100.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\FileManager\UpdateCallback100.h +# End Source File +# End Group +# Begin Group "Engine" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\ExtractGUI.cpp +# End Source File +# Begin Source File + +SOURCE=.\ExtractGUI.h +# End Source File +# Begin Source File + +SOURCE=.\GUI.cpp +# End Source File +# Begin Source File + +SOURCE=.\OpenCallbackGUI.cpp +# End Source File +# Begin Source File + +SOURCE=.\OpenCallbackGUI.h +# End Source File +# Begin Source File + +SOURCE=.\UpdateCallbackGUI.cpp +# End Source File +# Begin Source File + +SOURCE=.\UpdateCallbackGUI.h +# End Source File +# Begin Source File + +SOURCE=.\UpdateGUI.cpp +# End Source File +# Begin Source File + +SOURCE=.\UpdateGUI.h +# End Source File +# End Group +# Begin Group "7-zip Common" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\Common\FilePathAutoRename.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\FilePathAutoRename.h +# End Source File +# Begin Source File + +SOURCE=..\..\Common\FileStreams.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\FileStreams.h +# End Source File +# Begin Source File + +SOURCE=..\..\Common\StreamUtils.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\StreamUtils.h +# End Source File +# End Group +# Begin Group "Compress" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\Compress\Copy\CopyCoder.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Compress\Copy\CopyCoder.h +# End Source File +# End Group +# End Target +# End Project diff --git a/CPP/7zip/UI/GUI/GUI.dsw b/CPP/7zip/UI/GUI/GUI.dsw new file mode 100755 index 00000000..85d33484 --- /dev/null +++ b/CPP/7zip/UI/GUI/GUI.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "GUI"=.\GUI.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/CPP/7zip/UI/GUI/OpenCallbackGUI.cpp b/CPP/7zip/UI/GUI/OpenCallbackGUI.cpp new file mode 100755 index 00000000..bc6cf393 --- /dev/null +++ b/CPP/7zip/UI/GUI/OpenCallbackGUI.cpp @@ -0,0 +1,65 @@ +// OpenCallbackGUI.cpp + +#include "StdAfx.h" + +#include "OpenCallbackGUI.h" + +#include "Common/StdOutStream.h" +#include "Common/StdInStream.h" +#include "Common/StringConvert.h" + +#ifndef _NO_CRYPTO +#include "../../FileManager/Resource/PasswordDialog/PasswordDialog.h" +#endif + +HRESULT COpenCallbackGUI::CheckBreak() +{ + return S_OK; +} + +HRESULT COpenCallbackGUI::SetTotal(const UInt64 * /* files */, const UInt64 * /* bytes */) +{ + return S_OK; +} + +HRESULT COpenCallbackGUI::SetCompleted(const UInt64 * /* files */, const UInt64 * /* bytes */) +{ + return S_OK; +} + +#ifndef _NO_CRYPTO +HRESULT COpenCallbackGUI::CryptoGetTextPassword(BSTR *password) +{ + PasswordWasAsked = true; + if (!PasswordIsDefined) + { + CPasswordDialog dialog; + if (dialog.Create(ParentWindow) == IDCANCEL) + return E_ABORT; + Password = dialog.Password; + PasswordIsDefined = true; + } + CMyComBSTR tempName(Password); + *password = tempName.Detach(); + return S_OK; +} + +HRESULT COpenCallbackGUI::GetPasswordIfAny(UString &password) +{ + if (PasswordIsDefined) + password = Password; + return S_OK; +} + +bool COpenCallbackGUI::WasPasswordAsked() +{ + return PasswordWasAsked; +} + +void COpenCallbackGUI::ClearPasswordWasAskedFlag() +{ + PasswordWasAsked = false; +} + +#endif + diff --git a/CPP/7zip/UI/GUI/OpenCallbackGUI.h b/CPP/7zip/UI/GUI/OpenCallbackGUI.h new file mode 100755 index 00000000..6b531d3c --- /dev/null +++ b/CPP/7zip/UI/GUI/OpenCallbackGUI.h @@ -0,0 +1,35 @@ +// OpenCallbackGUI.h + +#ifndef __OPEN_CALLBACK_GUI_H +#define __OPEN_CALLBACK_GUI_H + +#include "../Common/ArchiveOpenCallback.h" + +class COpenCallbackGUI: public IOpenCallbackUI +{ +public: + HRESULT CheckBreak(); + HRESULT SetTotal(const UInt64 *files, const UInt64 *bytes); + HRESULT SetCompleted(const UInt64 *files, const UInt64 *bytes); + #ifndef _NO_CRYPTO + HRESULT CryptoGetTextPassword(BSTR *password); + HRESULT GetPasswordIfAny(UString &password); + bool WasPasswordAsked(); + void ClearPasswordWasAskedFlag(); + + bool PasswordIsDefined; + UString Password; + bool PasswordWasAsked; + #endif + + HWND ParentWindow; + + COpenCallbackGUI(): + #ifndef _NO_CRYPTO + PasswordIsDefined(false), + PasswordWasAsked(false), + #endif + ParentWindow(0) {} +}; + +#endif diff --git a/CPP/7zip/UI/GUI/StdAfx.cpp b/CPP/7zip/UI/GUI/StdAfx.cpp new file mode 100755 index 00000000..d0feea85 --- /dev/null +++ b/CPP/7zip/UI/GUI/StdAfx.cpp @@ -0,0 +1,3 @@ +// StdAfx.cpp + +#include "StdAfx.h" diff --git a/CPP/7zip/UI/GUI/StdAfx.h b/CPP/7zip/UI/GUI/StdAfx.h new file mode 100755 index 00000000..46ea51cf --- /dev/null +++ b/CPP/7zip/UI/GUI/StdAfx.h @@ -0,0 +1,13 @@ +// StdAfx.h + +#ifndef __STDAFX_H +#define __STDAFX_H + +#include +#include +#include +#include + +#include "Common/NewHandler.h" + +#endif diff --git a/CPP/7zip/UI/GUI/UpdateCallbackGUI.cpp b/CPP/7zip/UI/GUI/UpdateCallbackGUI.cpp new file mode 100755 index 00000000..eff29953 --- /dev/null +++ b/CPP/7zip/UI/GUI/UpdateCallbackGUI.cpp @@ -0,0 +1,167 @@ +// UpdateCallbackGUI.cpp + +#include "StdAfx.h" + +#include "UpdateCallbackGUI.h" + +#include "Common/StringConvert.h" +#include "Common/IntToString.h" +#include "Common/Defs.h" + +#include "Windows/PropVariant.h" +#include "Windows/Error.h" +#include "../../FileManager/Resource/MessagesDialog/MessagesDialog.h" +#include "../../FileManager/Resource/PasswordDialog/PasswordDialog.h" + +using namespace NWindows; + +CUpdateCallbackGUI::~CUpdateCallbackGUI() +{ + if (!Messages.IsEmpty()) + { + CMessagesDialog messagesDialog; + messagesDialog.Messages = &Messages; + messagesDialog.Create(ParentWindow); + } +} + +void CUpdateCallbackGUI::Init() +{ + FailedFiles.Clear(); + Messages.Clear(); + NumArchiveErrors = 0; +} + +void CUpdateCallbackGUI::AddErrorMessage(LPCWSTR message) +{ + Messages.Add(message); +} + +void CUpdateCallbackGUI::AddErrorMessage(const wchar_t *name, DWORD systemError) +{ + AddErrorMessage( + UString(L"WARNING: ") + + NError::MyFormatMessageW(systemError) + + UString(L": ") + + UString(name)); +} + +HRESULT CUpdateCallbackGUI::OpenResult(const wchar_t *name, HRESULT result) +{ + if (result != S_OK) + { + AddErrorMessage (UString(L"Error: ") + name + + UString(L" is not supported archive")); + } + return S_OK; +} + +HRESULT CUpdateCallbackGUI::StartScanning() +{ + return S_OK; +} + +HRESULT CUpdateCallbackGUI::CanNotFindError(const wchar_t *name, DWORD systemError) +{ + FailedFiles.Add(name); + AddErrorMessage(name, systemError); + return S_OK; +} + +HRESULT CUpdateCallbackGUI::FinishScanning() +{ + return S_OK; +} + +HRESULT CUpdateCallbackGUI::StartArchive(const wchar_t *name, bool /* updating */) +{ + ProgressDialog.ProgressSynch.SetTitleFileName(name); + return S_OK; +} + +HRESULT CUpdateCallbackGUI::FinishArchive() +{ + return S_OK; +} + +HRESULT CUpdateCallbackGUI::CheckBreak() +{ + for (;;) + { + if(ProgressDialog.ProgressSynch.GetStopped()) + return E_ABORT; + if(!ProgressDialog.ProgressSynch.GetPaused()) + break; + ::Sleep(100); + } + return S_OK; +} + +HRESULT CUpdateCallbackGUI::Finilize() +{ + return S_OK; +} + +HRESULT CUpdateCallbackGUI::SetTotal(UInt64 total) +{ + ProgressDialog.ProgressSynch.SetProgress(total, 0); + return S_OK; +} + +HRESULT CUpdateCallbackGUI::SetCompleted(const UInt64 *completeValue) +{ + RINOK(CheckBreak()); + if (completeValue != NULL) + ProgressDialog.ProgressSynch.SetPos(*completeValue); + return S_OK; +} + +HRESULT CUpdateCallbackGUI::GetStream(const wchar_t *name, bool /* isAnti */) +{ + ProgressDialog.ProgressSynch.SetCurrentFileName(name); + return S_OK; +} + +HRESULT CUpdateCallbackGUI::OpenFileError(const wchar_t *name, DWORD systemError) +{ + FailedFiles.Add(name); + // if (systemError == ERROR_SHARING_VIOLATION) + { + AddErrorMessage(name, systemError); + return S_FALSE; + } + // return systemError; +} + +HRESULT CUpdateCallbackGUI::SetOperationResult(Int32 /* operationResult */) +{ + return S_OK; +} + +HRESULT CUpdateCallbackGUI::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password) +{ + if (!PasswordIsDefined) + { + if (AskPassword) + { + CPasswordDialog dialog; + if (dialog.Create(ParentWindow) == IDCANCEL) + return E_ABORT; + Password = dialog.Password; + PasswordIsDefined = true; + } + } + *passwordIsDefined = BoolToInt(PasswordIsDefined); + CMyComBSTR tempName(Password); + *password = tempName.Detach(); + return S_OK; +} + +/* +It doesn't work, since main stream waits Dialog +HRESULT CUpdateCallbackGUI::CloseProgress() +{ + ProgressDialog.MyClose(); + return S_OK; +}; +*/ \ No newline at end of file diff --git a/CPP/7zip/UI/GUI/UpdateCallbackGUI.h b/CPP/7zip/UI/GUI/UpdateCallbackGUI.h new file mode 100755 index 00000000..16f0220c --- /dev/null +++ b/CPP/7zip/UI/GUI/UpdateCallbackGUI.h @@ -0,0 +1,63 @@ +// UpdateCallbackGUI.h + +#ifndef __UPDATE_CALLBACK_GUI_H +#define __UPDATE_CALLBACK_GUI_H + +#include "../Common/Update.h" +#include "../../FileManager/Resource/ProgressDialog2/ProgressDialog.h" + +class CUpdateCallbackGUI: public IUpdateCallbackUI2 +{ +public: + // bool StdOutMode; + bool PasswordIsDefined; + UString Password; + bool AskPassword; + + CUpdateCallbackGUI(): + PasswordIsDefined(false), + AskPassword(false), + // StdOutMode(false) + ParentWindow(0) + {} + + ~CUpdateCallbackGUI(); + void Init(); + + HRESULT OpenResult(const wchar_t *name, HRESULT result); + + HRESULT StartScanning(); + HRESULT CanNotFindError(const wchar_t *name, DWORD systemError); + HRESULT FinishScanning(); + + HRESULT StartArchive(const wchar_t *name, bool updating); + HRESULT FinishArchive(); + + HRESULT CheckBreak(); + HRESULT Finilize(); + HRESULT SetTotal(UInt64 total); + HRESULT SetCompleted(const UInt64 *completeValue); + + HRESULT GetStream(const wchar_t *name, bool isAnti); + HRESULT OpenFileError(const wchar_t *name, DWORD systemError); + HRESULT SetOperationResult(Int32 operationResult); + HRESULT CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password); + + // HRESULT CloseProgress(); + + UStringVector FailedFiles; + + CProgressDialog ProgressDialog; + HWND ParentWindow; + void StartProgressDialog(const UString &title) + { + ProgressDialog.Create(title, ParentWindow); + } + + UStringVector Messages; + int NumArchiveErrors; + void AddErrorMessage(LPCWSTR message); + void AddErrorMessage(const wchar_t *name, DWORD systemError); +}; + +#endif diff --git a/CPP/7zip/UI/GUI/UpdateGUI.cpp b/CPP/7zip/UI/GUI/UpdateGUI.cpp new file mode 100755 index 00000000..e39e7faf --- /dev/null +++ b/CPP/7zip/UI/GUI/UpdateGUI.cpp @@ -0,0 +1,397 @@ +// UpdateGUI.cpp + +#include "StdAfx.h" + +#include "UpdateGUI.h" + +#include "resource.h" +#include "Common/StringConvert.h" +#include "Common/IntToString.h" +#include "Common/StringToInt.h" + +#include "Windows/FileDir.h" +#include "Windows/Error.h" +#include "Windows/FileFind.h" +#include "Windows/Thread.h" + +#include "../../FileManager/FormatUtils.h" +#include "../../FileManager/ExtractCallback.h" +#include "../../FileManager/StringUtils.h" + +#include "../Common/ArchiveExtractCallback.h" +#include "../Common/WorkDir.h" +#include "../Explorer/MyMessages.h" +#include "../Resource/Extract/resource.h" + +#include "OpenCallbackGUI.h" +#include "CompressDialog.h" +#include "UpdateGUI.h" + +using namespace NWindows; +using namespace NFile; + +static const wchar_t *kIncorrectOutDir = L"Incorrect output directory path"; +static const wchar_t *kDefaultSfxModule = L"7z.sfx"; +static const wchar_t *kSFXExtension = L"exe"; + +struct CThreadUpdating +{ + CUpdateCallbackGUI *UpdateCallbackGUI; + + const NWildcard::CCensor *WildcardCensor; + CUpdateOptions *Options; + COpenCallbackGUI *OpenCallback; + + CUpdateErrorInfo *ErrorInfo; + HRESULT Result; + + DWORD Process() + { + UpdateCallbackGUI->ProgressDialog.WaitCreating(); + try + { + Result = UpdateArchive(*WildcardCensor, *Options, + *ErrorInfo, OpenCallback, UpdateCallbackGUI); + } + catch(const UString &s) + { + ErrorInfo->Message = s; + Result = E_FAIL; + } + catch(const wchar_t *s) + { + ErrorInfo->Message = s; + Result = E_FAIL; + } + catch(const char *s) + { + ErrorInfo->Message = GetUnicodeString(s); + Result = E_FAIL; + } + catch(...) + { + Result = E_FAIL; + } + UpdateCallbackGUI->ProgressDialog.MyClose(); + return 0; + } + static DWORD WINAPI MyThreadFunction(void *param) + { + return ((CThreadUpdating *)param)->Process(); + } +}; + +static void AddProp(CObjectVector &properties, + const UString &name, const UString &value) +{ + CProperty prop; + prop.Name = name; + prop.Value = value; + properties.Add(prop); +} + +static void AddProp(CObjectVector &properties, + const UString &name, UInt32 value) +{ + wchar_t tmp[32]; + ConvertUInt64ToString(value, tmp); + AddProp(properties, name, tmp); +} + +static void AddProp(CObjectVector &properties, + const UString &name, bool value) +{ + AddProp(properties, name, value ? UString(L"on"): UString(L"off")); +} + +static bool IsThereMethodOverride(bool is7z, const UString &propertiesString) +{ + UStringVector strings; + SplitString(propertiesString, strings); + for (int i = 0; i < strings.Size(); i++) + { + const UString &s = strings[i]; + if (is7z) + { + const wchar_t *end; + UInt64 n = ConvertStringToUInt64(s, &end); + if (n == 0 && *end == L'=') + return true; + } + else + { + if (s.Length() > 0) + if (s[0] == L'm' && s[1] == L'=') + return true; + } + } + return false; +} + +static void ParseAndAddPropertires(CObjectVector &properties, + const UString &propertiesString) +{ + UStringVector strings; + SplitString(propertiesString, strings); + for (int i = 0; i < strings.Size(); i++) + { + const UString &s = strings[i]; + CProperty property; + int index = s.Find(L'='); + if (index < 0) + property.Name = s; + else + { + property.Name = s.Left(index); + property.Value = s.Mid(index + 1); + } + properties.Add(property); + } +} + +static void SetOutProperties( + CObjectVector &properties, + bool is7z, + UInt32 level, + bool setMethod, + const UString &method, + UInt32 dictionary, + bool orderMode, + UInt32 order, + bool solidModeIsAllowed, bool solidMode, + bool multiThreadIsAllowed, bool multiThread, + const UString &encryptionMethod, + bool encryptHeadersIsAllowed, bool encryptHeaders, + bool /* sfxMode */) +{ + if (level != (UInt32)(Int32)-1) + AddProp(properties, L"x", (UInt32)level); + if (setMethod) + { + if (!method.IsEmpty()) + AddProp(properties, is7z ? L"0": L"m", method); + if (dictionary != (UInt32)(Int32)-1) + { + UString name; + if (is7z) + name = L"0"; + if (orderMode) + name += L"mem"; + else + name += L"d"; + wchar_t s[32]; + ConvertUInt64ToString(dictionary, s); + size_t len = wcslen(s); + s[len++] = L'B'; + s[len] = L'\0'; + AddProp(properties, name, UString(s)); + } + if (order != (UInt32)(Int32)-1) + { + UString name; + if (is7z) + name = L"0"; + if (orderMode) + name += L"o"; + else + name += L"fb"; + AddProp(properties, name, (UInt32)order); + } + } + + if (!encryptionMethod.IsEmpty()) + AddProp(properties, L"em", encryptionMethod); + + if (encryptHeadersIsAllowed) + AddProp(properties, L"he", encryptHeaders); + if (solidModeIsAllowed) + AddProp(properties, L"s", solidMode); + if (multiThreadIsAllowed) + AddProp(properties, L"mt", multiThread); +} + +static HRESULT ShowDialog(const NWildcard::CCensor &censor, + CUpdateOptions &options, CUpdateCallbackGUI *callback) +{ + if (options.Commands.Size() != 1) + throw "It must be one command"; + CObjectVector archivers; + CArchiverInfo archiverInfo; + ReadArchiverInfoList(archivers); + UString currentDirPrefix; + { + if (!NDirectory::MyGetCurrentDirectory(currentDirPrefix)) + return E_FAIL; + NName::NormalizeDirPathPrefix(currentDirPrefix); + } + + bool oneFile = false; + NFind::CFileInfoW fileInfo; + if (censor.Pairs.Size() > 0) + { + const NWildcard::CPair &pair = censor.Pairs[0]; + if (pair.Head.IncludeItems.Size() > 0) + { + const NWildcard::CItem &item = pair.Head.IncludeItems[0]; + if (item.ForFile) + { + UString name = pair.Prefix; + for (int i = 0; i < item.PathParts.Size(); i++) + { + if (i > 0) + name += L'\\'; + name += item.PathParts[i]; + } + if (NFind::FindFile(name, fileInfo)) + { + if (censor.Pairs.Size() == 1 && pair.Head.IncludeItems.Size() == 1) + oneFile = !fileInfo.IsDirectory(); + } + } + } + } + + CCompressDialog dialog; + NCompressDialog::CInfo &di = dialog.Info; + for(int i = 0; i < archivers.Size(); i++) + { + const CArchiverInfo &ai = archivers[i]; + if (ai.UpdateEnabled && (oneFile || !ai.KeepName)) + dialog.m_ArchiverInfoList.Add(ai); + } + if(dialog.m_ArchiverInfoList.Size() == 0) + { + MyMessageBox(L"No Update Engines"); + return E_FAIL; + } + + // di.ArchiveName = options.ArchivePath.GetFinalPath(); + di.ArchiveName = options.ArchivePath.GetPathWithoutExt(); + dialog.OriginalFileName = fileInfo.Name; + + di.CurrentDirPrefix = currentDirPrefix; + di.SFXMode = options.SfxMode; + + di.Solid = true; + di.MultiThread = false; + + if (callback->PasswordIsDefined) + di.Password = callback->Password; + + di.KeepName = !oneFile; + + if(dialog.Create(0) != IDOK) + return E_ABORT; + + options.VolumesSizes = di.VolumeSizes; + /* + if (di.VolumeSizeIsDefined) + { + MyMessageBox(L"Splitting to volumes is not supported"); + return E_FAIL; + } + */ + + NUpdateArchive::CActionSet &actionSet = options.Commands.Front().ActionSet; + + switch(di.UpdateMode) + { + case NCompressDialog::NUpdateMode::kAdd: + actionSet = NUpdateArchive::kAddActionSet; + break; + case NCompressDialog::NUpdateMode::kUpdate: + actionSet = NUpdateArchive::kUpdateActionSet; + break; + case NCompressDialog::NUpdateMode::kFresh: + actionSet = NUpdateArchive::kFreshActionSet; + break; + case NCompressDialog::NUpdateMode::kSynchronize: + actionSet = NUpdateArchive::kSynchronizeActionSet; + break; + default: + throw 1091756; + } + archiverInfo = dialog.m_ArchiverInfoList[di.ArchiverInfoIndex]; + callback->PasswordIsDefined = (!di.Password.IsEmpty()); + if (callback->PasswordIsDefined) + callback->Password = di.Password; + + options.MethodMode.Properties.Clear(); + + bool is7z = archiverInfo.Name.CompareNoCase(L"7z") == 0; + bool methodOverride = IsThereMethodOverride(is7z, di.Options); + + SetOutProperties( + options.MethodMode.Properties, + is7z, + di.Level, + !methodOverride, + di.Method, + di.Dictionary, + di.OrderMode, di.Order, + di.SolidIsAllowed, di.Solid, + di.MultiThreadIsAllowed, di.MultiThread, + di.EncryptionMethod, + di.EncryptHeadersIsAllowed, di.EncryptHeaders, + di.SFXMode); + + ParseAndAddPropertires(options.MethodMode.Properties, di.Options); + + if (di.SFXMode) + options.SfxMode = true; + options.MethodMode.FilePath = archiverInfo.FilePath; + options.MethodMode.ClassID = archiverInfo.ClassID; + + options.ArchivePath.VolExtension = archiverInfo.GetMainExtension(); + if(di.SFXMode) + options.ArchivePath.BaseExtension = kSFXExtension; + else + options.ArchivePath.BaseExtension = options.ArchivePath.VolExtension; + options.ArchivePath.ParseFromPath(di.ArchiveName); + + NWorkDir::CInfo workDirInfo; + ReadWorkDirInfo(workDirInfo); + options.WorkingDir.Empty(); + if (workDirInfo.Mode != NWorkDir::NMode::kCurrent) + { + UString fullPath; + NDirectory::MyGetFullPathName(di.ArchiveName, fullPath); + options.WorkingDir = GetWorkDir(workDirInfo, fullPath); + NFile::NDirectory::CreateComplexDirectory(options.WorkingDir); + } + return S_OK; +} + +HRESULT UpdateGUI( + const NWildcard::CCensor &censor, + CUpdateOptions &options, + bool showDialog, + CUpdateErrorInfo &errorInfo, + COpenCallbackGUI *openCallback, + CUpdateCallbackGUI *callback) +{ + if (showDialog) + { + RINOK(ShowDialog(censor, options, callback)); + } + if (options.SfxMode && options.SfxModule.IsEmpty()) + options.SfxModule = kDefaultSfxModule; + + CThreadUpdating tu; + + tu.UpdateCallbackGUI = callback; + tu.UpdateCallbackGUI->Init(); + + tu.WildcardCensor = &censor; + tu.Options = &options; + tu.OpenCallback = openCallback; + tu.ErrorInfo = &errorInfo; + + CThread thread; + if (!thread.Create(CThreadUpdating::MyThreadFunction, &tu)) + throw 271824; + tu.UpdateCallbackGUI->StartProgressDialog(LangString(IDS_PROGRESS_COMPRESSING, 0x02000DC0)); + return tu.Result; +} + + diff --git a/CPP/7zip/UI/GUI/UpdateGUI.h b/CPP/7zip/UI/GUI/UpdateGUI.h new file mode 100755 index 00000000..c5061aca --- /dev/null +++ b/CPP/7zip/UI/GUI/UpdateGUI.h @@ -0,0 +1,20 @@ +// GUI/UpdateGUI.h + +#ifndef __UPDATE_GUI_H +#define __UPDATE_GUI_H + +#include "../Common/Update.h" +#include "OpenCallbackGUI.h" +#include "UpdateCallbackGUI.h" + +#include "../../FileManager/UpdateCallback100.h" + +HRESULT UpdateGUI( + const NWildcard::CCensor &censor, + CUpdateOptions &options, + bool showDialog, + CUpdateErrorInfo &errorInfo, + COpenCallbackGUI *openCallback, + CUpdateCallbackGUI *callback); + +#endif diff --git a/CPP/7zip/UI/GUI/makefile b/CPP/7zip/UI/GUI/makefile new file mode 100755 index 00000000..bc6af149 --- /dev/null +++ b/CPP/7zip/UI/GUI/makefile @@ -0,0 +1,135 @@ +PROG = 7zG.exe +LIBS = $(LIBS) user32.lib advapi32.lib oleaut32.lib shell32.lib comctl32.lib htmlhelp.lib ole32.lib comdlg32.lib +CFLAGS = $(CFLAGS) -I ../../../ -DLANG -DCOMPRESS_MT -DWIN_LONG_PATH + +GUI_OBJS = \ + $O\CompressDialog.obj \ + $O\ExtractDialog.obj \ + $O\ExtractGUI.obj \ + $O\GUI.obj \ + $O\OpenCallbackGUI.obj \ + $O\UpdateCallbackGUI.obj \ + $O\UpdateGUI.obj \ + +COMMON_OBJS = \ + $O\Alloc.obj \ + $O\CommandLineParser.obj \ + $O\IntToString.obj \ + $O\Lang.obj \ + $O\ListFileUtils.obj \ + $O\NewHandler.obj \ + $O\StdInStream.obj \ + $O\String.obj \ + $O\StringConvert.obj \ + $O\StringToInt.obj \ + $O\TextConfig.obj \ + $O\UTFConvert.obj \ + $O\Vector.obj \ + $O\Wildcard.obj \ + +WIN_OBJS = \ + $O\CommonDialog.obj \ + $O\DLL.obj \ + $O\Error.obj \ + $O\FileDir.obj \ + $O\FileFind.obj \ + $O\FileIO.obj \ + $O\FileName.obj \ + $O\MemoryLock.obj \ + $O\PropVariant.obj \ + $O\PropVariantConversions.obj \ + $O\Registry.obj \ + $O\ResourceString.obj \ + $O\Shell.obj \ + $O\Synchronization.obj \ + $O\Window.obj \ + +WIN_CTRL_OBJS = \ + $O\ComboBox.obj \ + $O\Dialog.obj \ + $O\ListView.obj \ + +7ZIP_COMMON_OBJS = \ + $O\FilePathAutoRename.obj \ + $O\FileStreams.obj \ + $O\StreamUtils.obj \ + +UI_COMMON_OBJS = \ + $O\ArchiveCommandLine.obj \ + $O\ArchiveExtractCallback.obj \ + $O\ArchiveOpenCallback.obj \ + $O\ArchiverInfo.obj \ + $O\DefaultName.obj \ + $O\EnumDirItems.obj \ + $O\Extract.obj \ + $O\ExtractingFilePath.obj \ + $O\OpenArchive.obj \ + $O\PropIDUtils.obj \ + $O\SetProperties.obj \ + $O\SortUtils.obj \ + $O\TempFiles.obj \ + $O\Update.obj \ + $O\UpdateAction.obj \ + $O\UpdateCallback.obj \ + $O\UpdatePair.obj \ + $O\UpdateProduce.obj \ + $O\WorkDir.obj \ + $O\ZipRegistry.obj \ + +FM_OBJS = \ + $O\ExtractCallback.obj \ + $O\FormatUtils.obj \ + $O\HelpUtils.obj \ + $O\LangUtils.obj \ + $O\OpenCallback.obj \ + $O\ProgramLocation.obj \ + $O\RegistryUtils.obj \ + $O\SplitUtils.obj \ + $O\StringUtils.obj \ + $O\UpdateCallback100.obj \ + +OBJS = \ + $O\StdAfx.obj \ + $(GUI_OBJS) \ + $(COMMON_OBJS) \ + $(WIN_OBJS) \ + $(WIN_CTRL_OBJS) \ + $(7ZIP_COMMON_OBJS) \ + $(UI_COMMON_OBJS) \ + $(FM_OBJS)\ + $O\MyMessages.obj \ + $O\MessagesDialog.obj \ + $O\OverwriteDialog.obj \ + $O\PasswordDialog.obj \ + $O\ProgressDialog.obj \ + $O\CopyCoder.obj \ + $O\resource.res + +!include "../../../Build.mak" + +$(GUI_OBJS): $(*B).cpp + $(COMPL) +$(COMMON_OBJS): ../../../Common/$(*B).cpp + $(COMPL) +$(WIN_OBJS): ../../../Windows/$(*B).cpp + $(COMPL) +$(WIN_CTRL_OBJS): ../../../Windows/Control/$(*B).cpp + $(COMPL) +$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp + $(COMPL) +$(UI_COMMON_OBJS): ../Common/$(*B).cpp + $(COMPL) +$(FM_OBJS): ../../FileManager/$(*B).cpp + $(COMPL) +$O\MyMessages.obj: ../Explorer/MyMessages.cpp + $(COMPL) +$O\MessagesDialog.obj: ../../FileManager/Resource/MessagesDialog/$(*B).cpp + $(COMPL) +$O\OverwriteDialog.obj: ../../FileManager/Resource/OverwriteDialog./$(*B).cpp + $(COMPL) +$O\PasswordDialog.obj: ../../FileManager/Resource/PasswordDialog/$(*B).cpp + $(COMPL) +$O\ProgressDialog.obj: ../../FileManager/Resource/ProgressDialog2/$(*B).cpp + $(COMPL) +$O\CopyCoder.obj: ../../Compress/Copy/$(*B).cpp + $(COMPL) diff --git a/CPP/7zip/UI/GUI/resource.h b/CPP/7zip/UI/GUI/resource.h new file mode 100755 index 00000000..d88af787 --- /dev/null +++ b/CPP/7zip/UI/GUI/resource.h @@ -0,0 +1,45 @@ +#define IDS_CONTEXT_EXTRACT 42 +#define IDS_CONTEXT_EXTRACT_HELP 43 +#define IDS_CONTEXT_COMPRESS 44 +#define IDS_CONTEXT_COMPRESS_HELP 45 +#define IDS_CONTEXT_OPEN 46 +#define IDS_CONTEXT_OPEN_HELP 47 +#define IDS_CONTEXT_TEST 48 +#define IDS_CONTEXT_TEST_HELP 49 +#define IDS_CONTEXT_CAPTION_HELP 50 +#define IDS_CONTEXT_POPUP_CAPTION 51 +#define IDS_OPEN_TYPE_ALL_FILES 80 + +#define IDS_METHOD_STORE 81 +#define IDS_METHOD_NORMAL 82 +#define IDS_METHOD_MAXIMUM 83 +#define IDS_METHOD_FAST 84 +#define IDS_METHOD_FASTEST 85 +#define IDS_METHOD_ULTRA 86 + +#define IDS_COMPRESS_UPDATE_MODE_ADD 90 +#define IDS_COMPRESS_UPDATE_MODE_UPDATE 91 +#define IDS_COMPRESS_UPDATE_MODE_FRESH 92 +#define IDS_COMPRESS_UPDATE_MODE_SYNCHRONIZE 93 + +#define IDS_COMPRESS_SPLIT_CONFIRM_MESSAGE 94 +#define IDS_COMPRESS_INCORRECT_VOLUME_SIZE 95 + +#define IDS_COMPRESS_SET_ARCHIVE_DIALOG_TITLE 96 +#define IDS_CANT_UPDATE_ARCHIVE 97 + +#define IDS_PROGRESS_COMPRESSING 98 +#define IDS_PROGRESS_TESTING 99 +#define IDS_ERROR 100 +#define IDS_MESSAGE_NO_ERRORS 101 +#define IDS_CONFIG_DIALOG_CAPTION 102 + +#define IDS_PASSWORD_USE_ASCII 110 +#define IDS_PASSWORD_PASSWORDS_DO_NOT_MATCH 111 +#define IDS_PASSWORD_IS_TOO_LONG 112 + +#define IDD_DIALOG_EXTRACT 137 +#define IDB_DELETE 149 +#define IDC_LIST1 1067 +#define IDC_COLUMN_EDIT_WIDTH 1068 + diff --git a/CPP/7zip/UI/GUI/resource.rc b/CPP/7zip/UI/GUI/resource.rc new file mode 100755 index 00000000..19f7e61b --- /dev/null +++ b/CPP/7zip/UI/GUI/resource.rc @@ -0,0 +1,57 @@ +#include "../../MyVersionInfo.rc" +#include +#include "resource.h" + +MY_VERSION_INFO_APP("7-Zip GUI", "7zg") + +IDI_ICON1 ICON "FM.ico" + +1 24 MOVEABLE PURE "7zG.exe.manifest" + +STRINGTABLE +BEGIN + IDS_CONTEXT_EXTRACT "Extract files..." + IDS_CONTEXT_EXTRACT_HELP "Extracts files from the selected archive." + IDS_CONTEXT_COMPRESS "Add to archive..." + IDS_CONTEXT_COMPRESS_HELP "Adds the selected items to archive." + IDS_CONTEXT_OPEN "Open" + IDS_CONTEXT_OPEN_HELP "Opens the selected archive." + IDS_CONTEXT_TEST "Test archive" + IDS_CONTEXT_TEST_HELP "Tests integrity of the selected archive." + IDS_CONTEXT_CAPTION_HELP "7-Zip commands" + IDS_CONTEXT_POPUP_CAPTION "7-Zip" + IDS_OPEN_TYPE_ALL_FILES "All Files" + IDS_METHOD_STORE "Store" + IDS_METHOD_NORMAL "Normal" + IDS_METHOD_MAXIMUM "Maximum" + IDS_METHOD_FAST "Fast" + IDS_METHOD_FASTEST "Fastest" + IDS_METHOD_ULTRA "Ultra" + IDS_COMPRESS_UPDATE_MODE_ADD "Add and replace files" + IDS_COMPRESS_UPDATE_MODE_UPDATE "Update and add files" + IDS_COMPRESS_UPDATE_MODE_FRESH "Freshen existing files" + IDS_COMPRESS_UPDATE_MODE_SYNCHRONIZE "Synchronize files" + IDS_COMPRESS_SET_ARCHIVE_DIALOG_TITLE "Browse" + IDS_COMPRESS_INCORRECT_VOLUME_SIZE "Incorrect volume size" + IDS_COMPRESS_SPLIT_CONFIRM_MESSAGE "Specified volume size: {0} bytes.\nAre you sure you want to split archive into such volumes?" + + IDS_PASSWORD_USE_ASCII "Use only English letters, numbers and special characters (!, #, $, ...) for password." + IDS_PASSWORD_PASSWORDS_DO_NOT_MATCH "Passwords do not match" + IDS_PASSWORD_IS_TOO_LONG "Password is too long" + + IDS_CANT_UPDATE_ARCHIVE "Can not update archive '{0}'" + IDS_PROGRESS_COMPRESSING "Compressing" + IDS_PROGRESS_TESTING "Testing" + IDS_ERROR "Error" + IDS_MESSAGE_NO_ERRORS "There are no errors" + IDS_CONFIG_DIALOG_CAPTION "7-Zip Options" +END + +#include "../../FileManager/Resource/PropertyName/resource.rc" +#include "../../FileManager/Resource/OverwriteDialog/resource.rc" +#include "../../FileManager/Resource/PasswordDialog/resource.rc" +#include "../../FileManager/Resource/MessagesDialog/resource.rc" +#include "../../FileManager/Resource/ProgressDialog2/resource.rc" +#include "../Resource/Extract/resource.rc" +#include "../Resource/ExtractDialog/resource.rc" +#include "../Resource/CompressDialog/resource.rc" -- cgit v1.2.3