xref: /aosp_15_r20/external/lzma/CPP/7zip/UI/GUI/CompressDialog.h (revision f6dc9357d832569d4d1f5d24eacdb3935a1ae8e6)
1 // CompressDialog.h
2 
3 #ifndef ZIP7_INC_COMPRESS_DIALOG_H
4 #define ZIP7_INC_COMPRESS_DIALOG_H
5 
6 #include "../../../Common/Wildcard.h"
7 
8 #include "../../../Windows/Control/ComboBox.h"
9 #include "../../../Windows/Control/Edit.h"
10 
11 #include "../Common/LoadCodecs.h"
12 #include "../Common/ZipRegistry.h"
13 
14 #include "../FileManager/DialogSize.h"
15 
16 #include "CompressDialogRes.h"
17 
18 namespace NCompressDialog
19 {
20   namespace NUpdateMode
21   {
22     enum EEnum
23     {
24       kAdd,
25       kUpdate,
26       kFresh,
27       kSync
28     };
29   }
30 
31   struct CInfo
32   {
33     NUpdateMode::EEnum UpdateMode;
34     NWildcard::ECensorPathMode PathMode;
35 
36     bool SolidIsSpecified;
37     // bool MultiThreadIsAllowed;
38     UInt64 SolidBlockSize;
39     UInt32 NumThreads;
40 
41     NCompression::CMemUse MemUsage;
42 
43     CRecordVector<UInt64> VolumeSizes;
44 
45     UInt32 Level;
46     UString Method;
47     UInt64 Dict64;
48     // UInt64 Dict64_Chain;
49     bool OrderMode;
50     UInt32 Order;
51     UString Options;
52 
53     UString EncryptionMethod;
54 
55     bool SFXMode;
56     bool OpenShareForWrite;
57     bool DeleteAfterCompressing;
58 
59     CBoolPair SymLinks;
60     CBoolPair HardLinks;
61     CBoolPair AltStreams;
62     CBoolPair NtSecurity;
63 
64     CBoolPair PreserveATime;
65 
66     UInt32 TimePrec;
67     CBoolPair MTime;
68     CBoolPair CTime;
69     CBoolPair ATime;
70     CBoolPair SetArcMTime;
71 
72     UString ArcPath; // in: Relative or abs ; out: Relative or abs
73 
74     // FString CurrentDirPrefix;
75     bool KeepName;
76 
77     bool GetFullPathName(UString &result) const;
78 
79     int FormatIndex;
80 
81     UString Password;
82     bool EncryptHeadersIsAllowed;
83     bool EncryptHeaders;
84 
CInfoCInfo85     CInfo():
86         UpdateMode(NCompressDialog::NUpdateMode::kAdd),
87         PathMode(NWildcard::k_RelatPath),
88         SFXMode(false),
89         OpenShareForWrite(false),
90         DeleteAfterCompressing(false),
91         FormatIndex(-1)
92     {
93       Level = Order = (UInt32)(Int32)-1;
94       NumThreads = (UInt32)(Int32)-1;
95       SolidIsSpecified = false;
96       Dict64 = (UInt64)(Int64)(-1);
97       // Dict64_Chain = (UInt64)(Int64)(-1);
98       OrderMode = false;
99       Method.Empty();
100       Options.Empty();
101       EncryptionMethod.Empty();
102       TimePrec = (UInt32)(Int32)(-1);
103     }
104   };
105 }
106 
107 
108 struct CBool1
109 {
110   bool Val;
111   bool Supported;
112 
CBool1CBool1113   CBool1(): Val(false), Supported(false) {}
114 
InitCBool1115   void Init()
116   {
117     Val = false;
118     Supported = false;
119   }
120 
SetTrueTrueCBool1121   void SetTrueTrue()
122   {
123     Val = true;
124     Supported = true;
125   }
126 
SetVal_as_SupportedCBool1127   void SetVal_as_Supported(bool val)
128   {
129     Val = val;
130     Supported = true;
131   }
132 
133   /*
134   bool IsVal_True_and_Defined() const
135   {
136     return Def && Val;
137   }
138   */
139 };
140 
141 
142 class CCompressDialog: public NWindows::NControl::CModalDialog
143 {
144 public:
145   CBool1 SymLinks;
146   CBool1 HardLinks;
147   CBool1 AltStreams;
148   CBool1 NtSecurity;
149   CBool1 PreserveATime;
150 private:
151   bool _ramSize_Defined;
152 
153   NWindows::NControl::CComboBox m_ArchivePath;
154   NWindows::NControl::CComboBox m_Format;
155   NWindows::NControl::CComboBox m_Level;
156   NWindows::NControl::CComboBox m_Method;
157   NWindows::NControl::CComboBox m_Dictionary;
158   // NWindows::NControl::CComboBox m_Dictionary_Chain;
159   NWindows::NControl::CComboBox m_Order;
160   NWindows::NControl::CComboBox m_Solid;
161   NWindows::NControl::CComboBox m_NumThreads;
162   NWindows::NControl::CComboBox m_MemUse;
163   NWindows::NControl::CComboBox m_Volume;
164 
165   int _dictionaryCombo_left;
166 
167   UStringVector _memUse_Strings;
168 
169   NWindows::NControl::CDialogChildControl m_Params;
170 
171   NWindows::NControl::CComboBox m_UpdateMode;
172   NWindows::NControl::CComboBox m_PathMode;
173 
174   NWindows::NControl::CEdit _password1Control;
175   NWindows::NControl::CEdit _password2Control;
176   NWindows::NControl::CComboBox _encryptionMethod;
177 
178   int _auto_MethodId;
179   UInt32 _auto_Dict; // (UInt32)(Int32)-1 means unknown
180   UInt32 _auto_Dict_Chain; // (UInt32)(Int32)-1 means unknown
181   UInt32 _auto_Order;
182   UInt64 _auto_Solid;
183   UInt32 _auto_NumThreads;
184 
185   int _default_encryptionMethod_Index;
186 
187   int m_PrevFormat;
188   UString DirPrefix;
189   UString StartDirPrefix;
190 
191   size_t _ramSize;         // full RAM size avail
192   size_t _ramSize_Reduced; // full for 64-bit and reduced for 32-bit
193   UInt64 _ramUsage_Auto;
194 
195 public:
196   NCompression::CInfo m_RegistryInfo;
197 
198   void SetArchiveName(const UString &name);
199   int FindRegistryFormat(const UString &name);
200   unsigned FindRegistryFormat_Always(const UString &name);
201 
Get_ArcInfoEx()202   const CArcInfoEx &Get_ArcInfoEx()
203   {
204     return (*ArcFormats)[GetFormatIndex()];
205   }
206 
207   NCompression::CFormatOptions &Get_FormatOptions();
208 
209   void CheckSFXNameChange();
210   void SetArchiveName2(bool prevWasSFX);
211 
212   unsigned GetStaticFormatIndex();
213 
214   void SetNearestSelectComboBox(NWindows::NControl::CComboBox &comboBox, UInt32 value);
215 
216   void SetLevel2();
SetLevel()217   void SetLevel()
218   {
219     SetLevel2();
220     EnableMultiCombo(IDC_COMPRESS_LEVEL);
221     SetMethod();
222   }
223 
224   void SetMethod2(int keepMethodId);
225   void SetMethod(int keepMethodId = -1)
226   {
227     SetMethod2(keepMethodId);
228     EnableMultiCombo(IDC_COMPRESS_METHOD);
229   }
230 
MethodChanged()231   void MethodChanged()
232   {
233     SetDictionary2();
234     EnableMultiCombo(IDC_COMPRESS_DICTIONARY);
235     // EnableMultiCombo(IDC_COMPRESS_DICTIONARY2);
236     SetOrder2();
237     EnableMultiCombo(IDC_COMPRESS_ORDER);
238   }
239 
240   int GetMethodID_RAW();
241   int GetMethodID();
242 
243   UString GetMethodSpec(UString &estimatedName);
244   UString GetMethodSpec();
245   bool IsMethodEqualTo(const UString &s);
246   UString GetEncryptionMethodSpec();
247 
248   bool IsZipFormat();
249   bool IsXzFormat();
250 
251   void SetEncryptionMethod();
252 
253   int AddDict2(size_t sizeReal, size_t sizeShow);
254   int AddDict(size_t size);
255   // int AddDict_Chain(size_t size);
256 
257   void SetDictionary2();
258 
259   UInt32 GetComboValue(NWindows::NControl::CComboBox &c, int defMax = 0);
260   UInt64 GetComboValue_64(NWindows::NControl::CComboBox &c, int defMax = 0);
261 
GetLevel()262   UInt32 GetLevel()  { return GetComboValue(m_Level); }
GetLevelSpec()263   UInt32 GetLevelSpec()  { return GetComboValue(m_Level, 1); }
264   UInt32 GetLevel2();
265 
GetDictSpec()266   UInt64 GetDictSpec() { return GetComboValue_64(m_Dictionary, 1); }
267   // UInt64 GetDictChainSpec() { return GetComboValue_64(m_Dictionary_Chain, 1); }
268 
GetDict2()269   UInt64 GetDict2()
270   {
271     UInt64 num = GetDictSpec();
272     if (num == (UInt64)(Int64)-1)
273     {
274       if (_auto_Dict == (UInt32)(Int32)-1)
275         return (UInt64)(Int64)-1; // unknown
276       num = _auto_Dict;
277     }
278     return num;
279   }
280 
281   // UInt32 GetOrder() { return GetComboValue(m_Order); }
GetOrderSpec()282   UInt32 GetOrderSpec() { return GetComboValue(m_Order, 1); }
GetNumThreadsSpec()283   UInt32 GetNumThreadsSpec() { return GetComboValue(m_NumThreads, 1); }
284 
GetNumThreads2()285   UInt32 GetNumThreads2()
286   {
287     UInt32 num = GetNumThreadsSpec();
288     if (num == (UInt32)(Int32)-1)
289       num = _auto_NumThreads;
290     return num;
291   }
292 
GetBlockSizeSpec()293   UInt32 GetBlockSizeSpec() { return GetComboValue(m_Solid, 1); }
294 
295   /*
296   UInt32 GetPrecSpec() { return GetComboValue(m_Prec, 1); }
297   UInt32 GetPrec() { return GetComboValue(m_Prec, 0); }
298   */
299 
300 
301   int AddOrder(UInt32 size);
302   int AddOrder_Auto();
303 
304   void SetOrder2();
305 
306   bool GetOrderMode();
307 
308   void SetSolidBlockSize2();
SetSolidBlockSize()309   void SetSolidBlockSize(/* bool useDictionary = false */)
310   {
311     SetSolidBlockSize2();
312     EnableMultiCombo(IDC_COMPRESS_SOLID);
313   }
314 
315   void SetNumThreads2();
SetNumThreads()316   void SetNumThreads()
317   {
318     SetNumThreads2();
319     EnableMultiCombo(IDC_COMPRESS_THREADS);
320   }
321 
322   int AddMemComboItem(UInt64 val, bool isPercent = false, bool isDefault = false);
323   void SetMemUseCombo();
324   UString Get_MemUse_Spec();
325   UInt64 Get_MemUse_Bytes();
326 
327   UInt64 GetMemoryUsage_Dict_DecompMem(UInt64 dict, UInt64 &decompressMemory);
328   UInt64 GetMemoryUsage_Threads_Dict_DecompMem(UInt32 numThreads, UInt64 dict, UInt64 &decompressMemory);
329   UInt64 GetMemoryUsage_DecompMem(UInt64 &decompressMemory);
330   UInt64 GetMemoryUsageComp_Threads_Dict(UInt32 numThreads, UInt64 dict64);
331 
332   void PrintMemUsage(UINT res, UInt64 value);
333   void SetMemoryUsage();
334   void Print_Params();
335 
336   void SetParams();
337 
338   void SaveOptionsInMem();
339 
340   void UpdatePasswordControl();
IsShowPasswordChecked()341   bool IsShowPasswordChecked() const { return IsButtonCheckedBool(IDX_PASSWORD_SHOW); }
342 
343   unsigned GetFormatIndex();
344   bool SetArcPathFields(const UString &path, UString &name, bool always);
345   bool SetArcPathFields(const UString &path);
346   bool GetFinalPath_Smart(UString &resPath) const;
347   void ArcPath_WasChanged(const UString &newPath);
348 
349   void CheckSFXControlsEnable();
350   // void CheckVolumeEnable();
351   void EnableMultiCombo(unsigned id);
352   void FormatChanged(bool isChanged);
353 
354   void OnButtonSetArchive();
355   bool IsSFX();
356   void OnButtonSFX();
357 
358   virtual bool OnInit() Z7_override;
359   virtual bool OnMessage(UINT message, WPARAM wParam, LPARAM lParam) Z7_override;
360   virtual bool OnCommand(unsigned code, unsigned itemID, LPARAM lParam) Z7_override;
361   virtual bool OnButtonClicked(unsigned buttonID, HWND buttonHWND) Z7_override;
362   virtual void OnOK() Z7_override;
363   virtual void OnHelp() Z7_override;
364 
MessageBoxError(LPCWSTR message)365   void MessageBoxError(LPCWSTR message)
366   {
367     MessageBoxW(*this, message, L"7-Zip", MB_ICONERROR);
368   }
369 
370   void ShowOptionsString();
371 
372 public:
373   const CObjectVector<CArcInfoEx> *ArcFormats;
374   CUIntVector ArcIndices; // can not be empty, must contain Info.FormatIndex, if Info.FormatIndex >= 0
375   AStringVector ExternalMethods;
376 
377   void SetMethods(const CObjectVector<CCodecInfoUser> &userCodecs);
378 
379   NCompressDialog::CInfo Info;
380   UString OriginalFileName; // for bzip2, gzip2
381 
382   INT_PTR Create(HWND wndParent = NULL)
383   {
384     BIG_DIALOG_SIZE(400, 320);
385     return CModalDialog::Create(SIZED_DIALOG(IDD_COMPRESS), wndParent);
386   }
387 
CCompressDialog()388   CCompressDialog() {}
389 };
390 
391 
392 
393 
394 class COptionsDialog: public NWindows::NControl::CModalDialog
395 {
396   struct CBoolBox
397   {
398     bool IsSupported;
399     bool DefaultVal;
400     CBoolPair BoolPair;
401 
402     unsigned Id;
403     unsigned Set_Id;
404 
SetIDsCBoolBox405     void SetIDs(unsigned id, unsigned set_Id)
406     {
407       Id = id;
408       Set_Id = set_Id;
409     }
410 
CBoolBoxCBoolBox411     CBoolBox():
412         IsSupported(false),
413         DefaultVal(false)
414         {}
415   };
416 
417   CCompressDialog *cd;
418 
419   NWindows::NControl::CComboBox m_Prec;
420 
421   UInt32 _auto_Prec;
422   UInt32 TimePrec;
423 
Reset_TimePrec()424   void Reset_TimePrec() { TimePrec = (UInt32)(Int32)-1; }
IsSet_TimePrec()425   bool IsSet_TimePrec() const { return TimePrec != (UInt32)(Int32)-1; }
426 
427   CBoolBox MTime;
428   CBoolBox CTime;
429   CBoolBox ATime;
430   CBoolBox ZTime;
431 
432   UString SecString;
433   UString NsString;
434 
435 
436   void CheckButton_Bool1(UINT id, const CBool1 &b1);
437   void GetButton_Bool1(UINT id, CBool1 &b1);
438   void CheckButton_BoolBox(bool supported, const CBoolPair &b2, CBoolBox &bb);
439   void GetButton_BoolBox(CBoolBox &bb);
440 
441   void Store_TimeBoxes();
442 
443   UInt32 GetComboValue(NWindows::NControl::CComboBox &c, int defMax = 0);
GetPrecSpec()444   UInt32 GetPrecSpec()
445   {
446     UInt32 prec = GetComboValue(m_Prec, 1);
447     if (prec == _auto_Prec)
448       prec = (UInt32)(Int32)-1;
449     return prec;
450   }
GetPrec()451   UInt32 GetPrec() { return GetComboValue(m_Prec, 0); }
452 
453   // void OnButton_TimeDefault();
454   int AddPrec(unsigned prec, bool isDefault);
455   void SetPrec();
456   void SetTimeMAC();
457 
458   void On_CheckBoxSet_Prec_Clicked();
459   void On_CheckBoxSet_Clicked(const CBoolBox &bb);
460 
461   virtual bool OnInit() Z7_override;
462   virtual bool OnCommand(unsigned code, unsigned itemID, LPARAM lParam) Z7_override;
463   virtual bool OnButtonClicked(unsigned buttonID, HWND buttonHWND) Z7_override;
464   virtual void OnOK() Z7_override;
465   virtual void OnHelp() Z7_override;
466 
467 public:
468 
469   INT_PTR Create(HWND wndParent = NULL)
470   {
471     BIG_DIALOG_SIZE(240, 232);
472     return CModalDialog::Create(SIZED_DIALOG(IDD_COMPRESS_OPTIONS), wndParent);
473   }
474 
COptionsDialog(CCompressDialog * cdLoc)475   COptionsDialog(CCompressDialog *cdLoc):
476       cd(cdLoc)
477       // , TimePrec(0)
478       {
479         Reset_TimePrec();
480       }
481 };
482 
483 #endif
484