| 1 |
{ |
| 2 |
Double commander |
| 3 |
------------------------------------------------------------------------- |
| 4 |
WCX plugin for working with *.zip, *.gz, *.bz2, *.tar, *.tgz, *.tbz archives |
| 5 |
|
| 6 |
Copyright (C) 2008-2023 Alexander Koblov ([email protected]) |
| 7 |
|
| 8 |
This program is free software; you can redistribute it and/or |
| 9 |
modify it under the terms of the GNU General Public License as |
| 10 |
published by the Free Software Foundation; either version 2 of the |
| 11 |
License, or (at your option) any later version. |
| 12 |
|
| 13 |
This program is distributed in the hope that it will be useful, but |
| 14 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
General Public License for more details. |
| 17 |
|
| 18 |
You should have received a copy of the GNU General Public License |
| 19 |
in a file called COPYING along with this program; if not, write to |
| 20 |
the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA |
| 21 |
02139, USA. |
| 22 |
} |
| 23 |
|
| 24 |
unit ZipConfDlg; |
| 25 |
|
| 26 |
{$mode objfpc}{$H+} |
| 27 |
{$include calling.inc} |
| 28 |
|
| 29 |
{$R ZipConfDlg.lfm} |
| 30 |
|
| 31 |
interface |
| 32 |
|
| 33 |
uses |
| 34 |
SysUtils, Extension; |
| 35 |
|
| 36 |
procedure CreateZipConfDlg; |
| 37 |
|
| 38 |
implementation |
| 39 |
|
| 40 |
uses |
| 41 |
ZipFunc, ZipOpt, ZipLng, AbZipTyp; |
| 42 |
|
| 43 |
function GetComboBox(pDlg: PtrUInt; DlgItemName: PAnsiChar): PtrInt; |
| 44 |
begin |
| 45 |
with gStartupInfo do |
| 46 |
begin |
| 47 |
Result:= SendDlgMsg(pDlg, DlgItemName, DM_LISTGETITEMINDEX, 0, 0); |
| 48 |
if Result >= 0 then |
| 49 |
begin |
| 50 |
Result:= SendDlgMsg(pDlg, DlgItemName, DM_LISTGETDATA, Result, 0); |
| 51 |
end; |
| 52 |
end; |
| 53 |
end; |
| 54 |
|
| 55 |
procedure SetComboBox(pDlg: PtrUInt; DlgItemName: PAnsiChar; ItemData: PtrInt); |
| 56 |
var |
| 57 |
Index, Count: Integer; |
| 58 |
begin |
| 59 |
with gStartupInfo do |
| 60 |
begin |
| 61 |
Count:= SendDlgMsg(pDlg, DlgItemName, DM_LISTGETCOUNT, 0, 0); |
| 62 |
for Index:= 0 to Count - 1 do |
| 63 |
begin |
| 64 |
if SendDlgMsg(pDlg, DlgItemName, DM_LISTGETDATA, Index, 0) = ItemData then |
| 65 |
begin |
| 66 |
SendDlgMsg(pDlg, DlgItemName, DM_LISTSETITEMINDEX, Index, 0); |
| 67 |
Exit; |
| 68 |
end; |
| 69 |
end; |
| 70 |
end; |
| 71 |
end; |
| 72 |
|
| 73 |
function ComboBoxAdd(pDlg: PtrUInt; DlgItemName: PAnsiChar; ItemText: String; ItemData: PtrInt): IntPtr; |
| 74 |
var |
| 75 |
P: PAnsiChar; |
| 76 |
AText: IntPtr absolute P; |
| 77 |
begin |
| 78 |
P:= PAnsiChar(ItemText); |
| 79 |
Result:= gStartupInfo.SendDlgMsg(pDlg, DlgItemName, DM_LISTADD, AText, ItemData); |
| 80 |
end; |
| 81 |
|
| 82 |
function AddCompressionLevel(pDlg: PtrUInt; const AName: String; ALevel: IntPtr): IntPtr; |
| 83 |
var |
| 84 |
AText: String; |
| 85 |
begin |
| 86 |
AText:= AName + ' (' + IntToStr(ALevel) + ')'; |
| 87 |
Result:= ComboBoxAdd(pDlg, 'cbCompressionLevel', AText, ALevel); |
| 88 |
end; |
| 89 |
|
| 90 |
procedure UpdateLevel(pDlg: PtrUInt; ALevel: IntPtr); |
| 91 |
var |
| 92 |
Index: IntPtr; |
| 93 |
AFormat: TArchiveFormat; |
| 94 |
AMethod: TAbZipCompressionMethod; |
| 95 |
begin |
| 96 |
with gStartupInfo do |
| 97 |
begin |
| 98 |
SendDlgMsg(pDlg, 'cbCompressionLevel', DM_LISTCLEAR, 0, 0); |
| 99 |
AFormat:= TArchiveFormat(GetComboBox(pDlg, 'cbArchiveFormat')); |
| 100 |
Index:= SendDlgMsg(pDlg, 'cbCompressionMethod', DM_LISTGETITEMINDEX, 0, 0); |
| 101 |
AMethod:= TAbZipCompressionMethod(SendDlgMsg(pDlg, 'cbCompressionMethod', DM_LISTGETDATA, Index, 0)); |
| 102 |
if (AMethod = cmStored) then |
| 103 |
begin |
| 104 |
SendDlgMsg(pDlg, 'cbCompressionLevel', DM_ENABLE, 0, 0); |
| 105 |
end |
| 106 |
else begin |
| 107 |
SendDlgMsg(pDlg, 'cbCompressionLevel', DM_ENABLE, 1, 0); |
| 108 |
case AMethod of |
| 109 |
cmDeflated, |
| 110 |
cmEnhancedDeflated: |
| 111 |
begin |
| 112 |
AddCompressionLevel(pDlg, rsCompressionLevelFastest, 1); |
| 113 |
AddCompressionLevel(pDlg, rsCompressionLevelFast, 3); |
| 114 |
Index:= AddCompressionLevel(pDlg, rsCompressionLevelNormal, 6); |
| 115 |
AddCompressionLevel(pDlg, rsCompressionLevelMaximum, 9); |
| 116 |
end; |
| 117 |
cmXz, |
| 118 |
cmLZMA, |
| 119 |
cmBzip2: |
| 120 |
begin |
| 121 |
AddCompressionLevel(pDlg, rsCompressionLevelFastest, 1); |
| 122 |
AddCompressionLevel(pDlg, rsCompressionLevelFast, 3); |
| 123 |
Index:= AddCompressionLevel(pDlg, rsCompressionLevelNormal, 5); |
| 124 |
AddCompressionLevel(pDlg, rsCompressionLevelMaximum, 7); |
| 125 |
AddCompressionLevel(pDlg, rsCompressionLevelUltra, 9); |
| 126 |
end; |
| 127 |
cmZstd: |
| 128 |
begin |
| 129 |
AddCompressionLevel(pDlg, rsCompressionLevelFastest, 3); |
| 130 |
AddCompressionLevel(pDlg, rsCompressionLevelFast, 5); |
| 131 |
Index:= AddCompressionLevel(pDlg, rsCompressionLevelNormal, 11); |
| 132 |
AddCompressionLevel(pDlg, rsCompressionLevelMaximum, 17); |
| 133 |
AddCompressionLevel(pDlg, rsCompressionLevelUltra, 22); |
| 134 |
end; |
| 135 |
end; |
| 136 |
if ALevel < 0 then |
| 137 |
SendDlgMsg(pDlg, 'cbCompressionLevel', DM_LISTSETITEMINDEX, Index, 0) |
| 138 |
else begin |
| 139 |
SetComboBox(pDlg, 'cbCompressionLevel', PluginConfig[AFormat].Level); |
| 140 |
end; |
| 141 |
end; |
| 142 |
end; |
| 143 |
end; |
| 144 |
|
| 145 |
procedure UpdateMethod(pDlg: PtrUInt); |
| 146 |
var |
| 147 |
Index: IntPtr; |
| 148 |
AFormat: TArchiveFormat; |
| 149 |
begin |
| 150 |
with gStartupInfo do |
| 151 |
begin |
| 152 |
SendDlgMsg(pDlg, 'cbCompressionMethod', DM_LISTCLEAR, 0, 0); |
| 153 |
AFormat:= TArchiveFormat(GetComboBox(pDlg, 'cbArchiveFormat')); |
| 154 |
case AFormat of |
| 155 |
afGzip: |
| 156 |
ComboBoxAdd(pDlg, 'cbCompressionMethod', 'Deflate', PtrInt(cmDeflated)); |
| 157 |
afXzip: |
| 158 |
ComboBoxAdd(pDlg, 'cbCompressionMethod', 'LZMA2', PtrInt(cmXz)); |
| 159 |
afBzip2: |
| 160 |
ComboBoxAdd(pDlg, 'cbCompressionMethod', 'BZip2', PtrInt(cmBzip2)); |
| 161 |
afZstd: |
| 162 |
ComboBoxAdd(pDlg, 'cbCompressionMethod', 'Zstandard', PtrInt(cmZstd)); |
| 163 |
afZip: |
| 164 |
begin |
| 165 |
ComboBoxAdd(pDlg, 'cbCompressionMethod', rsCompressionMethodStore, PtrInt(cmStored)); |
| 166 |
ComboBoxAdd(pDlg, 'cbCompressionMethod', 'Deflate', PtrInt(cmDeflated)); |
| 167 |
ComboBoxAdd(pDlg, 'cbCompressionMethod', rsCompressionMethodOptimal, PtrInt(cmEnhancedDeflated)); |
| 168 |
end; |
| 169 |
afZipx: |
| 170 |
begin |
| 171 |
ComboBoxAdd(pDlg, 'cbCompressionMethod', 'LZMA2', PtrInt(cmXz)); |
| 172 |
ComboBoxAdd(pDlg, 'cbCompressionMethod', 'Zstandard', PtrInt(cmZstd)); |
| 173 |
end; |
| 174 |
end; // case |
| 175 |
Index:= SendDlgMsg(pDlg, 'cbCompressionMethod', DM_LISTGETCOUNT, 0, 0); |
| 176 |
if (Index = 1) then |
| 177 |
begin |
| 178 |
SendDlgMsg(pDlg, 'cbCompressionMethod', DM_LISTSETITEMINDEX, 0, 0); |
| 179 |
end |
| 180 |
else begin |
| 181 |
SetComboBox(pDlg, 'cbCompressionMethod', PluginConfig[AFormat].Method); |
| 182 |
end; |
| 183 |
// Randomly crashes under Qt |
| 184 |
// https://github.com/doublecmd/doublecmd/issues/1233 |
| 185 |
// SendDlgMsg(pDlg, 'cbCompressionMethod', DM_ENABLE, PtrInt(Index > 1), 0); |
| 186 |
end; |
| 187 |
UpdateLevel(pDlg, PluginConfig[AFormat].Level); |
| 188 |
end; |
| 189 |
|
| 190 |
function DlgProc (pDlg: PtrUInt; DlgItemName: PAnsiChar; Msg, wParam, lParam: PtrInt): PtrInt; dcpcall; |
| 191 |
var |
| 192 |
Index: IntPtr; |
| 193 |
AFormat: TArchiveFormat; |
| 194 |
begin |
| 195 |
Result:= 0; |
| 196 |
with gStartupInfo do |
| 197 |
begin |
| 198 |
case Msg of |
| 199 |
DN_INITDIALOG: |
| 200 |
begin |
| 201 |
ComboBoxAdd(pDlg, 'cbArchiveFormat', 'gz', PtrInt(afGzip)); |
| 202 |
ComboBoxAdd(pDlg, 'cbArchiveFormat', 'xz', PtrInt(afXzip)); |
| 203 |
ComboBoxAdd(pDlg, 'cbArchiveFormat', 'bz2', PtrInt(afBzip2)); |
| 204 |
ComboBoxAdd(pDlg, 'cbArchiveFormat', 'zst', PtrInt(afZstd)); |
| 205 |
Index:= ComboBoxAdd(pDlg, 'cbArchiveFormat', 'zip', PtrInt(afZip)); |
| 206 |
ComboBoxAdd(pDlg, 'cbArchiveFormat', 'zipx', PtrInt(afZipx)); |
| 207 |
|
| 208 |
SendDlgMsg(pDlg, 'cbArchiveFormat', DM_LISTSETITEMINDEX, Index, 0); |
| 209 |
|
| 210 |
UpdateMethod(pDlg); |
| 211 |
|
| 212 |
SendDlgMsg(pDlg, 'chkTarAutoHandle', DM_SETCHECK, PtrInt(gTarAutoHandle), 0); |
| 213 |
end; |
| 214 |
DN_CHANGE: |
| 215 |
begin |
| 216 |
if DlgItemName = 'cbArchiveFormat' then |
| 217 |
begin |
| 218 |
UpdateMethod(pDlg); |
| 219 |
end |
| 220 |
else if DlgItemName = 'cbCompressionMethod' then |
| 221 |
begin |
| 222 |
UpdateLevel(pDlg, -1); |
| 223 |
end; |
| 224 |
end; |
| 225 |
DN_CLICK: |
| 226 |
if DlgItemName = 'btnOK' then |
| 227 |
begin |
| 228 |
AFormat:= TArchiveFormat(GetComboBox(pDlg, 'cbArchiveFormat')); |
| 229 |
PluginConfig[AFormat].Level:= GetComboBox(pDlg, 'cbCompressionLevel'); |
| 230 |
PluginConfig[AFormat].Method:= GetComboBox(pDlg, 'cbCompressionMethod'); |
| 231 |
gTarAutoHandle:= Boolean(SendDlgMsg(pDlg, 'chkTarAutoHandle', DM_GETCHECK, 0, 0)); |
| 232 |
SaveConfiguration; |
| 233 |
SendDlgMsg(pDlg, DlgItemName, DM_CLOSE, 1, 0); |
| 234 |
end |
| 235 |
else if DlgItemName = 'btnCancel' then |
| 236 |
SendDlgMsg(pDlg, DlgItemName, DM_CLOSE, 2, 0); |
| 237 |
end;// case |
| 238 |
end; // with |
| 239 |
end; |
| 240 |
|
| 241 |
procedure CreateZipConfDlg; |
| 242 |
var |
| 243 |
ResHandle: TFPResourceHandle = 0; |
| 244 |
ResGlobal: TFPResourceHGLOBAL = 0; |
| 245 |
ResData: Pointer = nil; |
| 246 |
ResSize: LongWord; |
| 247 |
begin |
| 248 |
try |
| 249 |
ResHandle := FindResource(HINSTANCE, PChar('TDIALOGBOX'), MAKEINTRESOURCE(10) {RT_RCDATA}); |
| 250 |
if ResHandle <> 0 then |
| 251 |
begin |
| 252 |
ResGlobal := LoadResource(HINSTANCE, ResHandle); |
| 253 |
if ResGlobal <> 0 then |
| 254 |
begin |
| 255 |
ResData := LockResource(ResGlobal); |
| 256 |
ResSize := SizeofResource(HINSTANCE, ResHandle); |
| 257 |
|
| 258 |
with gStartupInfo do |
| 259 |
begin |
| 260 |
DialogBoxLRS(ResData, ResSize, @DlgProc); |
| 261 |
end; |
| 262 |
end; |
| 263 |
end; |
| 264 |
|
| 265 |
finally |
| 266 |
if ResGlobal <> 0 then |
| 267 |
begin |
| 268 |
UnlockResource(ResGlobal); |
| 269 |
FreeResource(ResGlobal); |
| 270 |
end; |
| 271 |
end; |
| 272 |
end; |
| 273 |
|
| 274 |
end. |
| 275 |
|