CodeDownloadFiles.iss 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. ; -- CodeDownloadFiles.iss --
  2. ;
  3. ; This script shows how the CreateDownloadPage support function can be used to
  4. ; download temporary files while showing the download progress to the user.
  5. [Setup]
  6. AppName=My Program
  7. AppVersion=1.5
  8. WizardStyle=modern
  9. DefaultDirName={autopf}\My Program
  10. DefaultGroupName=My Program
  11. UninstallDisplayIcon={app}\MyProg.exe
  12. OutputDir=userdocs:Inno Setup Examples Output
  13. [Files]
  14. ; Place any regular files here
  15. Source: "MyProg.exe"; DestDir: "{app}";
  16. Source: "MyProg.chm"; DestDir: "{app}";
  17. Source: "Readme.txt"; DestDir: "{app}"; Flags: isreadme;
  18. ; These files will be downloaded
  19. Source: "{tmp}\innosetup-latest.exe"; DestDir: "{app}"; Flags: external
  20. Source: "{tmp}\ISCrypt.dll"; DestDir: "{app}"; Flags: external
  21. [Icons]
  22. Name: "{group}\My Program"; Filename: "{app}\MyProg.exe"
  23. [Code]
  24. var
  25. DownloadPage: TDownloadWizardPage;
  26. function OnDownloadProgress(const Url, FileName: String; const Progress, ProgressMax: Int64): Boolean;
  27. begin
  28. if Progress = ProgressMax then
  29. Log(Format('Successfully downloaded file to {tmp}: %s', [FileName]));
  30. Result := True;
  31. end;
  32. procedure InitializeWizard;
  33. begin
  34. DownloadPage := CreateDownloadPage(SetupMessage(msgWizardPreparing), SetupMessage(msgPreparingDesc), @OnDownloadProgress);
  35. DownloadPage.ShowBaseNameInsteadOfUrl := True;
  36. end;
  37. function NextButtonClick(CurPageID: Integer): Boolean;
  38. begin
  39. if CurPageID = wpReady then begin
  40. DownloadPage.Clear;
  41. // Use AddEx to specify a username and password
  42. DownloadPage.Add('https://jrsoftware.org/download.php/is.exe?dontcount=1', 'innosetup-latest.exe', '');
  43. DownloadPage.Add('https://jrsoftware.org/download.php/iscrypt.dll?dontcount=1', 'ISCrypt.dll', '2f6294f9aa09f59a574b5dcd33be54e16b39377984f3d5658cda44950fa0f8fc');
  44. DownloadPage.Show;
  45. try
  46. try
  47. DownloadPage.Download; // This downloads the files to {tmp}
  48. Result := True;
  49. except
  50. if DownloadPage.AbortedByUser then
  51. Log('Aborted by user.')
  52. else
  53. SuppressibleMsgBox(AddPeriod(GetExceptionMessage), mbCriticalError, MB_OK, IDOK);
  54. Result := False;
  55. end;
  56. finally
  57. DownloadPage.Hide;
  58. end;
  59. end else
  60. Result := True;
  61. end;