Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 57 additions & 26 deletions CPP/7zip/UI/Common/ZipRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ static LPCTSTR const kElimDup = TEXT("ElimDup");
static LPCTSTR const kNtSecur = TEXT("Security");
static LPCTSTR const kMemLimit = TEXT("MemLimit");

static LPCTSTR const kFMCopyHistoryValueName = TEXT("CopyHistory");

void CInfo::Save() const
{
CS_LOCK
Expand All @@ -122,11 +124,13 @@ void CInfo::Save() const
Key_Set_BoolPair(key, kShowPassword, ShowPassword);
Key_Set_BoolPair(key, kOpnTrgFold, OpnTrgFold);

key.RecurseDeleteKey(kPathHistory);
if (WantPathHistory())
key.SetValue_Strings(kPathHistory, Paths);
else
key.SetValue_Strings(kPathHistory, Empty);
// Store path history in shared FM key (cross-dialog: Extract GUI + FM context menu)
key.Close();
if (key.Create(HKEY_CURRENT_USER, GetKeyPath(TEXT("FM"))) == ERROR_SUCCESS)
{
key.SetValue_Strings(kFMCopyHistoryValueName, Paths);
key.Close();
}
}

void Save_ShowPassword(bool showPassword)
Expand All @@ -137,6 +141,14 @@ void Save_ShowPassword(bool showPassword)
key.SetValue(kShowPassword, showPassword);
}

void Save_OpnTrgFold(bool open)
{
CS_LOCK
CKey key;
CreateMainKey(key, kKeyName);
key.SetValue(kOpnTrgFold, open);
}

void Save_LimitGB(UInt32 limit_GB)
{
CS_LOCK
Expand All @@ -158,29 +170,37 @@ void CInfo::Load()

CS_LOCK
CKey key;
if (OpenMainKey(key, kKeyName) != ERROR_SUCCESS)
return;

key.GetValue_Strings(kPathHistory, Paths);
UInt32 v;
if (key.GetValue_UInt32_IfOk(kExtractMode, v) == ERROR_SUCCESS && v <= NPathMode::kAbsPaths)

// Resilient against missing Extraction key; load paths from shared FM key
if (OpenMainKey(key, kKeyName) == ERROR_SUCCESS)
{
PathMode = (NPathMode::EEnum)v;
PathMode_Force = true;
UInt32 v;
if (key.GetValue_UInt32_IfOk(kExtractMode, v) == ERROR_SUCCESS && v <= NPathMode::kAbsPaths)
{
PathMode = (NPathMode::EEnum)v;
PathMode_Force = true;
}
if (key.GetValue_UInt32_IfOk(kOverwriteMode, v) == ERROR_SUCCESS && v <= NOverwriteMode::kRenameExisting)
{
OverwriteMode = (NOverwriteMode::EEnum)v;
OverwriteMode_Force = true;
}

Key_Get_BoolPair_true(key, kSplitDest, SplitDest);

Key_Get_BoolPair(key, kElimDup, ElimDup);
// Key_Get_BoolPair(key, kAltStreams, AltStreams);
Key_Get_BoolPair(key, kNtSecur, NtSecurity);
Key_Get_BoolPair(key, kShowPassword, ShowPassword);
Key_Get_BoolPair(key, kOpnTrgFold, OpnTrgFold);
key.Close();
}
if (key.GetValue_UInt32_IfOk(kOverwriteMode, v) == ERROR_SUCCESS && v <= NOverwriteMode::kRenameExisting)

if (key.Open(HKEY_CURRENT_USER, GetKeyPath(TEXT("FM")), KEY_READ) == ERROR_SUCCESS)
{
OverwriteMode = (NOverwriteMode::EEnum)v;
OverwriteMode_Force = true;
key.GetValue_Strings(kFMCopyHistoryValueName, Paths);
key.Close();
}

Key_Get_BoolPair_true(key, kSplitDest, SplitDest);

Key_Get_BoolPair(key, kElimDup, ElimDup);
// Key_Get_BoolPair(key, kAltStreams, AltStreams);
Key_Get_BoolPair(key, kNtSecur, NtSecurity);
Key_Get_BoolPair(key, kShowPassword, ShowPassword);
Key_Get_BoolPair(key, kOpnTrgFold, OpnTrgFold);
}

bool Read_ShowPassword()
Expand All @@ -194,6 +214,17 @@ bool Read_ShowPassword()
return showPassword;
}

bool Read_OpnTrgFold()
{
CS_LOCK
CKey key;
bool open = false;
if (OpenMainKey(key, kKeyName) != ERROR_SUCCESS)
return open;
key.GetValue_bool_IfOk(kOpnTrgFold, open);
return open;
}

UInt32 Read_LimitGB()
{
CS_LOCK
Expand Down Expand Up @@ -607,7 +638,7 @@ void CContextMenuInfo::Load()
Cascaded.Val = true;
Cascaded.Def = false;

MenuIcons.Val = false;
MenuIcons.Val = true;
MenuIcons.Def = false;

ElimDup.Val = true;
Expand All @@ -634,7 +665,7 @@ void CContextMenuInfo::Load()

Key_Get_BoolPair_true(key, kCascadedMenu, Cascaded);
Key_Get_BoolPair_true(key, kElimDup, ElimDup);
Key_Get_BoolPair(key, kMenuIcons, MenuIcons);
Key_Get_BoolPair_true(key, kMenuIcons, MenuIcons);

Key_Get_UInt32(key, kWriteZoneId, WriteZone);

Expand Down
3 changes: 3 additions & 0 deletions CPP/7zip/UI/Common/ZipRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ namespace NExtract
void Save_ShowPassword(bool showPassword);
bool Read_ShowPassword();

void Save_OpnTrgFold(bool open);
bool Read_OpnTrgFold();

void Save_LimitGB(UInt32 limit_GB);
UInt32 Read_LimitGB();
}
Expand Down
12 changes: 4 additions & 8 deletions CPP/7zip/UI/Explorer/ContextMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,14 +648,10 @@ Z7_COMWF_B CZipContextMenu::QueryContextMenu(HMENU hMenu, UINT indexMenu,
_elimDup = ci.ElimDup;
_writeZone = ci.WriteZone;

HBITMAP bitmap = NULL;
if (ci.MenuIcons.Val)
{
ODS("### 45")
if (!_bitmap)
_bitmap = ::LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_MENU_LOGO));
bitmap = _bitmap;
}
ODS("### 45")
if (!_bitmap)
_bitmap = ::LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_MENU_LOGO));
HBITMAP bitmap = _bitmap;

UINT subIndex = indexMenu;

Expand Down
55 changes: 53 additions & 2 deletions CPP/7zip/UI/FileManager/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,30 @@

#define kTempDirPrefix FTEXT("7zE")

// Walk up, delete found archive.
static void DeleteSourceArchive_WalkUp(CPanel &srcPanel, UString srcFilePath)
{
while (!srcFilePath.IsEmpty())
{
if (srcFilePath.Back() == L'\\')
srcFilePath.DeleteBack();
const DWORD dwAttr = GetFileAttributesW(srcFilePath); // NOSONAR cpp:S6004 — FM build is pre-C++17, init-statement not available

if (dwAttr != INVALID_FILE_ATTRIBUTES)

Check warning on line 55 in CPP/7zip/UI/FileManager/App.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use the init-statement to declare "dwAttr" inside the if statement.

See more on https://sonarcloud.io/project/issues?id=mcmilk_7-Zip-zstd&issues=AZ46YdPXruoyaBABjex7&open=AZ46YdPXruoyaBABjex7&pullRequest=490
{
if (dwAttr & FILE_ATTRIBUTE_ARCHIVE)
NDir::DeleteFileIfArchive(us2fs(srcFilePath));
return;
}

const int n = srcFilePath.ReverseFind(L'\\');
if (n == -1)
return;
srcPanel.OpenParentFolder();
srcFilePath.ReleaseBuf_SetEnd(n);
}
}

void CPanelCallbackImp::OnTab()
{
if (g_App.NumPanels != 1)
Expand Down Expand Up @@ -591,7 +615,7 @@

info.Add_LF();
info += _currentFolderPrefix;

for (i = 0; i < indices.Size() && (int)i < (int)kCopyDialog_NumInfoLines - 6; i++)
{
info.Add_LF();
Expand All @@ -612,7 +636,6 @@
bool IsCorrectFsName(const UString &name);



/* Returns true, if path is path that can be used as path for File System functions
*/

Expand Down Expand Up @@ -647,6 +670,9 @@

CRecordVector<UInt32> indices;
UString destPath;
bool openOutputFolder = false;
bool deleteSourceFile = false;
bool close7Zip = false;
bool useDestPanel = false;

{
Expand Down Expand Up @@ -685,10 +711,15 @@
LangString(move ? IDS_MOVE : IDS_COPY, copyDialog.Title);
LangString(move ? IDS_MOVE_TO : IDS_COPY_TO, copyDialog.Static);
copyDialog.Info = srcPanel.GetItemsInfoString(indices);
copyDialog.CurrentFolderPrefix = srcPanel._currentFolderPrefix;

if (copyDialog.Create(srcPanel.GetParent()) != IDOK)
return;

openOutputFolder = copyDialog.OpenOutputFolder;
deleteSourceFile = copyDialog.DeleteSourceFile;
close7Zip = copyDialog.Close7Zip;

destPath = copyDialog.Value;
}

Expand Down Expand Up @@ -820,6 +851,8 @@
SaveCopyHistory(copyFolders);
}

ProgressDialog_SetError(false);

bool useSrcPanel = !useDestPanel || !srcPanel.Is_IO_FS_Folder();

bool useTemp = useSrcPanel && useDestPanel;
Expand Down Expand Up @@ -916,6 +949,24 @@
disableNotify1.Restore();
disableNotify2.Restore();
srcPanel.SetFocusToList();

if (!ProgressDialog_HadError() && result == S_OK)
{
if (openOutputFolder && NFind::DoesDirExist_FollowLink(us2fs(destPath)))
{
StartApplicationDontWait(destPath, destPath, _window);
}
if (deleteSourceFile)
{
UString srcFilePath(srcPanel._currentFolderPrefix);
srcPanel.OpenParentFolder();
DeleteSourceArchive_WalkUp(srcPanel, srcFilePath);
}
if (close7Zip)
{
PostMessage(_window, WM_CLOSE, 0, 0);
}
}
}

void CApp::OnSetSameFolder(unsigned srcPanelIndex)
Expand Down
77 changes: 76 additions & 1 deletion CPP/7zip/UI/FileManager/BrowseDialog.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// BrowseDialog.cpp

#include "StdAfx.h"

#include <array>

#include "../../../Common/MyWindows.h"

#include "../../../Common/IntToString.h"
Expand Down Expand Up @@ -566,6 +568,79 @@
return s;
}


// "<N>.<NN> <unit>B" with 2 decimals, or "<N> B".
void FreeSpace_ConvertSizeToString(UInt64 v, wchar_t *s);
void FreeSpace_ConvertSizeToString(UInt64 v, wchar_t *s)
{
unsigned shift = 0;
wchar_t unit = 0;
if (v >= ((UInt64)1 << 50)) { shift = 50; unit = 'P'; }
else if (v >= ((UInt64)1 << 40)) { shift = 40; unit = 'T'; }
else if (v >= ((UInt64)1 << 30)) { shift = 30; unit = 'G'; }
else if (v >= ((UInt64)1 << 20)) { shift = 20; unit = 'M'; }
else if (v >= ((UInt64)1 << 10)) { shift = 10; unit = 'K'; }

if (unit == 0)
{
s = ConvertUInt64ToString(v, s);
*s++ = ' ';
*s++ = 'B';
*s = 0;
return;
}

const UInt64 whole = v >> shift;
UInt64 frac = ((v & (((UInt64)1 << shift) - 1)) * 100
+ ((UInt64)1 << (shift - 1))) >> shift;
if (frac >= 100)
frac = 99;

s = ConvertUInt64ToString(whole, s);
*s++ = '.';
*s++ = (wchar_t)('0' + (unsigned)(frac / 10));
*s++ = (wchar_t)('0' + (unsigned)(frac % 10));
*s++ = ' ';
*s++ = unit;
*s++ = 'B';
*s = 0;
}


// Trims path, then formats free/total.
void FormatPathFreeSpace(UString &strPath, UString &strText);
void FormatPathFreeSpace(UString &strPath, UString &strText)
{
strText.Empty();
strPath.Trim();
for (;;)
{
const DWORD attr = GetFileAttributesW(strPath); // NOSONAR cpp:S6004 — FM build is pre-C++17, init-statement not available
if (attr != INVALID_FILE_ATTRIBUTES && (attr & FILE_ATTRIBUTE_DIRECTORY))

Check warning on line 619 in CPP/7zip/UI/FileManager/BrowseDialog.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use the init-statement to declare "attr" inside the if statement.

See more on https://sonarcloud.io/project/issues?id=mcmilk_7-Zip-zstd&issues=AZ46BVIbBO_6kV5ueKGJ&open=AZ46BVIbBO_6kV5ueKGJ&pullRequest=490
break;
const int n = strPath.ReverseFind(L'\\');
if (n == -1)
return;
strPath.ReleaseBuf_SetEnd(n);
}

ULARGE_INTEGER freeBytes;
ULARGE_INTEGER totalBytes;
ULARGE_INTEGER totalFree;
if (!GetDiskFreeSpaceExW(strPath, &freeBytes, &totalBytes, &totalFree))
return;

std::array<wchar_t, 40> szFree;
std::array<wchar_t, 40> szTotal;
FreeSpace_ConvertSizeToString(totalFree.QuadPart, szFree.data());
FreeSpace_ConvertSizeToString(totalBytes.QuadPart, szTotal.data());
strText = szFree.data();
strText += L" Free (Total: ";
strText += szTotal.data();
strText += L")";
}


// Reload changes DirPrefix. Don't send DirPrefix in pathPrefix parameter

HRESULT CBrowseDialog::Reload(const UString &pathPrefix, const UString &selectedName)
Expand Down
Loading
Loading