2
0
Эх сурвалжийг харах

Merge branch 'main' into files-download

# Conflicts:
#	Projects/Src/Setup.Install.pas
Martijn Laan 3 сар өмнө
parent
commit
e2ce5b00b1

+ 3 - 6
Examples/CodeDownloadFiles.iss

@@ -72,17 +72,14 @@ begin
     DownloadPage.Clear;
     // Use AddEx or AddExWithISSigVerify to specify a username and password
     DownloadPage.AddWithISSigVerify(
-      'https://jrsoftware.org/download.php/is.exe?dontcount=1',
-      'https://jrsoftware.org/download.php/is.exe.issig',
+      'https://jrsoftware.org/download.php/is.exe?dontcount=1', '',
       'innosetup-latest.exe', AllowedKeysRuntimeIDs);
     DownloadPage.AddWithISSigVerify(
-      'https://jrsoftware.org/download.php/myprog-extrareadmes.7z',
-      'https://jrsoftware.org/download.php/myprog-extrareadmes.7z.issig',
+      'https://jrsoftware.org/download.php/myprog-extrareadmes.7z', '',
       'MyProg-ExtraReadmes.7z', AllowedKeysRuntimeIDs);
     DownloadPage.Add(
       'https://jrsoftware.org/download.php/iscrypt.dll?dontcount=1',
-      'ISCrypt.dll',
-      '2f6294f9aa09f59a574b5dcd33be54e16b39377984f3d5658cda44950fa0f8fc');
+      'ISCrypt.dll', '2f6294f9aa09f59a574b5dcd33be54e16b39377984f3d5658cda44950fa0f8fc');
     DownloadPage.Show;
     try
       try

+ 2 - 2
ISHelp/isxclasses.pas

@@ -778,9 +778,9 @@ TDownloadWizardPage = class(TOutputProgressWizardPage)
   property AbortButton: TNewButton; read;
   property AbortedByUser: Boolean; read;
   function Add(const Url, BaseName, RequiredSHA256OfFile: String): Integer;
-  function AddWithISSigVerify(const Url, IssigUrl, BaseName: String; const AllowedKeysRuntimeIDs: TStringList): Integer;
+  function AddWithISSigVerify(const Url, ISSigUrl, BaseName: String; const AllowedKeysRuntimeIDs: TStringList): Integer;
   function AddEx(const Url, BaseName, RequiredSHA256OfFile, UserName, Password: String): Integer;
-  function AddExWithISSigVerify(const Url, IssigUrl, BaseName, UserName, Password: String; const AllowedKeysRuntimeIDs: TStringList: Integer;
+  function AddExWithISSigVerify(const Url, ISSigUrl, BaseName, UserName, Password: String; const AllowedKeysRuntimeIDs: TStringList: Integer;
   procedure Clear;
   function Download: Int64;
   property ShowBaseNameInsteadOfUrl: Boolean; read write;

+ 2 - 2
ISHelp/isxclasses_wordlists_generated.pas

@@ -85,10 +85,10 @@ var
     'function AddEx(ACaption: String; ALevel: Byte; AExclusive: Boolean): Integer;',
     'function AddEx(ArchiveFileName, DestDir, Password: String; FullPaths: Boolean): Integer;',
     'function AddEx(Url, BaseName, RequiredSHA256OfFile, UserName, Password: String): Integer;',
-    'function AddExWithISSigVerify(Url, IssigUrl, BaseName, UserName, Password: String; AllowedKeysRuntimeIDs: TStringList: Integer;',
+    'function AddExWithISSigVerify(Url, ISSigUrl, BaseName, UserName, Password: String; AllowedKeysRuntimeIDs: TStringList: Integer;',
     'function AddGroup(ACaption, ASubItem: String; ALevel: Byte; AObject: TObject): Integer;',
     'function AddRadioButton(ACaption, ASubItem: String; ALevel: Byte; AChecked, AEnabled: Boolean; AObject: TObject): Integer;',
-    'function AddWithISSigVerify(Url, IssigUrl, BaseName: String; AllowedKeysRuntimeIDs: TStringList): Integer;',
+    'function AddWithISSigVerify(Url, ISSigUrl, BaseName: String; AllowedKeysRuntimeIDs: TStringList): Integer;',
     'function AdjustHeight: Integer;',
     'function AdjustLabelHeight(ALabel: TNewStaticText): Integer;',
     'function AdjustLinkLabelHeight(ALinkLabel: TNewLinkLabel): Integer;',

+ 3 - 3
ISHelp/isxfunc.xml

@@ -1860,8 +1860,9 @@ end;</pre>
       </function>
       <function>
         <name>DownloadTemporaryFileWithISSigVerify</name>
-        <prototype>function DownloadTemporaryFileWithISSigVerify(const Url, IssigUrl, BaseName: String; const AllowedKeysRuntimeIDs: TStringList; const OnDownloadProgress: TOnDownloadProgress): Int64;</prototype>
+        <prototype>function DownloadTemporaryFileWithISSigVerify(const Url, ISSigUrl, BaseName: String; const AllowedKeysRuntimeIDs: TStringList; const OnDownloadProgress: TOnDownloadProgress): Int64;</prototype>
         <description><p>Like <link topic="isxfunc_DownloadTemporaryFile">DownloadTemporaryFile</link>, but downloads an .issig signature file first from the specified second URL and uses it to verify the main file downloaded from the first URL.</p>
+<p>If the second URL is an empty string, Setup will instead append ".issig" (without quotes) to the path portion of the first URL and use the result as the URL to download the .issig signature file from.</p>        
 <p>Verification uses the specified allowed keys, looked up using <link topic="issigkeyssection">[ISSigKeys] section</link> parameter <tt>RuntimeID</tt>. To allow all keys set AllowedKeysRuntimeIDs to <tt>nil</tt>.</p>
 <p>An exception will be raised if there was an error. Otherwise, returns the number of bytes downloaded for the main file from the first URL. Returns 0 if the main file was already downloaded and still verified.</p></description>
         <seealso><p><link topic="isxfunc_DownloadTemporaryFile">DownloadTemporaryFile</link><br/>
@@ -1873,8 +1874,7 @@ function InitializeSetup: Boolean;
 begin
   try
     DownloadTemporaryFileWithISSigVerify(
-      'https://jrsoftware.org/download.php/myprog-extrareadmes.7z',
-      'https://jrsoftware.org/download.php/myprog-extrareadmes.7z.issig',
+      'https://jrsoftware.org/download.php/myprog-extrareadmes.7z', '',
       'myprog-extrareadmes.7z', nil, nil);
     Result := True;
   except

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

@@ -552,9 +552,9 @@ begin
     RegisterProperty('AbortedByUser', 'Boolean', iptr);
     RegisterProperty('ShowBaseNameInsteadOfUrl', 'Boolean', iptrw);
     RegisterMethod('function Add(const Url, BaseName, RequiredSHA256OfFile: String): Integer');
-    RegisterMethod('function AddWithISSigVerify(const Url, IssigUrl, BaseName: String; const AllowedKeysRuntimeIDs: TStringList): Integer;');
+    RegisterMethod('function AddWithISSigVerify(const Url, ISSigUrl, BaseName: String; const AllowedKeysRuntimeIDs: TStringList): Integer;');
     RegisterMethod('function AddEx(const Url, BaseName, RequiredSHA256OfFile, UserName, Password: String): Integer');
-    RegisterMethod('function AddExWithISSigVerify(const Url, IssigUrl, BaseName, UserName, Password: String; const AllowedKeysRuntimeIDs: TStringList): Integer;');
+    RegisterMethod('function AddExWithISSigVerify(const Url, ISSigUrl, BaseName, UserName, Password: String; const AllowedKeysRuntimeIDs: TStringList): Integer;');
     RegisterMethod('procedure Clear');
     RegisterMethod('function Download: Int64');
     RegisterMethod('procedure Show'); { Without this TOutputProgressWizardPage's Show will be called }

+ 1 - 1
Projects/Src/Compression.SevenZipDLLDecoder.pas

@@ -1071,7 +1071,7 @@ begin
 
         { Log start of extraction }
         if ExtractIntent then begin
-          LogFmt('Extracting archive %s to %s. Recurse subdirs? %s', [ArchiveFilename,
+          LogFmt('Start extracting archive %s to %s. Recurse subdirs? %s', [ArchiveFilename,
             RemoveBackslashUnlessRoot(DestDir), SYesNo[RecurseSubDirs]]);
           var Solid: Boolean;
           if GetProperty(State.InArchive, $FFFF, kpidSolid, Solid) and Solid then

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

@@ -38,7 +38,8 @@ 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
 
@@ -61,7 +62,6 @@ type
 var
   CurProgress: Integer64;
   ProgressShiftCount: Cardinal;
-  DownloadUser, DownloadPass: String;
 
 { TSetupUninstallLog }
 
@@ -2047,6 +2047,8 @@ var
           finally
             ArchiveFindClose(H);
           end;
+
+          Log('Successfully extracted the archive.');
         end;
       finally
         ISSigVerifySourceF.Free;
@@ -3722,25 +3724,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;
-var
-  Uri: TUri;
+function GetCredentialsAndCleanUrl(const Url, CustomUser, CustomPass: String; var User, Pass, CleanUrl: String) : Boolean;
 begin
-  Uri := TUri.Create(Url);
-  if DownloadUser = '' then
+  const Uri = TUri.Create(Url); { This is a record so no need to free }
+  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;
@@ -3751,6 +3754,17 @@ begin
     Log('Download is not using basic authentication');
 end;
 
+function GetISSigUrl(const Url, ISSigUrl: String): String;
+begin
+  if ISSigUrl <> '' then
+    Result := ISSigUrl
+  else begin
+    const Uri = TUri.Create(Url); { This is a record so no need to free }
+    Uri.Path := TNetEncoding.URL.Decode(Uri.Path) + ISSigExt;
+    Result := Uri.ToString;
+  end;
+end;
+
 function DownloadFile(const Url: String; const DestF: TFile;
   const ISSigVerify: Boolean; const ISSigAllowedKeys: AnsiString;
   const OnSimpleDownloadProgress: TOnSimpleDownloadProgress): Int64;
@@ -3773,7 +3787,7 @@ begin
   HandleStream := nil;
 
   try
-    HasCredentials := GetCredentialsAndCleanUrl(URL, User, Pass, CleanUrl);
+    HasCredentials := GetCredentialsAndCleanUrl(URL, '', '', User, Pass, CleanUrl);
 
     { Setup downloader }
     HTTPDataReceiver := THTTPDataReceiver.Create;
@@ -3895,7 +3909,8 @@ begin
   HandleStream := nil;
 
   try
-    HasCredentials := GetCredentialsAndCleanUrl(URL, User, Pass, CleanUrl);
+    HasCredentials := GetCredentialsAndCleanUrl(URL,
+      DownloadTemporaryFileUser, DownloadTemporaryFilePass, User, Pass, CleanUrl);
 
     { Setup downloader }
     HTTPDataReceiver := THTTPDataReceiver.Create;
@@ -4007,8 +4022,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);

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

@@ -197,10 +197,10 @@ type
       destructor Destroy; override;
       procedure Initialize; override;
       function Add(const Url, BaseName, RequiredSHA256OfFile: String): Integer;
-      function AddWithISSigVerify(const Url, IssigUrl, BaseName: String;
+      function AddWithISSigVerify(const Url, ISSigUrl, BaseName: String;
         const AllowedKeysRuntimeIDs: TStringList): Integer;
       function AddEx(const Url, BaseName, RequiredSHA256OfFile, UserName, Password: String): Integer;
-      function AddExWithISSigVerify(const Url, IssigUrl, BaseName, UserName, Password: String;
+      function AddExWithISSigVerify(const Url, ISSigUrl, BaseName, UserName, Password: String;
         const AllowedKeysRuntimeIDs: TStringList): Integer;
       procedure Clear;
       function Download: Int64;
@@ -1099,10 +1099,10 @@ begin
   Result := DoAdd(Url, BaseName, RequiredSHA256OfFile);
 end;
 
-function TDownloadWizardPage.AddWithISSigVerify(const Url, IssigUrl, BaseName: String;
+function TDownloadWizardPage.AddWithISSigVerify(const Url, ISSigUrl, BaseName: String;
   const AllowedKeysRuntimeIDs: TStringList): Integer;
 begin
-  Result := AddExWithISSigVerify(Url, IssigUrl, BaseName, '', '', AllowedKeysRuntimeIDs);
+  Result := AddExWithISSigVerify(Url, ISSigUrl, BaseName, '', '', AllowedKeysRuntimeIDs);
 end;
 
 function TDownloadWizardPage.AddEx(const Url, BaseName, RequiredSHA256OfFile, UserName, Password: String): Integer;
@@ -1110,12 +1110,12 @@ begin
   Result := DoAdd(Url, BaseName, RequiredSHA256OfFile, UserName, Password);
 end;
 
-function TDownloadWizardPage.AddExWithISSigVerify(const Url, IssigUrl, BaseName, UserName,
+function TDownloadWizardPage.AddExWithISSigVerify(const Url, ISSigUrl, BaseName, UserName,
   Password: String; const AllowedKeysRuntimeIDs: TStringList): Integer;
 begin
   { Also see Setup.ScriptFunc DownloadTemporaryFileWithISSigVerify }
   const ISSigAllowedKeys = ConvertAllowedKeysRuntimeIDsToISSigAllowedKeys(AllowedKeysRuntimeIDs);
-  DoAdd(IssigUrl, BaseName + ISSigExt, '', UserName, Password, False, '');
+  DoAdd(GetISSigUrl(Url, ISSigUrl), BaseName + ISSigExt, '', UserName, Password, False, '');
   Result := DoAdd(Url, BaseName, '', UserName, Password, True, ISSigAllowedKeys);
 end;
 
@@ -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 ---}

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

@@ -824,7 +824,7 @@ var
 
       { Also see Setup.ScriptDlg TDownloadWizardPage.AddExWithISSigVerify }
       if ISSigVerify then
-        DownloadTemporaryFile(IssigUrl, BaseName + ISSigExt, '', False, '', OnDownloadProgress);
+        DownloadTemporaryFile(GetISSigUrl(Url, ISSigUrl), BaseName + ISSigExt, '', False, '', OnDownloadProgress);
       Stack.SetInt64(PStart, DownloadTemporaryFile(Url, BaseName, RequiredSHA256OfFile, ISSigVerify, ISSigAllowedKeys, OnDownloadProgress));
     end);
     RegisterScriptFunc('DownloadTemporaryFileSize', sfNoUninstall, procedure(const Caller: TPSExec; const OrgName: AnsiString; const Stack: TPSStack; const PStart: Cardinal)
@@ -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;
 

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

@@ -317,7 +317,7 @@ initialization
     'procedure ExtractTemporaryFile(const FileName: String);',
     'function ExtractTemporaryFiles(const Pattern: String): Integer;',
     'function DownloadTemporaryFile(const Url, BaseName, RequiredSHA256OfFile: String; const OnDownloadProgress: TOnDownloadProgress): Int64;',
-    'function DownloadTemporaryFileWithISSigVerify(const Url, IssigUrl, BaseName: String; const AllowedKeysRuntimeIDs: TStringList; const OnDownloadProgress: TOnDownloadProgress): Int64;',
+    'function DownloadTemporaryFileWithISSigVerify(const Url, ISSigUrl, BaseName: String; const AllowedKeysRuntimeIDs: TStringList; const OnDownloadProgress: TOnDownloadProgress): Int64;',
     'function DownloadTemporaryFileSize(const Url: String): Int64;',
     'function DownloadTemporaryFileDate(const Url: String): String;',
     'procedure SetDownloadCredentials(const User, Pass: String);'