Skip to content

Commit

Permalink
Add basic progress reporting for 7-Zip extracting, not yet actually u…
Browse files Browse the repository at this point in the history
…sed.
  • Loading branch information
martijnlaan committed Nov 9, 2024
1 parent b445cf4 commit bda8555
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Components/Lzma2/Util/7z/7zMain.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
-Change main to mainW to support Unicode archive names
-Add specific error text for SZ_ERROR_ARCHIVE and SZ_ERROR_NO_ARCHIVE
-Return res on errors instead of always returning 1
-Add optional progress reporting
Otherwise unchanged */

#include "Precomp.h"
Expand Down Expand Up @@ -44,6 +45,9 @@
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);
#endif

static void Print(const char *s)
{
Expand Down Expand Up @@ -648,6 +652,20 @@ int Z7_CDECL mainW(int numargs, WCHAR *args[])
{
UInt32 i;

#ifdef REPORT_PROGRESS
UInt64 progressMax = 0;
for (i = 0; i < db.NumFiles; i++)
{
const BoolInt isDir = SzArEx_IsDir(&db, i);
if (!isDir)
{
UInt64 fileSize = SzArEx_GetFileSize(&db, i);
progressMax += fileSize;
}
}
UInt64 progress = 0;
#endif

/*
if you need cache, use these 3 variables.
if you use external function, you can make these variable as static.
Expand Down Expand Up @@ -735,6 +753,9 @@ int Z7_CDECL mainW(int numargs, WCHAR *args[])
Print("/");
else
{
#ifdef REPORT_PROGRESS
ReportProgress(temp, progress, progressMax);
#endif
res = SzArEx_Extract(&db, &lookStream.vt, i,
&blockIndex, &outBuffer, &outBufferSize,
&offset, &outSizeProcessed,
Expand Down Expand Up @@ -854,6 +875,11 @@ int Z7_CDECL mainW(int numargs, WCHAR *args[])
SetFileAttributesW((LPCWSTR)destPath, attrib);
}
#endif

#ifdef REPORT_PROGRESS
progress += processedSize;
ReportProgress(temp, progress, progressMax);
#endif
}
PrintLF();
}
Expand Down
5 changes: 5 additions & 0 deletions Projects/Src/Compression.SevenZipDecoder.pas
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ function __fputs(str: PAnsiChar; unused: Pointer): Integer; cdecl;
end;
end;

procedure _ReportProgress(const FileName: PChar; const Progress, ProgressMax: UInt64); cdecl;
begin
//Setup.LoggingFunc.Log(Format('%s: %d of %d', [FileName, Progress, ProgressMax]));
end;

function SevenZipDecode(const FileName, DestDir: String;
const FullPaths: Boolean): Integer;
begin
Expand Down
2 changes: 2 additions & 0 deletions Projects/Src/Compression.SevenZipDecoder/7zDecode/IS7zDec.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ int _fputs(char const* str, FILE* stream);
/* Include all needed SDK code. None of these require changes for the helper function to
work but 7zMain.c was changed for better Unicode support */

#define REPORT_PROGRESS

#include "../../../../Components/Lzma2/Util/7z/7zMain.c"

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

0 comments on commit bda8555

Please sign in to comment.