Skip to content

Commit

Permalink
Add abort option.
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnlaan committed Nov 9, 2024
1 parent 23bac88 commit 8155714
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
23 changes: 18 additions & 5 deletions Components/Lzma2/Util/7z/7zMain.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
/* Changes by Martijn Laan for Inno Setup:
-Use CP_UTF8 in PrintString
-Change main to mainW to support Unicode archive names
-Add specific error text for SZ_ERROR_ARCHIVE and SZ_ERROR_NO_ARCHIVE
-Add specific error text for SZ_ERROR_ARCHIVE, SZ_ERROR_NO_ARCHIVE, and SZ_ERROR_PROGRESS
-Return res on errors instead of always returning 1
-Add optional progress reporting
-Add optional progress reporting with abort option
Otherwise unchanged */

#include "Precomp.h"
Expand Down Expand Up @@ -46,7 +46,7 @@ static const ISzAlloc g_Alloc = { SzAlloc, SzFree };
// static const ISzAlloc g_Alloc_temp = { SzAllocTemp, SzFreeTemp };

#ifdef REPORT_PROGRESS
void ReportProgress(UInt16 *fileName, const UInt64 progress, const UInt64 progressMax);
void ReportProgress(UInt16 *fileName, const UInt64 progress, const UInt64 progressMax, BoolInt *abort);
#endif

static void Print(const char *s)
Expand Down Expand Up @@ -664,6 +664,7 @@ int Z7_CDECL mainW(int numargs, WCHAR *args[])
}
}
UInt64 progress = 0;
BoolInt abort = False;
#endif

/*
Expand Down Expand Up @@ -754,7 +755,12 @@ int Z7_CDECL mainW(int numargs, WCHAR *args[])
else
{
#ifdef REPORT_PROGRESS
ReportProgress(temp, progress, progressMax);
ReportProgress(temp, progress, progressMax, &abort);
if (abort)
{
res = SZ_ERROR_PROGRESS;
break;
}
#endif
res = SzArEx_Extract(&db, &lookStream.vt, i,
&blockIndex, &outBuffer, &outBufferSize,
Expand Down Expand Up @@ -878,7 +884,12 @@ int Z7_CDECL mainW(int numargs, WCHAR *args[])

#ifdef REPORT_PROGRESS
progress += processedSize;
ReportProgress(temp, progress, progressMax);
ReportProgress(temp, progress, progressMax, &abort);
if (abort)
{
res = SZ_ERROR_PROGRESS;
break;
}
#endif
}
PrintLF();
Expand Down Expand Up @@ -911,6 +922,8 @@ int Z7_CDECL mainW(int numargs, WCHAR *args[])
PrintError("not an archive");
else if (res == SZ_ERROR_READ /* || archiveStream.Res != 0 */)
PrintError_WRes("Read Error", archiveStream.wres);
else if (res == SZ_ERROR_PROGRESS)
PrintError("break from progress callback");
else
{
char s[32];
Expand Down
4 changes: 2 additions & 2 deletions Projects/Src/Compression.SevenZipDecoder.pas
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,10 @@ function __fputs(str: PAnsiChar; unused: Pointer): Integer; cdecl;
end;
end;

procedure _ReportProgress(const FileName: PChar; const Progress, ProgressMax: UInt64); cdecl;
procedure _ReportProgress(const FileName: PChar; const Progress, ProgressMax: UInt64; var Abort: Bool); cdecl;
begin
//Setup.LoggingFunc.Log(Format('%s: %d of %d', [FileName, Progress, ProgressMax]));
if DownloadTemporaryFileOrSevenZipDecodeProcessMessages then
if not Abort and DownloadTemporaryFileOrSevenZipDecodeProcessMessages then
Application.ProcessMessages;
end;

Expand Down
Binary file modified Projects/Src/Compression.SevenZipDecoder/7zDecode/IS7zDec.obj
Binary file not shown.

0 comments on commit 8155714

Please sign in to comment.