ADD: SevenZip - show external methods in options dialog

This commit is contained in:
Alexander Koblov 2017-09-03 10:25:16 +00:00
commit 10d97a2f45
5 changed files with 155 additions and 87 deletions

View file

@ -1,6 +1,6 @@
@echo off
set VERSION=17.09.02
set VERSION=17.09.03
rem The next two line must be changed before run on your computer
set lazpath=D:\Alexx\Prog\FreePascal\Lazarus

View file

@ -41,7 +41,10 @@ unit SevenZipCodecs;
interface
uses
Classes, SysUtils, SevenZip, fgl, ActiveX, Windows;
Classes, SysUtils, SevenZip, fgl, ActiveX, Windows, JclCompression;
const
cmMaximum = PtrInt(Ord(High(TJclCompressionMethod)));
type
@ -71,6 +74,7 @@ type
DecoderIsAssigned: LongBool;
Encoder: CLSID;
Decoder: CLSID;
ID: Cardinal;
Name: WideString;
end;
@ -90,6 +94,10 @@ type
end;
procedure LoadLibraries;
function GetCodecName(AMethod: Cardinal): WideString;
var
ACodecs: TFPGObjectList<TCodecInfo> = nil;
implementation
@ -192,7 +200,11 @@ begin
AInfo.EncoderIsAssigned:= True;
end;
if (GetMethodProperty(index, kName, Value) <> S_OK) then
if (GetMethodProperty(Index, kID, Value) <> S_OK) then
Exit(False);
if (Value.vt <> VT_EMPTY) then AInfo.ID:= OleVariant(Value);
if (GetMethodProperty(Index, kName, Value) <> S_OK) then
Exit(False);
if (Value.vt = VT_BSTR) then AInfo.Name:= OleVariant(Value);
@ -200,8 +212,7 @@ begin
end;
var
ACodecs: TFPGObjectList<TCodecInfo>;
ALibraries: TFPGObjectList<TLibraryInfo>;
ALibraries: TFPGObjectList<TLibraryInfo> = nil;
procedure LoadCodecs;
var
@ -296,15 +307,31 @@ begin
LoadCodecs;
end;
function GetCodecName(AMethod: Cardinal): WideString;
var
Index: Integer;
begin
if Assigned(ACodecs) then begin
for Index:= 0 to ACodecs.Count - 1 do
begin
if (ACodecs[Index].ID = AMethod) then
Exit(ACodecs[Index].Name);
end;
end;
Result:= EmptyWideStr;
end;
procedure Finish;
var
Index: Integer;
begin
for Index:= 0 to ALibraries.Count - 1 do
begin
if Assigned(ALibraries[Index].SetCodecs) then
ALibraries[Index].SetCodecs(nil);
FreeLibrary(ALibraries[Index].Handle);
if Assigned(ALibraries) then begin
for Index:= 0 to ALibraries.Count - 1 do
begin
if Assigned(ALibraries[Index].SetCodecs) then
ALibraries[Index].SetCodecs(nil);
FreeLibrary(ALibraries[Index].Handle);
end;
end;
end;

View file

@ -3,7 +3,7 @@
-------------------------------------------------------------------------
SevenZip archiver plugin, dialogs unit
Copyright (C) 2014-2015 Alexander Koblov (alexx2000@mail.ru)
Copyright (C) 2014-2017 Alexander Koblov (alexx2000@mail.ru)
Based on 7-Zip 15.06 (http://7-zip.org)
7-Zip Copyright (C) 1999-2015 Igor Pavlov
@ -37,6 +37,9 @@ function ShowPasswordQuery(var Encrypt: Boolean; var Password: WideString): Bool
implementation
uses
SevenZipCodecs;
{$R *.res}
const
@ -130,7 +133,7 @@ begin
end;
decompressMemory := -1;
Dictionary := GetComboBox(hwndDlg, IDC_COMP_DICT);
Dictionary := Cardinal(GetComboBox(hwndDlg, IDC_COMP_DICT));
Method := TJclCompressionMethod(GetComboBox(hwndDlg, IDC_COMP_METHOD));
if (Method <> cmDeflate) and (Method <> cmDeflate64) and (level >= clUltra) then
@ -210,9 +213,16 @@ procedure UpdateMemoryUsage(hwndDlg: HWND);
var
Comp, Decomp: Int64;
begin
Comp := GetMemoryUsage(hwndDlg, Decomp);
SetDlgItemText(hwndDlg, IDC_MEMORY_COMP, PAnsiChar(IntToStr(Comp div cMega) + 'Mb'));
SetDlgItemText(hwndDlg, IDC_MEMORY_DECOMP, PAnsiChar(IntToStr(Decomp div cMega) + 'Mb'));
if (GetComboBox(hwndDlg, IDC_COMP_METHOD) > cmMaximum) then
begin
SetDlgItemText(hwndDlg, IDC_MEMORY_COMP, '?');
SetDlgItemText(hwndDlg, IDC_MEMORY_DECOMP, '?');
end
else begin
Comp := GetMemoryUsage(hwndDlg, Decomp);
SetDlgItemText(hwndDlg, IDC_MEMORY_COMP, PAnsiChar(IntToStr(Comp div cMega) + 'Mb'));
SetDlgItemText(hwndDlg, IDC_MEMORY_DECOMP, PAnsiChar(IntToStr(Decomp div cMega) + 'Mb'));
end;
end;
procedure SetDefaultOptions(hwndDlg: HWND);
@ -372,14 +382,14 @@ begin
begin
ComboBoxAdd(hwndDlg, IDC_COMP_THREAD, IntToStr(Index), Index);
end;
wsMaxThread:= '/ ' + IntToStr(dwHardwareThreads);
wsMaxThread:= '/ ' + WideString(IntToStr(dwHardwareThreads));
SendDlgItemMessage(hwndDlg, IDC_COMP_THREAD, CB_SETCURSEL, dwDefaultValue - 1, 0);
SendDlgItemMessageW(hwndDlg, IDC_MAX_THREAD, WM_SETTEXT, 0, LPARAM(PWideChar(wsMaxThread)));
end;
procedure UpdateMethod(hwndDlg: HWND);
var
Index: Integer;
Index: PtrInt;
Format: TArchiveFormat;
dwAlgoThreadMax: LongWord = 1;
Method: TJclCompressionMethod;
@ -390,70 +400,80 @@ begin
Format:= TArchiveFormat(GetWindowLongPtr(hwndDlg, GWLP_USERDATA));
EnableWindow(GetDlgItem(hwndDlg, IDC_COMP_DICT), not (Format in [afTar, afWim]));
// Get Compression method
Method:= TJclCompressionMethod(GetComboBox(hwndDlg, IDC_COMP_METHOD));
EnableWindow(GetDlgItem(hwndDlg, IDC_COMP_WORD), (Format in [afSevenZip, afGzip, afXz, afZip]) and (Method <> cmBZip2));
case Method of
cmDeflate:
begin
for Index:= Low(DeflateDict) to High(DeflateDict) do
Index:= GetComboBox(hwndDlg, IDC_COMP_METHOD);
if Index > cmMaximum then
begin
dwAlgoThreadMax:= GetNumberOfProcessors;
EnableWindow(GetDlgItem(hwndDlg, IDC_COMP_DICT), False);
EnableWindow(GetDlgItem(hwndDlg, IDC_COMP_WORD), False);
end
else begin
Method:= TJclCompressionMethod(Index);
EnableWindow(GetDlgItem(hwndDlg, IDC_COMP_WORD), (Format in [afSevenZip, afGzip, afXz, afZip]) and (Method <> cmBZip2));
case Method of
cmDeflate:
begin
ComboBoxAdd(hwndDlg, IDC_COMP_DICT, FormatFileSize(DeflateDict[Index]), PtrInt(DeflateDict[Index]));
for Index:= Low(DeflateDict) to High(DeflateDict) do
begin
ComboBoxAdd(hwndDlg, IDC_COMP_DICT, FormatFileSize(DeflateDict[Index]), PtrInt(DeflateDict[Index]));
end;
for Index:= Low(DeflateWordSize) to High(DeflateWordSize) do
begin
ComboBoxAdd(hwndDlg, IDC_COMP_WORD, IntToStr(DeflateWordSize[Index]), PtrInt(DeflateWordSize[Index]));
end;
end;
for Index:= Low(DeflateWordSize) to High(DeflateWordSize) do
cmDeflate64:
begin
ComboBoxAdd(hwndDlg, IDC_COMP_WORD, IntToStr(DeflateWordSize[Index]), PtrInt(DeflateWordSize[Index]));
end;
end;
cmDeflate64:
begin
for Index:= Low(Deflate64Dict) to High(Deflate64Dict) do
begin
ComboBoxAdd(hwndDlg, IDC_COMP_DICT, FormatFileSize(Deflate64Dict[Index]), PtrInt(Deflate64Dict[Index]));
end;
for Index:= Low(Deflate64WordSize) to High(Deflate64WordSize) do
begin
ComboBoxAdd(hwndDlg, IDC_COMP_WORD, IntToStr(Deflate64WordSize[Index]), PtrInt(Deflate64WordSize[Index]));
end;
end;
cmLZMA,
cmLZMA2:
begin
for Index:= Low(LZMADict) to High(LZMADict) do
begin
ComboBoxAdd(hwndDlg, IDC_COMP_DICT, FormatFileSize(LZMADict[Index], False), PtrInt(LZMADict[Index]));
end;
for Index:= Low(LZMAWordSize) to High(LZMAWordSize) do
begin
ComboBoxAdd(hwndDlg, IDC_COMP_WORD, IntToStr(LZMAWordSize[Index]), PtrInt(LZMAWordSize[Index]));
end;
dwAlgoThreadMax:= IfThen(Method = cmLZMA, 2, 32);
end;
cmBZip2:
begin
for Index:= Low(BZip2Dict) to High(BZip2Dict) do
begin
ComboBoxAdd(hwndDlg, IDC_COMP_DICT, FormatFileSize(BZip2Dict[Index]), PtrInt(BZip2Dict[Index]));
end;
dwAlgoThreadMax:= 32;
end;
cmPPMd:
begin
for Index:= Low(PPMdDict) to High(PPMdDict) do
begin
ComboBoxAdd(hwndDlg, IDC_COMP_DICT, FormatFileSize(PPMdDict[Index], False), PtrInt(PPMdDict[Index]));
end;
for Index:= Low(PPMdWordSize) to High(PPMdWordSize) do
begin
ComboBoxAdd(hwndDlg, IDC_COMP_WORD, IntToStr(PPMdWordSize[Index]), PtrInt(PPMdWordSize[Index]));
for Index:= Low(Deflate64Dict) to High(Deflate64Dict) do
begin
ComboBoxAdd(hwndDlg, IDC_COMP_DICT, FormatFileSize(Deflate64Dict[Index]), PtrInt(Deflate64Dict[Index]));
end;
for Index:= Low(Deflate64WordSize) to High(Deflate64WordSize) do
begin
ComboBoxAdd(hwndDlg, IDC_COMP_WORD, IntToStr(Deflate64WordSize[Index]), PtrInt(Deflate64WordSize[Index]));
end;
end;
cmLZMA,
cmLZMA2:
begin
for Index:= Low(LZMADict) to High(LZMADict) do
begin
ComboBoxAdd(hwndDlg, IDC_COMP_DICT, FormatFileSize(LZMADict[Index], False), PtrInt(LZMADict[Index]));
end;
for Index:= Low(LZMAWordSize) to High(LZMAWordSize) do
begin
ComboBoxAdd(hwndDlg, IDC_COMP_WORD, IntToStr(LZMAWordSize[Index]), PtrInt(LZMAWordSize[Index]));
end;
dwAlgoThreadMax:= IfThen(Method = cmLZMA, 2, 32);
end;
cmBZip2:
begin
for Index:= Low(BZip2Dict) to High(BZip2Dict) do
begin
ComboBoxAdd(hwndDlg, IDC_COMP_DICT, FormatFileSize(BZip2Dict[Index]), PtrInt(BZip2Dict[Index]));
end;
dwAlgoThreadMax:= 32;
end;
cmPPMd:
begin
for Index:= Low(PPMdDict) to High(PPMdDict) do
begin
ComboBoxAdd(hwndDlg, IDC_COMP_DICT, FormatFileSize(PPMdDict[Index], False), PtrInt(PPMdDict[Index]));
end;
for Index:= Low(PPMdWordSize) to High(PPMdWordSize) do
begin
ComboBoxAdd(hwndDlg, IDC_COMP_WORD, IntToStr(PPMdWordSize[Index]), PtrInt(PPMdWordSize[Index]));
end;
end;
end;
if Format = afZip then dwAlgoThreadMax:= 128;
end;
if Format = afZip then dwAlgoThreadMax:= 128;
UpdateThread(hwndDlg, dwAlgoThreadMax);
end;
procedure FillMethod(hwndDlg: HWND);
var
Index: Integer;
Format: TArchiveFormat;
begin
// Clear combobox
@ -467,6 +487,11 @@ begin
ComboBoxAdd(hwndDlg, IDC_COMP_METHOD, 'LZMA2', PtrInt(cmLZMA2));
ComboBoxAdd(hwndDlg, IDC_COMP_METHOD, 'PPMd', PtrInt(cmPPMd));
ComboBoxAdd(hwndDlg, IDC_COMP_METHOD, 'BZip2', PtrInt(cmBZip2));
if Assigned(ACodecs) then begin
for Index:= 0 to ACodecs.Count - 1 do begin
ComboBoxAdd(hwndDlg, IDC_COMP_METHOD, ACodecs[Index].Name, PtrInt(ACodecs[Index].ID));
end;
end;
SetComboBox(hwndDlg, IDC_COMP_METHOD, PluginConfig[Format].Method);
end;
afBzip2:
@ -546,15 +571,18 @@ end;
procedure UpdateLevel(hwndDlg: HWND; First: Boolean);
var
MethodStd: Boolean;
Format: TArchiveFormat;
Level: TCompressionLevel;
begin
Format:= TArchiveFormat(GetWindowLongPtr(hwndDlg, GWLP_USERDATA));
// Get compression level
Level:= TCompressionLevel(GetComboBox(hwndDlg, IDC_COMP_LEVEL));
// Get compression method
MethodStd:= (GetComboBox(hwndDlg, IDC_COMP_METHOD) <= cmMaximum);
EnableWindow(GetDlgItem(hwndDlg, IDC_COMP_DICT), Level <> clStore);
EnableWindow(GetDlgItem(hwndDlg, IDC_COMP_WORD), Level <> clStore);
EnableWindow(GetDlgItem(hwndDlg, IDC_COMP_DICT), (Level <> clStore) and MethodStd);
EnableWindow(GetDlgItem(hwndDlg, IDC_COMP_WORD), (Level <> clStore) and MethodStd);
EnableWindow(GetDlgItem(hwndDlg, IDC_COMP_SOLID), (Format = afSevenZip) and (Level <> clStore));
if Level = clStore then

View file

@ -3,7 +3,7 @@
-------------------------------------------------------------------------
SevenZip archiver plugin, compression options
Copyright (C) 2014-2015 Alexander Koblov (alexx2000@mail.ru)
Copyright (C) 2014-2017 Alexander Koblov (alexx2000@mail.ru)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@ -222,7 +222,7 @@ var
implementation
uses
ActiveX, LazUTF8, SevenZipAdv;
ActiveX, LazUTF8, SevenZipAdv, SevenZipCodecs;
function GetNumberOfProcessors: LongWord;
var
@ -251,6 +251,7 @@ var
Index: Integer;
Start: Integer = 1;
Parameters: WideString;
MethodStandard: Boolean;
Method: TJclCompressionMethod;
JclArchive: TJclCompressionArchive;
@ -334,28 +335,37 @@ begin
AddOption(MaxInt);
end;
Parameters:= WideUpperCase(Parameters);
MethodStandard:= PluginConfig[AFormat].Method <= cmMaximum;
// Set word size parameter
Method:= TJclCompressionMethod(PluginConfig[AFormat].Method);
case Method of
cmLZMA, cmLZMA2,
cmDeflate, cmDeflate64:
begin
if (Pos('FB=', Parameters) = 0) and (Pos('1=', Parameters) = 0) then
AddCardinalProperty('fb', PluginConfig[AFormat].WordSize);
end;
cmPPMd:
begin
if Pos('O=', Parameters) = 0 then
AddCardinalProperty('o', PluginConfig[AFormat].WordSize);
end;
if MethodStandard then
begin
Method:= TJclCompressionMethod(PluginConfig[AFormat].Method);
case Method of
cmLZMA, cmLZMA2,
cmDeflate, cmDeflate64:
begin
if (Pos('FB=', Parameters) = 0) and (Pos('1=', Parameters) = 0) then
AddCardinalProperty('fb', PluginConfig[AFormat].WordSize);
end;
cmPPMd:
begin
if Pos('O=', Parameters) = 0 then
AddCardinalProperty('o', PluginConfig[AFormat].WordSize);
end;
end;
end;
// Set 7-zip compression method
if IsEqualGUID(CLSID_CFormat7z, PluginConfig[AFormat].ArchiveCLSID^) then
begin
if Pos('0=', Parameters) = 0 then begin
AddWideStringProperty('0', MethodName[Method]);
if Pos('0=', Parameters) = 0 then
begin
if MethodStandard then
AddWideStringProperty('0', MethodName[Method])
else begin
AddWideStringProperty('0', GetCodecName(PluginConfig[AFormat].Method));
end;
end;
if (Method <> cmCopy) and (Pos('D=', Parameters) = 0) then begin
if MethodStandard and (Method <> cmCopy) and (Pos('D=', Parameters) = 0) then begin
AddWideStringProperty('D', WideString(IntToStr(PluginConfig[AFormat].Dictionary) + 'B'));
end;
end;
@ -363,6 +373,7 @@ end;
procedure SetArchiveOptions(AJclArchive: IInterface);
var
MethodStd: Boolean;
ArchiveCLSID: TGUID;
SolidBlockSize: Int64;
Index: TArchiveFormat;
@ -384,7 +395,9 @@ begin
begin
if IsEqualGUID(ArchiveCLSID, PluginConfig[Index].ArchiveCLSID^) then
begin
if Supports(AJclArchive, IJclArchiveCompressionMethod, CompressionMethod) and Assigned(CompressionMethod) then
MethodStd:= (PluginConfig[Index].Method <= cmMaximum);
if MethodStd and Supports(AJclArchive, IJclArchiveCompressionMethod, CompressionMethod) and Assigned(CompressionMethod) then
CompressionMethod.SetCompressionMethod(TJclCompressionMethod(PluginConfig[Index].Method));
if Supports(AJclArchive, IJclArchiveCompressionLevel, CompressionLevel) and Assigned(CompressionLevel) then
@ -392,7 +405,7 @@ begin
if PluginConfig[Index].Level <> PtrInt(clStore) then
begin
if Supports(AJclArchive, IJclArchiveDictionarySize, DictionarySize) and Assigned(DictionarySize) then
if MethodStd and Supports(AJclArchive, IJclArchiveDictionarySize, DictionarySize) and Assigned(DictionarySize) then
DictionarySize.SetDictionarySize(PluginConfig[Index].Dictionary);
if Supports(AJclArchive, IJclArchiveSolid, Solid) and Assigned(Solid) then

View file

@ -21,7 +21,7 @@
<UseVersionInfo Value="True"/>
<MajorVersionNr Value="17"/>
<MinorVersionNr Value="9"/>
<RevisionNr Value="2"/>
<RevisionNr Value="3"/>
<CharSet Value="04B0"/>
<StringTable FileDescription="SevenZip archiver plugin" InternalName="SevenZip" LegalCopyright="Copyright (C) 2014-2017 Alexander Koblov" ProductVersion=""/>
</VersionInfo>