Skip to content

Commit

Permalink
Fix the archive name todo + log cleanup (there was double logging).
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnlaan committed Nov 14, 2024
1 parent dc634c9 commit c96fdb0
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 29 deletions.
19 changes: 1 addition & 18 deletions ISHelp/isxfunc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1849,7 +1849,7 @@ end;</pre>
<p>The archive must not be encrypted.</p>
<p>Set OnExtractionProgress to a function to be informed of progress, or <tt>nil</tt> otherwise.</p></description>
<remarks><p>TOnExtractionProgress is defined as:</p>
<p><tt>TOnExtractionProgress = function(const ArchiveFileName, FileName: string; const Progress, ProgressMax: Int64): Boolean;</tt></p>
<p><tt>TOnExtractionProgress = function(const ArchiveName, FileName: string; const Progress, ProgressMax: Int64): Boolean;</tt></p>
<p>Return True to allow the extraction to continue, False otherwise.</p>
<p><tt>Extract7ZipArchive</tt> uses an embedded version of the &quot;7z ANSI-C Decoder&quot; from the LZMA SDK by Igor Pavlov, as-is, except that Unicode support and error messages were improved and that it outputs memory requirements.</p>
<p>All output of the decoder is logged if logging is enabled, including error messages but excluding empty lines.</p>
Expand All @@ -1868,23 +1868,6 @@ In that example 7-Zip will use 512KB solid blocks. So it needs to decompress onl
<link topic="isxfunc_CreateDownloadPage">CreateDownloadPage</link><br />
<link topic="isxfunc_DownloadTemporaryFile">DownloadTemporaryFile</link><br />
<link topic="isxfunc_ExtractTemporaryFile">ExtractTemporaryFile</link></p></seealso>
<example><pre>
[Code]
function OnExtractionProgress(const ArchiveFileName, FileName: string; const Progress, ProgressMax: Int64): Boolean;
begin
Log(Format(' %s\%s: %d of %d bytes done.', [ArchiveFileName, FileName, Progress, ProgressMax]))
Result := True;
end;

function InitializeSetup: Boolean;
begin
try
Result := Extract7ZipArchive(ExpandConstant('{tmp}\Archive.7z'), ExpandConstant('{app}'), True, @OnExtractionProgress) = 0;
except
Log(GetExceptionMessage);
Result := False;
end;
end;</pre></example>
</function>
</subcategory>
<subcategory>
Expand Down
2 changes: 1 addition & 1 deletion Projects/Src/Compiler.ScriptFunc.pas
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ procedure ScriptFuncLibraryRegister_C(ScriptCompiler: TPSPascalCompiler;
'end');

RegisterType('TOnDownloadProgress', 'function(const Url, FileName: string; const Progress, ProgressMax: Int64): Boolean;');
RegisterType('TOnExtractionProgress', 'function(const ArchiveFileName, FileName: string; const Progress, ProgressMax: Int64): Boolean;');
RegisterType('TOnExtractionProgress', 'function(const ArchiveName, FileName: string; const Progress, ProgressMax: Int64): Boolean;');
RegisterType('TOnLog', 'procedure(const S: String; const Error, FirstLine: Boolean);');

for var ScriptFuncTable in ScriptFuncTables do
Expand Down
9 changes: 5 additions & 4 deletions Projects/Src/Compression.SevenZipDecoder.pas
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
interface

type
TOnExtractionProgress = function(const ArchiveFileName, FileName: string; const Progress, ProgressMax: Int64): Boolean of object;
TOnExtractionProgress = function(const ArchiveName, FileName: string; const Progress, ProgressMax: Int64): Boolean of object;

function Extract7ZipArchive(const ArchiveFileName, DestDir: String;
const FullPaths: Boolean; const OnExtractionProgress: TOnExtractionProgress): Integer;
Expand All @@ -29,6 +29,7 @@ implementation
TSevenZipDecodeState = record
ExpandedDestDir: String;
LogBuffer: AnsiString;
ExtractedArchiveName: String;
OnExtractionProgress: TOnExtractionProgress;
LastReportedProgress, LastReportedProgressMax: UInt64;
end;
Expand Down Expand Up @@ -241,8 +242,7 @@ procedure _ReportProgress(const FileName: PChar; const Progress, ProgressMax: UI
(Progress < State.LastReportedProgress) or (ProgressMax <> State.LastReportedProgressMax) or
((Progress - State.LastReportedProgress) > 524288) then begin
try
var ArchiveFileName := '?'; //todo: fix
if not State.OnExtractionProgress(ArchiveFileName, FileName, Progress, ProgressMax) then
if not State.OnExtractionProgress(State.ExtractedArchiveName, FileName, Progress, ProgressMax) then
Abort := True;
finally
State.LastReportedProgress := Progress;
Expand All @@ -269,8 +269,9 @@ function Extract7ZipArchive(const ArchiveFileName, DestDir: String;
if not SetCurrentDir(DestDir) then
Exit(-1);
try
State.LogBuffer := '';
State.ExpandedDestDir := AddBackslash(PathExpand(DestDir));
State.LogBuffer := '';
State.ExtractedArchiveName := PathExtractName(ArchiveFileName);
State.OnExtractionProgress := OnExtractionProgress;
State.LastReportedProgress := 0;
State.LastReportedProgressMax := 0;
Expand Down
10 changes: 5 additions & 5 deletions Projects/Src/Setup.ScriptDlg.pas
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ TExtractionWizardPage = class(TOutputProgressWizardPage)
FAbortButton: TNewButton;
FShowProgressControlsOnNextProgress, FAbortedByUser: Boolean;
procedure AbortButtonClick(Sender: TObject);
function InternalOnExtractionProgress(const ArchiveFileName, FileName: string; const Progress, ProgressMax: Int64): Boolean;
function InternalOnExtractionProgress(const ArchiveName, FileName: string; const Progress, ProgressMax: Int64): Boolean;
procedure ShowProgressControls(const AVisible: Boolean);
public
constructor Create(AOwner: TComponent); override;
Expand Down Expand Up @@ -1086,17 +1086,17 @@ procedure TExtractionWizardPage.AbortButtonClick(Sender: TObject);
FAbortedByUser := LoggedMsgBox(SetupMessages[msgStopDownload], '', mbConfirmation, MB_YESNO, True, ID_YES) = IDYES;
end;

function TExtractionWizardPage.InternalOnExtractionProgress(const ArchiveFileName, FileName: string; const Progress, ProgressMax: Int64): Boolean;
function TExtractionWizardPage.InternalOnExtractionProgress(const ArchiveName, FileName: string; const Progress, ProgressMax: Int64): Boolean;
var
Progress32, ProgressMax32: LongInt;
begin
if FAbortedByUser then begin
Log('Need to abort extraction.');
Result := False;
end else begin
Log(Format(' %d bytes done.', [Progress]));
{ Unlike TDownloadWizardPage we don't log progress here. This is because 7zMain.c already logs output dirs and names. }

FMsg2Label.Caption := IfThen(FShowArchiveInsteadOfFile, ArchiveFileName, FileName);
FMsg2Label.Caption := IfThen(FShowArchiveInsteadOfFile, ArchiveName, FileName);
if ProgressMax > MaxLongInt then begin
Progress32 := Round((Progress / ProgressMax) * MaxLongInt);
ProgressMax32 := MaxLongInt;
Expand All @@ -1113,7 +1113,7 @@ function TExtractionWizardPage.InternalOnExtractionProgress(const ArchiveFileNam
end;

if Assigned(FOnExtractionProgress) then
Result := FOnExtractionProgress(ArchiveFileName, FileName, Progress, ProgressMax)
Result := FOnExtractionProgress(ArchiveName, FileName, Progress, ProgressMax)
else
Result := True;
end;
Expand Down
2 changes: 1 addition & 1 deletion Projects/Src/Shared.ScriptFunc.pas
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ initialization
'function IsDotNetInstalled(const MinVersion: TDotNetVersion; const MinServicePack: Cardinal): Boolean;',
'function IsMsiProductInstalled(const UpgradeCode: String; const PackedMinVersion: Int64): Boolean;',
'function InitializeBitmapImageFromIcon(const BitmapImage: TBitmapImage; const IconFilename: String; const BkColor: TColor; const AscendingTrySizes: TArrayOfInteger): Boolean;',
'function Extract7ZipArchive(const FileName, DestDir: String; const FullPaths: Boolean; const OnExtractionProgress: TOnExtractionProgress): Integer;',
'function Extract7ZipArchive(const ArchiveFileName, DestDir: String; const FullPaths: Boolean; const OnExtractionProgress: TOnExtractionProgress): Integer;',
'function Debugging: Boolean;'
];

Expand Down

0 comments on commit c96fdb0

Please sign in to comment.