ADD: UpdateMemoryUsage

This commit is contained in:
Alexander Koblov 2015-08-29 13:24:42 +00:00
commit 5b3254c4bb

View file

@ -3,7 +3,10 @@
-------------------------------------------------------------------------
SevenZip archiver plugin, dialogs unit
Copyright (C) 2014 Alexander Koblov (alexx2000@mail.ru)
Copyright (C) 2014-2015 Alexander Koblov (alexx2000@mail.ru)
Based on 7-Zip 15.06 (http://7-zip.org)
7-Zip Copyright (C) 1999-2015 Igor Pavlov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@ -27,7 +30,7 @@ unit SevenZipDlg;
interface
uses
Classes, SysUtils, Windows, SevenZipOpt, SevenZipLng, JclCompression;
Classes, SysUtils, Windows, Math, SevenZipOpt, SevenZipLng, JclCompression;
procedure ShowConfigurationDialog(Parent: HWND);
function ShowPasswordQuery(var Encrypt: Boolean; var Password: WideString): Boolean;
@ -53,6 +56,8 @@ const
IDC_COMP_THREAD = 1082;
IDC_MAX_THREAD = 1083;
IDC_PARAMETERS = 1091;
IDC_MEMORY_COMP = 1027;
IDC_MEMORY_DECOMP = 1028;
function GetComboBox(hwndDlg: HWND; ItemID: Integer): PtrInt;
var
@ -107,6 +112,109 @@ begin
SendDlgItemMessage(hwndDlg, ItemID, CB_SETITEMDATA, Result, ItemData);
end;
function GetMemoryUsage(hwndDlg: HWND; out decompressMemory: Int64): Int64;
var
size: Int64 = 0;
Dictionary, hs,
numThreads, numThreads1,
numBlockThreads: Cardinal;
size1, chunkSize: Int64;
Level: TCompressionLevel;
Method: TJclCompressionMethod;
begin
Level := TCompressionLevel(GetComboBox(hwndDlg, IDC_COMP_LEVEL));
if (level = clStore) then
begin
decompressMemory := (1 shl 20);
Exit(decompressMemory);
end;
decompressMemory := -1;
Dictionary := GetComboBox(hwndDlg, IDC_COMP_DICT);
Method := TJclCompressionMethod(GetComboBox(hwndDlg, IDC_COMP_METHOD));
if (Method <> cmDeflate) and (Method <> cmDeflate64) and (level >= clUltra) then
size += (12 shl 20) * 2 + (5 shl 20);
numThreads := GetComboBox(hwndDlg, IDC_COMP_THREAD);
case (method) of
cmLZMA,
cmLZMA2:
begin
hs := dictionary - 1;
hs := hs or (hs shr 1);
hs := hs or (hs shr 2);
hs := hs or (hs shr 4);
hs := hs or (hs shr 8);
hs := hs shr 1;
hs := hs or $FFFF;
if (hs > (1 shl 24)) then
hs := hs shr 1;
Inc(hs);
size1 := Int64(hs) * 4;
size1 += Int64(dictionary) * 4;
if (level >= clNormal) then
size1 += Int64(dictionary) * 4;
size1 += (2 shl 20);
numThreads1 := 1;
if (numThreads > 1) and (level >= clNormal) then
begin
size1 += (2 shl 20) + (4 shl 20);
numThreads1 := 2;
end;
numBlockThreads := numThreads div numThreads1;
if (method = cmLZMA) or (numBlockThreads = 1) then
size1 += Int64(dictionary) * 3 div 2
else
begin
chunkSize := Int64(dictionary) shl 2;
chunkSize := Max(chunkSize, Int64(1 shl 20));
chunkSize := Min(chunkSize, Int64(1 shl 28));
chunkSize := Max(chunkSize, Int64(dictionary));
size1 += chunkSize * 2;
end;
size += size1 * numBlockThreads;
decompressMemory := Int64(dictionary) + (2 shl 20);
Exit(size);
end;
cmPPMd:
begin
decompressMemory := Int64(dictionary) + (2 shl 20);
Exit(size + decompressMemory);
end;
cmDeflate,
cmDeflate64:
begin
if (level >= clMaximum) then
size += (1 shl 20);
size += 3 shl 20;
decompressMemory := (2 shl 20);
Exit(size);
end;
cmBZip2:
begin
decompressMemory := (7 shl 20);
size1 := (10 shl 20);
Exit(size + size1 * numThreads);
end;
end;
Result := -1;
end;
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'));
end;
procedure SetDefaultOptions(hwndDlg: HWND);
var
Index: Integer;
@ -225,6 +333,7 @@ begin
end;
end;
end;
UpdateMemoryUsage(hwndDlg);
end;
procedure UpdateSolid(hwndDlg: HWND);
@ -263,7 +372,7 @@ begin
if dwAlgoThreadMax < dwNumberOfProcessors then dwNumberOfProcessors:= dwAlgoThreadMax;
for Index:= 1 to dwMaxThread do
begin
ComboBoxAdd(hwndDlg, IDC_COMP_THREAD, IntToStr(Index), 0);
ComboBoxAdd(hwndDlg, IDC_COMP_THREAD, IntToStr(Index), Index);
end;
wsMaxThread:= '/ ' + IntToStr(dwMaxThread);
SendDlgItemMessage(hwndDlg, IDC_COMP_THREAD, CB_SETCURSEL, dwNumberOfProcessors - 1, 0);
@ -495,6 +604,7 @@ begin
SetComboBox(hwndDlg, IDC_COMP_SOLID, PluginConfig[Format].SolidSize);
SetComboBox(hwndDlg, IDC_COMP_THREAD, PluginConfig[Format].ThreadCount);
SetDlgItemTextW(hwndDlg, IDC_PARAMETERS, PWideChar(PluginConfig[Format].Parameters));
UpdateMemoryUsage(hwndDlg);
end;
function DialogProc(hwndDlg: HWND; uMsg: UINT; wParam: WPARAM; lParam: LPARAM): INT_PTR; stdcall;
@ -533,6 +643,13 @@ begin
UpdateLevel(hwndDlg, False);
SetDefaultOptions(hwndDlg);
end;
IDC_COMP_DICT,
IDC_COMP_WORD,
IDC_COMP_THREAD:
if (HIWORD(wParam) = CBN_SELCHANGE) then
begin
UpdateMemoryUsage(hwndDlg);
end;
IDOK:
begin
SaveArchiver(hwndDlg);