Browse Source

Add ExtractArchive support to TExtractionWizardPage. Todo: add AddEx to specify password.

Martijn Laan 3 tháng trước cách đây
mục cha
commit
8c9f074319

+ 20 - 2
Examples/CodeDownloadFiles.iss

@@ -27,7 +27,18 @@ Name: "mykey"; \
   PublicX: "515dc7d6c16d4a46272ceb3d158c5630a96466ab4d948e72c2029d737c823097"; \
   PublicY: "f3c21f6b5156c52a35f6f28016ee3e31a3ded60c325b81fb7b1f88c221081a61"
 
+// Uncomment the following line to use the 7-Zip library for extraction
+//#define USE7ZDLL
+// Please see the Init7ZipLibrary topic in the help file for more information
+//
+#ifdef USE7ZDLL
+  #define _7ZDLL "7zxa.dll"
+#endif
+//
 [Files]
+#ifdef USE7ZDLL 
+Source: "{#_7ZDLL}"; Flags: dontcopy
+#endif
 ; Place any regular files here
 Source: "MyProg.exe"; DestDir: "{app}";
 Source: "MyProg.chm"; DestDir: "{app}";
@@ -96,13 +107,20 @@ begin
       Exit;
 
     ExtractionPage.Clear;
+    // Use AddEx to specify a password
     ExtractionPage.Add(ExpandConstant('{tmp}\MyProg-ExtraReadmes.7z'), ExpandConstant('{tmp}\MyProg-ExtraReadmes'), True);
     ExtractionPage.Show;
     try
       try
+        #ifdef USE7ZDLL
+          // Extract and initialize the 7-Zip library
+          // This which will make the ExtractionPage switch from using Extract7ZipArchive to using ExtractArchive
+          ExtractTemporaryFile('{#_7ZDLL}');
+          Init7ZipLibrary(ExpandConstant('{tmp}\{#_7ZDLL}'));
+        #endif
         // Extracts the archive to {tmp}\MyProg-ExtraReadmes
-        // Please see the Extract7ZipArchive topic in the help file for limitations before using this for you own archives
-        // Note that each file in this archive comes with an .issig signature file
+        // Please see the Extract7ZipArchive or ExtractArchive topic in the help file for limitations
+        // Note that each file in the MyProg-ExtraReadmes.7z example archive comes with an .issig signature file
         // These signature files are used by the [Files] section to verify the archive's content
         ExtractionPage.Extract;
         Result := True;

+ 8 - 1
Projects/Src/Compression.SevenZipDllDecoder.pas

@@ -19,6 +19,8 @@ uses
 
 procedure InitSevenZipLibrary(const DllFilename: String);
 
+function IsExtractArchiveRedirAvailable: Boolean;
+
 procedure ExtractArchiveRedir(const DisableFsRedir: Boolean;
   const ArchiveFilename, DestDir, Password: String; const FullPaths: Boolean;
   const OnExtractionProgress: TOnExtractionProgress);
@@ -446,6 +448,11 @@ begin
   end;
 end;
 
+function IsExtractArchiveRedirAvailable: Boolean;
+begin
+  Result := Assigned(CreateSevenZipObject);
+end;
+
 procedure ExtractArchiveRedir(const DisableFsRedir: Boolean;
   const ArchiveFilename, DestDir, Password: String;
   const FullPaths: Boolean; const OnExtractionProgress: TOnExtractionProgress);
@@ -481,7 +488,7 @@ procedure ExtractArchiveRedir(const DisableFsRedir: Boolean;
   end;
 
 begin
-  if not Assigned(CreateSevenZipObject) then
+  if not IsExtractArchiveRedirAvailable then
     InternalError('ExtractArchive: 7z(xa).dll not loaded');
   if ArchiveFileName = '' then
     InternalError('ExtractArchive: Invalid ArchiveFileName value');

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

@@ -240,7 +240,7 @@ uses
   StrUtils,
   Shared.Struct, Setup.MainFunc, Setup.SelectFolderForm, SetupLdrAndSetup.Messages,
   Shared.SetupMessageIDs, PathFunc, Shared.CommonFunc.Vcl, Shared.CommonFunc,
-  BrowseFunc, Setup.LoggingFunc, Setup.InstFunc;
+  BrowseFunc, Setup.LoggingFunc, Setup.InstFunc, Compression.SevenZipDllDecoder;
 
 const
   DefaultLabelHeight = 14;
@@ -251,7 +251,7 @@ const
 
 procedure SetCtlParent(const AControl, AParent: TWinControl);
 { Like assigning to AControl.Parent, but puts the control at the *bottom* of
-  the z-order instead of the top, for MSAA compatibility. }
+  the z-order instead of the top, for MSAA compatibility }
 var
   OldVisible: Boolean;
 begin
@@ -1071,7 +1071,7 @@ begin
 
   Result := 0;
   for var F in FFiles do begin
-    { Don't need to set DownloadTemporaryFileOrExtractArchiveProcessMessages before downloading since we already process messages ourselves. }
+    { Don't need to set DownloadTemporaryFileOrExtractArchiveProcessMessages before downloading since we already process messages ourselves }
     SetDownloadCredentials(F.UserName, F.Password);
     Result := Result + DownloadTemporaryFile(F.Url, F.BaseName, F.RequiredSHA256OfFile, InternalOnDownloadProgress);
   end;
@@ -1180,12 +1180,21 @@ begin
 end;
 
 procedure TExtractionWizardPage.Extract;
+const
+  SExtractionMode: array[Boolean] of String = ('Built-in', 'Using 7z(xa).dll');
 begin
   FAbortedByUser := False;
 
+  const ExtractArchiveRedirAvailable = IsExtractArchiveRedirAvailable;
+
+  LogFmt('Archive extraction mode: %s', [SExtractionMode[ExtractArchiveRedirAvailable]]);
+
   for var A in FArchives do begin
-    { Don't need to set DownloadTemporaryFileOrExtractArchiveProcessMessages before extraction since we already process messages ourselves. }
-    Extract7ZipArchiveRedir(ScriptFuncDisableFsRedir, A.FileName, A.DestDir, A.FullPaths, InternalOnExtractionProgress);
+    { Don't need to set DownloadTemporaryFileOrExtractArchiveProcessMessages before extraction since we already process messages ourselves }
+    if ExtractArchiveRedirAvailable then
+      ExtractArchiveRedir(ScriptFuncDisableFsRedir, A.FileName, A.DestDir, '', A.FullPaths, InternalOnExtractionProgress)
+    else
+      Extract7ZipArchiveRedir(ScriptFuncDisableFsRedir, A.FileName, A.DestDir, A.FullPaths, InternalOnExtractionProgress);
   end;
 end;