From 6936476598bd0bdcf5fe0f9a59c12e2562b3492c Mon Sep 17 00:00:00 2001 From: Tino Reichardt Date: Thu, 18 May 2017 14:43:39 +0200 Subject: [PATCH] new feature: use CompressDialog settings for "Add to xyz.7z" - the standard 7-Zip will always use LZMA2 Level 5 - my version used always: ZStandard Level 3 - but now, it uses: the registry settings from the last CompressDialog --- CPP/7zip/UI/Common/CompressCall.cpp | 48 +++++++++++++++++++++++- CPP/7zip/UI/FileManager/ViewSettings.cpp | 2 +- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/CPP/7zip/UI/Common/CompressCall.cpp b/CPP/7zip/UI/Common/CompressCall.cpp index 7e898b60..c58c2534 100644 --- a/CPP/7zip/UI/Common/CompressCall.cpp +++ b/CPP/7zip/UI/Common/CompressCall.cpp @@ -18,6 +18,7 @@ #include "../FileManager/RegistryUtils.h" +#include "ZipRegistry.h" #include "CompressCall.h" using namespace NWindows; @@ -41,6 +42,7 @@ using namespace NWindows; #define kStopSwitchParsing " --" #define kLargePagesDisable " -slp-" +static NCompression::CInfo m_RegistryInfo; extern HWND g_HWND; UString GetQuotedString(const UString &s) @@ -176,6 +178,29 @@ static HRESULT CreateMap(const UStringVector &names, return S_OK; } +int FindRegistryFormat(const UString &name) +{ + FOR_VECTOR (i, m_RegistryInfo.Formats) + { + const NCompression::CFormatOptions &fo = m_RegistryInfo.Formats[i]; + if (name.IsEqualTo_NoCase(GetUnicodeString(fo.FormatID))) + return i; + } + return -1; +} + +int FindRegistryFormatAlways(const UString &name) +{ + int index = FindRegistryFormat(name); + if (index < 0) + { + NCompression::CFormatOptions fo; + fo.FormatID = GetSystemString(name); + index = m_RegistryInfo.Formats.Add(fo); + } + return index; +} + HRESULT CompressFiles( const UString &arcPathPrefix, const UString &arcName, @@ -186,7 +211,7 @@ HRESULT CompressFiles( { MY_TRY_BEGIN UString params ('a'); - + CFileMapping fileMapping; NSynchronization::CManualResetEvent event; params += kIncludeSwitch; @@ -194,9 +219,30 @@ HRESULT CompressFiles( if (!arcType.IsEmpty()) { + int index; params += kArchiveTypeSwitch; params += arcType; + m_RegistryInfo.Load(); + index = FindRegistryFormatAlways(arcType); + if (index >= 0) + { + char temp[32]; + const NCompression::CFormatOptions &fo = m_RegistryInfo.Formats[index]; + params += " -m0="; + params += fo.Method; + params += " -mx"; + ConvertUInt64ToString(fo.Level, temp); + params += temp; + if (fo.NumThreads) + { + params += " -mmt"; + ConvertUInt64ToString(fo.NumThreads, temp); + params += temp; + } + } } + // for testing current params, /TR 2017-05-18 + // ErrorMessage(params); if (email) params += kEmailSwitch; diff --git a/CPP/7zip/UI/FileManager/ViewSettings.cpp b/CPP/7zip/UI/FileManager/ViewSettings.cpp index 5965fcc5..b4c0e6ce 100644 --- a/CPP/7zip/UI/FileManager/ViewSettings.cpp +++ b/CPP/7zip/UI/FileManager/ViewSettings.cpp @@ -15,7 +15,7 @@ using namespace NWindows; using namespace NRegistry; -#define REG_PATH_FM TEXT("Software") TEXT(STRING_PATH_SEPARATOR) TEXT("7-Zip") TEXT(STRING_PATH_SEPARATOR) TEXT("FM") +#define REG_PATH_FM TEXT("Software") TEXT(STRING_PATH_SEPARATOR) TEXT("7-Zip-ZStandard") TEXT(STRING_PATH_SEPARATOR) TEXT("FM") static LPCTSTR const kCUBasePath = REG_PATH_FM; static LPCTSTR const kCulumnsKeyName = REG_PATH_FM TEXT(STRING_PATH_SEPARATOR) TEXT("Columns");