Debian Codegraph @

plugins/wcx/sevenzip/src/SevenZipDlg.pas

raw
1 {
2 Double Commander
3 -------------------------------------------------------------------------
4 SevenZip archiver plugin, dialogs unit
5
6 Copyright (C) 2014-2017 Alexander Koblov ([email protected])
7
8 Based on 7-Zip 15.06 (http://7-zip.org)
9 7-Zip Copyright (C) 1999-2015 Igor Pavlov
10
11 This library is free software; you can redistribute it and/or
12 modify it under the terms of the GNU Lesser General Public
13 License as published by the Free Software Foundation; either
14 version 2.1 of the License, or (at your option) any later version.
15
16 This library is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Lesser General Public License for more details.
20
21 You should have received a copy of the GNU Lesser General Public
22 License along with this library; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 }
25
26 unit SevenZipDlg;
27
28 {$mode delphi}
29
30 interface
31
32 uses
33 Classes, SysUtils, Windows, Math, SevenZipOpt, SevenZipLng, JclCompression;
34
35 procedure ShowConfigurationDialog(Parent: HWND);
36 function ShowPasswordQuery(var Encrypt: Boolean; var Password: WideString): Boolean;
37
38 implementation
39
40 uses
41 LazUTF8, SevenZipCodecs;
42
43 {$R *.res}
44
45 const
46 IDC_PASSWORD = 1001;
47 IDC_SHOW_PASSWORD = 1002;
48 IDC_ENCRYPT_HEADER = 0;
49
50 const
51 IDC_APPLY_BUTTON = 9;
52 IDC_COMP_FORMAT = 1076;
53 IDC_COMP_METHOD = 1078;
54 IDC_COMP_LEVEL = 1074;
55 IDC_VOLUME_SIZE = 1077;
56 IDC_COMP_DICT = 1079;
57 IDC_COMP_WORD = 1080;
58 IDC_COMP_SOLID = 1081;
59 IDC_COMP_THREAD = 1082;
60 IDC_MAX_THREAD = 1083;
61 IDC_PARAMETERS = 1091;
62 IDC_MEMORY_COMP = 1027;
63 IDC_MEMORY_DECOMP = 1028;
64
65 function GetComboBox(hwndDlg: HWND; ItemID: Integer): PtrInt;
66 var
67 Index: Integer;
68 begin
69 Index:= SendDlgItemMessage(hwndDlg, ItemID, CB_GETCURSEL, 0, 0);
70 Result:= SendDlgItemMessage(hwndDlg, ItemID, CB_GETITEMDATA, Index, 0);
71 end;
72
73 procedure SetComboBox(hwndDlg: HWND; ItemID: Integer; ItemData: PtrInt);
74 var
75 Index, Count: Integer;
76 begin
77 Count:= SendDlgItemMessage(hwndDlg, ItemID, CB_GETCOUNT, 0, 0);
78 for Index:= 0 to Count - 1 do
79 begin
80 if SendDlgItemMessage(hwndDlg, ItemID, CB_GETITEMDATA, Index, 0) = ItemData then
81 begin
82 SendDlgItemMessage(hwndDlg, ItemID, CB_SETCURSEL, Index, 0);
83 Exit;
84 end;
85 end;
86 end;
87
88 procedure SaveArchiver(hwndDlg: HWND);
89 var
90 Format: TArchiveFormat;
91 Parameters: array[0..MAX_PATH] of WideChar;
92 begin
93 Format:= TArchiveFormat(GetWindowLongPtr(hwndDlg, GWLP_USERDATA));
94 PluginConfig[Format].Level:= GetComboBox(hwndDlg, IDC_COMP_LEVEL);
95 PluginConfig[Format].Method:= GetComboBox(hwndDlg, IDC_COMP_METHOD);
96 if PluginConfig[Format].Level <> PtrInt(clStore) then
97 begin
98 PluginConfig[Format].Dictionary:= GetComboBox(hwndDlg, IDC_COMP_DICT);
99 PluginConfig[Format].WordSize:= GetComboBox(hwndDlg, IDC_COMP_WORD);
100 PluginConfig[Format].SolidSize:= GetComboBox(hwndDlg, IDC_COMP_SOLID);
101 PluginConfig[Format].ThreadCount:= GetComboBox(hwndDlg, IDC_COMP_THREAD);
102 end;
103 GetDlgItemTextW(hwndDlg, IDC_PARAMETERS, Parameters, MAX_PATH);
104 PluginConfig[Format].Parameters:= Parameters;
105
106 SaveConfiguration;
107 end;
108
109 function ComboBoxAdd(hwndDlg: HWND; ItemID: Integer; ItemText: String; ItemData: PtrInt): Integer;
110 var
111 Text: UnicodeString;
112 begin
113 Text:= UTF8ToUTF16(ItemText);
114 Result:= SendDlgItemMessageW(hwndDlg, ItemID, CB_ADDSTRING, 0, LPARAM(PWideChar(Text)));
115 SendDlgItemMessage(hwndDlg, ItemID, CB_SETITEMDATA, Result, ItemData);
116 end;
117
118 function GetMemoryUsage(hwndDlg: HWND; out decompressMemory: Int64): Int64;
119 var
120 size: Int64 = 0;
121 Dictionary, hs,
122 numThreads, numThreads1,
123 numBlockThreads: Cardinal;
124 size1, chunkSize: Int64;
125 Level: TCompressionLevel;
126 Method: TJclCompressionMethod;
127 begin
128 Level := TCompressionLevel(GetComboBox(hwndDlg, IDC_COMP_LEVEL));
129 if (level = clStore) then
130 begin
131 decompressMemory := (1 shl 20);
132 Exit(decompressMemory);
133 end;
134
135 decompressMemory := -1;
136 Dictionary := Cardinal(GetComboBox(hwndDlg, IDC_COMP_DICT));
137 Method := TJclCompressionMethod(GetComboBox(hwndDlg, IDC_COMP_METHOD));
138
139 if (Method <> cmDeflate) and (Method <> cmDeflate64) and (level >= clUltra) then
140 size += (12 shl 20) * 2 + (5 shl 20);
141
142 numThreads := GetComboBox(hwndDlg, IDC_COMP_THREAD);
143
144 case (method) of
145 cmLZMA,
146 cmLZMA2:
147 begin
148 hs := dictionary - 1;
149 hs := hs or (hs shr 1);
150 hs := hs or (hs shr 2);
151 hs := hs or (hs shr 4);
152 hs := hs or (hs shr 8);
153 hs := hs shr 1;
154 hs := hs or $FFFF;
155 if (hs > (1 shl 24)) then
156 hs := hs shr 1;
157 Inc(hs);
158 size1 := Int64(hs) * 4;
159 size1 += Int64(dictionary) * 4;
160 if (level >= clNormal) then
161 size1 += Int64(dictionary) * 4;
162 size1 += (2 shl 20);
163
164 numThreads1 := 1;
165 if (numThreads > 1) and (level >= clNormal) then
166 begin
167 size1 += (2 shl 20) + (4 shl 20);
168 numThreads1 := 2;
169 end;
170
171 numBlockThreads := numThreads div numThreads1;
172
173 if (method = cmLZMA) or (numBlockThreads = 1) then
174 size1 += Int64(dictionary) * 3 div 2
175 else
176 begin
177 chunkSize := Int64(dictionary) shl 2;
178 chunkSize := Max(chunkSize, Int64(1 shl 20));
179 chunkSize := Min(chunkSize, Int64(1 shl 28));
180 chunkSize := Max(chunkSize, Int64(dictionary));
181 size1 += chunkSize * 2;
182 end;
183 size += size1 * numBlockThreads;
184
185 decompressMemory := Int64(dictionary) + (2 shl 20);
186 Exit(size);
187 end;
188 cmPPMd:
189 begin
190 decompressMemory := Int64(dictionary) + (2 shl 20);
191 Exit(size + decompressMemory);
192 end;
193 cmDeflate,
194 cmDeflate64:
195 begin
196 if (level >= clMaximum) then
197 size += (1 shl 20);
198 size += 3 shl 20;
199 decompressMemory := (2 shl 20);
200 Exit(size);
201 end;
202 cmBZip2:
203 begin
204 decompressMemory := (7 shl 20);
205 size1 := (10 shl 20);
206 Exit(size + size1 * numThreads);
207 end;
208 end;
209 Result := -1;
210 end;
211
212 procedure UpdateMemoryUsage(hwndDlg: HWND);
213 var
214 Comp, Decomp: Int64;
215 begin
216 if (GetComboBox(hwndDlg, IDC_COMP_METHOD) > cmMaximum) then
217 begin
218 SetDlgItemText(hwndDlg, IDC_MEMORY_COMP, '?');
219 SetDlgItemText(hwndDlg, IDC_MEMORY_DECOMP, '?');
220 end
221 else begin
222 Comp := GetMemoryUsage(hwndDlg, Decomp);
223 SetDlgItemText(hwndDlg, IDC_MEMORY_COMP, PAnsiChar(IntToStr(Comp div cMega) + 'Mb'));
224 SetDlgItemText(hwndDlg, IDC_MEMORY_DECOMP, PAnsiChar(IntToStr(Decomp div cMega) + 'Mb'));
225 end;
226 end;
227
228 procedure SetDefaultOptions(hwndDlg: HWND);
229 var
230 Value: PtrInt;
231 Level: TCompressionLevel;
232 Method: TJclCompressionMethod;
233 begin
234 Value:= GetComboBox(hwndDlg, IDC_COMP_METHOD);
235
236 if (Value <= cmMaximum) then
237 begin
238 // Get compression method
239 Method:= TJclCompressionMethod(Value);
240 // Get compression level
241 Level:= TCompressionLevel(GetComboBox(hwndDlg, IDC_COMP_LEVEL));
242
243 case Method of
244 cmDeflate,
245 cmDeflate64:
246 begin
247 case Level of
248 clFastest,
249 clFast,
250 clNormal:
251 SetComboBox(hwndDlg, IDC_COMP_WORD, 32);
252 clMaximum:
253 SetComboBox(hwndDlg, IDC_COMP_WORD, 64);
254 clUltra:
255 SetComboBox(hwndDlg, IDC_COMP_WORD, 128);
256 end;
257 SendDlgItemMessage(hwndDlg, IDC_COMP_DICT, CB_SETCURSEL, 0, 0);
258 end;
259 cmBZip2:
260 begin
261 case Level of
262 clFastest:
263 begin
264 SetComboBox(hwndDlg, IDC_COMP_DICT, 100 * cKilo);
265 SetComboBox(hwndDlg, IDC_COMP_SOLID, 8 * cKilo);
266 end;
267 clFast:
268 begin
269 SetComboBox(hwndDlg, IDC_COMP_DICT, 500 * cKilo);
270 SetComboBox(hwndDlg, IDC_COMP_SOLID, 32 * cKilo);
271 end;
272 clNormal,
273 clMaximum,
274 clUltra:
275 begin
276 SetComboBox(hwndDlg, IDC_COMP_DICT, 900 * cKilo);
277 SetComboBox(hwndDlg, IDC_COMP_SOLID, 64 * cKilo);
278 end;
279 end;
280 end;
281 cmLZMA,
282 cmLZMA2:
283 begin
284 case Level of
285 clFastest:
286 begin
287 SetComboBox(hwndDlg, IDC_COMP_DICT, 64 * cKilo);
288 SetComboBox(hwndDlg, IDC_COMP_WORD, 32);
289 SetComboBox(hwndDlg, IDC_COMP_SOLID, 8 * cKilo);
290 end;
291 clFast:
292 begin
293 SetComboBox(hwndDlg, IDC_COMP_DICT, cMega);
294 SetComboBox(hwndDlg, IDC_COMP_WORD, 32);
295 SetComboBox(hwndDlg, IDC_COMP_SOLID, 128 * cKilo);
296 end;
297 clNormal:
298 begin
299 SetComboBox(hwndDlg, IDC_COMP_DICT, 16 * cMega);
300 SetComboBox(hwndDlg, IDC_COMP_WORD, 32);
301 SetComboBox(hwndDlg, IDC_COMP_SOLID, 2 * cMega);
302 end;
303 clMaximum:
304 begin
305 SetComboBox(hwndDlg, IDC_COMP_DICT, 32 * cMega);
306 SetComboBox(hwndDlg, IDC_COMP_WORD, 64);
307 SetComboBox(hwndDlg, IDC_COMP_SOLID, 4 * cMega);
308 end;
309 clUltra:
310 begin
311 SetComboBox(hwndDlg, IDC_COMP_DICT, 64 * cMega);
312 SetComboBox(hwndDlg, IDC_COMP_WORD, 64);
313 SetComboBox(hwndDlg, IDC_COMP_SOLID, 4 * cMega);
314 end;
315 end;
316 end;
317 cmPPMd:
318 begin
319 case Level of
320 clFastest,
321 clFast:
322 begin
323 SetComboBox(hwndDlg, IDC_COMP_DICT, 4 * cMega);
324 SetComboBox(hwndDlg, IDC_COMP_WORD, 4);
325 SetComboBox(hwndDlg, IDC_COMP_SOLID, 512 * cKilo);
326 end;
327 clNormal:
328 begin
329 SetComboBox(hwndDlg, IDC_COMP_DICT, 16 * cMega);
330 SetComboBox(hwndDlg, IDC_COMP_WORD, 6);
331 SetComboBox(hwndDlg, IDC_COMP_SOLID, 2 * cMega);
332 end;
333 clMaximum:
334 begin
335 SetComboBox(hwndDlg, IDC_COMP_DICT, 64 * cMega);
336 SetComboBox(hwndDlg, IDC_COMP_WORD, 16);
337 SetComboBox(hwndDlg, IDC_COMP_SOLID, 4 * cMega);
338 end;
339 clUltra:
340 begin
341 SetComboBox(hwndDlg, IDC_COMP_DICT, 192 * cMega);
342 SetComboBox(hwndDlg, IDC_COMP_WORD, 16);
343 SetComboBox(hwndDlg, IDC_COMP_SOLID, 4 * cMega);
344 end;
345 end;
346 end;
347 end;
348 end;
349 UpdateMemoryUsage(hwndDlg);
350 end;
351
352 procedure UpdateSolid(hwndDlg: HWND);
353 var
354 Index: Integer;
355 Format: TArchiveFormat;
356 Level: TCompressionLevel;
357 begin
358 SendDlgItemMessage(hwndDlg, IDC_COMP_SOLID, CB_RESETCONTENT, 0, 0);
359 // Get compression level
360 Level:= TCompressionLevel(GetComboBox(hwndDlg, IDC_COMP_LEVEL));
361 Format:= TArchiveFormat(GetWindowLongPtr(hwndDlg, GWLP_USERDATA));
362 if (Format in [afSevenZip]) and (Level <> clStore) then
363 begin
364 ComboBoxAdd(hwndDlg, IDC_COMP_SOLID, rsSolidBlockNonSolid, kNoSolidBlockSize);
365 for Index:= Low(SolidBlock) to High(SolidBlock) do
366 begin
367 ComboBoxAdd(hwndDlg, IDC_COMP_SOLID, FormatFileSize(Int64(SolidBlock[Index]) * cKilo), PtrInt(SolidBlock[Index]));
368 end;
369 ComboBoxAdd(hwndDlg, IDC_COMP_SOLID, rsSolidBlockSolid, kSolidBlockSize);
370 end;
371 end;
372
373 procedure UpdateThread(hwndDlg: HWND; dwAlgoThreadMax: LongWord);
374 var
375 Index: LongWord;
376 dwMaxThread: LongWord;
377 dwDefaultValue: DWORD;
378 wsMaxThread: WideString;
379 dwHardwareThreads: DWORD;
380 begin
381 SendDlgItemMessage(hwndDlg, IDC_COMP_THREAD, CB_RESETCONTENT, 0, 0);
382 dwHardwareThreads:= GetNumberOfProcessors;
383 dwDefaultValue:= dwHardwareThreads;
384 dwMaxThread:= dwHardwareThreads * 2;
385 if dwMaxThread > dwAlgoThreadMax then dwMaxThread:= dwAlgoThreadMax;
386 if dwAlgoThreadMax < dwDefaultValue then dwDefaultValue:= dwAlgoThreadMax;
387 for Index:= 1 to dwMaxThread do
388 begin
389 ComboBoxAdd(hwndDlg, IDC_COMP_THREAD, IntToStr(Index), Index);
390 end;
391 wsMaxThread:= '/ ' + WideString(IntToStr(dwHardwareThreads));
392 SendDlgItemMessage(hwndDlg, IDC_COMP_THREAD, CB_SETCURSEL, dwDefaultValue - 1, 0);
393 SendDlgItemMessageW(hwndDlg, IDC_MAX_THREAD, WM_SETTEXT, 0, LPARAM(PWideChar(wsMaxThread)));
394 end;
395
396 procedure UpdateMethod(hwndDlg: HWND);
397 var
398 Index: PtrInt;
399 Format: TArchiveFormat;
400 dwAlgoThreadMax: LongWord = 1;
401 Method: TJclCompressionMethod;
402 begin
403 // Clear comboboxes
404 SendDlgItemMessage(hwndDlg, IDC_COMP_DICT, CB_RESETCONTENT, 0, 0);
405 SendDlgItemMessage(hwndDlg, IDC_COMP_WORD, CB_RESETCONTENT, 0, 0);
406 Format:= TArchiveFormat(GetWindowLongPtr(hwndDlg, GWLP_USERDATA));
407 EnableWindow(GetDlgItem(hwndDlg, IDC_COMP_DICT), not (Format in [afTar, afWim]));
408 // Get Compression method
409 Index:= GetComboBox(hwndDlg, IDC_COMP_METHOD);
410 if Index > cmMaximum then
411 begin
412 dwAlgoThreadMax:= GetNumberOfProcessors;
413 EnableWindow(GetDlgItem(hwndDlg, IDC_COMP_DICT), False);
414 EnableWindow(GetDlgItem(hwndDlg, IDC_COMP_WORD), False);
415 end
416 else begin
417 Method:= TJclCompressionMethod(Index);
418 EnableWindow(GetDlgItem(hwndDlg, IDC_COMP_WORD), (Format in [afSevenZip, afGzip, afXz, afZip]) and (Method <> cmBZip2));
419 case Method of
420 cmDeflate:
421 begin
422 for Index:= Low(DeflateDict) to High(DeflateDict) do
423 begin
424 ComboBoxAdd(hwndDlg, IDC_COMP_DICT, FormatFileSize(DeflateDict[Index]), PtrInt(DeflateDict[Index]));
425 end;
426 for Index:= Low(DeflateWordSize) to High(DeflateWordSize) do
427 begin
428 ComboBoxAdd(hwndDlg, IDC_COMP_WORD, IntToStr(DeflateWordSize[Index]), PtrInt(DeflateWordSize[Index]));
429 end;
430 end;
431 cmDeflate64:
432 begin
433 for Index:= Low(Deflate64Dict) to High(Deflate64Dict) do
434 begin
435 ComboBoxAdd(hwndDlg, IDC_COMP_DICT, FormatFileSize(Deflate64Dict[Index]), PtrInt(Deflate64Dict[Index]));
436 end;
437 for Index:= Low(Deflate64WordSize) to High(Deflate64WordSize) do
438 begin
439 ComboBoxAdd(hwndDlg, IDC_COMP_WORD, IntToStr(Deflate64WordSize[Index]), PtrInt(Deflate64WordSize[Index]));
440 end;
441 end;
442 cmLZMA,
443 cmLZMA2:
444 begin
445 for Index:= Low(LZMADict) to High(LZMADict) do
446 begin
447 ComboBoxAdd(hwndDlg, IDC_COMP_DICT, FormatFileSize(LZMADict[Index], False), PtrInt(LZMADict[Index]));
448 end;
449 for Index:= Low(LZMAWordSize) to High(LZMAWordSize) do
450 begin
451 ComboBoxAdd(hwndDlg, IDC_COMP_WORD, IntToStr(LZMAWordSize[Index]), PtrInt(LZMAWordSize[Index]));
452 end;
453 dwAlgoThreadMax:= IfThen(Method = cmLZMA, 2, 32);
454 end;
455 cmBZip2:
456 begin
457 for Index:= Low(BZip2Dict) to High(BZip2Dict) do
458 begin
459 ComboBoxAdd(hwndDlg, IDC_COMP_DICT, FormatFileSize(BZip2Dict[Index]), PtrInt(BZip2Dict[Index]));
460 end;
461 dwAlgoThreadMax:= 32;
462 end;
463 cmPPMd:
464 begin
465 for Index:= Low(PPMdDict) to High(PPMdDict) do
466 begin
467 ComboBoxAdd(hwndDlg, IDC_COMP_DICT, FormatFileSize(PPMdDict[Index], False), PtrInt(PPMdDict[Index]));
468 end;
469 for Index:= Low(PPMdWordSize) to High(PPMdWordSize) do
470 begin
471 ComboBoxAdd(hwndDlg, IDC_COMP_WORD, IntToStr(PPMdWordSize[Index]), PtrInt(PPMdWordSize[Index]));
472 end;
473 end;
474 end;
475 if Format = afZip then dwAlgoThreadMax:= 128;
476 end;
477 UpdateThread(hwndDlg, dwAlgoThreadMax);
478 end;
479
480 procedure FillMethod(hwndDlg: HWND);
481 var
482 Index: Integer;
483 Format: TArchiveFormat;
484 begin
485 // Clear combobox
486 SendDlgItemMessage(hwndDlg, IDC_COMP_METHOD, CB_RESETCONTENT, 0, 0);
487 Format:= TArchiveFormat(GetWindowLongPtr(hwndDlg, GWLP_USERDATA));
488 case Format of
489 afSevenZip:
490 begin
491 // Fill compression method
492 ComboBoxAdd(hwndDlg, IDC_COMP_METHOD, 'LZMA', PtrInt(cmLZMA));
493 ComboBoxAdd(hwndDlg, IDC_COMP_METHOD, 'LZMA2', PtrInt(cmLZMA2));
494 ComboBoxAdd(hwndDlg, IDC_COMP_METHOD, 'PPMd', PtrInt(cmPPMd));
495 ComboBoxAdd(hwndDlg, IDC_COMP_METHOD, 'BZip2', PtrInt(cmBZip2));
496 if Assigned(ACodecs) then begin
497 for Index:= 0 to ACodecs.Count - 1 do begin
498 ComboBoxAdd(hwndDlg, IDC_COMP_METHOD, ACodecs[Index].Name, PtrInt(ACodecs[Index].ID));
499 end;
500 end;
501 SetComboBox(hwndDlg, IDC_COMP_METHOD, PluginConfig[Format].Method);
502 end;
503 afBzip2:
504 begin
505 // Fill compression method
506 ComboBoxAdd(hwndDlg, IDC_COMP_METHOD, 'BZip2', PtrInt(cmBZip2));
507 SendDlgItemMessage(hwndDlg, IDC_COMP_METHOD, CB_SETCURSEL, 0, 0);
508 end;
509 afGzip:
510 begin
511 // Fill compression method
512 ComboBoxAdd(hwndDlg, IDC_COMP_METHOD, 'Deflate', PtrInt(cmDeflate));
513 SendDlgItemMessage(hwndDlg, IDC_COMP_METHOD, CB_SETCURSEL, 0, 0);
514 end;
515 afXz:
516 begin
517 // Fill compression method
518 ComboBoxAdd(hwndDlg, IDC_COMP_METHOD, 'LZMA2', PtrInt(cmLZMA2));
519 SendDlgItemMessage(hwndDlg, IDC_COMP_METHOD, CB_SETCURSEL, 0, 0);
520 end;
521 afZip:
522 begin
523 // Fill compression method
524 ComboBoxAdd(hwndDlg, IDC_COMP_METHOD, 'Deflate', PtrInt(cmDeflate));
525 ComboBoxAdd(hwndDlg, IDC_COMP_METHOD, 'Deflate64', PtrInt(cmDeflate64));
526 ComboBoxAdd(hwndDlg, IDC_COMP_METHOD, 'BZip2', PtrInt(cmBZip2));
527 ComboBoxAdd(hwndDlg, IDC_COMP_METHOD, 'LZMA', PtrInt(cmLZMA));
528 ComboBoxAdd(hwndDlg, IDC_COMP_METHOD, 'PPMd', PtrInt(cmPPMd));
529 end;
530 end;
531 end;
532
533 procedure UpdateFormat(hwndDlg: HWND);
534 var
535 Format: TArchiveFormat;
536 begin
537 // Clear comboboxes
538 SendDlgItemMessage(hwndDlg, IDC_COMP_LEVEL, CB_RESETCONTENT, 0, 0);
539 // Get archive format
540 Format:= TArchiveFormat(GetComboBox(hwndDlg, IDC_COMP_FORMAT));
541 SetWindowLongPtr(hwndDlg, GWLP_USERDATA, LONG_PTR(Format));
542 EnableWindow(GetDlgItem(hwndDlg, IDC_COMP_SOLID), Format = afSevenZip);
543 // 7Zip and Zip
544 if Format in [afSevenZip, afZip] then
545 begin
546 // Fill compression level
547 ComboBoxAdd(hwndDlg, IDC_COMP_LEVEL, rsCompressionLevelStore, PtrInt(clStore));
548 ComboBoxAdd(hwndDlg, IDC_COMP_LEVEL, rsCompressionLevelFastest, PtrInt(clFastest));
549 ComboBoxAdd(hwndDlg, IDC_COMP_LEVEL, rsCompressionLevelFast, PtrInt(clFast));
550 ComboBoxAdd(hwndDlg, IDC_COMP_LEVEL, rsCompressionLevelNormal, PtrInt(clNormal));
551 ComboBoxAdd(hwndDlg, IDC_COMP_LEVEL, rsCompressionLevelMaximum, PtrInt(clMaximum));
552 ComboBoxAdd(hwndDlg, IDC_COMP_LEVEL, rsCompressionLevelUltra, PtrInt(clUltra));
553 end
554 else if Format in [afBzip2, afXz] then
555 begin
556 // Fill compression level
557 ComboBoxAdd(hwndDlg, IDC_COMP_LEVEL, rsCompressionLevelFastest, PtrInt(clFastest));
558 ComboBoxAdd(hwndDlg, IDC_COMP_LEVEL, rsCompressionLevelFast, PtrInt(clFast));
559 ComboBoxAdd(hwndDlg, IDC_COMP_LEVEL, rsCompressionLevelNormal, PtrInt(clNormal));
560 ComboBoxAdd(hwndDlg, IDC_COMP_LEVEL, rsCompressionLevelMaximum, PtrInt(clMaximum));
561 ComboBoxAdd(hwndDlg, IDC_COMP_LEVEL, rsCompressionLevelUltra, PtrInt(clUltra));
562 end
563 else if Format in [afGzip] then
564 begin
565 // Fill compression level
566 ComboBoxAdd(hwndDlg, IDC_COMP_LEVEL, rsCompressionLevelFast, PtrInt(clFast));
567 ComboBoxAdd(hwndDlg, IDC_COMP_LEVEL, rsCompressionLevelNormal, PtrInt(clNormal));
568 ComboBoxAdd(hwndDlg, IDC_COMP_LEVEL, rsCompressionLevelMaximum, PtrInt(clMaximum));
569 ComboBoxAdd(hwndDlg, IDC_COMP_LEVEL, rsCompressionLevelUltra, PtrInt(clUltra));
570 end
571 else begin
572 // Fill compression level
573 ComboBoxAdd(hwndDlg, IDC_COMP_LEVEL, rsCompressionLevelStore, PtrInt(clStore));
574 end;
575 FillMethod(hwndDlg);
576 end;
577
578 procedure UpdateLevel(hwndDlg: HWND; First: Boolean);
579 var
580 MethodStd: Boolean;
581 Format: TArchiveFormat;
582 Level: TCompressionLevel;
583 begin
584 Format:= TArchiveFormat(GetWindowLongPtr(hwndDlg, GWLP_USERDATA));
585 // Get compression level
586 Level:= TCompressionLevel(GetComboBox(hwndDlg, IDC_COMP_LEVEL));
587 // Get compression method
588 MethodStd:= (GetComboBox(hwndDlg, IDC_COMP_METHOD) <= cmMaximum);
589
590 EnableWindow(GetDlgItem(hwndDlg, IDC_COMP_DICT), (Level <> clStore) and MethodStd);
591 EnableWindow(GetDlgItem(hwndDlg, IDC_COMP_WORD), (Level <> clStore) and MethodStd);
592 EnableWindow(GetDlgItem(hwndDlg, IDC_COMP_SOLID), (Format = afSevenZip) and (Level <> clStore));
593
594 if Level = clStore then
595 begin
596 SendDlgItemMessage(hwndDlg, IDC_COMP_METHOD, CB_RESETCONTENT, 0, 0);
597 SendDlgItemMessage(hwndDlg, IDC_COMP_DICT, CB_RESETCONTENT, 0, 0);
598 SendDlgItemMessage(hwndDlg, IDC_COMP_WORD, CB_RESETCONTENT, 0, 0);
599 SendDlgItemMessage(hwndDlg, IDC_COMP_SOLID, CB_RESETCONTENT, 0, 0);
600 ComboBoxAdd(hwndDlg, IDC_COMP_METHOD, MethodName[cmCopy], PtrInt(cmCopy));
601 SendDlgItemMessage(hwndDlg, IDC_COMP_METHOD, CB_SETCURSEL, 0, 0);
602 UpdateThread(hwndDlg, 1);
603 end
604 else if not First then
605 begin
606 FillMethod(hwndDlg);
607 PluginConfig[Format].Method:= DefaultConfig[Format].Method;
608 SetComboBox(hwndDlg, IDC_COMP_METHOD, PluginConfig[Format].Method);
609 UpdateMethod(hwndDlg);
610 UpdateSolid(hwndDlg);
611 EnableWindow(GetDlgItem(hwndDlg, IDC_COMP_SOLID), Format = afSevenZip);
612 end;
613 end;
614
615 procedure SelectFormat(hwndDlg: HWND);
616 var
617 Format: TArchiveFormat;
618 begin
619 UpdateFormat(hwndDlg);
620 Format:= TArchiveFormat(GetWindowLongPtr(hwndDlg, GWLP_USERDATA));
621 SetComboBox(hwndDlg, IDC_COMP_LEVEL, PluginConfig[Format].Level);
622 SetComboBox(hwndDlg, IDC_COMP_METHOD, PluginConfig[Format].Method);
623 UpdateMethod(hwndDlg);
624 UpdateLevel(hwndDlg, True);
625 UpdateSolid(hwndDlg);
626 SetComboBox(hwndDlg, IDC_COMP_DICT, PluginConfig[Format].Dictionary);
627 SetComboBox(hwndDlg, IDC_COMP_WORD, PluginConfig[Format].WordSize);
628 SetComboBox(hwndDlg, IDC_COMP_SOLID, PluginConfig[Format].SolidSize);
629 SetComboBox(hwndDlg, IDC_COMP_THREAD, PluginConfig[Format].ThreadCount);
630 SetDlgItemTextW(hwndDlg, IDC_PARAMETERS, PWideChar(PluginConfig[Format].Parameters));
631 UpdateMemoryUsage(hwndDlg);
632 end;
633
634 function DialogProc(hwndDlg: HWND; uMsg: UINT; wParam: WPARAM; lParam: LPARAM): INT_PTR; stdcall;
635 var
636 Index: TArchiveFormat;
637 begin
638 case uMsg of
639 WM_INITDIALOG:
640 begin
641 EnableWindow(GetDlgItem(hwndDlg, IDC_VOLUME_SIZE), False);
642 for Index:= Low(ArchiveExtension) to High(ArchiveExtension) do
643 ComboBoxAdd(hwndDlg, IDC_COMP_FORMAT, ArchiveExtension[Index], PtrInt(Index));
644 SendDlgItemMessage(hwndDlg, IDC_COMP_FORMAT, CB_SETCURSEL, 0, 0);
645 SelectFormat(hwndDlg);
646 Result:= 1;
647 end;
648 WM_COMMAND:
649 begin
650 case LOWORD(wParam) of
651 IDC_COMP_FORMAT:
652 begin
653 if (HIWORD(wParam) = CBN_SELCHANGE) then
654 begin
655 SelectFormat(hwndDlg);
656 end;
657 end;
658 IDC_COMP_METHOD:
659 if (HIWORD(wParam) = CBN_SELCHANGE) then
660 begin
661 UpdateMethod(hwndDlg);
662 SetDefaultOptions(hwndDlg);
663 end;
664 IDC_COMP_LEVEL:
665 if (HIWORD(wParam) = CBN_SELCHANGE) then
666 begin
667 UpdateLevel(hwndDlg, False);
668 SetDefaultOptions(hwndDlg);
669 end;
670 IDC_COMP_DICT,
671 IDC_COMP_WORD,
672 IDC_COMP_THREAD:
673 if (HIWORD(wParam) = CBN_SELCHANGE) then
674 begin
675 UpdateMemoryUsage(hwndDlg);
676 end;
677 IDOK:
678 begin
679 SaveArchiver(hwndDlg);
680 EndDialog(hwndDlg, IDOK);
681 end;
682 IDCANCEL:
683 EndDialog(hwndDlg, IDCANCEL);
684 IDC_APPLY_BUTTON:
685 SaveArchiver(hwndDlg);
686 end;
687 end;
688 WM_CLOSE:
689 begin
690 EndDialog(hwndDlg, 0);
691 end
692 else begin
693 Result:= 0;
694 end;
695 end;
696 end;
697
698 function PasswordDialog(hwndDlg: HWND; uMsg: UINT; wParam: WPARAM; lParam: LPARAM): INT_PTR; stdcall;
699 var
700 PasswordData: PPasswordData;
701 begin
702 case uMsg of
703 WM_INITDIALOG:
704 begin
705 PasswordData:= PPasswordData(lParam);
706 SetWindowLongPtr(hwndDlg, GWLP_USERDATA, LONG_PTR(lParam));
707 SetDlgItemTextW(hwndDlg, IDC_PASSWORD, PasswordData^.Password);
708 SendDlgItemMessage(hwndDlg, IDC_PASSWORD, EM_SETLIMITTEXT, MAX_PATH, 0);
709 EnableWindow(GetDlgItem(hwndDlg, IDC_ENCRYPT_HEADER), PasswordData^.EncryptHeader);
710 Exit(1);
711 end;
712 WM_COMMAND:
713 begin
714 case LOWORD(wParam) of
715 IDOK:
716 begin
717 PasswordData:= PPasswordData(GetWindowLongPtr(hwndDlg, GWLP_USERDATA));
718 PasswordData^.EncryptHeader:= IsDlgButtonChecked(hwndDlg, IDC_ENCRYPT_HEADER) <> 0;
719 GetDlgItemTextW(hwndDlg, IDC_PASSWORD, PasswordData^.Password, MAX_PATH);
720 EndDialog(hwndDlg, IDOK);
721 end;
722 IDCANCEL:
723 EndDialog(hwndDlg, IDCANCEL);
724 IDC_SHOW_PASSWORD:
725 begin
726 wParam:= (not IsDlgButtonChecked(hwndDlg, IDC_SHOW_PASSWORD) and $01) * $2A;
727 SendDlgItemMessageW(hwndDlg, IDC_PASSWORD, EM_SETPASSWORDCHAR, wParam, 0);
728 RedrawWindow(hwndDlg, nil, 0, RDW_INVALIDATE or RDW_UPDATENOW);
729 end;
730 end;
731 end;
732 end;
733 Result:= 0;
734 end;
735
736 function ShowPasswordQuery(var Encrypt: Boolean; var Password: WideString): Boolean;
737 var
738 PasswordData: TPasswordData;
739 begin
740 PasswordData.Password:= Password;
741 PasswordData.EncryptHeader:= Encrypt;
742 Result:= (DialogBoxParam(hInstance, 'DIALOG_PWD', 0, @PasswordDialog, LPARAM(@PasswordData)) = IDOK);
743 if Result then
744 begin
745 Password:= PasswordData.Password;
746 Encrypt:= PasswordData.EncryptHeader;
747 end;
748 end;
749
750 procedure ShowConfigurationDialog(Parent: HWND);
751 begin
752 DialogBox(hInstance, 'DIALOG_CFG', Parent, @DialogProc);
753 end;
754
755 end.
756