easy 7-zip mod for 23.01: rebased from 19.00

This commit is contained in:
glachancecmaisonneuve
2019-04-04 02:12:44 -04:00
committed by shunf4
parent 082657f61b
commit 18725aeba6
28 changed files with 1084 additions and 55 deletions

View File

@@ -12,8 +12,8 @@
#ifndef Z7_NO_REGISTRY
#include "../FileManager/HelpUtils.h"
#endif
#include <stdio.h>
#include "../FileManager/ViewSettings.h"
#include "../FileManager/BrowseDialog.h"
#include "../FileManager/LangUtils.h"
#include "../FileManager/resourceGui.h"
@@ -88,7 +88,7 @@ static const UInt32 kLangIDs[] =
// static const int kWildcardsButtonIndex = 2;
#ifndef Z7_NO_REGISTRY
static const unsigned kHistorySize = 16;
static const unsigned kHistorySize = 30;
#endif
#ifndef Z7_SFX
@@ -135,6 +135,20 @@ void CExtractDialog::GetButton_Bools(UINT id, CBoolPair &b1, CBoolPair &b2)
#endif
void StartApplication(const UString &dir, const UString &path)
{
SHELLEXECUTEINFOW execInfo;
ZeroMemory(&execInfo, sizeof(execInfo));
execInfo.cbSize = sizeof(execInfo);
execInfo.fMask = SEE_MASK_FLAG_DDEWAIT;
execInfo.hwnd = NULL;
execInfo.lpVerb = NULL;
execInfo.lpFile = path;
execInfo.lpParameters = NULL;
execInfo.lpDirectory = dir.IsEmpty() ? NULL : (LPCWSTR)dir;
execInfo.nShow = SW_SHOWNORMAL;
ShellExecuteExW(&execInfo);
}
bool CExtractDialog::OnInit()
{
#ifdef Z7_LANG
@@ -222,6 +236,16 @@ bool CExtractDialog::OnInit()
_path.SetCurSel(-1);
*/
#ifndef Z7_SFX
m_bOpenOutputFolder = ReadOptOpenOutputFolder();
CheckButton(IDC_EXTRACT_CHECK_OPEN_OUTPUT_FOLDER, m_bOpenOutputFolder);
#endif
#ifndef Z7_SFX
m_bOpenOutputFolder = ReadOptOpenOutputFolder();
CheckButton(IDC_EXTRACT_CHECK_OPEN_OUTPUT_FOLDER, m_bOpenOutputFolder);
#endif
#ifndef Z7_SFX
_pathMode.Attach(GetItem(IDC_EXTRACT_PATH_MODE));
@@ -260,6 +284,21 @@ bool CExtractDialog::OnButtonClicked(unsigned buttonID, HWND buttonHWND)
case IDB_EXTRACT_SET_PATH:
OnButtonSetPath();
return true;
case IDC_EXTRACT_BUTTON_OPEN_PATH:
OnButtonOpenPath();
return true;
case IDC_EXTRACT_CHECK_OPEN_OUTPUT_FOLDER:
m_bOpenOutputFolder = IsButtonCheckedBool(IDC_EXTRACT_CHECK_OPEN_OUTPUT_FOLDER);
return true;
#ifndef Z7_SFX
case IDC_CHECK_DELETE_SOURCE_FILE:
m_bDeleteSourceFile = IsButtonCheckedBool(IDC_CHECK_DELETE_SOURCE_FILE);
return true;
#endif
#ifndef Z7_SFX
case IDX_EXTRACT_NAME_ENABLE:
ShowItem_Bool(IDE_EXTRACT_NAME, IsButtonCheckedBool(IDX_EXTRACT_NAME_ENABLE));
@@ -286,6 +325,7 @@ void CExtractDialog::OnButtonSetPath()
_path.SetCurSel(-1);
#endif
_path.SetText(resultPath);
ShowPathFreeSpace(resultPath);
}
void AddUniqueString(UStringVector &list, const UString &s);
@@ -299,6 +339,10 @@ void AddUniqueString(UStringVector &list, const UString &s)
void CExtractDialog::OnOK()
{
#ifndef Z7_SFX
SaveOptOpenOutputFolder(m_bOpenOutputFolder);
#endif
#ifndef Z7_SFX
int pathMode2 = kPathModeButtonsVals[_pathMode.GetCurSel()];
if (PathMode != NExtract::NPathMode::kCurPaths ||
@@ -419,3 +463,147 @@ void CExtractDialog::OnHelp()
CModalDialog::OnHelp();
}
#endif
BOOL IsDirectory(const wchar_t * lpszPathFile)
{
DWORD dwAttr;
dwAttr = GetFileAttributesW(lpszPathFile);
return (dwAttr != (DWORD)-1) && (dwAttr & FILE_ATTRIBUTE_DIRECTORY);
}
void CExtractDialog::OnButtonOpenPath()
{
UString currentPath;
_path.GetText(currentPath);
if (IsDirectory(currentPath))
{
StartApplication(currentPath, currentPath);
}
else
{
wchar_t szMsg[1024];
wsprintfW(szMsg, L"Folder \"%s\" is not available yet.\n\n"
L"Note: the program will create the folder automatically when extracting.", (LPCWSTR)currentPath);
MessageBoxW((HWND)_window, szMsg, L"7-Zip", MB_ICONEXCLAMATION);
}
}
static int MakeByteSizeString64(wchar_t * lpszBuf, size_t ccBuf, unsigned __int64 n64Byte)
{
int nRet = 0;
if (n64Byte < 1000ui64)
{
// < 1K
nRet = swprintf(lpszBuf, ccBuf,
L"%I64d B", n64Byte);
}
else if (n64Byte < 1024000ui64) // 1024 * 1000
{
// 1K <= n64Byte < 1M
nRet = swprintf(lpszBuf, ccBuf,
L"%.1f KB", (double)n64Byte / 1024.0);
}
else if (n64Byte < 1048576000ui64) // 1024 * 1024 * 1000
{
// 1M <= n64Byte < 1G
nRet = swprintf(lpszBuf, ccBuf,
L"%.2f MB", (double)n64Byte / 1048576.0); // 1024 * 1024
}
else if (n64Byte < 1073741824000ui64) // 1024 * 1024 * 1024 * 1000
{
// 1 G <= n64Byte < 1T
nRet = swprintf(lpszBuf, ccBuf,
L"%.2f GB", (double)n64Byte / 1073741824.0); // 1024.0F * 1024.0F * 1024.0F
}
else
{
// n64Byte >= 1T
nRet = swprintf(lpszBuf, ccBuf,
L"%.2f TB", (double)n64Byte / 1099511627776.0);
// 1024.0F * 1024.0F * 1024.0F * 1024.0F
}
return nRet;
}
void CExtractDialog::ShowPathFreeSpace(UString & strPath)
{
bool bBadPath;
UString strText;
strText.Empty();
bBadPath = false;
strPath.Trim();
for (; !IsDirectory(strPath); )
{
int n = strPath.ReverseFind(L'\\');
if (n == -1)
{
bBadPath = true;
break;
}
else
{
strPath.ReleaseBuf_SetEnd(n);
}
}
if (!bBadPath)
{
unsigned __int64 n64FreeBytesAvailable;
unsigned __int64 n64TotalNumberOfBytes;
unsigned __int64 n64TotalNumberOfFreeBytes;
if (GetDiskFreeSpaceExW(strPath, (PULARGE_INTEGER)&n64FreeBytesAvailable,
(PULARGE_INTEGER)&n64TotalNumberOfBytes, (PULARGE_INTEGER)&n64TotalNumberOfFreeBytes))
{
wchar_t szFreeBytes[1024];
wchar_t szTotalBytes[1024];
MakeByteSizeString64(szFreeBytes, 1024-4, n64TotalNumberOfFreeBytes);
MakeByteSizeString64(szTotalBytes, 1024-4, n64TotalNumberOfBytes);
int nLen = swprintf(strText.GetBuf(1024), 1024-4, L"%s Free (Total: %s)", szFreeBytes, szTotalBytes);
strText.ReleaseBuf_SetEnd(nLen);
}
}
_freeSpace.SetText(strText);
}
bool CExtractDialog::OnCommand(int code, int itemID, LPARAM lParam)
{
if (itemID == IDC_EXTRACT_PATH)
{
#ifdef NO_REGISTRY
if (code == EN_CHANGE)
#else
if (code == CBN_EDITCHANGE)
#endif
{
UString strPath;
_path.GetText(strPath);
ShowPathFreeSpace(strPath);
return true;
}
#ifndef NO_REGISTRY
else if (code == CBN_SELCHANGE)
{
int nSel = _path.GetCurSel();
if (nSel != CB_ERR)
{
UString strPath;
_path.GetLBText(nSel, strPath);
ShowPathFreeSpace(strPath);
}
return true;
}
#endif
}
return CModalDialog::OnCommand(code, itemID, lParam);
}

View File

@@ -7,6 +7,7 @@
#include "../../../Windows/Control/ComboBox.h"
#include "../../../Windows/Control/Edit.h"
#include "../../../Windows/Control/Static.h"
#include "../Common/ExtractMode.h"
@@ -31,6 +32,7 @@ namespace NExtractionDialog
*/
}
void StartApplication(const UString &dir, const UString &path);
class CExtractDialog: public NWindows::NControl::CModalDialog
{
#ifdef Z7_NO_REGISTRY
@@ -45,7 +47,7 @@ class CExtractDialog: public NWindows::NControl::CModalDialog
NWindows::NControl::CComboBox _pathMode;
NWindows::NControl::CComboBox _overwriteMode;
#endif
NWindows::NControl::CStatic _freeSpace;
#ifndef Z7_SFX
// int GetFilesMode() const;
void UpdatePasswordControl();
@@ -58,6 +60,8 @@ class CExtractDialog: public NWindows::NControl::CModalDialog
virtual bool OnInit() Z7_override;
virtual bool OnButtonClicked(unsigned buttonID, HWND buttonHWND) Z7_override;
virtual void OnOK() Z7_override;
void OnButtonOpenPath();
virtual bool OnCommand(int code, int itemID, LPARAM lParam);
#ifndef Z7_NO_REGISTRY
@@ -67,6 +71,7 @@ class CExtractDialog: public NWindows::NControl::CModalDialog
#endif
void ShowPathFreeSpace(UString & strPath);
bool IsShowPasswordChecked() const { return IsButtonCheckedBool(IDX_PASSWORD_SHOW); }
public:
// bool _enableSelectedFilesButton;
@@ -84,6 +89,8 @@ public:
NExtract::NPathMode::EEnum PathMode;
NExtract::NOverwriteMode::EEnum OverwriteMode;
bool m_bOpenOutputFolder;
bool m_bDeleteSourceFile;
#ifndef Z7_SFX
// CBoolPair AltStreams;
CBoolPair NtSecurity;
@@ -101,10 +108,12 @@ public:
return CModalDialog::Create(SIZED_DIALOG(IDD_EXTRACT), aWndParent);
}
CExtractDialog():
PathMode_Force(false),
OverwriteMode_Force(false)
CExtractDialog()
{
PathMode_Force = false;
OverwriteMode_Force = false;
m_bOpenOutputFolder = false;
m_bDeleteSourceFile = false;
ElimDup.Val = true;
}

View File

@@ -2,7 +2,7 @@
#include "../../GuiCommon.rc"
#define xc 336
#define yc 168
#define yc 200
#undef g1xs
#undef g2x
@@ -18,6 +18,13 @@
#define g2xs (xc - g1xs - gSpace)
#define g2xs2 (g2xs - m - m)
#define bxsOpen 30
#define xsSpace 4
#define e7zYbase 58
#define newControlHeight 42
#define newControlHeight2 58
#undef GROUP_Y_SIZE
#ifdef UNDER_CE
#define GROUP_Y_SIZE 8
@@ -29,30 +36,36 @@ IDD_EXTRACT DIALOG 0, 0, xs, ys MY_MODAL_DIALOG_STYLE MY_FONT
CAPTION "Extract"
BEGIN
LTEXT "E&xtract to:", IDT_EXTRACT_EXTRACT_TO, m, m, xc, 8
COMBOBOX IDC_EXTRACT_PATH, m, m + 12, xc - bxsDots - 12, 100, MY_COMBO_WITH_EDIT
PUSHBUTTON "...", IDB_EXTRACT_SET_PATH, xs - m - bxsDots, m + 12 - 2, bxsDots, bys, WS_GROUP
COMBOBOX IDC_EXTRACT_PATH, m, m + 12, xc - bxsDots - xsSpace - bxsOpen - xsSpace, 160, MY_COMBO_WITH_EDIT
PUSHBUTTON "...", IDB_EXTRACT_SET_PATH, xs - m - bxsDots - xsSpace - bxsOpen, m + 12 - 1, bxsDots, bys-1, WS_GROUP
PUSHBUTTON "&Open", IDC_EXTRACT_BUTTON_OPEN_PATH, xs - m - bxsOpen, m + 12 - 1, bxsOpen, bys-1, WS_GROUP
CONTROL "", IDX_EXTRACT_NAME_ENABLE, MY_CHECKBOX, m, m + 34, 12, 10
EDITTEXT IDE_EXTRACT_NAME, m + 12 + 2, m + 32, g1xs - 12 - 2, 14, ES_AUTOHSCROLL
EDITTEXT IDE_EXTRACT_NAME, m + 12 + 2, m + 32, xc - 12 - 2, 14, ES_AUTOHSCROLL
LTEXT "Path mode:", IDT_EXTRACT_PATH_MODE, m, m + 52, g1xs, 8
COMBOBOX IDC_EXTRACT_PATH_MODE, m, m + 64, g1xs, 140, MY_COMBO
LTEXT "", IDC_STATIC_EXTRACT_FREE_SPACE, m, e7zYbase, xc, 8
GROUPBOX "After extraction completes successfully", IDC_GUI_AFTER_EXTRACT, m, e7zYbase+12, xc, 27
CONTROL "O&pen output folder", IDC_EXTRACT_CHECK_OPEN_OUTPUT_FOLDER, MY_CHECKBOX, 14, e7zYbase+24, 100, 10
CONTROL "&Delete source archives", IDC_CHECK_DELETE_SOURCE_FILE, MY_CHECKBOX, 125, e7zYbase+24, 120, 10
LTEXT "Path mode:", IDT_EXTRACT_PATH_MODE, m, m + 52 + newControlHeight, g1xs, 8
COMBOBOX IDC_EXTRACT_PATH_MODE, m, m + 64 + newControlHeight, g1xs, 140, MY_COMBO
CONTROL "Eliminate duplication of root folder", IDX_EXTRACT_ELIM_DUP, MY_CHECKBOX,
m, m + 84, g1xs, 10
m, m + 84 + newControlHeight, g1xs, 10
LTEXT "Overwrite mode:", IDT_EXTRACT_OVERWRITE_MODE, m, m + 104, g1xs, 8
COMBOBOX IDC_EXTRACT_OVERWRITE_MODE, m, m + 116, g1xs, 140, MY_COMBO
LTEXT "Overwrite mode:", IDT_EXTRACT_OVERWRITE_MODE, m, m + 104 + newControlHeight, g1xs, 8
COMBOBOX IDC_EXTRACT_OVERWRITE_MODE, m, m + 116 + newControlHeight, g1xs, 140, MY_COMBO
GROUPBOX "Password", IDG_PASSWORD, g2x, m + 36, g2xs, GROUP_Y_SIZE
EDITTEXT IDE_EXTRACT_PASSWORD, g2x2, m + 50, g2xs2, 14, ES_PASSWORD | ES_AUTOHSCROLL
CONTROL "Show Password", IDX_PASSWORD_SHOW, MY_CHECKBOX, g2x2, m + 72, g2xs2, 10
GROUPBOX "Password", IDG_PASSWORD, g2x, m + 36 + newControlHeight2, g2xs, GROUP_Y_SIZE
EDITTEXT IDE_EXTRACT_PASSWORD, g2x2, m + 50 + newControlHeight2, g2xs2, 14, ES_PASSWORD | ES_AUTOHSCROLL
CONTROL "Show Password", IDX_PASSWORD_SHOW, MY_CHECKBOX, g2x2, m + 72 + newControlHeight2, g2xs2, 10
// CONTROL "Restore alternate data streams", IDX_EXTRACT_ALT_STREAMS, MY_CHECKBOX,
// g2x, m + 104, g2xs, 10
CONTROL "Restore file security", IDX_EXTRACT_NT_SECUR, MY_CHECKBOX,
g2x, m + 104, g2xs, 10
g2x, m + 100 + newControlHeight2, g2xs, 10
DEFPUSHBUTTON "OK", IDOK, bx3, by, bxs, bys, WS_GROUP
PUSHBUTTON "Cancel", IDCANCEL, bx2, by, bxs, bys

View File

@@ -6,6 +6,12 @@
#define IDC_EXTRACT_PATH_MODE 102
#define IDC_EXTRACT_OVERWRITE_MODE 103
#define IDC_EXTRACT_BUTTON_OPEN_PATH 105
#define IDC_EXTRACT_CHECK_OPEN_OUTPUT_FOLDER 106
#define IDC_STATIC_EXTRACT_FREE_SPACE 107
#define IDC_CHECK_DELETE_SOURCE_FILE 108
#define IDC_GUI_AFTER_EXTRACT 109
#define IDE_EXTRACT_PASSWORD 120
#define IDE_EXTRACT_NAME 130

View File

@@ -15,6 +15,7 @@
#include "../FileManager/LangUtils.h"
#include "../FileManager/resourceGui.h"
#include "../FileManager/OverwriteDialogRes.h"
#include "../FileManager/ViewSettings.h"
#include "../Common/ArchiveExtractCallback.h"
#include "../Common/PropIDUtils.h"
@@ -33,6 +34,7 @@
using namespace NWindows;
using namespace NFile;
using namespace NDir;
extern bool g_bProcessError;
static const wchar_t * const kIncorrectOutDir = L"Incorrect output directory path";
@@ -152,10 +154,10 @@ HRESULT CThreadExtracting::ProcessVirt()
AddSizePair(s, IDS_PROP_ALT_STREAMS_SIZE, Stat.AltStreams_UnpackSize);
}
s.Add_LF();
AddLangString(s, IDS_MESSAGE_NO_ERRORS);
FinalMessage.OkMessage.Title = Title;
FinalMessage.OkMessage.Message = s;
}
AddLangString(s, IDS_MESSAGE_NO_ERRORS);
FinalMessage.OkMessage.Title = Title;
FinalMessage.OkMessage.Message = s;
}
}
#endif
@@ -181,7 +183,11 @@ HRESULT ExtractGUI(
CExtractCallbackImp *extractCallback,
HWND hwndParent)
{
bool openOutputFolder = false;
bool deleteSourceFile = false;
messageWasDisplayed = false;
g_bProcessError = false;
CThreadExtracting extracter;
/*
@@ -239,6 +245,9 @@ HRESULT ExtractGUI(
options.PathMode = dialog.PathMode;
options.ElimDup = dialog.ElimDup;
openOutputFolder = dialog.m_bOpenOutputFolder;
deleteSourceFile = dialog.m_bDeleteSourceFile;
#ifndef Z7_SFX
// options.NtOptions.AltStreams = dialog.AltStreams;
options.NtOptions.NtSecurity = dialog.NtSecurity;
@@ -255,7 +264,7 @@ HRESULT ExtractGUI(
NName::NormalizeDirPathPrefix(options.OutputDir);
/*
if (!CreateComplexDirectory(options.OutputDir))
if(!CreateComplexDirectory(options.OutputDir))
{
UString s = GetUnicodeString(NError::MyFormatMessage(GetLastError()));
UString s2 = MyFormatNew(IDS_CANNOT_CREATE_FOLDER,
@@ -293,5 +302,33 @@ HRESULT ExtractGUI(
RINOK(extracter.Create(title, hwndParent))
messageWasDisplayed = extracter.ThreadFinishedOK && extracter.MessagesDisplayed;
if (extracter.ThreadFinishedOK && !g_bProcessError)
{
if (openOutputFolder)
{
StartApplication(options.OutputDir, options.OutputDir);
}
if (deleteSourceFile)
{
DWORD dwAttr;
UString strFilePath;
for (unsigned i = 0; i < archivePathsFull.Size(); i++)
{
strFilePath = archivePathsFull[i];
dwAttr = GetFileAttributesW(strFilePath);
if ((dwAttr != INVALID_FILE_ATTRIBUTES)
&& (dwAttr & FILE_ATTRIBUTE_ARCHIVE))
{
if (dwAttr & FILE_ATTRIBUTE_READONLY)
{
dwAttr &= (~FILE_ATTRIBUTE_READONLY);
SetFileAttributesW(strFilePath, dwAttr);
}
::DeleteFileW(strFilePath);
}
}
}
}
return extracter.Result;
}

View File

@@ -20,6 +20,7 @@ GUI_OBJS = \
$O\UpdateCallbackGUI.obj \
$O\UpdateCallbackGUI2.obj \
$O\UpdateGUI.obj \
$O\ViewSettings.obj \
COMMON_OBJS = \
$O\CommandLineParser.obj \