Kaynağa Gözat

Cherry pick into 6.5.1: Improve: actually stay responsive when there's no download progress yet.

Martijn Laan 3 ay önce
ebeveyn
işleme
05317197d7

+ 24 - 7
Projects/Src/Setup.DownloadFileFunc.pas

@@ -17,17 +17,21 @@ 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;
+  TOnSimpleDownloadNoProgress = procedure;
 
 function DownloadFile(const Url, CustomUserName, CustomPassword: String;
   const DestF: TFile; [ref] const Verification: TSetupFileVerification; const ISSigSourceFilename: String;
   const OnSimpleDownloadProgress: TOnSimpleDownloadProgress;
-  const OnSimpleDownloadProgressParam: Integer64): Int64;
+  const OnSimpleDownloadProgressParam: Integer64;
+  const OnSimpleDownloadNoProgress: TOnSimpleDownloadNoProgress): Int64;
 
   function DownloadTemporaryFile(const Url, BaseName: String;
-  [ref] const Verification: TSetupFileVerification; const OnDownloadProgress: TOnDownloadProgress): Int64; overload;
+  [ref] const Verification: TSetupFileVerification; const OnDownloadProgress: TOnDownloadProgress;
+  const OnDownloadNoProgress: TOnDownloadNoProgress): Int64; overload;
 function DownloadTemporaryFile(const Url, BaseName: String;
   [ref] const Verification: TSetupFileVerification; const OnDownloadProgress: TOnDownloadProgress;
-  out DestFile: String): Int64; overload;
+  const OnDownloadNoProgress: TOnDownloadNoProgress; out DestFile: String): Int64; overload;
 function DownloadTemporaryFileSize(const Url: String): Int64;
 function DownloadTemporaryFileDate(const Url: String): String;
 procedure SetDownloadTemporaryFileCredentials(const User, Pass: String);
@@ -59,8 +63,10 @@ type
       FUser, FPass: String;
       FDestFile: TFile;
       FOnDownloadProgress: TOnDownloadProgress;
+      FOnDownloadNoProgress: TOnDownloadNoProgress;
       FOnSimpleDownloadProgress: TOnSimpleDownloadProgress;
       FOnSimpleDownloadProgressParam: Integer64;
+      FOnSimpleDownloadNoProgress: TOnSimpleDownloadNoProgress;
       FLock: TObject;
       FProgress, FProgressMax: Int64;
       FProgressSet: Boolean;
@@ -76,8 +82,10 @@ type
     destructor Destroy; override;
     property BaseName: String write FBaseName;
     property OnDownloadProgress: TOnDownloadProgress write FOnDownloadProgress;
+    property OnDownloadNoProgress: TOnDownloadNoProgress write FOnDownloadNoProgress;
     property OnSimpleDownloadProgress: TOnSimpleDownloadProgress write FOnSimpleDownloadProgress;
     property OnSimpleDownloadProgressParam: Integer64 write FOnSimpleDownloadProgressParam;
+    property OnSimpleDownloadNoProgress: TOnSimpleDownloadNoProgress write FOnSimpleDownloadNoProgress;
     property Aborted: Boolean read FAbort;
     property Progress: Int64 read FProgress;
     property ProgressMax: Int64 read FProgressMax;
@@ -208,6 +216,11 @@ begin
       else
         raise;
     end;
+  end else begin
+    if Assigned(FOnDownloadNoProgress) then
+      FOnDownloadNoProgress
+    else if Assigned(FOnSimpleDownloadNoProgress) then
+      FOnSimpleDownloadNoProgress;
   end;
 
   if DownloadTemporaryFileOrExtractArchiveProcessMessages then
@@ -323,7 +336,8 @@ end;
 function DownloadFile(const Url, CustomUserName, CustomPassword: String;
   const DestF: TFile; [ref] const Verification: TSetupFileVerification; const ISSigSourceFilename: String;
   const OnSimpleDownloadProgress: TOnSimpleDownloadProgress;
-  const OnSimpleDownloadProgressParam: Integer64): Int64;
+  const OnSimpleDownloadProgressParam: Integer64;
+  const OnSimpleDownloadNoProgress: TOnSimpleDownloadNoProgress): Int64;
 var
   HTTPDataReceiver: THTTPDataReceiver;
 begin
@@ -336,6 +350,7 @@ begin
   try
     HTTPDataReceiver.OnSimpleDownloadProgress := OnSimpleDownloadProgress;
     HTTPDataReceiver.OnSimpleDownloadProgressParam := OnSimpleDownloadProgressParam;
+    HTTPDataReceiver.OnSimpleDownloadNoProgress := OnSimpleDownloadNoProgress;
 
     { Download to specified handle }
     Result := HTTPDataReceiver.Download(False);
@@ -366,7 +381,7 @@ end;
 
 function DownloadTemporaryFile(const Url, BaseName: String;
   [ref] const Verification: TSetupFileVerification; const OnDownloadProgress: TOnDownloadProgress;
-  out DestFile: String): Int64;
+  const OnDownloadNoProgress: TOnDownloadNoProgress; out DestFile: String): Int64;
 var
   TempFile: String;
   TempF: TFile;
@@ -430,6 +445,7 @@ begin
   try
     HTTPDataReceiver.BaseName := BaseName;
     HTTPDataReceiver.OnDownloadProgress := OnDownloadProgress;
+    HTTPDataReceiver.OnDownloadNoProgress := OnDownloadNoProgress;
 
     { To test redirects: https://jrsoftware.org/download.php/is.exe
       To test expired certificates: https://expired.badssl.com/
@@ -492,10 +508,11 @@ begin
 end;
 
 function DownloadTemporaryFile(const Url, BaseName: String;
-  [ref] const Verification: TSetupFileVerification; const OnDownloadProgress: TOnDownloadProgress): Int64;
+  [ref] const Verification: TSetupFileVerification; const OnDownloadProgress: TOnDownloadProgress;
+  const OnDownloadNoProgress: TOnDownloadNoProgress): Int64;
 begin
   var DestFile: String;
-  Result := DownloadTemporaryFile(Url, BaseName, Verification, OnDownloadProgress, DestFile);
+  Result := DownloadTemporaryFile(Url, BaseName, Verification, OnDownloadProgress, OnDownloadNoProgress, DestFile);
 end;
 
 procedure DownloadTemporaryFileSizeAndDate(const Url: String; var FileSize: Int64; var FileDate: String);

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

@@ -1096,11 +1096,11 @@ Retry:
                 { Download the .issig file }
                 const ISSigUrl = GetISSigUrl(SourceFile, ExpandConst(CurFile^.DownloadISSigSource));
                 DownloadFile(ISSigUrl, DownloadUserName, DownloadPassword,
-                  ISSigDestF, NoVerification, '', JustProcessEventsProc64, To64(0));
+                  ISSigDestF, NoVerification, '', JustProcessEventsProc64, To64(0), ProcessEvents);
                 FreeAndNil(ISSigDestF);
                 { Download and verify the actual file }
                 DownloadFile(SourceFile, DownloadUserName, DownloadPassword,
-                  DestF, CurFile^.Verification, TempFile, ExternalProgressProc64, MaxProgress);
+                  DestF, CurFile^.Verification, TempFile, ExternalProgressProc64, MaxProgress, ProcessEvents);
               finally
                 ISSigDestF.Free;
                 { Delete the .issig file }
@@ -1108,7 +1108,7 @@ Retry:
               end;
             end else
               DownloadFile(SourceFile, DownloadUserName, DownloadPassword,
-                DestF, CurFile^.Verification, '', ExternalProgressProc64, MaxProgress);
+                DestF, CurFile^.Verification, '', ExternalProgressProc64, MaxProgress, ProcessEvents);
           end
           else begin
             { Copy a duplicated non-external file, or an external file }

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

@@ -1179,7 +1179,7 @@ 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, DestFile);
+      Result := Result + DownloadTemporaryFile(F.Url, F.BaseName, F.Verification, InternalOnDownloadProgress, ProcessMsgs, DestFile);
       if Assigned(OnDownloadFileCompleted) then begin
         var Remove := False;
         OnDownloadFileCompleted(F, DestFile, Remove);

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

@@ -835,9 +835,9 @@ var
       try
         { Also see Setup.ScriptDlg TDownloadWizardPage.AddExWithISSigVerify }
         if ISSigVerify then
-          DownloadTemporaryFile(GetISSigUrl(Url, ISSigUrl), BaseName + ISSigExt, NoVerification, Throttler.OnDownloadProgress);
+          DownloadTemporaryFile(GetISSigUrl(Url, ISSigUrl), BaseName + ISSigExt, NoVerification, Throttler.OnDownloadProgress, nil);
         Throttler.Reset;
-        Stack.SetInt64(PStart, DownloadTemporaryFile(Url, BaseName, Verification, Throttler.OnDownloadProgress));
+        Stack.SetInt64(PStart, DownloadTemporaryFile(Url, BaseName, Verification, Throttler.OnDownloadProgress, nil));
       finally
         Throttler.Free;
       end;