• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   NWindows::NControl::CComboBox m_ArchivePath;
145   NWindows::NControl::CComboBox m_Format;
146   NWindows::NControl::CComboBox m_Level;
147   NWindows::NControl::CComboBox m_Method;
148   NWindows::NControl::CComboBox m_Dictionary;
149   // NWindows::NControl::CComboBox m_Dictionary_Chain;
150   NWindows::NControl::CComboBox m_Order;
151   NWindows::NControl::CComboBox m_Solid;
152   NWindows::NControl::CComboBox m_NumThreads;
153   NWindows::NControl::CComboBox m_MemUse;
154   NWindows::NControl::CComboBox m_Volume;
155 
156   int _dictionaryCombo_left;
157 
158   UStringVector _memUse_Strings;
159 
160   NWindows::NControl::CDialogChildControl m_Params;
161 
162   NWindows::NControl::CComboBox m_UpdateMode;
163   NWindows::NControl::CComboBox m_PathMode;
164 
165   NWindows::NControl::CEdit _password1Control;
166   NWindows::NControl::CEdit _password2Control;
167   NWindows::NControl::CComboBox _encryptionMethod;
168 
169   int _auto_MethodId;
170   UInt32 _auto_Dict; // (UInt32)(Int32)-1 means unknown
171   UInt32 _auto_Dict_Chain; // (UInt32)(Int32)-1 means unknown
172   UInt32 _auto_Order;
173   UInt64 _auto_Solid;
174   UInt32 _auto_NumThreads;
175 
176   int _default_encryptionMethod_Index;
177 
178   int m_PrevFormat;
179   UString DirPrefix;
180   UString StartDirPrefix;
181 
182   bool _ramSize_Defined;
183   UInt64 _ramSize;         // full RAM size avail
184   UInt64 _ramSize_Reduced; // full for 64-bit and reduced for 32-bit
185   UInt64 _ramUsage_Auto;
186 
187 public:
188   NCompression::CInfo m_RegistryInfo;
189 
190   CBool1 SymLinks;
191   CBool1 HardLinks;
192   CBool1 AltStreams;
193   CBool1 NtSecurity;
194   CBool1 PreserveATime;
195 
196   void SetArchiveName(const UString &name);
197   int FindRegistryFormat(const UString &name);
198   unsigned FindRegistryFormat_Always(const UString &name);
199 
Get_ArcInfoEx()200   const CArcInfoEx &Get_ArcInfoEx()
201   {
202     return (*ArcFormats)[GetFormatIndex()];
203   }
204 
205   NCompression::CFormatOptions &Get_FormatOptions();
206 
207   void CheckSFXNameChange();
208   void SetArchiveName2(bool prevWasSFX);
209 
210   unsigned GetStaticFormatIndex();
211 
212   void SetNearestSelectComboBox(NWindows::NControl::CComboBox &comboBox, UInt32 value);
213 
214   void SetLevel2();
SetLevel()215   void SetLevel()
216   {
217     SetLevel2();
218     EnableMultiCombo(IDC_COMPRESS_LEVEL);
219     SetMethod();
220   }
221 
222   void SetMethod2(int keepMethodId);
223   void SetMethod(int keepMethodId = -1)
224   {
225     SetMethod2(keepMethodId);
226     EnableMultiCombo(IDC_COMPRESS_METHOD);
227   }
228 
MethodChanged()229   void MethodChanged()
230   {
231     SetDictionary2();
232     EnableMultiCombo(IDC_COMPRESS_DICTIONARY);
233     // EnableMultiCombo(IDC_COMPRESS_DICTIONARY2);
234     SetOrder2();
235     EnableMultiCombo(IDC_COMPRESS_ORDER);
236   }
237 
238   int GetMethodID_RAW();
239   int GetMethodID();
240 
241   UString GetMethodSpec(UString &estimatedName);
242   UString GetMethodSpec();
243   bool IsMethodEqualTo(const UString &s);
244   UString GetEncryptionMethodSpec();
245 
246   bool IsZipFormat();
247   bool IsXzFormat();
248 
249   void SetEncryptionMethod();
250 
251   int AddDict2(size_t sizeReal, size_t sizeShow);
252   int AddDict(size_t size);
253   // int AddDict_Chain(size_t size);
254 
255   void SetDictionary2();
256 
257   UInt32 GetComboValue(NWindows::NControl::CComboBox &c, int defMax = 0);
258   UInt64 GetComboValue_64(NWindows::NControl::CComboBox &c, int defMax = 0);
259 
GetLevel()260   UInt32 GetLevel()  { return GetComboValue(m_Level); }
GetLevelSpec()261   UInt32 GetLevelSpec()  { return GetComboValue(m_Level, 1); }
262   UInt32 GetLevel2();
263 
GetDictSpec()264   UInt64 GetDictSpec() { return GetComboValue_64(m_Dictionary, 1); }
265   // UInt64 GetDictChainSpec() { return GetComboValue_64(m_Dictionary_Chain, 1); }
266 
GetDict2()267   UInt64 GetDict2()
268   {
269     UInt64 num = GetDictSpec();
270     if (num == (UInt64)(Int64)-1)
271     {
272       if (_auto_Dict == (UInt32)(Int32)-1)
273         return (UInt64)(Int64)-1; // unknown
274       num = _auto_Dict;
275     }
276     return num;
277   }
278 
279   // UInt32 GetOrder() { return GetComboValue(m_Order); }
GetOrderSpec()280   UInt32 GetOrderSpec() { return GetComboValue(m_Order, 1); }
GetNumThreadsSpec()281   UInt32 GetNumThreadsSpec() { return GetComboValue(m_NumThreads, 1); }
282 
GetNumThreads2()283   UInt32 GetNumThreads2()
284   {
285     UInt32 num = GetNumThreadsSpec();
286     if (num == (UInt32)(Int32)-1)
287       num = _auto_NumThreads;
288     return num;
289   }
290 
GetBlockSizeSpec()291   UInt32 GetBlockSizeSpec() { return GetComboValue(m_Solid, 1); }
292 
293   /*
294   UInt32 GetPrecSpec() { return GetComboValue(m_Prec, 1); }
295   UInt32 GetPrec() { return GetComboValue(m_Prec, 0); }
296   */
297 
298 
299   int AddOrder(UInt32 size);
300   int AddOrder_Auto();
301 
302   void SetOrder2();
303 
304   bool GetOrderMode();
305 
306   void SetSolidBlockSize2();
SetSolidBlockSize()307   void SetSolidBlockSize(/* bool useDictionary = false */)
308   {
309     SetSolidBlockSize2();
310     EnableMultiCombo(IDC_COMPRESS_SOLID);
311   }
312 
313   void SetNumThreads2();
SetNumThreads()314   void SetNumThreads()
315   {
316     SetNumThreads2();
317     EnableMultiCombo(IDC_COMPRESS_THREADS);
318   }
319 
320   int AddMemComboItem(UInt64 val, bool isPercent = false, bool isDefault = false);
321   void SetMemUseCombo();
322   UString Get_MemUse_Spec();
323   UInt64 Get_MemUse_Bytes();
324 
325   UInt64 GetMemoryUsage_Dict_DecompMem(UInt64 dict, UInt64 &decompressMemory);
326   UInt64 GetMemoryUsage_Threads_Dict_DecompMem(UInt32 numThreads, UInt64 dict, UInt64 &decompressMemory);
327   UInt64 GetMemoryUsage_DecompMem(UInt64 &decompressMemory);
328   UInt64 GetMemoryUsageComp_Threads_Dict(UInt32 numThreads, UInt64 dict64);
329 
330   void PrintMemUsage(UINT res, UInt64 value);
331   void SetMemoryUsage();
332   void Print_Params();
333 
334   void SetParams();
335 
336   void SaveOptionsInMem();
337 
338   void UpdatePasswordControl();
IsShowPasswordChecked()339   bool IsShowPasswordChecked() const { return IsButtonCheckedBool(IDX_PASSWORD_SHOW); }
340 
341   unsigned GetFormatIndex();
342   bool SetArcPathFields(const UString &path, UString &name, bool always);
343   bool SetArcPathFields(const UString &path);
344   bool GetFinalPath_Smart(UString &resPath) const;
345   void ArcPath_WasChanged(const UString &newPath);
346 
347   void CheckSFXControlsEnable();
348   // void CheckVolumeEnable();
349   void EnableMultiCombo(unsigned id);
350   void FormatChanged(bool isChanged);
351 
352   void OnButtonSetArchive();
353   bool IsSFX();
354   void OnButtonSFX();
355 
356   virtual bool OnInit() Z7_override;
357   virtual bool OnMessage(UINT message, WPARAM wParam, LPARAM lParam) Z7_override;
358   virtual bool OnCommand(unsigned code, unsigned itemID, LPARAM lParam) Z7_override;
359   virtual bool OnButtonClicked(unsigned buttonID, HWND buttonHWND) Z7_override;
360   virtual void OnOK() Z7_override;
361   virtual void OnHelp() Z7_override;
362 
MessageBoxError(LPCWSTR message)363   void MessageBoxError(LPCWSTR message)
364   {
365     MessageBoxW(*this, message, L"7-Zip", MB_ICONERROR);
366   }
367 
368   void ShowOptionsString();
369 
370 public:
371   const CObjectVector<CArcInfoEx> *ArcFormats;
372   CUIntVector ArcIndices; // can not be empty, must contain Info.FormatIndex, if Info.FormatIndex >= 0
373   AStringVector ExternalMethods;
374 
375   void SetMethods(const CObjectVector<CCodecInfoUser> &userCodecs);
376 
377   NCompressDialog::CInfo Info;
378   UString OriginalFileName; // for bzip2, gzip2
379 
380   INT_PTR Create(HWND wndParent = NULL)
381   {
382     BIG_DIALOG_SIZE(400, 320);
383     return CModalDialog::Create(SIZED_DIALOG(IDD_COMPRESS), wndParent);
384   }
385 
CCompressDialog()386   CCompressDialog() {}
387 };
388 
389 
390 
391 
392 class COptionsDialog: public NWindows::NControl::CModalDialog
393 {
394   struct CBoolBox
395   {
396     bool IsSupported;
397     bool DefaultVal;
398     CBoolPair BoolPair;
399 
400     unsigned Id;
401     unsigned Set_Id;
402 
SetIDsCBoolBox403     void SetIDs(unsigned id, unsigned set_Id)
404     {
405       Id = id;
406       Set_Id = set_Id;
407     }
408 
CBoolBoxCBoolBox409     CBoolBox():
410         IsSupported(false),
411         DefaultVal(false)
412         {}
413   };
414 
415   CCompressDialog *cd;
416 
417   NWindows::NControl::CComboBox m_Prec;
418 
419   UInt32 _auto_Prec;
420   UInt32 TimePrec;
421 
Reset_TimePrec()422   void Reset_TimePrec() { TimePrec = (UInt32)(Int32)-1; }
IsSet_TimePrec()423   bool IsSet_TimePrec() const { return TimePrec != (UInt32)(Int32)-1; }
424 
425   CBoolBox MTime;
426   CBoolBox CTime;
427   CBoolBox ATime;
428   CBoolBox ZTime;
429 
430   UString SecString;
431   UString NsString;
432 
433 
434   void CheckButton_Bool1(UINT id, const CBool1 &b1);
435   void GetButton_Bool1(UINT id, CBool1 &b1);
436   void CheckButton_BoolBox(bool supported, const CBoolPair &b2, CBoolBox &bb);
437   void GetButton_BoolBox(CBoolBox &bb);
438 
439   void Store_TimeBoxes();
440 
441   UInt32 GetComboValue(NWindows::NControl::CComboBox &c, int defMax = 0);
GetPrecSpec()442   UInt32 GetPrecSpec()
443   {
444     UInt32 prec = GetComboValue(m_Prec, 1);
445     if (prec == _auto_Prec)
446       prec = (UInt32)(Int32)-1;
447     return prec;
448   }
GetPrec()449   UInt32 GetPrec() { return GetComboValue(m_Prec, 0); }
450 
451   // void OnButton_TimeDefault();
452   int AddPrec(unsigned prec, bool isDefault);
453   void SetPrec();
454   void SetTimeMAC();
455 
456   void On_CheckBoxSet_Prec_Clicked();
457   void On_CheckBoxSet_Clicked(const CBoolBox &bb);
458 
459   virtual bool OnInit() Z7_override;
460   virtual bool OnCommand(unsigned code, unsigned itemID, LPARAM lParam) Z7_override;
461   virtual bool OnButtonClicked(unsigned buttonID, HWND buttonHWND) Z7_override;
462   virtual void OnOK() Z7_override;
463   virtual void OnHelp() Z7_override;
464 
465 public:
466 
467   INT_PTR Create(HWND wndParent = NULL)
468   {
469     BIG_DIALOG_SIZE(240, 232);
470     return CModalDialog::Create(SIZED_DIALOG(IDD_COMPRESS_OPTIONS), wndParent);
471   }
472 
COptionsDialog(CCompressDialog * cdLoc)473   COptionsDialog(CCompressDialog *cdLoc):
474       cd(cdLoc)
475       // , TimePrec(0)
476       {
477         Reset_TimePrec();
478       }
479 };
480 
481 #endif
482