Created
January 8, 2023 11:40
-
-
Save rc-chuah/a7a576e60f74cd276990b319fb4959a3 to your computer and use it in GitHub Desktop.
This script shows how the CreateDownloadPage support function can be used to download temporary files while showing the download progress to the user.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; -- CodeDownloadFiles.iss -- | |
; | |
; This script shows how the CreateDownloadPage support function can be used to | |
; download temporary files while showing the download progress to the user. | |
[Setup] | |
AppName=My Program | |
AppVersion=1.5 | |
WizardStyle=modern | |
DefaultDirName={autopf}\My Program | |
DefaultGroupName=My Program | |
UninstallDisplayIcon={app}\MyProg.exe | |
OutputDir=userdocs:Inno Setup Examples Output | |
[Files] | |
; Place any regular files here | |
Source: "MyProg.exe"; DestDir: "{app}"; | |
Source: "MyProg.chm"; DestDir: "{app}"; | |
Source: "Readme.txt"; DestDir: "{app}"; Flags: isreadme; | |
; These files will be downloaded | |
Source: "{tmp}\innosetup-latest.exe"; DestDir: "{app}"; Flags: external | |
Source: "{tmp}\ISCrypt.dll"; DestDir: "{app}"; Flags: external | |
[Icons] | |
Name: "{group}\My Program"; Filename: "{app}\MyProg.exe" | |
[Code] | |
var | |
DownloadPage: TDownloadWizardPage; | |
function OnDownloadProgress(const Url, FileName: String; const Progress, ProgressMax: Int64): Boolean; | |
begin | |
if Progress = ProgressMax then | |
Log(Format('Successfully downloaded file to {tmp}: %s', [FileName])); | |
Result := True; | |
end; | |
procedure InitializeWizard; | |
begin | |
DownloadPage := CreateDownloadPage(SetupMessage(msgWizardPreparing), SetupMessage(msgPreparingDesc), @OnDownloadProgress); | |
end; | |
function NextButtonClick(CurPageID: Integer): Boolean; | |
begin | |
if CurPageID = wpReady then begin | |
DownloadPage.Clear; | |
DownloadPage.Add('https://jrsoftware.org/download.php/is.exe', 'innosetup-latest.exe', ''); | |
DownloadPage.Add('https://jrsoftware.org/download.php/iscrypt.dll', 'ISCrypt.dll', '2f6294f9aa09f59a574b5dcd33be54e16b39377984f3d5658cda44950fa0f8fc'); | |
DownloadPage.Show; | |
try | |
try | |
DownloadPage.Download; // This downloads the files to {tmp} | |
Result := True; | |
except | |
if DownloadPage.AbortedByUser then | |
Log('Aborted by user.') | |
else | |
SuppressibleMsgBox(AddPeriod(GetExceptionMessage), mbCriticalError, MB_OK, IDOK); | |
Result := False; | |
end; | |
finally | |
DownloadPage.Hide; | |
end; | |
end else | |
Result := True; | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment