Sfoglia il codice sorgente

Cherry pick into 6.5.1: Improve: handle pre-progress aborting as well.

Martijn Laan 3 mesi fa
parent
commit
b2fbcd506b
2 ha cambiato i file con 28 aggiunte e 14 eliminazioni
  1. 14 13
      Projects/Src/Setup.DownloadFileFunc.pas
  2. 14 1
      Projects/Src/Setup.ScriptDlg.pas

+ 14 - 13
Projects/Src/Setup.DownloadFileFunc.pas

@@ -17,7 +17,7 @@ uses
 type
   TOnDownloadProgress = function(const Url, BaseName: string; const Progress, ProgressMax: Int64): Boolean of object;
   TOnSimpleDownloadProgress = procedure(const Bytes, Param: Integer64);
-  TOnDownloadNoProgress = procedure of object;
+  TOnDownloadNoProgress = function: Boolean of object;
   TOnSimpleDownloadNoProgress = procedure;
 
 function DownloadFile(const Url, CustomUserName, CustomPassword: String;
@@ -198,8 +198,8 @@ begin
     System.TMonitor.Exit(FLock);
   end;
 
-  if ProgressSet then begin
-    try
+  try
+    if ProgressSet then begin
       if Assigned(FOnDownloadProgress) then begin
         if not FOnDownloadProgress(FCleanUrl, FBaseName, Progress, ProgressMax) then
           FAbort := True; { Atomic so no lock }
@@ -210,17 +210,18 @@ begin
           FLastReportedProgress := Progress;
         end;
       end;
-    except
-      if ExceptObject is EAbort then { FOnSimpleDownloadProgress always uses Abort to abort }
-        FAbort := True { Atomic so no lock }
-      else
-        raise;
+    end else begin
+      if Assigned(FOnDownloadNoProgress) then begin
+        if not FOnDownloadNoProgress then
+          FAbort := True; { Atomic so no lock }
+      end else if Assigned(FOnSimpleDownloadNoProgress) then
+        FOnSimpleDownloadNoProgress;
     end;
-  end else begin
-    if Assigned(FOnDownloadNoProgress) then
-      FOnDownloadNoProgress
-    else if Assigned(FOnSimpleDownloadNoProgress) then
-      FOnSimpleDownloadNoProgress;
+  except
+    if ExceptObject is EAbort then { FOnSimpleDownload(No)Progress always uses Abort to abort }
+      FAbort := True { Atomic so no lock }
+    else
+      raise;
   end;
 
   if DownloadTemporaryFileOrExtractArchiveProcessMessages then

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

@@ -198,6 +198,7 @@ type
         const ISSigAllowedKeys: AnsiString; const DotISSigEntry: Boolean; const Data: NativeUInt): Integer;
       procedure AbortButtonClick(Sender: TObject);
       function InternalOnDownloadProgress(const Url, BaseName: string; const Progress, ProgressMax: Int64): Boolean;
+      function InternalOnDownloadNoProgress: Boolean;
       function InternalThrottledOnDownloadProgress(const Url, BaseName: string; const Progress, ProgressMax: Int64): Boolean;
       procedure ShowProgressControls(const AVisible: Boolean);
     public
@@ -1021,6 +1022,17 @@ begin
   end;
 end;
 
+function TDownloadWizardPage.InternalOnDownloadNoProgress: Boolean;
+begin
+  if FAbortedByUser then begin { Currently always False because the Abort button isn't visible yet }
+    Log('Need to abort download.');
+    Result := False;
+  end else begin
+    ProcessMsgs;
+    Result := True;
+  end;
+end;
+
 function TDownloadWizardPage.InternalThrottledOnDownloadProgress(const Url, BaseName: string; const Progress, ProgressMax: Int64): Boolean;
 begin
   if ProgressMax > 0 then
@@ -1179,7 +1191,8 @@ begin
       FLastBaseNameOrUrl := IfThen(FShowBaseNameInsteadOfUrl, PathExtractName(F.BaseName), F.Url);
       SetDownloadTemporaryFileCredentials(F.UserName, F.Password);
       var DestFile: String;
-      Result := Result + DownloadTemporaryFile(F.Url, F.BaseName, F.Verification, InternalOnDownloadProgress, ProcessMsgs, DestFile);
+      Result := Result + DownloadTemporaryFile(F.Url, F.BaseName, F.Verification,
+        InternalOnDownloadProgress, InternalOnDownloadNoProgress, DestFile);
       if Assigned(OnDownloadFileCompleted) then begin
         var Remove := False;
         OnDownloadFileCompleted(F, DestFile, Remove);