소스 검색

Finish/fix the page + make Extract7ZipArchive use exceptions on errors, just like DownloadTemporaryFile. Todo: fix messages. Also found new issue (not related to this branch): turns out 7zMain.c doesn't work from the current dir like I thought, instead it works from the archive dir. So the DestDir parameter doesn't work at the moment, doh!

Martijn Laan 10 달 전
부모
커밋
8d38ccb084

+ 1 - 1
ISHelp/isxclasses.pas

@@ -785,7 +785,7 @@ TExtractionWizardPage = class(TOutputProgressWizardPage)
   property AbortedByUser: Boolean; read;
   property AbortedByUser: Boolean; read;
   procedure Add(const ArchiveFileName, DestDir: String; const FullPaths: Boolean);
   procedure Add(const ArchiveFileName, DestDir: String; const FullPaths: Boolean);
   procedure Clear;
   procedure Clear;
-  function Extract: Integer;
+  procedure Extract;
   property ShowArchiveInsteadOfFile: Boolean; read write;
   property ShowArchiveInsteadOfFile: Boolean; read write;
 end;
 end;
 
 

+ 1 - 1
ISHelp/isxclasses_wordlists_generated.pas

@@ -90,7 +90,6 @@ var
     'function CheckItem(Index: Integer; AOperation: TCheckItemOperation): Boolean;',
     'function CheckItem(Index: Integer; AOperation: TCheckItemOperation): Boolean;',
     'function CopyFrom(Source: TStream; ByteCount: Int64; BufferSize: Integer): Int64;',
     'function CopyFrom(Source: TStream; ByteCount: Int64; BufferSize: Integer): Int64;',
     'function Download: Int64;',
     'function Download: Int64;',
-    'function Extract: Integer;',
     'function Find(S: String; var Index: Integer): Boolean;',
     'function Find(S: String; var Index: Integer): Boolean;',
     'function FindComponent(AName: String): TComponent;',
     'function FindComponent(AName: String): TComponent;',
     'function FindNextPage(CurPage: TNewNotebookPage; GoForward: Boolean): TNewNotebookPage;',
     'function FindNextPage(CurPage: TNewNotebookPage; GoForward: Boolean): TNewNotebookPage;',
@@ -124,6 +123,7 @@ var
     'procedure Destroying;',
     'procedure Destroying;',
     'procedure Draw(X, Y: Integer; Graphic: TGraphic);',
     'procedure Draw(X, Y: Integer; Graphic: TGraphic);',
     'procedure Ellipse(X1, Y1, X2, Y2: Integer);',
     'procedure Ellipse(X1, Y1, X2, Y2: Integer);',
+    'procedure Extract;',
     'procedure FlipSizeAndCenterIfNeeded(ACenterInsideControl: Boolean; CenterInsideControlCtl: TWinControl; CenterInsideControlInsideClientArea: Boolean);',
     'procedure FlipSizeAndCenterIfNeeded(ACenterInsideControl: Boolean; CenterInsideControlCtl: TWinControl; CenterInsideControlInsideClientArea: Boolean);',
     'procedure FloodFill(X, Y: Integer; Color: TColor; FillStyle: Byte);',
     'procedure FloodFill(X, Y: Integer; Color: TColor; FillStyle: Byte);',
     'procedure Free;',
     'procedure Free;',

+ 2 - 2
ISHelp/isxfunc.xml

@@ -1843,9 +1843,9 @@ end;</pre>
       </function>
       </function>
       <function>
       <function>
         <name>Extract7ZipArchive</name>
         <name>Extract7ZipArchive</name>
-        <prototype>function Extract7ZipArchive(const ArchiveFileName, DestDir: String; const FullPaths: Boolean; const OnExtractionProgress: TOnExtractionProgress): Integer;</prototype>
+        <prototype>procedure Extract7ZipArchive(const ArchiveFileName, DestDir: String; const FullPaths: Boolean; const OnExtractionProgress: TOnExtractionProgress);</prototype>
         <description><p>Extracts the specified 7-Zip archive to the specified directory, with or without using path names.</p>
         <description><p>Extracts the specified 7-Zip archive to the specified directory, with or without using path names.</p>
-<p>Returns zero if successful, nonzero otherwise</p>
+<p>An exception will be raised if there was an error.</p>
 <p>The archive must not be encrypted.</p>
 <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>
 <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>
         <remarks><p>TOnExtractionProgress is defined as:</p>

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

@@ -576,7 +576,7 @@ begin
     RegisterProperty('ShowArchiveInsteadOfFile', 'Boolean', iptrw);
     RegisterProperty('ShowArchiveInsteadOfFile', 'Boolean', iptrw);
     RegisterMethod('procedure Add(const ArchiveFileName, DestDir: String; const FullPaths: Boolean)');
     RegisterMethod('procedure Add(const ArchiveFileName, DestDir: String; const FullPaths: Boolean)');
     RegisterMethod('procedure Clear');
     RegisterMethod('procedure Clear');
-    RegisterMethod('function Extract: Integer');
+    RegisterMethod('procedure Extract');
     RegisterMethod('procedure Show'); { Without this TOutputProgressWizardPage's Show will be called }
     RegisterMethod('procedure Show'); { Without this TOutputProgressWizardPage's Show will be called }
   end;
   end;
 end;
 end;

+ 18 - 10
Projects/Src/Compression.SevenZipDecoder.pas

@@ -15,15 +15,15 @@ interface
 type
 type
   TOnExtractionProgress = function(const ArchiveName, 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;
+procedure Extract7ZipArchive(const ArchiveFileName, DestDir: String;
+  const FullPaths: Boolean; const OnExtractionProgress: TOnExtractionProgress);
 
 
 implementation
 implementation
 
 
 uses
 uses
   Windows, SysUtils, Forms,
   Windows, SysUtils, Forms,
   PathFunc,
   PathFunc,
-  Setup.LoggingFunc, Setup.MainFunc, Setup.InstFunc;
+  Shared.SetupMessageIDs, SetupLdrAndSetup.Messages, Setup.LoggingFunc, Setup.MainFunc, Setup.InstFunc;
 
 
 type
 type
   TSevenZipDecodeState = record
   TSevenZipDecodeState = record
@@ -32,6 +32,7 @@ type
     ExtractedArchiveName: String;
     ExtractedArchiveName: String;
     OnExtractionProgress: TOnExtractionProgress;
     OnExtractionProgress: TOnExtractionProgress;
     LastReportedProgress, LastReportedProgressMax: UInt64;
     LastReportedProgress, LastReportedProgressMax: UInt64;
+    Aborted: Boolean;
   end;
   end;
 
 
 var
 var
@@ -253,10 +254,13 @@ begin
 
 
   if not Abort and DownloadTemporaryFileOrSevenZipDecodeProcessMessages then
   if not Abort and DownloadTemporaryFileOrSevenZipDecodeProcessMessages then
     Application.ProcessMessages;
     Application.ProcessMessages;
+
+  if Abort then
+    State.Aborted := True;
 end;
 end;
 
 
-function Extract7ZipArchive(const ArchiveFileName, DestDir: String;
-  const FullPaths: Boolean; const OnExtractionProgress: TOnExtractionProgress): Integer;
+procedure Extract7ZipArchive(const ArchiveFileName, DestDir: String;
+  const FullPaths: Boolean; const OnExtractionProgress: TOnExtractionProgress);
 begin
 begin
   if ArchiveFileName = '' then
   if ArchiveFileName = '' then
     InternalError('Extract7ZipArchive: Invalid ArchiveFileName value');
     InternalError('Extract7ZipArchive: Invalid ArchiveFileName value');
@@ -266,8 +270,8 @@ begin
   LogFmt('Extracting 7-Zip archive %s to %s. Full paths? %s', [ArchiveFileName, DestDir, SYesNo[FullPaths]]);
   LogFmt('Extracting 7-Zip archive %s to %s. Full paths? %s', [ArchiveFileName, DestDir, SYesNo[FullPaths]]);
 
 
   var SaveCurDir := GetCurrentDir;
   var SaveCurDir := GetCurrentDir;
-  if not SetCurrentDir(DestDir) then
-    Exit(-1);
+  if not ForceDirectories(False, DestDir) or not SetCurrentDir(DestDir) then
+    raise Exception.Create(FmtSetupMessage(msgErrorDownloadFailed, ['-1', ''])); //todo: fix message
   try
   try
     State.ExpandedDestDir := AddBackslash(PathExpand(DestDir));
     State.ExpandedDestDir := AddBackslash(PathExpand(DestDir));
     State.LogBuffer := '';
     State.LogBuffer := '';
@@ -275,13 +279,17 @@ begin
     State.OnExtractionProgress := OnExtractionProgress;
     State.OnExtractionProgress := OnExtractionProgress;
     State.LastReportedProgress := 0;
     State.LastReportedProgress := 0;
     State.LastReportedProgressMax := 0;
     State.LastReportedProgressMax := 0;
+    State.Aborted := False;
 
 
-    Result := IS_7zDec(PChar(ArchiveFileName), FullPaths);
-
-    //todo: throw exception on Result <> 0 like DownloadTemporaryFile uses exceptions?
+    var Res := IS_7zDec(PChar(ArchiveFileName), FullPaths);
 
 
     if State.LogBuffer <> '' then
     if State.LogBuffer <> '' then
       Log(State.LogBuffer);
       Log(State.LogBuffer);
+
+    if State.Aborted then
+      raise Exception.Create(SetupMessages[msgErrorDownloadAborted]) //todo: fix message
+    else if Res <> 0 then
+      raise Exception.Create(FmtSetupMessage(msgErrorDownloadFailed, [Res.ToString, ''])) //todo: fix message
   finally
   finally
     SetCurrentDir(SaveCurDir);
     SetCurrentDir(SaveCurDir);
   end;
   end;

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

@@ -225,7 +225,7 @@ type
       procedure Initialize; override;
       procedure Initialize; override;
       procedure Add(const ArchiveFileName, DestDir: String; const FullPaths: Boolean);
       procedure Add(const ArchiveFileName, DestDir: String; const FullPaths: Boolean);
       procedure Clear;
       procedure Clear;
-      function Extract: Integer;
+      procedure Extract;
       property OnExtractionProgress: TOnExtractionProgress write FOnExtractionProgress;
       property OnExtractionProgress: TOnExtractionProgress write FOnExtractionProgress;
       procedure Show; override;
       procedure Show; override;
     published
     published
@@ -1180,15 +1180,13 @@ begin
   FArchives.Clear;
   FArchives.Clear;
 end;
 end;
 
 
-function TExtractionWizardPage.Extract: Integer;
+procedure TExtractionWizardPage.Extract;
 begin
 begin
   FAbortedByUser := False;
   FAbortedByUser := False;
 
 
-  Result := 0;
   for var A in FArchives do begin
   for var A in FArchives do begin
     { Don't need to set DownloadTemporaryFileOrSevenZipDecodeProcessMessages before extraction since we already process messages ourselves. }
     { Don't need to set DownloadTemporaryFileOrSevenZipDecodeProcessMessages before extraction since we already process messages ourselves. }
-    if Extract7ZipArchive(A.FileName, A.DestDir, A.FullPaths, InternalOnExtractionProgress) = 0 then
-      Inc(Result);
+    Extract7ZipArchive(A.FileName, A.DestDir, A.FullPaths, InternalOnExtractionProgress);
   end;
   end;
 end;
 end;
 
 

+ 3 - 3
Projects/Src/Setup.ScriptFunc.pas

@@ -291,7 +291,7 @@ begin
       raise;
       raise;
     end;
     end;
     Stack.SetClass(PStart, NewDownloadPage);
     Stack.SetClass(PStart, NewDownloadPage);
-  end else if Proc.Name = 'CREATEXTRACTIONPAGE' then begin
+  end else if Proc.Name = 'CREATEEXTRACTIONPAGE' then begin
     if IsUninstaller then
     if IsUninstaller then
       NoUninstallFuncError(Proc.Name);
       NoUninstallFuncError(Proc.Name);
     var P: PPSVariantProcPtr := Stack.Items[PStart-3];
     var P: PPSVariantProcPtr := Stack.Items[PStart-3];
@@ -2118,14 +2118,14 @@ begin
       AscendingTrySizes[I] := VNGetInt(PSGetArrayField(Arr, I));
       AscendingTrySizes[I] := VNGetInt(PSGetArrayField(Arr, I));
     Stack.SetBool(PStart, TBitmapImage(Stack.GetClass(PStart-1)).InitializeFromIcon(0, PChar(Stack.GetString(PStart-2)), Stack.GetInt(PStart-3), AscendingTrySizes));
     Stack.SetBool(PStart, TBitmapImage(Stack.GetClass(PStart-1)).InitializeFromIcon(0, PChar(Stack.GetString(PStart-2)), Stack.GetInt(PStart-3), AscendingTrySizes));
   end else if Proc.Name = 'EXTRACT7ZIPARCHIVE' then begin
   end else if Proc.Name = 'EXTRACT7ZIPARCHIVE' then begin
-    var P: PPSVariantProcPtr := Stack.Items[PStart-4];
+    var P: PPSVariantProcPtr := Stack.Items[PStart-3];
     var OnExtractionProgress: TOnExtractionProgress;
     var OnExtractionProgress: TOnExtractionProgress;
     { ProcNo 0 means nil was passed by the script }
     { ProcNo 0 means nil was passed by the script }
     if P.ProcNo <> 0 then
     if P.ProcNo <> 0 then
       OnExtractionProgress := TOnExtractionProgress(Caller.GetProcAsMethod(P.ProcNo))
       OnExtractionProgress := TOnExtractionProgress(Caller.GetProcAsMethod(P.ProcNo))
     else
     else
       OnExtractionProgress := nil;
       OnExtractionProgress := nil;
-    Stack.SetInt(PStart, Extract7ZipArchive(Stack.GetString(PStart-1), Stack.GetString(PStart-2), Stack.GetBool(PStart-3), OnExtractionProgress));
+    Extract7ZipArchive(Stack.GetString(PStart), Stack.GetString(PStart-1), Stack.GetBool(PStart-2), OnExtractionProgress);
   end else if Proc.Name = 'DEBUGGING' then begin
   end else if Proc.Name = 'DEBUGGING' then begin
     Stack.SetBool(PStart, Debugging);
     Stack.SetBool(PStart, Debugging);
   end else
   end else

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

@@ -540,7 +540,7 @@ initialization
     'function IsDotNetInstalled(const MinVersion: TDotNetVersion; const MinServicePack: Cardinal): Boolean;',
     'function IsDotNetInstalled(const MinVersion: TDotNetVersion; const MinServicePack: Cardinal): Boolean;',
     'function IsMsiProductInstalled(const UpgradeCode: String; const PackedMinVersion: Int64): 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 InitializeBitmapImageFromIcon(const BitmapImage: TBitmapImage; const IconFilename: String; const BkColor: TColor; const AscendingTrySizes: TArrayOfInteger): Boolean;',
-    'function Extract7ZipArchive(const ArchiveFileName, DestDir: String; const FullPaths: Boolean; const OnExtractionProgress: TOnExtractionProgress): Integer;',
+    'procedure Extract7ZipArchive(const ArchiveFileName, DestDir: String; const FullPaths: Boolean; const OnExtractionProgress: TOnExtractionProgress);',
     'function Debugging: Boolean;'
     'function Debugging: Boolean;'
   ];
   ];