This commit is contained in:
glachancecmaisonneuve
2019-04-04 02:12:44 -04:00
parent a6e2c7e401
commit aec3e4502e
30 changed files with 1082 additions and 60 deletions

View File

@@ -12,8 +12,8 @@
#ifndef 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 NO_REGISTRY
static const unsigned kHistorySize = 16;
static const unsigned kHistorySize = 30;
#endif
#ifndef _SFX
@@ -133,6 +133,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 LANG
@@ -220,6 +234,11 @@ bool CExtractDialog::OnInit()
_path.SetCurSel(-1);
*/
#ifndef _SFX
m_bOpenOutputFolder = ReadOptOpenOutputFolder();
CheckButton(IDC_EXTRACT_CHECK_OPEN_OUTPUT_FOLDER, m_bOpenOutputFolder);
#endif
#ifndef _SFX
_pathMode.Attach(GetItem(IDC_EXTRACT_PATH_MODE));
@@ -258,6 +277,21 @@ bool CExtractDialog::OnButtonClicked(int 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 _SFX
case IDC_CHECK_DELETE_SOURCE_FILE:
m_bDeleteSourceFile = IsButtonCheckedBool(IDC_CHECK_DELETE_SOURCE_FILE);
return true;
#endif
#ifndef _SFX
case IDX_EXTRACT_NAME_ENABLE:
ShowItem_Bool(IDE_EXTRACT_NAME, IsButtonCheckedBool(IDX_EXTRACT_NAME_ENABLE));
@@ -284,6 +318,7 @@ void CExtractDialog::OnButtonSetPath()
_path.SetCurSel(-1);
#endif
_path.SetText(resultPath);
ShowPathFreeSpace(resultPath);
}
void AddUniqueString(UStringVector &list, const UString &s)
@@ -296,6 +331,10 @@ void AddUniqueString(UStringVector &list, const UString &s)
void CExtractDialog::OnOK()
{
#ifndef _SFX
SaveOptOpenOutputFolder(m_bOpenOutputFolder);
#endif
#ifndef _SFX
int pathMode2 = kPathModeButtonsVals[_pathMode.GetCurSel()];
if (PathMode != NExtract::NPathMode::kCurPaths ||
@@ -416,3 +455,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);
}