浏览代码

SetDownloadCredentials cleanup.

Martijn Laan 3 月之前
父节点
当前提交
8e6d25739d
共有 3 个文件被更改,包括 19 次插入15 次删除
  1. 16 12
      Projects/Src/Setup.Install.pas
  2. 2 2
      Projects/Src/Setup.ScriptDlg.pas
  3. 1 1
      Projects/Src/Setup.ScriptFunc.pas

+ 16 - 12
Projects/Src/Setup.Install.pas

@@ -34,7 +34,7 @@ function DownloadTemporaryFile(const Url, BaseName, RequiredSHA256OfFile: String
   const OnDownloadProgress: TOnDownloadProgress): Int64;
 function DownloadTemporaryFileSize(const Url: String): Int64;
 function DownloadTemporaryFileDate(const Url: String): String;
-procedure SetDownloadCredentials(const User, Pass: String);
+procedure SetDownloadTemporaryFileCredentials(const User, Pass: String);
 function GetISSigUrl(const Url, ISSigUrl: String): String;
 
 implementation
@@ -58,7 +58,6 @@ type
 var
   CurProgress: Integer64;
   ProgressShiftCount: Cardinal;
-  DownloadUser, DownloadPass: String;
 
 { TSetupUninstallLog }
 
@@ -3665,23 +3664,26 @@ begin
     Result := URL;
 end;
 
-procedure SetDownloadCredentials(const User, Pass: String);
+var
+  DownloadTemporaryFileUser, DownloadTemporaryFilePass: String;
+
+procedure SetDownloadTemporaryFileCredentials(const User, Pass: String);
 begin
-  DownloadUser := User;
-  DownloadPass := Pass;
+  DownloadTemporaryFileUser := User;
+  DownloadTemporaryFilePass := Pass;
 end;
 
-function GetCredentialsAndCleanUrl(const Url: String; var User, Pass, CleanUrl: String) : Boolean;
+function GetCredentialsAndCleanUrl(const Url, CustomUser, CustomPass: String; var User, Pass, CleanUrl: String) : Boolean;
 begin
   const Uri = TUri.Create(Url); { This is a record so no need to free }
-  if DownloadUser = '' then
+  if CustomUser = '' then
     User := TNetEncoding.URL.Decode(Uri.Username)
   else
-    User := DownloadUser;
-  if DownloadPass = '' then
+    User := CustomUser;
+  if CustomPass = '' then
     Pass := TNetEncoding.URL.Decode(Uri.Password, [TURLEncoding.TDecodeOption.PlusAsSpaces])
   else
-    Pass := DownloadPass;
+    Pass := CustomPass;
   Uri.Username := '';
   Uri.Password := '';
   CleanUrl := Uri.ToString;
@@ -3769,7 +3771,8 @@ begin
   HandleStream := nil;
 
   try
-    HasCredentials := GetCredentialsAndCleanUrl(URL, User, Pass, CleanUrl);
+    HasCredentials := GetCredentialsAndCleanUrl(URL,
+      DownloadTemporaryFileUser, DownloadTemporaryFilePass, User, Pass, CleanUrl);
 
     { Setup downloader }
     HTTPDataReceiver := THTTPDataReceiver.Create;
@@ -3881,8 +3884,9 @@ var
 begin
   HTTPClient := THTTPClient.Create;
   Base64 := nil;
-  HasCredentials := GetCredentialsAndCleanUrl(Url, User, Pass, CleanUrl);
   try
+    HasCredentials := GetCredentialsAndCleanUrl(Url,
+      DownloadTemporaryFileUser, DownloadTemporaryFilePass, User, Pass, CleanUrl);
     if HasCredentials then begin
       Base64 := TBase64Encoding.Create(0);
       HTTPClient.CustomHeaders['Authorization'] := 'Basic ' + Base64.Encode(User + ':' + Pass);

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

@@ -1131,11 +1131,11 @@ begin
   Result := 0;
   for var F in FFiles do begin
     { Don't need to set DownloadTemporaryFileOrExtractArchiveProcessMessages before downloading since we already process messages ourselves }
-    SetDownloadCredentials(F.UserName, F.Password);
+    SetDownloadTemporaryFileCredentials(F.UserName, F.Password);
     Result := Result + DownloadTemporaryFile(F.Url, F.BaseName, F.RequiredSHA256OfFile,
       F.ISSigVerify, F.ISSigAllowedKeys, InternalOnDownloadProgress);
   end;
-  SetDownloadCredentials('', '');
+  SetDownloadTemporaryFileCredentials('', '');
 end;
 
 {--- Extraction ---}

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

@@ -837,7 +837,7 @@ var
     end);
     RegisterScriptFunc('SetDownloadCredentials', sfNoUninstall, procedure(const Caller: TPSExec; const OrgName: AnsiString; const Stack: TPSStack; const PStart: Cardinal)
     begin
-      SetDownloadCredentials(Stack.GetString(PStart),Stack.GetString(PStart-1));
+      SetDownloadTemporaryFileCredentials(Stack.GetString(PStart),Stack.GetString(PStart-1));
     end);
   end;