瀏覽代碼

Fix the archive name todo + log cleanup (there was double logging).

Martijn Laan 9 月之前
父節點
當前提交
c96fdb04a4

+ 1 - 18
ISHelp/isxfunc.xml

@@ -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>
@@ -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>

+ 1 - 1
Projects/Src/Compiler.ScriptFunc.pas

@@ -139,7 +139,7 @@ begin
     '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

+ 5 - 4
Projects/Src/Compression.SevenZipDecoder.pas

@@ -13,7 +13,7 @@ unit Compression.SevenZipDecoder;
 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;
@@ -29,6 +29,7 @@ type
   TSevenZipDecodeState = record
     ExpandedDestDir: String;
     LogBuffer: AnsiString;
+    ExtractedArchiveName: String;
     OnExtractionProgress: TOnExtractionProgress;
     LastReportedProgress, LastReportedProgressMax: UInt64;
   end;
@@ -241,8 +242,7 @@ begin
        (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;
@@ -269,8 +269,9 @@ begin
   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;

+ 5 - 5
Projects/Src/Setup.ScriptDlg.pas

@@ -217,7 +217,7 @@ type
       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;
@@ -1086,7 +1086,7 @@ begin
   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
@@ -1094,9 +1094,9 @@ 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;
@@ -1113,7 +1113,7 @@ begin
     end;
 
     if Assigned(FOnExtractionProgress) then
-      Result := FOnExtractionProgress(ArchiveFileName, FileName, Progress, ProgressMax)
+      Result := FOnExtractionProgress(ArchiveName, FileName, Progress, ProgressMax)
     else
       Result := True;
   end;

+ 1 - 1
Projects/Src/Shared.ScriptFunc.pas

@@ -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;'
   ];