| 1 |
unit ZipOpt; |
| 2 |
|
| 3 |
{$mode ObjFPC}{$H+} |
| 4 |
|
| 5 |
interface |
| 6 |
|
| 7 |
uses |
| 8 |
Classes, SysUtils, AbUtils, AbZipTyp; |
| 9 |
|
| 10 |
type |
| 11 |
TArchiveFormat = ( |
| 12 |
afNil, |
| 13 |
afZip, |
| 14 |
afZipx, |
| 15 |
afGzip, |
| 16 |
afBzip2, |
| 17 |
afXzip, |
| 18 |
afLzma, |
| 19 |
afZstd |
| 20 |
); |
| 21 |
|
| 22 |
TFormatOptions = record |
| 23 |
Level: PtrInt; |
| 24 |
Method: PtrInt; |
| 25 |
end; |
| 26 |
|
| 27 |
const |
| 28 |
ARCHIVE_FORMAT: array[TAbArchiveType] of TArchiveFormat = |
| 29 |
( |
| 30 |
afNil, afZip, afZip, afZip, afNil, afGzip, afGzip, afNil, |
| 31 |
afBzip2, afBzip2, afXzip, afXzip, afLzma, afLzma, afZstd, afZstd |
| 32 |
); |
| 33 |
|
| 34 |
const |
| 35 |
DefaultConfig: array[TArchiveFormat] of TFormatOptions = |
| 36 |
( |
| 37 |
(Level: 0; Method: 0;), |
| 38 |
(Level: 6; Method: PtrInt(cmDeflated);), |
| 39 |
(Level: 7; Method: PtrInt(cmXz);), |
| 40 |
(Level: 6; Method: PtrInt(cmDeflated);), |
| 41 |
(Level: 9; Method: PtrInt(cmBzip2);), |
| 42 |
(Level: 7; Method: PtrInt(cmXz);), |
| 43 |
(Level: 7; Method: PtrInt(cmLZMA);), |
| 44 |
(Level: 11; Method: PtrInt(cmZstd);) |
| 45 |
); |
| 46 |
|
| 47 |
var |
| 48 |
PluginConfig: array[TArchiveFormat] of TFormatOptions; |
| 49 |
|
| 50 |
procedure LoadConfiguration; |
| 51 |
procedure SaveConfiguration; |
| 52 |
|
| 53 |
implementation |
| 54 |
|
| 55 |
uses |
| 56 |
TypInfo, DCClassesUtf8, Extension, ZipFunc; |
| 57 |
|
| 58 |
procedure LoadConfiguration; |
| 59 |
var |
| 60 |
Ini: TIniFileEx; |
| 61 |
Section: AnsiString; |
| 62 |
ArchiveFormat: TArchiveFormat; |
| 63 |
begin |
| 64 |
try |
| 65 |
Ini:= TIniFileEx.Create(gStartupInfo.PluginConfDir + IniFileName); |
| 66 |
try |
| 67 |
for ArchiveFormat:= Succ(Low(TArchiveFormat)) to High(TArchiveFormat) do |
| 68 |
begin |
| 69 |
Section:= Copy(GetEnumName(TypeInfo(TArchiveFormat), PtrInt(ArchiveFormat)), 3, MaxInt); |
| 70 |
PluginConfig[ArchiveFormat].Level:= Ini.ReadInteger(Section, 'Level', DefaultConfig[ArchiveFormat].Level); |
| 71 |
PluginConfig[ArchiveFormat].Method:= Ini.ReadInteger(Section, 'Method', DefaultConfig[ArchiveFormat].Method); |
| 72 |
end; |
| 73 |
gTarAutoHandle:= Ini.ReadBool('Configuration', 'TarAutoHandle', True); |
| 74 |
// Backward compatibility |
| 75 |
case Ini.ReadInteger('Configuration', 'DeflationOption', -1) of |
| 76 |
IntPtr(doSuperFast): PluginConfig[afZip].Level:= 1; |
| 77 |
IntPtr(doFast): PluginConfig[afZip].Level:= 3; |
| 78 |
IntPtr(doNormal): PluginConfig[afZip].Level:= 6; |
| 79 |
IntPtr(doMaximum): PluginConfig[afZip].Level:= 9; |
| 80 |
end; |
| 81 |
case Ini.ReadInteger('Configuration', 'CompressionMethodToUse', -1) of |
| 82 |
IntPtr(smStored): PluginConfig[afZip].Method:= IntPtr(cmStored); |
| 83 |
IntPtr(smDeflated): PluginConfig[afZip].Method:= IntPtr(cmDeflated); |
| 84 |
IntPtr(smBestMethod): PluginConfig[afZip].Method:= IntPtr(cmEnhancedDeflated); |
| 85 |
end; |
| 86 |
finally |
| 87 |
Ini.Free; |
| 88 |
end; |
| 89 |
except |
| 90 |
// Ignore |
| 91 |
end; |
| 92 |
end; |
| 93 |
|
| 94 |
procedure SaveConfiguration; |
| 95 |
var |
| 96 |
Ini: TIniFileEx; |
| 97 |
Section: AnsiString; |
| 98 |
ArchiveFormat: TArchiveFormat; |
| 99 |
begin |
| 100 |
try |
| 101 |
Ini:= TIniFileEx.Create(gStartupInfo.PluginConfDir + IniFileName); |
| 102 |
try |
| 103 |
for ArchiveFormat:= Succ(Low(TArchiveFormat)) to High(TArchiveFormat) do |
| 104 |
begin |
| 105 |
Section:= Copy(GetEnumName(TypeInfo(TArchiveFormat), PtrInt(ArchiveFormat)), 3, MaxInt); |
| 106 |
Ini.WriteInteger(Section, 'Level', PluginConfig[ArchiveFormat].Level); |
| 107 |
Ini.WriteInteger(Section, 'Method', PluginConfig[ArchiveFormat].Method); |
| 108 |
end; |
| 109 |
Ini.DeleteKey('Configuration', 'DeflationOption'); |
| 110 |
Ini.DeleteKey('Configuration', 'CompressionMethodToUse'); |
| 111 |
Ini.WriteBool('Configuration', 'TarAutoHandle', gTarAutoHandle); |
| 112 |
Ini.UpdateFile; |
| 113 |
finally |
| 114 |
Ini.Free; |
| 115 |
end; |
| 116 |
except |
| 117 |
on E: Exception do |
| 118 |
begin |
| 119 |
gStartupInfo.MessageBox(PAnsiChar(E.Message), nil, MB_OK or MB_ICONERROR); |
| 120 |
end; |
| 121 |
end; |
| 122 |
end; |
| 123 |
|
| 124 |
initialization |
| 125 |
Move(DefaultConfig[Low(DefaultConfig)], PluginConfig[Low(PluginConfig)], SizeOf(PluginConfig)); |
| 126 |
|
| 127 |
end. |
| 128 |
|