From a4fd9bfc81d3586e229d6b2b992e139e98fc165c Mon Sep 17 00:00:00 2001 From: R-YaTian <47445484+R-YaTian@users.noreply.github.com> Date: Mon, 13 Jan 2025 21:59:46 +0800 Subject: [PATCH] Implement Smart Extraction (#546) --- .../CPP/7zip/UI/Common/ArchiveCommandLine.cpp | 16 +++++++++++- .../SevenZip/CPP/7zip/UI/Common/Extract.cpp | 25 ++++++++++++++++++- .../SevenZip/CPP/7zip/UI/Common/Extract.h | 3 +++ .../CPP/7zip/UI/Common/ArchiveCommandLine.cpp | 14 +++++++++++ .../CPP/7zip/UI/Common/CompressCall.cpp | 9 ++++++- .../CPP/7zip/UI/Common/CompressCall.h | 5 +++- .../SevenZip/CPP/7zip/UI/Common/Extract.cpp | 23 +++++++++++++++++ .../SevenZip/CPP/7zip/UI/Common/Extract.h | 3 +++ .../CPP/7zip/UI/Explorer/ContextMenu.cpp | 20 ++++++++++++++- .../CPP/7zip/UI/Explorer/ContextMenu.h | 3 +++ .../CPP/7zip/UI/Explorer/ContextMenuFlags.h | 3 +++ .../SevenZip/CPP/7zip/UI/Explorer/resource.h | 3 +++ .../CPP/7zip/UI/Explorer/resource2.rc | 3 +++ .../CPP/7zip/UI/FileManager/MenuPage.cpp | 3 +++ NanaZip.UI.Modern/NanaZip.ShellExtension.cpp | 19 +++++++++++++- .../CPP/7zip/UI/Common/ArchiveCommandLine.cpp | 14 +++++++++++ .../CPP/7zip/UI/Common/CompressCall.cpp | 9 ++++++- .../CPP/7zip/UI/Common/CompressCall.h | 5 +++- .../SevenZip/CPP/7zip/UI/Common/Extract.cpp | 23 +++++++++++++++++ .../SevenZip/CPP/7zip/UI/Common/Extract.h | 3 +++ .../CPP/7zip/UI/Explorer/ContextMenu.cpp | 20 ++++++++++++++- .../CPP/7zip/UI/Explorer/ContextMenu.h | 3 +++ .../CPP/7zip/UI/Explorer/ContextMenuFlags.h | 3 +++ .../SevenZip/CPP/7zip/UI/Explorer/resource.h | 3 +++ .../CPP/7zip/UI/Explorer/resource2.rc | 3 +++ .../CPP/7zip/UI/FileManager/MenuPage.cpp | 3 +++ NanaZipPackage/Strings/cy/Legacy.resw | 4 --- NanaZipPackage/Strings/en/Legacy.resw | 5 +++- NanaZipPackage/Strings/it/Legacy.resw | 9 ------- NanaZipPackage/Strings/sw/Legacy.resw | 3 --- NanaZipPackage/Strings/yo-latn/Legacy.resw | 6 ----- NanaZipPackage/Strings/zh-Hans/Legacy.resw | 9 +++++++ NanaZipPackage/Strings/zh-Hant/Legacy.resw | 9 +++++++ 33 files changed, 254 insertions(+), 32 deletions(-) diff --git a/NanaZip.Core/SevenZip/CPP/7zip/UI/Common/ArchiveCommandLine.cpp b/NanaZip.Core/SevenZip/CPP/7zip/UI/Common/ArchiveCommandLine.cpp index 0c1b8d21b..d51a4efb2 100644 --- a/NanaZip.Core/SevenZip/CPP/7zip/UI/Common/ArchiveCommandLine.cpp +++ b/NanaZip.Core/SevenZip/CPP/7zip/UI/Common/ArchiveCommandLine.cpp @@ -158,6 +158,9 @@ enum Enum kUseSlashMark, kDisableWildcardParsing, kElimDup, +// **************** NanaZip Modification Start **************** + kSmartExtract, +// **************** NanaZip Modification End **************** kFullPathMode, kHardLinks, @@ -309,6 +312,9 @@ static const CSwitchForm kSwitchForms[] = { "spm", SWFRM_STRING_SINGL(0) }, { "spd", SWFRM_SIMPLE }, { "spe", SWFRM_MINUS }, +// **************** NanaZip Modification Start **************** + { "sps", SWFRM_MINUS }, +// **************** NanaZip Modification End **************** { "spf", SWFRM_STRING_SINGL(0) }, { "snh", SWFRM_MINUS }, @@ -1329,7 +1335,15 @@ void CArcCmdLineParser::Parse2(CArcCmdLineOptions &options) options.ExtractOptions.ElimDup.Def = true; options.ExtractOptions.ElimDup.Val = !parser[NKey::kElimDup].WithMinus; } - + + // **************** NanaZip Modification Start **************** + if (parser[NKey::kSmartExtract].ThereIs) + { + options.ExtractOptions.SmartExtract.Def = true; + options.ExtractOptions.SmartExtract.Val = !parser[NKey::kSmartExtract].WithMinus; + } + // **************** NanaZip Modification End **************** + NWildcard::ECensorPathMode censorPathMode = NWildcard::k_RelatPath; bool fullPathMode = parser[NKey::kFullPathMode].ThereIs; if (fullPathMode) diff --git a/NanaZip.Core/SevenZip/CPP/7zip/UI/Common/Extract.cpp b/NanaZip.Core/SevenZip/CPP/7zip/UI/Common/Extract.cpp index c7a1335b6..1db141ef7 100644 --- a/NanaZip.Core/SevenZip/CPP/7zip/UI/Common/Extract.cpp +++ b/NanaZip.Core/SevenZip/CPP/7zip/UI/Common/Extract.cpp @@ -155,7 +155,30 @@ static HRESULT DecompressArchive( realIndices.Add(i); } - + + // **************** NanaZip Modification Start **************** + if (options.SmartExtract.Val) + { + UInt32 firstLevelCount = 0; + for (UInt32 i = 0; i < numItems; i++) + { + RINOK(arc.GetItem(i, item)); + const UString &path = + #ifdef SUPPORT_ALT_STREAMS + item.MainPath; + #else + item.Path; + #endif + if (path.Find(L'/') == -1 && path.Find(L'\\') == -1) + firstLevelCount++; + if (firstLevelCount > 1) + break; + } + if (firstLevelCount > 1) + outDir += replaceName; + } + // **************** NanaZip Modification End **************** + if (realIndices.Size() == 0) { callback->ThereAreNoFiles(); diff --git a/NanaZip.Core/SevenZip/CPP/7zip/UI/Common/Extract.h b/NanaZip.Core/SevenZip/CPP/7zip/UI/Common/Extract.h index 0e88cf88a..e3af4b168 100644 --- a/NanaZip.Core/SevenZip/CPP/7zip/UI/Common/Extract.h +++ b/NanaZip.Core/SevenZip/CPP/7zip/UI/Common/Extract.h @@ -17,6 +17,9 @@ struct CExtractOptionsBase { CBoolPair ElimDup; +// **************** NanaZip Modification Start **************** + CBoolPair SmartExtract; +// **************** NanaZip Modification End **************** bool ExcludeDirItems; bool ExcludeFileItems; diff --git a/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Common/ArchiveCommandLine.cpp b/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Common/ArchiveCommandLine.cpp index 343e268b6..40a8f3f24 100644 --- a/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Common/ArchiveCommandLine.cpp +++ b/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Common/ArchiveCommandLine.cpp @@ -154,6 +154,9 @@ enum Enum kUseSlashMark, kDisableWildcardParsing, kElimDup, +// **************** NanaZip Modification Start **************** + kSmartExtract, +// **************** NanaZip Modification End **************** kFullPathMode, kHardLinks, @@ -302,6 +305,9 @@ static const CSwitchForm kSwitchForms[] = { "spm", SWFRM_STRING_SINGL(0) }, { "spd", SWFRM_SIMPLE }, { "spe", SWFRM_MINUS }, +// **************** NanaZip Modification Start **************** + { "sps", SWFRM_MINUS }, +// **************** NanaZip Modification End **************** { "spf", SWFRM_STRING_SINGL(0) }, { "snh", SWFRM_MINUS }, @@ -1256,6 +1262,14 @@ void CArcCmdLineParser::Parse2(CArcCmdLineOptions &options) options.ExtractOptions.ElimDup.Val = !parser[NKey::kElimDup].WithMinus; } + // **************** NanaZip Modification Start **************** + if (parser[NKey::kSmartExtract].ThereIs) + { + options.ExtractOptions.SmartExtract.Def = true; + options.ExtractOptions.SmartExtract.Val = !parser[NKey::kSmartExtract].WithMinus; + } + // **************** NanaZip Modification End **************** + NWildcard::ECensorPathMode censorPathMode = NWildcard::k_RelatPath; bool fullPathMode = parser[NKey::kFullPathMode].ThereIs; if (fullPathMode) diff --git a/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Common/CompressCall.cpp b/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Common/CompressCall.cpp index a134631f2..1a3bb29c6 100644 --- a/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Common/CompressCall.cpp +++ b/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Common/CompressCall.cpp @@ -334,7 +334,10 @@ static void ExtractGroupCommand(const UStringVector &arcPaths, UString ¶ms, ErrorMessageHRESULT(result); } -void ExtractArchives(const UStringVector &arcPaths, const UString &outFolder, bool showDialog, bool elimDup, UInt32 writeZone) +// **************** NanaZip Modification Start **************** +// void ExtractArchives(const UStringVector &arcPaths, const UString &outFolder, bool showDialog, bool elimDup, UInt32 writeZone); +void ExtractArchives(const UStringVector &arcPaths, const UString &outFolder, bool showDialog, bool elimDup, UInt32 writeZone, bool smartExtract) +// **************** NanaZip Modification End **************** { MY_TRY_BEGIN UString params ('x'); @@ -345,6 +348,10 @@ void ExtractArchives(const UStringVector &arcPaths, const UString &outFolder, bo } if (elimDup) params += " -spe"; + // **************** NanaZip Modification Start **************** + if (smartExtract) + params += " -sps"; + // **************** NanaZip Modification End **************** if (writeZone != (UInt32)(Int32)-1) { params += " -snz"; diff --git a/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Common/CompressCall.h b/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Common/CompressCall.h index 53b3d1df1..4ca742228 100644 --- a/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Common/CompressCall.h +++ b/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Common/CompressCall.h @@ -15,7 +15,10 @@ HRESULT CompressFiles( const UStringVector &names, bool email, bool showDialog, bool waitFinish); -void ExtractArchives(const UStringVector &arcPaths, const UString &outFolder, bool showDialog, bool elimDup, UInt32 writeZone); +// **************** NanaZip Modification Start **************** +// void ExtractArchives(const UStringVector &arcPaths, const UString &outFolder, bool showDialog, bool elimDup, UInt32 writeZone); +void ExtractArchives(const UStringVector &arcPaths, const UString &outFolder, bool showDialog, bool elimDup, UInt32 writeZone, bool smartExtract = false); +// **************** NanaZip Modification End **************** void TestArchives(const UStringVector &arcPaths, bool hashMode = false); void CalcChecksum(const UStringVector &paths, diff --git a/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Common/Extract.cpp b/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Common/Extract.cpp index 1d723e4a4..363a9a54e 100644 --- a/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Common/Extract.cpp +++ b/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Common/Extract.cpp @@ -157,6 +157,29 @@ static HRESULT DecompressArchive( realIndices.Add(i); } + // **************** NanaZip Modification Start **************** + if (options.SmartExtract.Val) + { + UInt32 firstLevelCount = 0; + for (UInt32 i = 0; i < numItems; i++) + { + RINOK(arc.GetItem(i, item)); + const UString &path = + #ifdef SUPPORT_ALT_STREAMS + item.MainPath; + #else + item.Path; + #endif + if (path.Find(L'/') == -1 && path.Find(L'\\') == -1) + firstLevelCount++; + if (firstLevelCount > 1) + break; + } + if (firstLevelCount > 1) + outDir += replaceName; + } + // **************** NanaZip Modification End **************** + if (realIndices.Size() == 0) { callback->ThereAreNoFiles(); diff --git a/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Common/Extract.h b/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Common/Extract.h index fd47ec468..5955245ff 100644 --- a/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Common/Extract.h +++ b/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Common/Extract.h @@ -17,6 +17,9 @@ struct CExtractOptionsBase { CBoolPair ElimDup; +// **************** NanaZip Modification Start **************** + CBoolPair SmartExtract; +// **************** NanaZip Modification End **************** bool ExcludeDirItems; bool ExcludeFileItems; diff --git a/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Explorer/ContextMenu.cpp b/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Explorer/ContextMenu.cpp index eb7454ac8..e9e6ad4dd 100644 --- a/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Explorer/ContextMenu.cpp +++ b/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Explorer/ContextMenu.cpp @@ -214,6 +214,9 @@ static const CContextMenuCommand g_Commands[] = CMD_REC( kOpen, "Open", IDS_CONTEXT_OPEN), CMD_REC( kExtract, "Extract", IDS_CONTEXT_EXTRACT), CMD_REC( kExtractHere, "ExtractHere", IDS_CONTEXT_EXTRACT_HERE), + // **************** NanaZip Modification Start **************** + CMD_REC( kExtractHereSmart, "ExtractHereSmart", IDS_CONTEXT_EXTRACT_HERE_SMART), + // **************** NanaZip Modification End **************** CMD_REC( kExtractTo, "ExtractTo", IDS_CONTEXT_EXTRACT_TO), CMD_REC( kTest, "Test", IDS_CONTEXT_TEST), CMD_REC( kCompress, "Compress", IDS_CONTEXT_COMPRESS), @@ -753,6 +756,17 @@ STDMETHODIMP CZipContextMenu::QueryContextMenu(HMENU hMenu, UINT indexMenu, MyInsertMenu(popupMenu, subIndex++, currentCommandID++, mainString, bitmap); } + // **************** NanaZip Modification Start **************** + if ((contextMenuFlags & NContextMenuFlags::kExtractHereSmart) != 0) + { + // Extract Here + CCommandMapItem cmi; + cmi.Folder = baseFolder; + AddCommand(kExtractHereSmart, mainString, cmi); + MyInsertMenu(popupMenu, subIndex++, currentCommandID++, mainString, bitmap); + } + // **************** NanaZip Modification End **************** + if ((contextMenuFlags & NContextMenuFlags::kExtractTo) != 0) { // Extract To @@ -1179,15 +1193,19 @@ HRESULT CZipContextMenu::InvokeCommandCommon(const CCommandMapItem &cmi) } case kExtract: case kExtractHere: + // **************** NanaZip Modification Start **************** + case kExtractHereSmart: case kExtractTo: { ExtractArchives(_fileNames, cmi.Folder, (cmdID == kExtract), // showDialog (cmdID == kExtractTo) && _elimDup.Val, // elimDup - _writeZone + _writeZone, + (cmdID == kExtractHereSmart) ); break; } + // **************** NanaZip Modification End **************** case kTest: { TestArchives(_fileNames); diff --git a/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Explorer/ContextMenu.h b/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Explorer/ContextMenu.h index 93067abb3..59d103a73 100644 --- a/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Explorer/ContextMenu.h +++ b/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Explorer/ContextMenu.h @@ -38,6 +38,9 @@ class CZipContextMenu: kOpen, kExtract, kExtractHere, + // **************** NanaZip Modification Start **************** + kExtractHereSmart, + // **************** NanaZip Modification End **************** kExtractTo, kTest, kCompress, diff --git a/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Explorer/ContextMenuFlags.h b/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Explorer/ContextMenuFlags.h index a0e1a71d3..1786b8364 100644 --- a/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Explorer/ContextMenuFlags.h +++ b/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Explorer/ContextMenuFlags.h @@ -8,6 +8,9 @@ namespace NContextMenuFlags const UInt32 kExtract = 1 << 0; const UInt32 kExtractHere = 1 << 1; const UInt32 kExtractTo = 1 << 2; +// **************** NanaZip Modification Start **************** + const UInt32 kExtractHereSmart = 1 << 3; +// **************** NanaZip Modification End **************** const UInt32 kTest = 1 << 4; const UInt32 kOpen = 1 << 5; diff --git a/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Explorer/resource.h b/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Explorer/resource.h index da02337b4..2fdf9e8a5 100644 --- a/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Explorer/resource.h +++ b/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Explorer/resource.h @@ -9,5 +9,8 @@ #define IDS_CONTEXT_COMPRESS_TO 2328 #define IDS_CONTEXT_COMPRESS_EMAIL 2329 #define IDS_CONTEXT_COMPRESS_TO_EMAIL 2330 +// **************** NanaZip Modification Start **************** +#define IDS_CONTEXT_EXTRACT_HERE_SMART 2331 +// **************** NanaZip Modification End **************** #define IDB_MENU_LOGO 190 diff --git a/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Explorer/resource2.rc b/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Explorer/resource2.rc index 2cde945a6..fe683f354 100644 --- a/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Explorer/resource2.rc +++ b/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Explorer/resource2.rc @@ -9,6 +9,9 @@ BEGIN IDS_CONTEXT_COMPRESS "Add to archive..." IDS_CONTEXT_TEST "Test archive" IDS_CONTEXT_EXTRACT_HERE "Extract Here" + // **************** NanaZip Modification Start **************** + IDS_CONTEXT_EXTRACT_HERE_SMART "Extract Here (Smart)" + // **************** NanaZip Modification End **************** IDS_CONTEXT_EXTRACT_TO "Extract to {0}" IDS_CONTEXT_COMPRESS_TO "Add to {0}" IDS_CONTEXT_COMPRESS_EMAIL "Compress and email..." diff --git a/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/FileManager/MenuPage.cpp b/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/FileManager/MenuPage.cpp index d5914aa3d..3168a9aaa 100644 --- a/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/FileManager/MenuPage.cpp +++ b/NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/FileManager/MenuPage.cpp @@ -57,6 +57,9 @@ static const CContextMenuItem kMenuItems[] = { IDS_CONTEXT_EXTRACT, kExtract }, { IDS_CONTEXT_EXTRACT_HERE, kExtractHere }, +// **************** NanaZip Modification Start **************** + { IDS_CONTEXT_EXTRACT_HERE_SMART, kExtractHereSmart }, +// **************** NanaZip Modification End **************** { IDS_CONTEXT_EXTRACT_TO, kExtractTo }, { IDS_CONTEXT_COMPRESS, kCompress }, diff --git a/NanaZip.UI.Modern/NanaZip.ShellExtension.cpp b/NanaZip.UI.Modern/NanaZip.ShellExtension.cpp index 229a15232..806534025 100644 --- a/NanaZip.UI.Modern/NanaZip.ShellExtension.cpp +++ b/NanaZip.UI.Modern/NanaZip.ShellExtension.cpp @@ -180,6 +180,7 @@ namespace NanaZip::ShellExtension Extract, ExtractHere, + ExtractHereSmart, ExtractTo, Compress, @@ -442,6 +443,7 @@ namespace NanaZip::ShellExtension } case CommandID::Extract: case CommandID::ExtractHere: + case CommandID::ExtractHereSmart: case CommandID::ExtractTo: { if (!NeedExtract) @@ -461,7 +463,8 @@ namespace NanaZip::ShellExtension (this->m_CommandID == CommandID::Extract), ((this->m_CommandID == CommandID::ExtractTo) && this->m_ElimDup.Val), - this->m_WriteZone); + this->m_WriteZone, + (this->m_CommandID == CommandID::ExtractHereSmart)); break; } @@ -765,6 +768,20 @@ namespace NanaZip::ShellExtension ContextMenuWriteZone)); } + if (ContextMenuFlags & NContextMenuFlags::kExtractHereSmart) + { + UString TranslatedString; + LangString(IDS_CONTEXT_EXTRACT_HERE_SMART, TranslatedString); + this->m_SubCommands.push_back( + winrt::make( + std::wstring( + TranslatedString.Ptr(), + TranslatedString.Len()), + CommandID::ExtractHereSmart, + ContextMenuElimDup, + ContextMenuWriteZone)); + } + if (ContextMenuFlags & NContextMenuFlags::kExtractTo) { UString TranslatedString; diff --git a/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Common/ArchiveCommandLine.cpp b/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Common/ArchiveCommandLine.cpp index 343e268b6..40a8f3f24 100644 --- a/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Common/ArchiveCommandLine.cpp +++ b/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Common/ArchiveCommandLine.cpp @@ -154,6 +154,9 @@ enum Enum kUseSlashMark, kDisableWildcardParsing, kElimDup, +// **************** NanaZip Modification Start **************** + kSmartExtract, +// **************** NanaZip Modification End **************** kFullPathMode, kHardLinks, @@ -302,6 +305,9 @@ static const CSwitchForm kSwitchForms[] = { "spm", SWFRM_STRING_SINGL(0) }, { "spd", SWFRM_SIMPLE }, { "spe", SWFRM_MINUS }, +// **************** NanaZip Modification Start **************** + { "sps", SWFRM_MINUS }, +// **************** NanaZip Modification End **************** { "spf", SWFRM_STRING_SINGL(0) }, { "snh", SWFRM_MINUS }, @@ -1256,6 +1262,14 @@ void CArcCmdLineParser::Parse2(CArcCmdLineOptions &options) options.ExtractOptions.ElimDup.Val = !parser[NKey::kElimDup].WithMinus; } + // **************** NanaZip Modification Start **************** + if (parser[NKey::kSmartExtract].ThereIs) + { + options.ExtractOptions.SmartExtract.Def = true; + options.ExtractOptions.SmartExtract.Val = !parser[NKey::kSmartExtract].WithMinus; + } + // **************** NanaZip Modification End **************** + NWildcard::ECensorPathMode censorPathMode = NWildcard::k_RelatPath; bool fullPathMode = parser[NKey::kFullPathMode].ThereIs; if (fullPathMode) diff --git a/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Common/CompressCall.cpp b/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Common/CompressCall.cpp index c7903903e..fcb1f153c 100644 --- a/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Common/CompressCall.cpp +++ b/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Common/CompressCall.cpp @@ -334,7 +334,10 @@ static void ExtractGroupCommand(const UStringVector &arcPaths, UString ¶ms, ErrorMessageHRESULT(result); } -void ExtractArchives(const UStringVector &arcPaths, const UString &outFolder, bool showDialog, bool elimDup, UInt32 writeZone) +// **************** NanaZip Modification Start **************** +// void ExtractArchives(const UStringVector &arcPaths, const UString &outFolder, bool showDialog, bool elimDup, UInt32 writeZone); +void ExtractArchives(const UStringVector &arcPaths, const UString &outFolder, bool showDialog, bool elimDup, UInt32 writeZone, bool smartExtract) +// **************** NanaZip Modification End **************** { MY_TRY_BEGIN UString params ('x'); @@ -345,6 +348,10 @@ void ExtractArchives(const UStringVector &arcPaths, const UString &outFolder, bo } if (elimDup) params += " -spe"; + // **************** NanaZip Modification Start **************** + if (smartExtract) + params += " -sps"; + // **************** NanaZip Modification End **************** if (writeZone != (UInt32)(Int32)-1) { params += " -snz"; diff --git a/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Common/CompressCall.h b/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Common/CompressCall.h index 53b3d1df1..4ca742228 100644 --- a/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Common/CompressCall.h +++ b/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Common/CompressCall.h @@ -15,7 +15,10 @@ HRESULT CompressFiles( const UStringVector &names, bool email, bool showDialog, bool waitFinish); -void ExtractArchives(const UStringVector &arcPaths, const UString &outFolder, bool showDialog, bool elimDup, UInt32 writeZone); +// **************** NanaZip Modification Start **************** +// void ExtractArchives(const UStringVector &arcPaths, const UString &outFolder, bool showDialog, bool elimDup, UInt32 writeZone); +void ExtractArchives(const UStringVector &arcPaths, const UString &outFolder, bool showDialog, bool elimDup, UInt32 writeZone, bool smartExtract = false); +// **************** NanaZip Modification End **************** void TestArchives(const UStringVector &arcPaths, bool hashMode = false); void CalcChecksum(const UStringVector &paths, diff --git a/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Common/Extract.cpp b/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Common/Extract.cpp index 1d723e4a4..363a9a54e 100644 --- a/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Common/Extract.cpp +++ b/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Common/Extract.cpp @@ -157,6 +157,29 @@ static HRESULT DecompressArchive( realIndices.Add(i); } + // **************** NanaZip Modification Start **************** + if (options.SmartExtract.Val) + { + UInt32 firstLevelCount = 0; + for (UInt32 i = 0; i < numItems; i++) + { + RINOK(arc.GetItem(i, item)); + const UString &path = + #ifdef SUPPORT_ALT_STREAMS + item.MainPath; + #else + item.Path; + #endif + if (path.Find(L'/') == -1 && path.Find(L'\\') == -1) + firstLevelCount++; + if (firstLevelCount > 1) + break; + } + if (firstLevelCount > 1) + outDir += replaceName; + } + // **************** NanaZip Modification End **************** + if (realIndices.Size() == 0) { callback->ThereAreNoFiles(); diff --git a/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Common/Extract.h b/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Common/Extract.h index fd47ec468..5955245ff 100644 --- a/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Common/Extract.h +++ b/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Common/Extract.h @@ -17,6 +17,9 @@ struct CExtractOptionsBase { CBoolPair ElimDup; +// **************** NanaZip Modification Start **************** + CBoolPair SmartExtract; +// **************** NanaZip Modification End **************** bool ExcludeDirItems; bool ExcludeFileItems; diff --git a/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Explorer/ContextMenu.cpp b/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Explorer/ContextMenu.cpp index cf9f36469..a804dc321 100644 --- a/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Explorer/ContextMenu.cpp +++ b/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Explorer/ContextMenu.cpp @@ -214,6 +214,9 @@ static const CContextMenuCommand g_Commands[] = CMD_REC( kOpen, "Open", IDS_CONTEXT_OPEN), CMD_REC( kExtract, "Extract", IDS_CONTEXT_EXTRACT), CMD_REC( kExtractHere, "ExtractHere", IDS_CONTEXT_EXTRACT_HERE), + // **************** NanaZip Modification Start **************** + CMD_REC( kExtractHereSmart, "ExtractHereSmart", IDS_CONTEXT_EXTRACT_HERE_SMART), + // **************** NanaZip Modification End **************** CMD_REC( kExtractTo, "ExtractTo", IDS_CONTEXT_EXTRACT_TO), CMD_REC( kTest, "Test", IDS_CONTEXT_TEST), CMD_REC( kCompress, "Compress", IDS_CONTEXT_COMPRESS), @@ -753,6 +756,17 @@ STDMETHODIMP CZipContextMenu::QueryContextMenu(HMENU hMenu, UINT indexMenu, MyInsertMenu(popupMenu, subIndex++, currentCommandID++, mainString, bitmap); } + // **************** NanaZip Modification Start **************** + if ((contextMenuFlags & NContextMenuFlags::kExtractHereSmart) != 0) + { + // Extract Here + CCommandMapItem cmi; + cmi.Folder = baseFolder; + AddCommand(kExtractHereSmart, mainString, cmi); + MyInsertMenu(popupMenu, subIndex++, currentCommandID++, mainString, bitmap); + } + // **************** NanaZip Modification End **************** + if ((contextMenuFlags & NContextMenuFlags::kExtractTo) != 0) { // Extract To @@ -1179,15 +1193,19 @@ HRESULT CZipContextMenu::InvokeCommandCommon(const CCommandMapItem &cmi) } case kExtract: case kExtractHere: + // **************** NanaZip Modification Start **************** + case kExtractHereSmart: case kExtractTo: { ExtractArchives(_fileNames, cmi.Folder, (cmdID == kExtract), // showDialog (cmdID == kExtractTo) && _elimDup.Val, // elimDup - _writeZone + _writeZone, + (cmdID == kExtractHereSmart) ); break; } + // **************** NanaZip Modification End **************** case kTest: { TestArchives(_fileNames); diff --git a/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Explorer/ContextMenu.h b/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Explorer/ContextMenu.h index 93067abb3..59d103a73 100644 --- a/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Explorer/ContextMenu.h +++ b/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Explorer/ContextMenu.h @@ -38,6 +38,9 @@ class CZipContextMenu: kOpen, kExtract, kExtractHere, + // **************** NanaZip Modification Start **************** + kExtractHereSmart, + // **************** NanaZip Modification End **************** kExtractTo, kTest, kCompress, diff --git a/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Explorer/ContextMenuFlags.h b/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Explorer/ContextMenuFlags.h index a0e1a71d3..1786b8364 100644 --- a/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Explorer/ContextMenuFlags.h +++ b/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Explorer/ContextMenuFlags.h @@ -8,6 +8,9 @@ namespace NContextMenuFlags const UInt32 kExtract = 1 << 0; const UInt32 kExtractHere = 1 << 1; const UInt32 kExtractTo = 1 << 2; +// **************** NanaZip Modification Start **************** + const UInt32 kExtractHereSmart = 1 << 3; +// **************** NanaZip Modification End **************** const UInt32 kTest = 1 << 4; const UInt32 kOpen = 1 << 5; diff --git a/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Explorer/resource.h b/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Explorer/resource.h index da02337b4..2fdf9e8a5 100644 --- a/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Explorer/resource.h +++ b/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Explorer/resource.h @@ -9,5 +9,8 @@ #define IDS_CONTEXT_COMPRESS_TO 2328 #define IDS_CONTEXT_COMPRESS_EMAIL 2329 #define IDS_CONTEXT_COMPRESS_TO_EMAIL 2330 +// **************** NanaZip Modification Start **************** +#define IDS_CONTEXT_EXTRACT_HERE_SMART 2331 +// **************** NanaZip Modification End **************** #define IDB_MENU_LOGO 190 diff --git a/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Explorer/resource2.rc b/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Explorer/resource2.rc index 2cde945a6..fe683f354 100644 --- a/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Explorer/resource2.rc +++ b/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Explorer/resource2.rc @@ -9,6 +9,9 @@ BEGIN IDS_CONTEXT_COMPRESS "Add to archive..." IDS_CONTEXT_TEST "Test archive" IDS_CONTEXT_EXTRACT_HERE "Extract Here" + // **************** NanaZip Modification Start **************** + IDS_CONTEXT_EXTRACT_HERE_SMART "Extract Here (Smart)" + // **************** NanaZip Modification End **************** IDS_CONTEXT_EXTRACT_TO "Extract to {0}" IDS_CONTEXT_COMPRESS_TO "Add to {0}" IDS_CONTEXT_COMPRESS_EMAIL "Compress and email..." diff --git a/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/FileManager/MenuPage.cpp b/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/FileManager/MenuPage.cpp index d5914aa3d..3168a9aaa 100644 --- a/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/FileManager/MenuPage.cpp +++ b/NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/FileManager/MenuPage.cpp @@ -57,6 +57,9 @@ static const CContextMenuItem kMenuItems[] = { IDS_CONTEXT_EXTRACT, kExtract }, { IDS_CONTEXT_EXTRACT_HERE, kExtractHere }, +// **************** NanaZip Modification Start **************** + { IDS_CONTEXT_EXTRACT_HERE_SMART, kExtractHereSmart }, +// **************** NanaZip Modification End **************** { IDS_CONTEXT_EXTRACT_TO, kExtractTo }, { IDS_CONTEXT_COMPRESS, kCompress }, diff --git a/NanaZipPackage/Strings/cy/Legacy.resw b/NanaZipPackage/Strings/cy/Legacy.resw index c23c82973..1b7bc4c83 100644 --- a/NanaZipPackage/Strings/cy/Legacy.resw +++ b/NanaZipPackage/Strings/cy/Legacy.resw @@ -471,10 +471,6 @@ Mae NanaZip yn meddalwedd am ddim. Ond, gallwch cefnogi yNanaZip - - -datblygiad o NanaZip trwy cofrestru. - Mae na ddim wallau diff --git a/NanaZipPackage/Strings/en/Legacy.resw b/NanaZipPackage/Strings/en/Legacy.resw index 33c09e6cc..639de6470 100644 --- a/NanaZipPackage/Strings/en/Legacy.resw +++ b/NanaZipPackage/Strings/en/Legacy.resw @@ -591,6 +591,9 @@ Compress to {0} and email + + Extract Here (Smart) + Folders @@ -656,7 +659,7 @@ Open folder after extracting - + About NanaZip diff --git a/NanaZipPackage/Strings/it/Legacy.resw b/NanaZipPackage/Strings/it/Legacy.resw index 4c846c502..5dcce3fec 100644 --- a/NanaZipPackage/Strings/it/Legacy.resw +++ b/NanaZipPackage/Strings/it/Legacy.resw @@ -875,15 +875,6 @@ Vuoi aggiornare l'archivio? Inizio dell'archivio non confermato - - - - - - - - - Funzionalità non supportata diff --git a/NanaZipPackage/Strings/sw/Legacy.resw b/NanaZipPackage/Strings/sw/Legacy.resw index f8a928d9b..6b3618e2f 100644 --- a/NanaZipPackage/Strings/sw/Legacy.resw +++ b/NanaZipPackage/Strings/sw/Legacy.resw @@ -450,9 +450,6 @@ Ni mti - - - Aina ya hitilafu diff --git a/NanaZipPackage/Strings/yo-latn/Legacy.resw b/NanaZipPackage/Strings/yo-latn/Legacy.resw index 361461607..dbe04a436 100644 --- a/NanaZipPackage/Strings/yo-latn/Legacy.resw +++ b/NanaZipPackage/Strings/yo-latn/Legacy.resw @@ -258,12 +258,6 @@ Ala - - 960na - - - &Àkóónú... - Nípa NanaZip... diff --git a/NanaZipPackage/Strings/zh-Hans/Legacy.resw b/NanaZipPackage/Strings/zh-Hans/Legacy.resw index b5abfe3fd..a4dee5919 100644 --- a/NanaZipPackage/Strings/zh-Hans/Legacy.resw +++ b/NanaZipPackage/Strings/zh-Hans/Legacy.resw @@ -312,6 +312,9 @@ 字典大小 + + CRC + 类型 @@ -591,6 +594,9 @@ 压缩 {0} 并邮寄 + + 提取到当前位置(智能) + 文件夹 @@ -654,6 +660,9 @@ 使用小写校验值 + + 解压后打开目标文件夹 + 关于 NanaZip diff --git a/NanaZipPackage/Strings/zh-Hant/Legacy.resw b/NanaZipPackage/Strings/zh-Hant/Legacy.resw index c02815d36..6c7a9d4b3 100644 --- a/NanaZipPackage/Strings/zh-Hant/Legacy.resw +++ b/NanaZipPackage/Strings/zh-Hant/Legacy.resw @@ -312,6 +312,9 @@ 字典大小 + + CRC + 類型 @@ -591,6 +594,9 @@ 壓縮成 {0} 並郵寄 + + 解壓縮至此(自動) + 資料夾 @@ -654,6 +660,9 @@ 使用小寫字母驗證值 + + 解壓縮後開啟目標資料夾 + 關於 NanaZip