aboutsummaryrefslogtreecommitdiff
path: root/CPP/7zip/UI/GUI/CompressDialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'CPP/7zip/UI/GUI/CompressDialog.cpp')
-rw-r--r--CPP/7zip/UI/GUI/CompressDialog.cpp943
1 files changed, 790 insertions, 153 deletions
diff --git a/CPP/7zip/UI/GUI/CompressDialog.cpp b/CPP/7zip/UI/GUI/CompressDialog.cpp
index b85ae1e..c2aee6c 100644
--- a/CPP/7zip/UI/GUI/CompressDialog.cpp
+++ b/CPP/7zip/UI/GUI/CompressDialog.cpp
@@ -29,14 +29,15 @@
29extern bool g_IsNT; 29extern bool g_IsNT;
30#endif 30#endif
31 31
32#ifdef LANG
33#include "../FileManager/LangUtils.h" 32#include "../FileManager/LangUtils.h"
34#endif
35 33
36#include "CompressDialogRes.h" 34#include "CompressDialogRes.h"
37#include "ExtractRes.h" 35#include "ExtractRes.h"
36#include "resource2.h"
37
38// #define PRINT_PARAMS
38 39
39#ifdef LANG 40#ifdef Z7_LANG
40 41
41// #define IDS_OPTIONS 2100 42// #define IDS_OPTIONS 2100
42 43
@@ -88,6 +89,21 @@ static const UInt32 kSolidLog_FullSolid = 64;
88 89
89static const UInt32 kLzmaMaxDictSize = (UInt32)15 << 28; 90static const UInt32 kLzmaMaxDictSize = (UInt32)15 << 28;
90 91
92static const UINT k_Message_ArcChanged = WM_APP + 1;
93
94/*
95static const UInt32 kZstd_MAX_DictSize = (UInt32)1 << MY_ZSTD_WINDOWLOG_MAX;
96*/
97
98/* The top value for windowLog_Chain:
99 (MY_ZSTD_CHAINLOG_MAX - 1): in BT mode
100 (MY_ZSTD_CHAINLOG_MAX) : in non-BT mode. But such big value is useless in most cases.
101 So we always reduce top value to (MY_ZSTD_CHAINLOG_MAX - 1) */
102/*
103static const unsigned kMaxDictChain = MY_ZSTD_CHAINLOG_MAX - 1;
104static const UInt32 kZstd_MAX_DictSize_Chain = (UInt32)1 << kMaxDictChain;
105*/
106
91static LPCSTR const kExeExt = ".exe"; 107static LPCSTR const kExeExt = ".exe";
92 108
93static const UInt32 g_Levels[] = 109static const UInt32 g_Levels[] =
@@ -114,6 +130,7 @@ enum EMethodID
114 kDeflate, 130 kDeflate,
115 kDeflate64, 131 kDeflate64,
116 kPPMdZip, 132 kPPMdZip,
133 // kZSTD,
117 kSha256, 134 kSha256,
118 kSha1, 135 kSha1,
119 kCrc32, 136 kCrc32,
@@ -132,6 +149,7 @@ static LPCSTR const kMethodsNames[] =
132 , "Deflate" 149 , "Deflate"
133 , "Deflate64" 150 , "Deflate64"
134 , "PPMd" 151 , "PPMd"
152 // , "ZSTD"
135 , "SHA256" 153 , "SHA256"
136 , "SHA1" 154 , "SHA1"
137 , "CRC32" 155 , "CRC32"
@@ -148,6 +166,7 @@ static const EMethodID g_7zMethods[] =
148 kBZip2 166 kBZip2
149 , kDeflate 167 , kDeflate
150 , kDeflate64 168 , kDeflate64
169 // , kZSTD
151 , kCopy 170 , kCopy
152}; 171};
153 172
@@ -166,6 +185,7 @@ static const EMethodID g_ZipMethods[] =
166 kBZip2, 185 kBZip2,
167 kLZMA, 186 kLZMA,
168 kPPMdZip 187 kPPMdZip
188 // , kZSTD
169}; 189};
170 190
171static const EMethodID g_GZipMethods[] = 191static const EMethodID g_GZipMethods[] =
@@ -183,6 +203,13 @@ static const EMethodID g_XzMethods[] =
183 kLZMA2 203 kLZMA2
184}; 204};
185 205
206/*
207static const EMethodID g_ZstdMethods[] =
208{
209 kZSTD
210};
211*/
212
186static const EMethodID g_SwfcMethods[] = 213static const EMethodID g_SwfcMethods[] =
187{ 214{
188 kDeflate 215 kDeflate
@@ -236,7 +263,7 @@ struct CFormatInfo
236 bool SFX_() const { return (Flags & kFF_SFX) != 0; } 263 bool SFX_() const { return (Flags & kFF_SFX) != 0; }
237}; 264};
238 265
239#define METHODS_PAIR(x) ARRAY_SIZE(x), x 266#define METHODS_PAIR(x) Z7_ARRAY_SIZE(x), x
240 267
241static const CFormatInfo g_Formats[] = 268static const CFormatInfo g_Formats[] =
242{ 269{
@@ -282,6 +309,17 @@ static const CFormatInfo g_Formats[] =
282 METHODS_PAIR(g_XzMethods), 309 METHODS_PAIR(g_XzMethods),
283 kFF_Solid | kFF_MultiThread | kFF_MemUse 310 kFF_Solid | kFF_MultiThread | kFF_MemUse
284 }, 311 },
312 /*
313 {
314 "zstd",
315 // (1 << (MY_ZSTD_LEVEL_MAX + 1)) - 1,
316 (1 << (9 + 1)) - 1,
317 METHODS_PAIR(g_ZstdMethods),
318 // kFF_Solid |
319 kFF_MultiThread
320 | kFF_MemUse
321 },
322 */
285 { 323 {
286 "Swfc", 324 "Swfc",
287 (1 << 1) | (1 << 3) | (1 << 5) | (1 << 7) | (1 << 9), 325 (1 << 1) | (1 << 3) | (1 << 5) | (1 << 7) | (1 << 9),
@@ -312,7 +350,7 @@ static const CFormatInfo g_Formats[] =
312 350
313static bool IsMethodSupportedBySfx(int methodID) 351static bool IsMethodSupportedBySfx(int methodID)
314{ 352{
315 for (unsigned i = 0; i < ARRAY_SIZE(g_7zSfxMethods); i++) 353 for (unsigned i = 0; i < Z7_ARRAY_SIZE(g_7zSfxMethods); i++)
316 if (methodID == g_7zSfxMethods[i]) 354 if (methodID == g_7zSfxMethods[i])
317 return true; 355 return true;
318 return false; 356 return false;
@@ -370,10 +408,10 @@ void CCompressDialog::SetMethods(const CObjectVector<CCodecInfoUser> &userCodecs
370 || c.NumStreams != 1) 408 || c.NumStreams != 1)
371 continue; 409 continue;
372 unsigned k; 410 unsigned k;
373 for (k = 0; k < ARRAY_SIZE(g_7zMethods); k++) 411 for (k = 0; k < Z7_ARRAY_SIZE(g_7zMethods); k++)
374 if (c.Name.IsEqualTo_Ascii_NoCase(kMethodsNames[g_7zMethods[k]])) 412 if (c.Name.IsEqualTo_Ascii_NoCase(kMethodsNames[g_7zMethods[k]]))
375 break; 413 break;
376 if (k != ARRAY_SIZE(g_7zMethods)) 414 if (k != Z7_ARRAY_SIZE(g_7zMethods))
377 continue; 415 continue;
378 ExternalMethods.Add(c.Name); 416 ExternalMethods.Add(c.Name);
379 } 417 }
@@ -383,9 +421,9 @@ void CCompressDialog::SetMethods(const CObjectVector<CCodecInfoUser> &userCodecs
383 421
384bool CCompressDialog::OnInit() 422bool CCompressDialog::OnInit()
385{ 423{
386 #ifdef LANG 424 #ifdef Z7_LANG
387 LangSetWindowText(*this, IDD_COMPRESS); 425 LangSetWindowText(*this, IDD_COMPRESS);
388 LangSetDlgItems(*this, kLangIDs, ARRAY_SIZE(kLangIDs)); 426 LangSetDlgItems(*this, kLangIDs, Z7_ARRAY_SIZE(kLangIDs));
389 // LangSetDlgItemText(*this, IDB_COMPRESS_OPTIONS, IDS_OPTIONS); // IDG_COMPRESS_OPTIONS 427 // LangSetDlgItemText(*this, IDB_COMPRESS_OPTIONS, IDS_OPTIONS); // IDG_COMPRESS_OPTIONS
390 #endif 428 #endif
391 429
@@ -420,10 +458,21 @@ bool CCompressDialog::OnInit()
420 _default_encryptionMethod_Index = -1; 458 _default_encryptionMethod_Index = -1;
421 459
422 m_ArchivePath.Attach(GetItem(IDC_COMPRESS_ARCHIVE)); 460 m_ArchivePath.Attach(GetItem(IDC_COMPRESS_ARCHIVE));
423 m_Format.Attach(GetItem(IDC_COMPRESS_FORMAT)); 461 m_Format.Attach(GetItem(IDC_COMPRESS_FORMAT)); // that combo has CBS_SORT style in resources
424 m_Level.Attach(GetItem(IDC_COMPRESS_LEVEL)); 462 m_Level.Attach(GetItem(IDC_COMPRESS_LEVEL));
425 m_Method.Attach(GetItem(IDC_COMPRESS_METHOD)); 463 m_Method.Attach(GetItem(IDC_COMPRESS_METHOD));
426 m_Dictionary.Attach(GetItem(IDC_COMPRESS_DICTIONARY)); 464 m_Dictionary.Attach(GetItem(IDC_COMPRESS_DICTIONARY));
465
466 /*
467 {
468 RECT r;
469 GetClientRectOfItem(IDC_COMPRESS_DICTIONARY, r);
470 _dictionaryCombo_left = r.left;
471 }
472 */
473 _dictionaryCombo_left = 0; // 230;
474
475 // m_Dictionary_Chain.Attach(GetItem(IDC_COMPRESS_DICTIONARY2));
427 m_Order.Attach(GetItem(IDC_COMPRESS_ORDER)); 476 m_Order.Attach(GetItem(IDC_COMPRESS_ORDER));
428 m_Solid.Attach(GetItem(IDC_COMPRESS_SOLID)); 477 m_Solid.Attach(GetItem(IDC_COMPRESS_SOLID));
429 m_NumThreads.Attach(GetItem(IDC_COMPRESS_THREADS)); 478 m_NumThreads.Attach(GetItem(IDC_COMPRESS_THREADS));
@@ -444,13 +493,13 @@ bool CCompressDialog::OnInit()
444 UpdatePasswordControl(); 493 UpdatePasswordControl();
445 494
446 { 495 {
447 bool needSetMain = (Info.FormatIndex < 0); 496 const bool needSetMain = (Info.FormatIndex < 0);
448 FOR_VECTOR(i, ArcIndices) 497 FOR_VECTOR(i, ArcIndices)
449 { 498 {
450 unsigned arcIndex = ArcIndices[i]; 499 const unsigned arcIndex = ArcIndices[i];
451 const CArcInfoEx &ai = (*ArcFormats)[arcIndex]; 500 const CArcInfoEx &ai = (*ArcFormats)[arcIndex];
452 int index = (int)m_Format.AddString(ai.Name); 501 const int index = (int)m_Format.AddString(ai.Name);
453 m_Format.SetItemData(index, arcIndex); 502 m_Format.SetItemData(index, (LPARAM)arcIndex);
454 if (!needSetMain) 503 if (!needSetMain)
455 { 504 {
456 if (Info.FormatIndex == (int)arcIndex) 505 if (Info.FormatIndex == (int)arcIndex)
@@ -460,7 +509,7 @@ bool CCompressDialog::OnInit()
460 if (i == 0 || ai.Name.IsEqualTo_NoCase(m_RegistryInfo.ArcType)) 509 if (i == 0 || ai.Name.IsEqualTo_NoCase(m_RegistryInfo.ArcType))
461 { 510 {
462 m_Format.SetCurSel(index); 511 m_Format.SetCurSel(index);
463 Info.FormatIndex = arcIndex; 512 Info.FormatIndex = (int)arcIndex;
464 } 513 }
465 } 514 }
466 } 515 }
@@ -477,10 +526,10 @@ bool CCompressDialog::OnInit()
477 for (unsigned i = 0; i < m_RegistryInfo.ArcPaths.Size() && i < kHistorySize; i++) 526 for (unsigned i = 0; i < m_RegistryInfo.ArcPaths.Size() && i < kHistorySize; i++)
478 m_ArchivePath.AddString(m_RegistryInfo.ArcPaths[i]); 527 m_ArchivePath.AddString(m_RegistryInfo.ArcPaths[i]);
479 528
480 AddComboItems(m_UpdateMode, k_UpdateMode_IDs, ARRAY_SIZE(k_UpdateMode_IDs), 529 AddComboItems(m_UpdateMode, k_UpdateMode_IDs, Z7_ARRAY_SIZE(k_UpdateMode_IDs),
481 k_UpdateMode_Vals, Info.UpdateMode); 530 k_UpdateMode_Vals, Info.UpdateMode);
482 531
483 AddComboItems(m_PathMode, k_PathMode_IDs, ARRAY_SIZE(k_PathMode_IDs), 532 AddComboItems(m_PathMode, k_PathMode_IDs, Z7_ARRAY_SIZE(k_PathMode_IDs),
484 k_PathMode_Vals, Info.PathMode); 533 k_PathMode_Vals, Info.PathMode);
485 534
486 535
@@ -518,10 +567,10 @@ namespace NCompressDialog
518 567
519void CCompressDialog::UpdatePasswordControl() 568void CCompressDialog::UpdatePasswordControl()
520{ 569{
521 bool showPassword = IsShowPasswordChecked(); 570 const bool showPassword = IsShowPasswordChecked();
522 TCHAR c = showPassword ? (TCHAR)0: TEXT('*'); 571 const TCHAR c = showPassword ? (TCHAR)0: TEXT('*');
523 _password1Control.SetPasswordChar(c); 572 _password1Control.SetPasswordChar((WPARAM)c);
524 _password2Control.SetPasswordChar(c); 573 _password2Control.SetPasswordChar((WPARAM)c);
525 UString password; 574 UString password;
526 _password1Control.GetText(password); 575 _password1Control.GetText(password);
527 _password1Control.SetText(password); 576 _password1Control.SetText(password);
@@ -532,7 +581,7 @@ void CCompressDialog::UpdatePasswordControl()
532 _password2Control.Show_Bool(!showPassword); 581 _password2Control.Show_Bool(!showPassword);
533} 582}
534 583
535bool CCompressDialog::OnButtonClicked(int buttonID, HWND buttonHWND) 584bool CCompressDialog::OnButtonClicked(unsigned buttonID, HWND buttonHWND)
536{ 585{
537 switch (buttonID) 586 switch (buttonID)
538 { 587 {
@@ -703,13 +752,13 @@ void CCompressDialog::FormatChanged(bool isChanged)
703 752
704bool CCompressDialog::IsSFX() 753bool CCompressDialog::IsSFX()
705{ 754{
706 CWindow sfxButton = GetItem(IDX_COMPRESS_SFX); 755 return IsWindowEnabled(GetItem(IDX_COMPRESS_SFX))
707 return sfxButton.IsEnabled() && IsButtonCheckedBool(IDX_COMPRESS_SFX); 756 && IsButtonCheckedBool(IDX_COMPRESS_SFX);
708} 757}
709 758
710static int GetExtDotPos(const UString &s) 759static int GetExtDotPos(const UString &s)
711{ 760{
712 int dotPos = s.ReverseFind_Dot(); 761 const int dotPos = s.ReverseFind_Dot();
713 if (dotPos > s.ReverseFind_PathSepar() + 1) 762 if (dotPos > s.ReverseFind_PathSepar() + 1)
714 return dotPos; 763 return dotPos;
715 return -1; 764 return -1;
@@ -719,7 +768,7 @@ void CCompressDialog::OnButtonSFX()
719{ 768{
720 UString fileName; 769 UString fileName;
721 m_ArchivePath.GetText(fileName); 770 m_ArchivePath.GetText(fileName);
722 int dotPos = GetExtDotPos(fileName); 771 const int dotPos = GetExtDotPos(fileName);
723 if (IsSFX()) 772 if (IsSFX())
724 { 773 {
725 if (dotPos >= 0) 774 if (dotPos >= 0)
@@ -731,7 +780,7 @@ void CCompressDialog::OnButtonSFX()
731 { 780 {
732 if (dotPos >= 0) 781 if (dotPos >= 0)
733 { 782 {
734 UString ext = fileName.Ptr(dotPos); 783 const UString ext = fileName.Ptr(dotPos);
735 if (ext.IsEqualTo_Ascii_NoCase(kExeExt)) 784 if (ext.IsEqualTo_Ascii_NoCase(kExeExt))
736 { 785 {
737 fileName.DeleteFrom(dotPos); 786 fileName.DeleteFrom(dotPos);
@@ -744,36 +793,38 @@ void CCompressDialog::OnButtonSFX()
744 // CheckVolumeEnable(); 793 // CheckVolumeEnable();
745} 794}
746 795
747bool CCompressDialog::GetFinalPath_Smart(UString &resPath) 796
797bool CCompressDialog::GetFinalPath_Smart(UString &resPath) const
748{ 798{
799 resPath.Empty();
749 UString name; 800 UString name;
750 m_ArchivePath.GetText(name); 801 m_ArchivePath.GetText(name);
751 name.Trim(); 802 name.Trim();
752 UString tempPath = name; 803 FString fullPath;
753 if (!IsAbsolutePath(name)) 804 UString dirPrefx = DirPrefix;
754 { 805 if (dirPrefx.IsEmpty())
755 UString newDirPrefix = DirPrefix; 806 dirPrefx = StartDirPrefix;
756 if (newDirPrefix.IsEmpty()) 807 const bool res = !dirPrefx.IsEmpty() ?
757 newDirPrefix = StartDirPrefix; 808 NName::GetFullPath(us2fs(dirPrefx), us2fs(name), fullPath):
758 FString resultF; 809 NName::GetFullPath( us2fs(name), fullPath);
759 if (!MyGetFullPathName(us2fs(newDirPrefix + name), resultF)) 810 if (res)
760 return false; 811 resPath = fs2us(fullPath);
761 tempPath = fs2us(resultF); 812 return res;
762 } 813}
763 if (!SetArcPathFields(tempPath, name, false)) 814
764 return false; 815
765 FString resultF; 816bool CCompressDialog::SetArcPathFields(const UString &path)
766 if (!MyGetFullPathName(us2fs(DirPrefix + name), resultF)) 817{
767 return false; 818 UString name;
768 resPath = fs2us(resultF); 819 return SetArcPathFields(path, name, true); // always
769 return true;
770} 820}
771 821
822
772bool CCompressDialog::SetArcPathFields(const UString &path, UString &name, bool always) 823bool CCompressDialog::SetArcPathFields(const UString &path, UString &name, bool always)
773{ 824{
774 FString resDirPrefix; 825 FString resDirPrefix;
775 FString resFileName; 826 FString resFileName;
776 bool res = GetFullPathAndSplit(us2fs(path), resDirPrefix, resFileName); 827 const bool res = GetFullPathAndSplit(us2fs(path), resDirPrefix, resFileName);
777 if (res) 828 if (res)
778 { 829 {
779 DirPrefix = fs2us(resDirPrefix); 830 DirPrefix = fs2us(resDirPrefix);
@@ -791,8 +842,26 @@ bool CCompressDialog::SetArcPathFields(const UString &path, UString &name, bool
791 return res; 842 return res;
792} 843}
793 844
845
794static const wchar_t * const k_IncorrectPathMessage = L"Incorrect archive path"; 846static const wchar_t * const k_IncorrectPathMessage = L"Incorrect archive path";
795 847
848static void AddFilter(CObjectVector<CBrowseFilterInfo> &filters,
849 const UString &description, const UString &ext)
850{
851 CBrowseFilterInfo &f = filters.AddNew();
852 UString mask ("*.");
853 mask += ext;
854 f.Masks.Add(mask);
855 f.Description = description;
856 f.Description += " (";
857 f.Description += mask;
858 f.Description += ")";
859}
860
861
862static const char * const k_DontSave_Exts =
863 "xpi odt ods docx xlsx ";
864
796void CCompressDialog::OnButtonSetArchive() 865void CCompressDialog::OnButtonSetArchive()
797{ 866{
798 UString path; 867 UString path;
@@ -802,23 +871,133 @@ void CCompressDialog::OnButtonSetArchive()
802 return; 871 return;
803 } 872 }
804 873
805 UString title = LangString(IDS_COMPRESS_SET_ARCHIVE_BROWSE); 874 int filterIndex;
806 UString filterDescription = LangString(IDS_OPEN_TYPE_ALL_FILES); 875 CObjectVector<CBrowseFilterInfo> filters;
807 filterDescription += " (*.*)"; 876 unsigned numFormats = 0;
808 UString resPath; 877
809 CurrentDirWasChanged = true; 878 const bool isSFX = IsSFX();
810 if (!MyBrowseForFile(*this, title, 879 if (isSFX)
811 // DirPrefix.IsEmpty() ? NULL : (const wchar_t *)DirPrefix, 880 {
812 // NULL, 881 filterIndex = 0;
813 path, 882 const UString ext ("exe");
814 filterDescription, 883 AddFilter(filters, ext, ext);
815 NULL, // L"*.*", 884 }
816 resPath)) 885 else
886 {
887 filterIndex = m_Format.GetCurSel();
888 numFormats = (unsigned)m_Format.GetCount();
889
890 // filters [0, ... numFormats - 1] corresponds to items in m_Format combo
891 UString desc;
892 UStringVector masks;
893 CStringFinder finder;
894
895 for (unsigned i = 0; i < numFormats; i++)
896 {
897 const CArcInfoEx &ai = (*ArcFormats)[(unsigned)m_Format.GetItemData(i)];
898 CBrowseFilterInfo &f = filters.AddNew();
899 f.Description = ai.Name;
900 f.Description += " (";
901 bool needSpace_desc = false;
902
903 FOR_VECTOR (k, ai.Exts)
904 {
905 const UString &ext = ai.Exts[k].Ext;
906 UString mask ("*.");
907 mask += ext;
908
909 if (finder.FindWord_In_LowCaseAsciiList_NoCase(k_DontSave_Exts, ext))
910 continue;
911
912 f.Masks.Add(mask);
913 masks.Add(mask);
914 if (needSpace_desc)
915 f.Description.Add_Space();
916 needSpace_desc = true;
917 f.Description += ext;
918 }
919 f.Description += ")";
920 // we use only main ext in desc to reduce the size of list
921 if (i != 0)
922 desc.Add_Space();
923 desc += ai.GetMainExt();
924 }
925
926 CBrowseFilterInfo &f = filters.AddNew();
927 f.Description = LangString(IDT_COMPRESS_ARCHIVE); // IDS_ARCHIVES_COLON;
928 if (f.Description.IsEmpty())
929 GetItemText(IDT_COMPRESS_ARCHIVE, f.Description);
930 f.Description.RemoveChar(L'&');
931 // f.Description = "archive";
932 f.Description += " (";
933 f.Description += desc;
934 f.Description += ")";
935 f.Masks = masks;
936 }
937
938 AddFilter(filters, LangString(IDS_OPEN_TYPE_ALL_FILES), UString("*"));
939 if (filterIndex < 0)
940 filterIndex = (int)filters.Size() - 1;
941
942 const UString title = LangString(IDS_COMPRESS_SET_ARCHIVE_BROWSE);
943 CBrowseInfo bi;
944 bi.lpstrTitle = title;
945 bi.SaveMode = true;
946 bi.FilterIndex = filterIndex;
947 bi.hwndOwner = *this;
948 bi.FilePath = path;
949
950 if (!bi.BrowseForFile(filters))
951 return;
952
953 path = bi.FilePath;
954
955 if (isSFX)
956 {
957 const int dotPos = GetExtDotPos(path);
958 if (dotPos >= 0)
959 path.DeleteFrom(dotPos);
960 path += kExeExt;
961 }
962 else
963 // if (bi.FilterIndex >= 0)
964 // if (bi.FilterIndex != filterIndex)
965 if ((unsigned)bi.FilterIndex < numFormats)
966 {
967 // archive format was confirmed. So we try to set format extension
968 bool needAddExt = true;
969 const CArcInfoEx &ai = (*ArcFormats)[(unsigned)m_Format.GetItemData((unsigned)bi.FilterIndex)];
970 const int dotPos = GetExtDotPos(path);
971 if (dotPos >= 0)
972 {
973 const UString ext = path.Ptr(dotPos + 1);
974 if (ai.FindExtension(ext) >= 0)
975 needAddExt = false;
976 }
977 if (needAddExt)
978 {
979 if (path.IsEmpty() || path.Back() != '.')
980 path.Add_Dot();
981 path += ai.GetMainExt();
982 }
983 }
984
985 SetArcPathFields(path);
986
987 if (!isSFX)
988 if ((unsigned)bi.FilterIndex < numFormats)
989 if (bi.FilterIndex != m_Format.GetCurSel())
990 {
991 m_Format.SetCurSel(bi.FilterIndex);
992 SaveOptionsInMem();
993 FormatChanged(true); // isChanged
817 return; 994 return;
818 UString dummyName; 995 }
819 SetArcPathFields(resPath, dummyName, true); 996
997 ArcPath_WasChanged(path);
820} 998}
821 999
1000
822// in ExtractDialog.cpp 1001// in ExtractDialog.cpp
823extern void AddUniqueString(UStringVector &strings, const UString &srcString); 1002extern void AddUniqueString(UStringVector &strings, const UString &srcString);
824 1003
@@ -826,7 +1005,7 @@ static bool IsAsciiString(const UString &s)
826{ 1005{
827 for (unsigned i = 0; i < s.Len(); i++) 1006 for (unsigned i = 0; i < s.Len(); i++)
828 { 1007 {
829 wchar_t c = s[i]; 1008 const wchar_t c = s[i];
830 if (c < 0x20 || c > 0x7F) 1009 if (c < 0x20 || c > 0x7F)
831 return false; 1010 return false;
832 } 1011 }
@@ -844,6 +1023,7 @@ static void AddSize_MB(UString &s, UInt64 size)
844} 1023}
845 1024
846 1025
1026void SetErrorMessage_MemUsage(UString &s, UInt64 reqSize, UInt64 ramSize, UInt64 ramLimit, const UString &usageString);
847void SetErrorMessage_MemUsage(UString &s, UInt64 reqSize, UInt64 ramSize, UInt64 ramLimit, const UString &usageString) 1027void SetErrorMessage_MemUsage(UString &s, UInt64 reqSize, UInt64 ramSize, UInt64 ramLimit, const UString &usageString)
848{ 1028{
849 s += "The operation was blocked by 7-Zip"; 1029 s += "The operation was blocked by 7-Zip";
@@ -927,6 +1107,8 @@ void CCompressDialog::OnOK()
927 } 1107 }
928 1108
929 SaveOptionsInMem(); 1109 SaveOptionsInMem();
1110
1111 UStringVector arcPaths;
930 { 1112 {
931 UString s; 1113 UString s;
932 if (!GetFinalPath_Smart(s)) 1114 if (!GetFinalPath_Smart(s))
@@ -934,17 +1116,16 @@ void CCompressDialog::OnOK()
934 ShowErrorMessage(*this, k_IncorrectPathMessage); 1116 ShowErrorMessage(*this, k_IncorrectPathMessage);
935 return; 1117 return;
936 } 1118 }
937
938 m_RegistryInfo.ArcPaths.Clear();
939 AddUniqueString(m_RegistryInfo.ArcPaths, s);
940 Info.ArcPath = s; 1119 Info.ArcPath = s;
1120 AddUniqueString(arcPaths, s);
941 } 1121 }
942 1122
943 Info.UpdateMode = (NCompressDialog::NUpdateMode::EEnum)k_UpdateMode_Vals[m_UpdateMode.GetCurSel()];; 1123 Info.UpdateMode = (NCompressDialog::NUpdateMode::EEnum)k_UpdateMode_Vals[m_UpdateMode.GetCurSel()];
944 Info.PathMode = (NWildcard::ECensorPathMode)k_PathMode_Vals[m_PathMode.GetCurSel()]; 1124 Info.PathMode = (NWildcard::ECensorPathMode)k_PathMode_Vals[m_PathMode.GetCurSel()];
945 1125
946 Info.Level = GetLevelSpec(); 1126 Info.Level = GetLevelSpec();
947 Info.Dict64 = GetDictSpec(); 1127 Info.Dict64 = GetDictSpec();
1128 // Info.Dict64_Chain = GetDictChainSpec();
948 Info.Order = GetOrderSpec(); 1129 Info.Order = GetOrderSpec();
949 Info.OrderMode = GetOrderMode(); 1130 Info.OrderMode = GetOrderMode();
950 Info.NumThreads = GetNumThreadsSpec(); 1131 Info.NumThreads = GetNumThreadsSpec();
@@ -975,7 +1156,7 @@ void CCompressDialog::OnOK()
975 1156
976 Info.Method = GetMethodSpec(); 1157 Info.Method = GetMethodSpec();
977 Info.EncryptionMethod = GetEncryptionMethodSpec(); 1158 Info.EncryptionMethod = GetEncryptionMethodSpec();
978 Info.FormatIndex = GetFormatIndex(); 1159 Info.FormatIndex = (int)GetFormatIndex();
979 Info.SFXMode = IsSFX(); 1160 Info.SFXMode = IsSFX();
980 Info.OpenShareForWrite = IsButtonCheckedBool(IDX_COMPRESS_SHARED); 1161 Info.OpenShareForWrite = IsButtonCheckedBool(IDX_COMPRESS_SHARED);
981 Info.DeleteAfterCompressing = IsButtonCheckedBool(IDX_COMPRESS_DEL); 1162 Info.DeleteAfterCompressing = IsButtonCheckedBool(IDX_COMPRESS_DEL);
@@ -1040,34 +1221,83 @@ void CCompressDialog::OnOK()
1040 } 1221 }
1041 } 1222 }
1042 1223
1043 for (int i = 0; i < m_ArchivePath.GetCount(); i++)
1044 {
1045 UString sTemp;
1046 m_ArchivePath.GetLBText(i, sTemp);
1047 sTemp.Trim();
1048 AddUniqueString(m_RegistryInfo.ArcPaths, sTemp);
1049 }
1050
1051 if (m_RegistryInfo.ArcPaths.Size() > kHistorySize)
1052 m_RegistryInfo.ArcPaths.DeleteBack();
1053
1054 if (Info.FormatIndex >= 0) 1224 if (Info.FormatIndex >= 0)
1055 m_RegistryInfo.ArcType = (*ArcFormats)[Info.FormatIndex].Name; 1225 m_RegistryInfo.ArcType = (*ArcFormats)[Info.FormatIndex].Name;
1056 m_RegistryInfo.ShowPassword = IsShowPasswordChecked(); 1226 m_RegistryInfo.ShowPassword = IsShowPasswordChecked();
1057 1227
1228 FOR_VECTOR (i, m_RegistryInfo.ArcPaths)
1229 {
1230 if (arcPaths.Size() >= kHistorySize)
1231 break;
1232 AddUniqueString(arcPaths, m_RegistryInfo.ArcPaths[i]);
1233 }
1234 m_RegistryInfo.ArcPaths = arcPaths;
1235
1058 m_RegistryInfo.Save(); 1236 m_RegistryInfo.Save();
1059 1237
1060 CModalDialog::OnOK(); 1238 CModalDialog::OnOK();
1061} 1239}
1062 1240
1063#define kHelpTopic "fm/plugins/7-zip/add.htm" 1241#define kHelpTopic "fm/plugins/7-zip/add.htm"
1242#define kHelpTopic_Options "fm/plugins/7-zip/add.htm#options"
1064 1243
1065void CCompressDialog::OnHelp() 1244void CCompressDialog::OnHelp()
1066{ 1245{
1067 ShowHelpWindow(kHelpTopic); 1246 ShowHelpWindow(kHelpTopic);
1068} 1247}
1069 1248
1070bool CCompressDialog::OnCommand(int code, int itemID, LPARAM lParam) 1249
1250void CCompressDialog::ArcPath_WasChanged(const UString &path)
1251{
1252 const int dotPos = GetExtDotPos(path);
1253 if (dotPos < 0)
1254 return;
1255 const UString ext = path.Ptr(dotPos + 1);
1256 {
1257 const CArcInfoEx &ai = Get_ArcInfoEx();
1258 if (ai.FindExtension(ext) >= 0)
1259 return;
1260 }
1261
1262 const unsigned count = (unsigned)m_Format.GetCount();
1263 for (unsigned i = 0; i < count; i++)
1264 {
1265 const CArcInfoEx &ai = (*ArcFormats)[(unsigned)m_Format.GetItemData(i)];
1266 if (ai.FindExtension(ext) >= 0)
1267 {
1268 m_Format.SetCurSel(i);
1269 SaveOptionsInMem();
1270 FormatChanged(true); // isChanged
1271 return;
1272 }
1273 }
1274}
1275
1276
1277bool CCompressDialog::OnMessage(UINT message, WPARAM wParam, LPARAM lParam)
1278{
1279 switch (message)
1280 {
1281 case k_Message_ArcChanged:
1282 {
1283 // UString path;
1284 // m_ArchivePath.GetText(path);
1285 const int select = m_ArchivePath.GetCurSel();
1286 if ((unsigned)select < m_RegistryInfo.ArcPaths.Size())
1287 // if (path == m_RegistryInfo.ArcPaths[select])
1288 {
1289 const UString &path = m_RegistryInfo.ArcPaths[select];
1290 SetArcPathFields(path);
1291 // ArcPath_WasChanged(path);
1292 }
1293 return 0;
1294 }
1295 }
1296 return CModalDialog::OnMessage(message, wParam, lParam);
1297}
1298
1299
1300bool CCompressDialog::OnCommand(unsigned code, unsigned itemID, LPARAM lParam)
1071{ 1301{
1072 if (code == CBN_SELCHANGE) 1302 if (code == CBN_SELCHANGE)
1073 { 1303 {
@@ -1075,21 +1305,21 @@ bool CCompressDialog::OnCommand(int code, int itemID, LPARAM lParam)
1075 { 1305 {
1076 case IDC_COMPRESS_ARCHIVE: 1306 case IDC_COMPRESS_ARCHIVE:
1077 { 1307 {
1078 // we can 't change m_ArchivePath in that handler ! 1308 /* CBN_SELCHANGE is called before actual value of combo text will be changed.
1079 DirPrefix.Empty(); 1309 So GetText() here returns old value (before change) of combo text.
1080 SetItemText(IDT_COMPRESS_ARCHIVE_FOLDER, DirPrefix); 1310 So here we can change all controls except of m_ArchivePath.
1081 1311 */
1082 /* 1312 const int select = m_ArchivePath.GetCurSel();
1083 UString path; 1313 if ((unsigned)select < m_RegistryInfo.ArcPaths.Size())
1084 m_ArchivePath.GetText(path);
1085 m_ArchivePath.SetText(L"");
1086 if (IsAbsolutePath(path))
1087 { 1314 {
1088 UString fileName; 1315 // DirPrefix.Empty();
1089 SetArcPathFields(path, fileName); 1316 // SetItemText(IDT_COMPRESS_ARCHIVE_FOLDER, DirPrefix);
1090 SetArchiveName(fileName); 1317 const UString &path = m_RegistryInfo.ArcPaths[select];
1318 // SetArcPathFields(path);
1319 ArcPath_WasChanged(path);
1320 // we use PostMessage(k_Message_ArcChanged) here that later will change m_ArchivePath control
1321 PostMsg(k_Message_ArcChanged);
1091 } 1322 }
1092 */
1093 return true; 1323 return true;
1094 } 1324 }
1095 1325
@@ -1106,7 +1336,17 @@ bool CCompressDialog::OnCommand(int code, int itemID, LPARAM lParam)
1106 { 1336 {
1107 Get_FormatOptions().ResetForLevelChange(); 1337 Get_FormatOptions().ResetForLevelChange();
1108 1338
1109 SetMethod(); 1339 SetMethod(); // call it if level changes method
1340
1341 // call the following if level change keeps old method
1342 /*
1343 {
1344 // try to keep old method
1345 SetMethod(GetMethodID());
1346 MethodChanged();
1347 }
1348 */
1349
1110 SetSolidBlockSize(); 1350 SetSolidBlockSize();
1111 SetNumThreads(); 1351 SetNumThreads();
1112 CheckSFXNameChange(); 1352 CheckSFXNameChange();
@@ -1128,6 +1368,7 @@ bool CCompressDialog::OnCommand(int code, int itemID, LPARAM lParam)
1128 } 1368 }
1129 1369
1130 case IDC_COMPRESS_DICTIONARY: 1370 case IDC_COMPRESS_DICTIONARY:
1371 // case IDC_COMPRESS_DICTIONARY2:
1131 { 1372 {
1132 /* we want to change the reported threads for Auto line 1373 /* we want to change the reported threads for Auto line
1133 and keep selected NumThreads option 1374 and keep selected NumThreads option
@@ -1142,6 +1383,7 @@ bool CCompressDialog::OnCommand(int code, int itemID, LPARAM lParam)
1142 // SetSolidBlockSize(true); 1383 // SetSolidBlockSize(true);
1143 } 1384 }
1144 1385
1386 SetDictionary2();
1145 SetSolidBlockSize(); 1387 SetSolidBlockSize();
1146 SetNumThreads(); // we want to change the reported threads for Auto line only 1388 SetNumThreads(); // we want to change the reported threads for Auto line only
1147 SetMemoryUsage(); 1389 SetMemoryUsage();
@@ -1149,7 +1391,12 @@ bool CCompressDialog::OnCommand(int code, int itemID, LPARAM lParam)
1149 } 1391 }
1150 1392
1151 case IDC_COMPRESS_ORDER: 1393 case IDC_COMPRESS_ORDER:
1394 {
1395 #ifdef PRINT_PARAMS
1396 Print_Params();
1397 #endif
1152 return true; 1398 return true;
1399 }
1153 1400
1154 case IDC_COMPRESS_SOLID: 1401 case IDC_COMPRESS_SOLID:
1155 { 1402 {
@@ -1199,7 +1446,7 @@ void CCompressDialog::SetArchiveName2(bool prevWasSFX)
1199 prevExtension = kExeExt; 1446 prevExtension = kExeExt;
1200 else 1447 else
1201 { 1448 {
1202 prevExtension += '.'; 1449 prevExtension.Add_Dot();
1203 prevExtension += prevArchiverInfo.GetMainExt(); 1450 prevExtension += prevArchiverInfo.GetMainExt();
1204 } 1451 }
1205 const unsigned prevExtensionLen = prevExtension.Len(); 1452 const unsigned prevExtensionLen = prevExtension.Len();
@@ -1217,7 +1464,7 @@ void CCompressDialog::SetArchiveName2(bool prevWasSFX)
1217void CCompressDialog::SetArchiveName(const UString &name) 1464void CCompressDialog::SetArchiveName(const UString &name)
1218{ 1465{
1219 UString fileName = name; 1466 UString fileName = name;
1220 Info.FormatIndex = GetFormatIndex(); 1467 Info.FormatIndex = (int)GetFormatIndex();
1221 const CArcInfoEx &ai = (*ArcFormats)[Info.FormatIndex]; 1468 const CArcInfoEx &ai = (*ArcFormats)[Info.FormatIndex];
1222 m_PrevFormat = Info.FormatIndex; 1469 m_PrevFormat = Info.FormatIndex;
1223 if (ai.Flags_KeepName()) 1470 if (ai.Flags_KeepName())
@@ -1238,7 +1485,7 @@ void CCompressDialog::SetArchiveName(const UString &name)
1238 fileName += kExeExt; 1485 fileName += kExeExt;
1239 else 1486 else
1240 { 1487 {
1241 fileName += '.'; 1488 fileName.Add_Dot();
1242 UString ext = ai.GetMainExt(); 1489 UString ext = ai.GetMainExt();
1243 if (ai.Flags_HashHandler()) 1490 if (ai.Flags_HashHandler())
1244 { 1491 {
@@ -1262,7 +1509,7 @@ int CCompressDialog::FindRegistryFormat(const UString &name)
1262 { 1509 {
1263 const NCompression::CFormatOptions &fo = m_RegistryInfo.Formats[i]; 1510 const NCompression::CFormatOptions &fo = m_RegistryInfo.Formats[i];
1264 if (name.IsEqualTo_NoCase(GetUnicodeString(fo.FormatID))) 1511 if (name.IsEqualTo_NoCase(GetUnicodeString(fo.FormatID)))
1265 return i; 1512 return (int)i;
1266 } 1513 }
1267 return -1; 1514 return -1;
1268} 1515}
@@ -1270,14 +1517,14 @@ int CCompressDialog::FindRegistryFormat(const UString &name)
1270 1517
1271unsigned CCompressDialog::FindRegistryFormat_Always(const UString &name) 1518unsigned CCompressDialog::FindRegistryFormat_Always(const UString &name)
1272{ 1519{
1273 int index = FindRegistryFormat(name); 1520 const int index = FindRegistryFormat(name);
1274 if (index < 0) 1521 if (index >= 0)
1522 return (unsigned)index;
1275 { 1523 {
1276 NCompression::CFormatOptions fo; 1524 NCompression::CFormatOptions fo;
1277 fo.FormatID = GetSystemString(name); 1525 fo.FormatID = GetSystemString(name);
1278 index = m_RegistryInfo.Formats.Add(fo); 1526 return m_RegistryInfo.Formats.Add(fo);
1279 } 1527 }
1280 return index;
1281} 1528}
1282 1529
1283 1530
@@ -1288,10 +1535,10 @@ NCompression::CFormatOptions &CCompressDialog::Get_FormatOptions()
1288} 1535}
1289 1536
1290 1537
1291int CCompressDialog::GetStaticFormatIndex() 1538unsigned CCompressDialog::GetStaticFormatIndex()
1292{ 1539{
1293 const CArcInfoEx &ai = Get_ArcInfoEx(); 1540 const CArcInfoEx &ai = Get_ArcInfoEx();
1294 for (unsigned i = 0; i < ARRAY_SIZE(g_Formats); i++) 1541 for (unsigned i = 0; i < Z7_ARRAY_SIZE(g_Formats); i++)
1295 if (ai.Name.IsEqualTo_Ascii_NoCase(g_Formats[i].Name)) 1542 if (ai.Name.IsEqualTo_Ascii_NoCase(g_Formats[i].Name))
1296 return i; 1543 return i;
1297 return 0; // -1; 1544 return 0; // -1;
@@ -1329,18 +1576,25 @@ void CCompressDialog::SetLevel2()
1329 } 1576 }
1330 } 1577 }
1331 1578
1579 const bool isZstd = ai.Is_Zstd();
1580
1332 for (unsigned i = 0; i < sizeof(UInt32) * 8; i++) 1581 for (unsigned i = 0; i < sizeof(UInt32) * 8; i++)
1333 { 1582 {
1334 const UInt32 mask = (UInt32)1 << i; 1583 const UInt32 mask = (UInt32)1 << i;
1335 if ((fi.LevelsMask & mask) != 0) 1584 if ((fi.LevelsMask & mask) != 0)
1336 { 1585 {
1337 UInt32 langID = g_Levels[i]; 1586 const UInt32 langID = g_Levels[i];
1338 UString s; 1587 UString s;
1339 s.Add_UInt32(i); 1588 s.Add_UInt32(i);
1340 s += " - "; 1589 // if (fi.LevelsMask < (1 << (MY_ZSTD_LEVEL_MAX + 1)) - 1)
1341 s += LangString(langID); 1590 if (langID)
1342 int index = (int)m_Level.AddString(s); 1591 if (i != 0 || !isZstd)
1343 m_Level.SetItemData(index, i); 1592 {
1593 s += " - ";
1594 s += LangString(langID);
1595 }
1596 const int index = (int)m_Level.AddString(s);
1597 m_Level.SetItemData(index, (LPARAM)i);
1344 } 1598 }
1345 if (fi.LevelsMask <= mask) 1599 if (fi.LevelsMask <= mask)
1346 break; 1600 break;
@@ -1354,12 +1608,11 @@ static LRESULT ComboBox_AddStringAscii(NControl::CComboBox &cb, const char *s)
1354 return cb.AddString((CSysString)s); 1608 return cb.AddString((CSysString)s);
1355} 1609}
1356 1610
1357// static const char *k_Auto = "- "; // "auto : "; 1611static const char *k_Auto_Prefix = "* ";
1358 1612
1359static void Modify_Auto(AString &s) 1613static void Modify_Auto(AString &s)
1360{ 1614{
1361 s.Insert(0, "* "); 1615 s.Insert(0, k_Auto_Prefix);
1362 // s += " -";
1363} 1616}
1364 1617
1365void CCompressDialog::SetMethod2(int keepMethodId) 1618void CCompressDialog::SetMethod2(int keepMethodId)
@@ -1370,7 +1623,8 @@ void CCompressDialog::SetMethod2(int keepMethodId)
1370 const CArcInfoEx &ai = Get_ArcInfoEx(); 1623 const CArcInfoEx &ai = Get_ArcInfoEx();
1371 if (GetLevel() == 0 && !ai.Flags_HashHandler()) 1624 if (GetLevel() == 0 && !ai.Flags_HashHandler())
1372 { 1625 {
1373 if (!ai.Is_Tar()) 1626 if (!ai.Is_Tar() &&
1627 !ai.Is_Zstd())
1374 { 1628 {
1375 MethodChanged(); 1629 MethodChanged();
1376 return; 1630 return;
@@ -1409,10 +1663,10 @@ void CCompressDialog::SetMethod2(int keepMethodId)
1409 { 1663 {
1410 if (!is7z) 1664 if (!is7z)
1411 break; 1665 break;
1412 unsigned extIndex = m - fi.NumMethods; 1666 const unsigned extIndex = m - fi.NumMethods;
1413 if (extIndex >= ExternalMethods.Size()) 1667 if (extIndex >= ExternalMethods.Size())
1414 break; 1668 break;
1415 methodID = ARRAY_SIZE(kMethodsNames) + extIndex; 1669 methodID = (int)(Z7_ARRAY_SIZE(kMethodsNames) + extIndex);
1416 method = ExternalMethods[extIndex].Ptr(); 1670 method = ExternalMethods[extIndex].Ptr();
1417 } 1671 }
1418 if (isSfx) 1672 if (isSfx)
@@ -1516,10 +1770,10 @@ UString CCompressDialog::GetMethodSpec(UString &estimatedName)
1516 UString s; 1770 UString s;
1517 if (methodId >= 0) 1771 if (methodId >= 0)
1518 { 1772 {
1519 if ((unsigned)methodId < ARRAY_SIZE(kMethodsNames)) 1773 if ((unsigned)methodId < Z7_ARRAY_SIZE(kMethodsNames))
1520 estimatedName = kMethodsNames[methodId]; 1774 estimatedName = kMethodsNames[methodId];
1521 else 1775 else
1522 estimatedName = ExternalMethods[methodId - ARRAY_SIZE(kMethodsNames)]; 1776 estimatedName = ExternalMethods[(unsigned)methodId - (unsigned)Z7_ARRAY_SIZE(kMethodsNames)];
1523 if (methodIdRaw >= 0) 1777 if (methodIdRaw >= 0)
1524 s = estimatedName; 1778 s = estimatedName;
1525 } 1779 }
@@ -1556,10 +1810,10 @@ UString CCompressDialog::GetEncryptionMethodSpec()
1556 return s; 1810 return s;
1557} 1811}
1558 1812
1559static const size_t k_Auto_Dict = (size_t)0 - 1;
1560 1813
1814static const size_t k_Auto_Dict = (size_t)0 - 1;
1561 1815
1562int CCompressDialog::AddDict2(size_t sizeReal, size_t sizeShow) 1816static int Combo_AddDict2(NWindows::NControl::CComboBox &cb, size_t sizeReal, size_t sizeShow)
1563{ 1817{
1564 char c = 0; 1818 char c = 0;
1565 unsigned moveBits = 0; 1819 unsigned moveBits = 0;
@@ -1568,43 +1822,106 @@ int CCompressDialog::AddDict2(size_t sizeReal, size_t sizeShow)
1568 AString s; 1822 AString s;
1569 s.Add_UInt64(sizeShow >> moveBits); 1823 s.Add_UInt64(sizeShow >> moveBits);
1570 s.Add_Space(); 1824 s.Add_Space();
1571 if (moveBits != 0) 1825 if (c != 0)
1572 s += c; 1826 s += c;
1573 s += 'B'; 1827 s += 'B';
1574 if (sizeReal == k_Auto_Dict) 1828 if (sizeReal == k_Auto_Dict)
1575 Modify_Auto(s); 1829 Modify_Auto(s);
1576 const int index = (int)ComboBox_AddStringAscii(m_Dictionary, s); 1830 const int index = (int)ComboBox_AddStringAscii(cb, s);
1577 m_Dictionary.SetItemData(index, sizeReal); 1831 cb.SetItemData(index, (LPARAM)sizeReal);
1578 return index; 1832 return index;
1579} 1833}
1580 1834
1835int CCompressDialog::AddDict2(size_t sizeReal, size_t sizeShow)
1836{
1837 return Combo_AddDict2(m_Dictionary, sizeReal, sizeShow);
1838}
1581 1839
1582int CCompressDialog::AddDict(size_t size) 1840int CCompressDialog::AddDict(size_t size)
1583{ 1841{
1584 return AddDict2(size, size); 1842 return AddDict2(size, size);
1585} 1843}
1586 1844
1845/*
1846int CCompressDialog::AddDict_Chain(size_t size)
1847{
1848 return Combo_AddDict2(m_Dictionary_Chain, size, size);
1849}
1850*/
1587 1851
1588void CCompressDialog::SetDictionary2() 1852void CCompressDialog::SetDictionary2()
1589{ 1853{
1590 m_Dictionary.ResetContent(); 1854 m_Dictionary.ResetContent();
1855 // m_Dictionary_Chain.ResetContent();
1856
1591 // _auto_Dict = (UInt32)1 << 24; // we can use this dictSize to calculate _auto_Solid for unknown method for 7z 1857 // _auto_Dict = (UInt32)1 << 24; // we can use this dictSize to calculate _auto_Solid for unknown method for 7z
1592 _auto_Dict = (UInt32)(Int32)-1; // for debug: 1858 _auto_Dict = (UInt32)(Int32)-1; // for debug
1859 // _auto_Dict_Chain = (UInt32)(Int32)-1; // for debug
1593 1860
1594 const CArcInfoEx &ai = Get_ArcInfoEx(); 1861 const CArcInfoEx &ai = Get_ArcInfoEx();
1595 UInt32 defaultDict = (UInt32)(Int32)-1; 1862 UInt32 defaultDict = (UInt32)(Int32)-1;
1863 // UInt32 defaultDict_Chain = (UInt32)(Int32)-1;
1596 { 1864 {
1597 const int index = FindRegistryFormat(ai.Name); 1865 const int index = FindRegistryFormat(ai.Name);
1598 if (index >= 0) 1866 if (index >= 0)
1599 { 1867 {
1600 const NCompression::CFormatOptions &fo = m_RegistryInfo.Formats[index]; 1868 const NCompression::CFormatOptions &fo = m_RegistryInfo.Formats[index];
1601 if (IsMethodEqualTo(fo.Method)) 1869 if (IsMethodEqualTo(fo.Method))
1870 {
1602 defaultDict = fo.Dictionary; 1871 defaultDict = fo.Dictionary;
1872 // defaultDict_Chain = fo.DictionaryChain;
1873 }
1603 } 1874 }
1604 } 1875 }
1605 1876
1606 const int methodID = GetMethodID(); 1877 const int methodID = GetMethodID();
1607 const UInt32 level = GetLevel2(); 1878 const UInt32 level = GetLevel2();
1879
1880 {
1881 RECT r, rLabel;
1882 GetClientRectOfItem(IDT_COMPRESS_DICTIONARY, rLabel);
1883 GetClientRectOfItem(IDC_COMPRESS_DICTIONARY, r);
1884 if (_dictionaryCombo_left == 0)
1885 _dictionaryCombo_left = r.left;
1886
1887 // bool showDict2;
1888 int newLableRight;
1889 int newDictLeft;
1890
1891 /*
1892 if (methodID == kZSTD)
1893 {
1894 showDict2 = true;
1895 newDictLeft = _dictionaryCombo_left;
1896 RECT r2;
1897 GetClientRectOfItem(IDC_COMPRESS_DICTIONARY2, r2);
1898 newLableRight = r2.left;
1899 }
1900 else
1901 */
1902 {
1903 // showDict2 = false;
1904 RECT rBig;
1905 GetClientRectOfItem(IDC_COMPRESS_METHOD, rBig);
1906 newDictLeft= rBig.left;
1907 newLableRight = newDictLeft;
1908 }
1909
1910 if (newLableRight != rLabel.right)
1911 {
1912 rLabel.right = newLableRight;
1913 MoveItem_RECT(IDT_COMPRESS_DICTIONARY, rLabel);
1914 InvalidateRect(&rLabel);
1915 }
1916 if (newDictLeft != r.left)
1917 {
1918 r.left = newDictLeft;
1919 MoveItem_RECT(IDC_COMPRESS_DICTIONARY, r);
1920 // InvalidateRect(&r);
1921 }
1922 // ShowItem_Bool(IDC_COMPRESS_DICTIONARY2, showDict2);
1923 }
1924
1608 if (methodID < 0) 1925 if (methodID < 0)
1609 return; 1926 return;
1610 1927
@@ -1659,6 +1976,86 @@ void CCompressDialog::SetDictionary2()
1659 m_Dictionary.SetCurSel(curSel); 1976 m_Dictionary.SetCurSel(curSel);
1660 break; 1977 break;
1661 } 1978 }
1979
1980 /*
1981 case kZSTD:
1982 {
1983 if (defaultDict != (UInt32)(Int32)-1 &&
1984 defaultDict > kZstd_MAX_DictSize)
1985 defaultDict = kZstd_MAX_DictSize;
1986
1987 if (defaultDict_Chain != (UInt32)(Int32)-1 &&
1988 defaultDict_Chain > kZstd_MAX_DictSize_Chain)
1989 defaultDict_Chain = kZstd_MAX_DictSize_Chain;
1990
1991 {
1992 CZstdEncProps props;
1993 ZstdEncProps_Init(&props);
1994 // props.level_zstd = level;
1995 props.level_7z = level;
1996 ZstdEncProps_Set_WindowSize(&props, defaultDict != (UInt32)(Int32)-1 ? defaultDict: 0);
1997 ZstdEncProps_NormalizeFull(&props);
1998 _auto_Dict_Chain = (UInt32)1 << props.windowLog_Chain;
1999 }
2000 {
2001 CZstdEncProps props;
2002 ZstdEncProps_Init(&props);
2003 // props.level_zstd = level;
2004 props.level_7z = level;
2005 ZstdEncProps_Set_WindowChainSize(&props, defaultDict_Chain != (UInt32)(Int32)-1 ? defaultDict_Chain: 0);
2006 ZstdEncProps_NormalizeFull(&props);
2007 _auto_Dict = (UInt32)1 << props.windowLog;
2008 }
2009
2010 // if there is collision of two window sizes, we reduce dict_Chain
2011 if (defaultDict != (UInt32)(Int32)-1 &&
2012 defaultDict_Chain != (UInt32)(Int32)-1 &&
2013 defaultDict < defaultDict_Chain)
2014 defaultDict_Chain = defaultDict;
2015
2016 {
2017 int curSel = AddDict2(k_Auto_Dict, _auto_Dict);
2018
2019 // defaultDict = 12 << 10; // for debug
2020 const UInt32 kWinStart = 18;
2021 if (defaultDict != 0 && defaultDict < ((UInt32)1 << kWinStart))
2022 curSel = AddDict(defaultDict);
2023
2024 for (unsigned i = kWinStart; i <= MY_ZSTD_WINDOWLOG_MAX; i++)
2025 {
2026 const size_t dict = (size_t)1 << i;
2027 const int index = AddDict(dict);
2028 if (defaultDict != (UInt32)(Int32)-1)
2029 if (dict <= defaultDict || curSel <= 0)
2030 curSel = index;
2031 }
2032 m_Dictionary.SetCurSel(curSel);
2033 }
2034
2035 {
2036 int curSel = Combo_AddDict2(m_Dictionary_Chain, k_Auto_Dict, _auto_Dict_Chain);
2037
2038 // defaultDict_Chain = 10 << 10; // for debug
2039 const UInt32 kWinChainStart = 15;
2040 if (defaultDict_Chain != 0 && defaultDict_Chain < ((UInt32)1 << kWinChainStart))
2041 curSel = AddDict_Chain(defaultDict_Chain);
2042
2043 for (unsigned i = kWinChainStart; i <= kMaxDictChain; i++)
2044 {
2045 const size_t dict = (size_t)1 << i;
2046 if (defaultDict != (UInt32)(Int32)-1 && dict > defaultDict)
2047 break;
2048 const int index = AddDict_Chain(dict);
2049 if (defaultDict_Chain != (UInt32)(Int32)-1)
2050 if (dict <= defaultDict_Chain || curSel <= 0)
2051 curSel = index;
2052 }
2053 m_Dictionary_Chain.SetCurSel(curSel);
2054 }
2055
2056 break;
2057 }
2058 */
1662 2059
1663 case kPPMd: 2060 case kPPMd:
1664 { 2061 {
@@ -1795,8 +2192,8 @@ int CCompressDialog::AddOrder(UInt32 size)
1795{ 2192{
1796 char s[32]; 2193 char s[32];
1797 ConvertUInt32ToString(size, s); 2194 ConvertUInt32ToString(size, s);
1798 int index = (int)ComboBox_AddStringAscii(m_Order, s); 2195 const int index = (int)ComboBox_AddStringAscii(m_Order, s);
1799 m_Order.SetItemData(index, size); 2196 m_Order.SetItemData(index, (LPARAM)size);
1800 return index; 2197 return index;
1801} 2198}
1802 2199
@@ -1855,6 +2252,39 @@ void CCompressDialog::SetOrder2()
1855 break; 2252 break;
1856 } 2253 }
1857 2254
2255 /*
2256 case kZSTD:
2257 {
2258 {
2259 CZstdEncProps props;
2260 ZstdEncProps_Init(&props);
2261 // props.level_zstd = level;
2262 props.level_7z = level;
2263 ZstdEncProps_NormalizeFull(&props);
2264 _auto_Order = props.targetLength;
2265 if (props.strategy < ZSTD_strategy_btopt)
2266 {
2267 // ZSTD_strategy_fast uses targetLength to change fast level.
2268 // targetLength probably is used only in ZSTD_strategy_btopt and higher
2269 break;
2270 }
2271 }
2272 int curSel = AddOrder_Auto();
2273
2274 for (unsigned i = 6; i <= 9 * 2; i++)
2275 {
2276 UInt32 order = ((UInt32)(2 + (i & 1)) << (i / 2));
2277 // if (order > 999) order = 999;
2278 const int index = AddOrder(order);
2279 if (defaultOrder != (UInt32)(Int32)-1)
2280 if (order <= defaultOrder || curSel <= 0)
2281 curSel = index;
2282 }
2283 m_Order.SetCurSel(curSel);
2284 break;
2285 }
2286 */
2287
1858 case kDeflate: 2288 case kDeflate:
1859 case kDeflate64: 2289 case kDeflate64:
1860 { 2290 {
@@ -2051,8 +2481,8 @@ void CCompressDialog::SetSolidBlockSize2()
2051 AString s; 2481 AString s;
2052 Add_Size(s, _auto_Solid); 2482 Add_Size(s, _auto_Solid);
2053 Modify_Auto(s); 2483 Modify_Auto(s);
2054 int index = (int)ComboBox_AddStringAscii(m_Solid, s); 2484 const int index = (int)ComboBox_AddStringAscii(m_Solid, s);
2055 m_Solid.SetItemData(index, (UInt32)(Int32)-1); 2485 m_Solid.SetItemData(index, (LPARAM)(UInt32)(Int32)-1);
2056 curSel = index; 2486 curSel = index;
2057 } 2487 }
2058 2488
@@ -2063,7 +2493,7 @@ void CCompressDialog::SetSolidBlockSize2()
2063 if (is7z) 2493 if (is7z)
2064 LangString(IDS_COMPRESS_NON_SOLID, s); 2494 LangString(IDS_COMPRESS_NON_SOLID, s);
2065 const int index = (int)m_Solid.AddString(s); 2495 const int index = (int)m_Solid.AddString(s);
2066 m_Solid.SetItemData(index, (UInt32)kSolidLog_NoSolid); 2496 m_Solid.SetItemData(index, (LPARAM)(UInt32)kSolidLog_NoSolid);
2067 if (defaultBlockSize == kSolidLog_NoSolid) 2497 if (defaultBlockSize == kSolidLog_NoSolid)
2068 curSel = index; 2498 curSel = index;
2069 } 2499 }
@@ -2073,7 +2503,7 @@ void CCompressDialog::SetSolidBlockSize2()
2073 AString s; 2503 AString s;
2074 Add_Size(s, (UInt64)1 << i); 2504 Add_Size(s, (UInt64)1 << i);
2075 const int index = (int)ComboBox_AddStringAscii(m_Solid, s); 2505 const int index = (int)ComboBox_AddStringAscii(m_Solid, s);
2076 m_Solid.SetItemData(index, (UInt32)i); 2506 m_Solid.SetItemData(index, (LPARAM)(UInt32)i);
2077 if (defaultBlockSize != (UInt32)(Int32)-1) 2507 if (defaultBlockSize != (UInt32)(Int32)-1)
2078 if (i <= defaultBlockSize || index <= 1) 2508 if (i <= defaultBlockSize || index <= 1)
2079 curSel = index; 2509 curSel = index;
@@ -2081,7 +2511,7 @@ void CCompressDialog::SetSolidBlockSize2()
2081 2511
2082 { 2512 {
2083 const int index = (int)m_Solid.AddString(LangString(IDS_COMPRESS_SOLID)); 2513 const int index = (int)m_Solid.AddString(LangString(IDS_COMPRESS_SOLID));
2084 m_Solid.SetItemData(index, kSolidLog_FullSolid); 2514 m_Solid.SetItemData(index, (LPARAM)kSolidLog_FullSolid);
2085 if (defaultBlockSize == kSolidLog_FullSolid) 2515 if (defaultBlockSize == kSolidLog_FullSolid)
2086 curSel = index; 2516 curSel = index;
2087 } 2517 }
@@ -2090,6 +2520,43 @@ void CCompressDialog::SetSolidBlockSize2()
2090} 2520}
2091 2521
2092 2522
2523/*
2524static void ZstdEncProps_SetDictProps_From_CompressDialog(CZstdEncProps *props, CCompressDialog &cd)
2525{
2526 {
2527 const UInt64 d64 = cd.GetDictSpec();
2528 UInt32 d32 = 0; // 0 is default for ZstdEncProps::windowLog
2529 if (d64 != (UInt64)(Int64)-1)
2530 {
2531 d32 = (UInt32)d64;
2532 if (d32 != d64)
2533 d32 = (UInt32)(Int32)-2;
2534 }
2535 ZstdEncProps_Set_WindowSize(props, d32);
2536 }
2537 {
2538 const UInt64 d64 = cd.GetDictChainSpec();
2539 UInt32 d32 = 0; // 0 is default for ZstdEncProps::windowLog_Chain
2540 if (d64 != (UInt64)(Int64)-1)
2541 {
2542 d32 = (UInt32)d64;
2543 if (d32 != d64)
2544 d32 = (UInt32)(Int32)-2;
2545 }
2546 ZstdEncProps_Set_WindowChainSize(props, d32);
2547 }
2548}
2549
2550static bool Is_Zstd_Mt_Supported()
2551{
2552 if (!GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "InitializeConditionVariable"))
2553 return false;
2554 return true;
2555}
2556*/
2557
2558static const char *k_ST_Threads = " (ST)";
2559
2093void CCompressDialog::SetNumThreads2() 2560void CCompressDialog::SetNumThreads2()
2094{ 2561{
2095 _auto_NumThreads = 1; 2562 _auto_NumThreads = 1;
@@ -2119,13 +2586,17 @@ void CCompressDialog::SetNumThreads2()
2119 } 2586 }
2120 } 2587 }
2121 2588
2589 // const UInt32 num_ZSTD_threads_MAX = Is_Zstd_Mt_Supported() ? MY_ZSTDMT_NBWORKERS_MAX : 0;
2590
2122 UInt32 numAlgoThreadsMax = numHardwareThreads * 2; 2591 UInt32 numAlgoThreadsMax = numHardwareThreads * 2;
2123 const int methodID = GetMethodID(); 2592 const int methodID = GetMethodID();
2593
2124 switch (methodID) 2594 switch (methodID)
2125 { 2595 {
2126 case kLZMA: numAlgoThreadsMax = 2; break; 2596 case kLZMA: numAlgoThreadsMax = 2; break;
2127 case kLZMA2: numAlgoThreadsMax = 256; break; 2597 case kLZMA2: numAlgoThreadsMax = 256; break;
2128 case kBZip2: numAlgoThreadsMax = 32; break; 2598 case kBZip2: numAlgoThreadsMax = 32; break;
2599 // case kZSTD: numAlgoThreadsMax = num_ZSTD_threads_MAX; break;
2129 case kCopy: 2600 case kCopy:
2130 case kPPMd: 2601 case kPPMd:
2131 case kDeflate: 2602 case kDeflate:
@@ -2150,7 +2621,10 @@ void CCompressDialog::SetNumThreads2()
2150 2621
2151 const UInt64 memUse_Limit = Get_MemUse_Bytes(); 2622 const UInt64 memUse_Limit = Get_MemUse_Bytes();
2152 2623
2153 if (autoThreads > 1 && _ramSize_Defined) 2624 if (_ramSize_Defined)
2625 if (autoThreads > 1
2626 // || (autoThreads == 0 && methodID == kZSTD)
2627 )
2154 { 2628 {
2155 if (isZip) 2629 if (isZip)
2156 { 2630 {
@@ -2178,6 +2652,20 @@ void CCompressDialog::SetNumThreads2()
2178 } 2652 }
2179 autoThreads = numBlockThreads * numThreads1; 2653 autoThreads = numBlockThreads * numThreads1;
2180 } 2654 }
2655 /*
2656 else if (methodID == kZSTD)
2657 {
2658 if (num_ZSTD_threads_MAX != 0)
2659 {
2660 CZstdEncProps props;
2661 ZstdEncProps_Init(&props);
2662 // props.level_zstd = level;
2663 props.level_7z = GetLevel2();
2664 ZstdEncProps_SetDictProps_From_CompressDialog(&props, *this);
2665 autoThreads = ZstdEncProps_GetNumThreads_for_MemUsageLimit(&props, memUse_Limit, autoThreads);
2666 }
2667 }
2668 */
2181 } 2669 }
2182 2670
2183 _auto_NumThreads = autoThreads; 2671 _auto_NumThreads = autoThreads;
@@ -2186,8 +2674,9 @@ void CCompressDialog::SetNumThreads2()
2186 { 2674 {
2187 AString s; 2675 AString s;
2188 s.Add_UInt32(autoThreads); 2676 s.Add_UInt32(autoThreads);
2677 if (autoThreads == 0) s += k_ST_Threads;
2189 Modify_Auto(s); 2678 Modify_Auto(s);
2190 int index = (int)ComboBox_AddStringAscii(m_NumThreads, s); 2679 const int index = (int)ComboBox_AddStringAscii(m_NumThreads, s);
2191 m_NumThreads.SetItemData(index, (LPARAM)(INT_PTR)(-1)); 2680 m_NumThreads.SetItemData(index, (LPARAM)(INT_PTR)(-1));
2192 // m_NumThreads.SetItemData(index, autoThreads); 2681 // m_NumThreads.SetItemData(index, autoThreads);
2193 if (useAutoThreads) 2682 if (useAutoThreads)
@@ -2195,12 +2684,16 @@ void CCompressDialog::SetNumThreads2()
2195 } 2684 }
2196 2685
2197 if (numAlgoThreadsMax != autoThreads || autoThreads != 1) 2686 if (numAlgoThreadsMax != autoThreads || autoThreads != 1)
2198 for (UInt32 i = 1; i <= numHardwareThreads * 2 && i <= numAlgoThreadsMax; i++) 2687 for (UInt32 i =
2688 // (methodID == kZSTD) ? 0 :
2689 1;
2690 i <= numHardwareThreads * 2 && i <= numAlgoThreadsMax; i++)
2199 { 2691 {
2200 char s[32]; 2692 AString s;
2201 ConvertUInt32ToString(i, s); 2693 s.Add_UInt32(i);
2202 int index = (int)ComboBox_AddStringAscii(m_NumThreads, s); 2694 if (i == 0) s += k_ST_Threads;
2203 m_NumThreads.SetItemData(index, (UInt32)i); 2695 const int index = (int)ComboBox_AddStringAscii(m_NumThreads, s);
2696 m_NumThreads.SetItemData(index, (LPARAM)(UInt32)i);
2204 if (!useAutoThreads && i == defaultValue) 2697 if (!useAutoThreads && i == defaultValue)
2205 curSel = index; 2698 curSel = index;
2206 } 2699 }
@@ -2236,7 +2729,7 @@ int CCompressDialog::AddMemComboItem(UInt64 val, bool isPercent, bool isDefault)
2236 s.Add_UInt64(val); 2729 s.Add_UInt64(val);
2237 s += '%'; 2730 s += '%';
2238 if (isDefault) 2731 if (isDefault)
2239 sUser = "* "; 2732 sUser = k_Auto_Prefix;
2240 else 2733 else
2241 sRegistry = s; 2734 sRegistry = s;
2242 sUser += s; 2735 sUser += s;
@@ -2247,7 +2740,7 @@ int CCompressDialog::AddMemComboItem(UInt64 val, bool isPercent, bool isDefault)
2247 sRegistry = sUser; 2740 sRegistry = sUser;
2248 for (;;) 2741 for (;;)
2249 { 2742 {
2250 int pos = sRegistry.Find(L' '); 2743 const int pos = sRegistry.Find(L' ');
2251 if (pos < 0) 2744 if (pos < 0)
2252 break; 2745 break;
2253 sRegistry.Delete(pos); 2746 sRegistry.Delete(pos);
@@ -2258,7 +2751,7 @@ int CCompressDialog::AddMemComboItem(UInt64 val, bool isPercent, bool isDefault)
2258 } 2751 }
2259 const unsigned dataIndex = _memUse_Strings.Add(sRegistry); 2752 const unsigned dataIndex = _memUse_Strings.Add(sRegistry);
2260 const int index = (int)m_MemUse.AddString(sUser); 2753 const int index = (int)m_MemUse.AddString(sUser);
2261 m_MemUse.SetItemData(index, dataIndex); 2754 m_MemUse.SetItemData(index, (LPARAM)dataIndex);
2262 return index; 2755 return index;
2263} 2756}
2264 2757
@@ -2382,11 +2875,16 @@ UInt64 CCompressDialog::GetMemoryUsage_DecompMem(UInt64 &decompressMemory)
2382 return GetMemoryUsage_Dict_DecompMem(GetDict2(), decompressMemory); 2875 return GetMemoryUsage_Dict_DecompMem(GetDict2(), decompressMemory);
2383} 2876}
2384 2877
2878
2879/*
2880we could use that function to reduce the dictionary if small RAM
2385UInt64 CCompressDialog::GetMemoryUsageComp_Threads_Dict(UInt32 numThreads, UInt64 dict64) 2881UInt64 CCompressDialog::GetMemoryUsageComp_Threads_Dict(UInt32 numThreads, UInt64 dict64)
2386{ 2882{
2387 UInt64 decompressMemory; 2883 UInt64 decompressMemory;
2388 return GetMemoryUsage_Threads_Dict_DecompMem(numThreads, dict64, decompressMemory); 2884 return GetMemoryUsage_Threads_Dict_DecompMem(numThreads, dict64, decompressMemory);
2389} 2885}
2886*/
2887
2390 2888
2391UInt64 CCompressDialog::GetMemoryUsage_Dict_DecompMem(UInt64 dict64, UInt64 &decompressMemory) 2889UInt64 CCompressDialog::GetMemoryUsage_Dict_DecompMem(UInt64 dict64, UInt64 &decompressMemory)
2392{ 2890{
@@ -2396,11 +2894,9 @@ UInt64 CCompressDialog::GetMemoryUsage_Dict_DecompMem(UInt64 dict64, UInt64 &dec
2396UInt64 CCompressDialog::GetMemoryUsage_Threads_Dict_DecompMem(UInt32 numThreads, UInt64 dict64, UInt64 &decompressMemory) 2894UInt64 CCompressDialog::GetMemoryUsage_Threads_Dict_DecompMem(UInt32 numThreads, UInt64 dict64, UInt64 &decompressMemory)
2397{ 2895{
2398 decompressMemory = (UInt64)(Int64)-1; 2896 decompressMemory = (UInt64)(Int64)-1;
2399 if (dict64 == (UInt64)(Int64)-1)
2400 return (UInt64)(Int64)-1;
2401 2897
2402 UInt32 level = GetLevel2(); 2898 const UInt32 level = GetLevel2();
2403 if (level == 0) 2899 if (level == 0 && !Get_ArcInfoEx().Is_Zstd())
2404 { 2900 {
2405 decompressMemory = (1 << 20); 2901 decompressMemory = (1 << 20);
2406 return decompressMemory; 2902 return decompressMemory;
@@ -2427,6 +2923,12 @@ UInt64 CCompressDialog::GetMemoryUsage_Threads_Dict_DecompMem(UInt32 numThreads,
2427 } 2923 }
2428 2924
2429 const int methodId = GetMethodID(); 2925 const int methodId = GetMethodID();
2926
2927 if (dict64 == (UInt64)(Int64)-1
2928 // && methodId != kZSTD
2929 )
2930 return (UInt64)(Int64)-1;
2931
2430 2932
2431 switch (methodId) 2933 switch (methodId)
2432 { 2934 {
@@ -2507,7 +3009,23 @@ UInt64 CCompressDialog::GetMemoryUsage_Threads_Dict_DecompMem(UInt32 numThreads,
2507 decompressMemory = dict + (2 << 20); 3009 decompressMemory = dict + (2 << 20);
2508 return size; 3010 return size;
2509 } 3011 }
2510 3012
3013 /*
3014 case kZSTD:
3015 {
3016 CZstdEncProps props;
3017 ZstdEncProps_Init(&props);
3018 // props.level_zstd = level;
3019 props.level_7z = level;
3020 props.nbWorkers = numThreads;
3021 ZstdEncProps_SetDictProps_From_CompressDialog(&props, *this);
3022 ZstdEncProps_NormalizeFull(&props);
3023 size = ZstdEncProps_GetMemUsage(&props);
3024 decompressMemory = (UInt64)1 << props.windowLog;
3025 return size;
3026 }
3027 */
3028
2511 case kPPMd: 3029 case kPPMd:
2512 { 3030 {
2513 decompressMemory = dict64 + (2 << 20); 3031 decompressMemory = dict64 + (2 << 20);
@@ -2613,8 +3131,109 @@ void CCompressDialog::SetMemoryUsage()
2613 const UInt64 memUsage = GetMemoryUsage_DecompMem(decompressMem); 3131 const UInt64 memUsage = GetMemoryUsage_DecompMem(decompressMem);
2614 PrintMemUsage(IDT_COMPRESS_MEMORY_VALUE, memUsage); 3132 PrintMemUsage(IDT_COMPRESS_MEMORY_VALUE, memUsage);
2615 PrintMemUsage(IDT_COMPRESS_MEMORY_DE_VALUE, decompressMem); 3133 PrintMemUsage(IDT_COMPRESS_MEMORY_DE_VALUE, decompressMem);
3134 #ifdef PRINT_PARAMS
3135 Print_Params();
3136 #endif
2616} 3137}
2617 3138
3139
3140
3141#ifdef PRINT_PARAMS
3142
3143static const char kPropDelimeter = ' '; // ':'
3144
3145static void AddPropName(AString &s, const char *name)
3146{
3147 if (!s.IsEmpty())
3148 s += kPropDelimeter;
3149 s += name;
3150}
3151
3152static void AddProp(AString &s, const char *name, unsigned v)
3153{
3154 AddPropName(s, name);
3155 s.Add_UInt32(v);
3156}
3157
3158static void AddProp_switch(AString &s, const char *name, E_ZSTD_paramSwitch_e e)
3159{
3160 AddPropName(s, name);
3161 s += e == k_ZSTD_ps_enable ? "" : "-";
3162}
3163
3164static void PrintPropAsLog(AString &s, const char *name, size_t v)
3165{
3166 AddPropName(s, name);
3167 for (unsigned i = 0; i < sizeof(size_t) * 8; i++)
3168 {
3169 if (((size_t)1 << i) == v)
3170 {
3171 s.Add_UInt32(i);
3172 return;
3173 }
3174 }
3175 char c = 'b';
3176 if ((v & 0x3FFFFFFF) == 0) { v >>= 30; c = 'G'; }
3177 else if ((v & 0xFFFFF) == 0) { v >>= 20; c = 'M'; }
3178 else if ((v & 0x3FF) == 0) { v >>= 10; c = 'K'; }
3179 s.Add_UInt64(v);
3180 s += c;
3181}
3182
3183static void ZstdEncProps_Print(CZstdEncProps *props, AString &s)
3184{
3185 if (props->level_zstd >= 0)
3186 AddProp(s, "zx", props->level_zstd);
3187 else
3188 AddProp(s, "zf", -(props->level_zstd));
3189 AddProp(s, "a", props->strategy);
3190 AddProp(s, "d", props->windowLog);
3191 AddProp(s, "zclog", props->chainLog);
3192 AddProp(s, "zhb", props->hashLog);
3193 AddProp(s, "mml", props->minMatch);
3194 AddProp(s, "mcb", props->searchLog);
3195 AddProp(s, "fb", props->targetLength);
3196 AddProp(s, "mt", props->nbWorkers);
3197 PrintPropAsLog(s, "c", props->jobSize);
3198 AddProp(s, "zov", props->overlapLog);
3199 PrintPropAsLog(s, "ztps", props->targetPrefixSize);
3200 AddProp_switch(s, "zmfr", props->useRowMatchFinder);
3201 if (props->ldmParams.enableLdm == k_ZSTD_ps_enable)
3202 {
3203 AddProp_switch(s, "zle", props->ldmParams.enableLdm);
3204 AddProp(s, "zlhb", props->ldmParams.hashLog);
3205 AddProp(s, "zlbb", props->ldmParams.bucketSizeLog);
3206 AddProp(s, "zlmml", props->ldmParams.minMatchLength);
3207 AddProp(s, "zlhrb", props->ldmParams.hashRateLog);
3208 }
3209}
3210
3211void CCompressDialog::Print_Params()
3212{
3213 {
3214 CZstdEncProps props;
3215 ZstdEncProps_Init(&props);
3216 // props.level_zstd = level;
3217 props.level_7z = GetLevel2();
3218 ZstdEncProps_SetDictProps_From_CompressDialog(&props, *this);
3219 {
3220 UInt32 order = GetOrderSpec();
3221 if (order != (UInt32)(Int32)-1)
3222 props.targetLength = GetOrderSpec();
3223 }
3224 props.nbWorkers = GetNumThreads2();
3225 // props.windowLog = 18; // for debug
3226 ZstdEncProps_NormalizeFull(&props);
3227 AString s;
3228 ZstdEncProps_Print(&props, s);
3229 SetItemTextA(IDT_COMPRESS_PARAMS_INFO, s);
3230 }
3231}
3232
3233#endif // PRINT_PARAMS
3234
3235
3236
2618void CCompressDialog::SetParams() 3237void CCompressDialog::SetParams()
2619{ 3238{
2620 const CArcInfoEx &ai = Get_ArcInfoEx(); 3239 const CArcInfoEx &ai = Get_ArcInfoEx();
@@ -2663,6 +3282,24 @@ void CCompressDialog::SaveOptionsInMem()
2663 } 3282 }
2664 fo.Dictionary = dict32; 3283 fo.Dictionary = dict32;
2665 } 3284 }
3285 /*
3286 {
3287 const UInt64 dict64 = GetDictChainSpec();
3288 UInt32 dict32;
3289 if (dict64 == (UInt64)(Int64)-1)
3290 dict32 = (UInt32)(Int32)-1;
3291 else
3292 {
3293 dict32 = (UInt32)dict64;
3294 if (dict64 != dict32)
3295 {
3296 dict32 = (UInt32)(Int32)-2;
3297 // dict32 = k_Zstd_MAX_DictSize; // it must be larger than threshold
3298 }
3299 }
3300 fo.DictionaryChain = dict32;
3301 }
3302 */
2666 3303
2667 fo.Order = GetOrderSpec(); 3304 fo.Order = GetOrderSpec();
2668 fo.Method = GetMethodSpec(); 3305 fo.Method = GetMethodSpec();
@@ -2836,7 +3473,7 @@ int COptionsDialog::AddPrec(unsigned prec, bool isDefault)
2836 else 3473 else
2837 s.Add_UInt32(prec); 3474 s.Add_UInt32(prec);
2838 const int index = (int)m_Prec.AddString(s); 3475 const int index = (int)m_Prec.AddString(s);
2839 m_Prec.SetItemData(index, writePrec); 3476 m_Prec.SetItemData(index, (LPARAM)writePrec);
2840 return index; 3477 return index;
2841} 3478}
2842 3479
@@ -2874,7 +3511,7 @@ void COptionsDialog::SetPrec()
2874 // flags = (UInt32)1 << kTimePrec_Unix; 3511 // flags = (UInt32)1 << kTimePrec_Unix;
2875 3512
2876 s += ":"; 3513 s += ":";
2877 if (methodID >= 0 && (unsigned)methodID < ARRAY_SIZE(kMethodsNames)) 3514 if (methodID >= 0 && (unsigned)methodID < Z7_ARRAY_SIZE(kMethodsNames))
2878 s += kMethodsNames[methodID]; 3515 s += kMethodsNames[methodID];
2879 if (methodID == kPosix) 3516 if (methodID == kPosix)
2880 { 3517 {
@@ -3038,7 +3675,7 @@ void COptionsDialog::On_CheckBoxSet_Clicked(const CBoolBox &bb)
3038 3675
3039 3676
3040 3677
3041#ifdef LANG 3678#ifdef Z7_LANG
3042static const UInt32 kLangIDs_Options[] = 3679static const UInt32 kLangIDs_Options[] =
3043{ 3680{
3044 IDX_COMPRESS_NT_SYM_LINKS, 3681 IDX_COMPRESS_NT_SYM_LINKS,
@@ -3059,9 +3696,9 @@ static const UInt32 kLangIDs_Options[] =
3059 3696
3060bool COptionsDialog::OnInit() 3697bool COptionsDialog::OnInit()
3061{ 3698{
3062 #ifdef LANG 3699 #ifdef Z7_LANG
3063 LangSetWindowText(*this, IDB_COMPRESS_OPTIONS); // IDS_OPTIONS 3700 LangSetWindowText(*this, IDB_COMPRESS_OPTIONS); // IDS_OPTIONS
3064 LangSetDlgItems(*this, kLangIDs_Options, ARRAY_SIZE(kLangIDs_Options)); 3701 LangSetDlgItems(*this, kLangIDs_Options, Z7_ARRAY_SIZE(kLangIDs_Options));
3065 // LangSetDlgItemText(*this, IDB_COMPRESS_TIME_DEFAULT, IDB_COMPRESS_TIME_DEFAULT); 3702 // LangSetDlgItemText(*this, IDB_COMPRESS_TIME_DEFAULT, IDB_COMPRESS_TIME_DEFAULT);
3066 // LangSetDlgItemText(*this, IDX_COMPRESS_TIME_DEFAULT, IDX_COMPRESS_TIME_DEFAULT); 3703 // LangSetDlgItemText(*this, IDX_COMPRESS_TIME_DEFAULT, IDX_COMPRESS_TIME_DEFAULT);
3067 #endif 3704 #endif
@@ -3124,7 +3761,7 @@ bool COptionsDialog::OnInit()
3124} 3761}
3125 3762
3126 3763
3127bool COptionsDialog::OnCommand(int code, int itemID, LPARAM lParam) 3764bool COptionsDialog::OnCommand(unsigned code, unsigned itemID, LPARAM lParam)
3128{ 3765{
3129 if (code == CBN_SELCHANGE) 3766 if (code == CBN_SELCHANGE)
3130 { 3767 {
@@ -3142,7 +3779,7 @@ bool COptionsDialog::OnCommand(int code, int itemID, LPARAM lParam)
3142} 3779}
3143 3780
3144 3781
3145bool COptionsDialog::OnButtonClicked(int buttonID, HWND buttonHWND) 3782bool COptionsDialog::OnButtonClicked(unsigned buttonID, HWND buttonHWND)
3146{ 3783{
3147 switch (buttonID) 3784 switch (buttonID)
3148 { 3785 {
@@ -3179,5 +3816,5 @@ void COptionsDialog::OnOK()
3179 3816
3180void COptionsDialog::OnHelp() 3817void COptionsDialog::OnHelp()
3181{ 3818{
3182 ShowHelpWindow(kHelpTopic); 3819 ShowHelpWindow(kHelpTopic_Options);
3183} 3820}