iscrypt.iss 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // -- IsCrypt.iss --
  2. // Include file with support functions to download encryption support
  3. // Must be included before adding [Files] entries
  4. //
  5. #if FileExists('iscrypt-custom.ico')
  6. #define iscryptico 'iscrypt-custom.ico'
  7. #define iscrypticosizes '[32, 48, 64]'
  8. #else
  9. #define iscryptico 'iscrypt.ico'
  10. #define iscrypticosizes '[32]'
  11. #endif
  12. //
  13. [Files]
  14. Source: "{#iscryptico}"; DestName: "iscrypt.ico"; Flags: dontcopy
  15. Source: "{tmp}\ISCrypt.dll"; DestDir: "{app}"; Flags: ignoreversion external skipifsourcedoesntexist touch
  16. [Code]
  17. const
  18. ISCryptHash = '2f6294f9aa09f59a574b5dcd33be54e16b39377984f3d5658cda44950fa0f8fc';
  19. var
  20. ISCryptPage: TWizardPage;
  21. ISCryptCheckBox: TCheckBox;
  22. procedure CreateCustomOption(Page: TWizardPage; ACheckCaption: String; var CheckBox: TCheckBox; PreviousControl: TControl);
  23. begin
  24. CheckBox := TCheckBox.Create(Page);
  25. with CheckBox do begin
  26. Top := PreviousControl.Top + PreviousControl.Height + ScaleY(12);
  27. Width := Page.SurfaceWidth;
  28. Height := ScaleY(Height);
  29. Anchors := [akLeft, akTop, akRight];
  30. Caption := ACheckCaption;
  31. Parent := Page.Surface;
  32. end;
  33. end;
  34. function CreateCustomOptionPage(AAfterId: Integer; ACaption, ASubCaption, AIconFileName, ALabel1Caption, ALabel2Caption,
  35. ACheckCaption: String; var CheckBox: TCheckBox): TWizardPage;
  36. var
  37. Page: TWizardPage;
  38. BitmapImage: TBitmapImage;
  39. Label1, Label2: TNewStaticText;
  40. begin
  41. Page := CreateCustomPage(AAfterID, ACaption, ASubCaption);
  42. AIconFileName := ExpandConstant('{tmp}\' + AIconFileName);
  43. if not FileExists(AIconFileName) then
  44. ExtractTemporaryFile(ExtractFileName(AIconFileName));
  45. BitmapImage := TBitmapImage.Create(Page);
  46. with BitmapImage do begin
  47. Width := ScaleX(34);
  48. Height := ScaleY(34);
  49. Parent := Page.Surface;
  50. end;
  51. InitializeBitmapImageFromIcon(BitmapImage, AIconFileName, Page.SurfaceColor, {#iscrypticosizes});
  52. Label1 := TNewStaticText.Create(Page);
  53. with Label1 do begin
  54. AutoSize := False;
  55. Left := WizardForm.SelectDirLabel.Left;
  56. Width := Page.SurfaceWidth - Left;
  57. Anchors := [akLeft, akTop, akRight];
  58. WordWrap := True;
  59. Caption := ALabel1Caption;
  60. Parent := Page.Surface;
  61. AdjustHeight;
  62. end;
  63. Label2 := TNewStaticText.Create(Page);
  64. with Label2 do begin
  65. AutoSize := False;
  66. Top := Label1.Top + Label1.Height + ScaleY(12);
  67. Width := Page.SurfaceWidth;
  68. Anchors := [akLeft, akTop, akRight];
  69. WordWrap := True;
  70. Caption := ALabel2Caption;
  71. Parent := Page.Surface;
  72. AdjustHeight;
  73. end;
  74. CreateCustomOption(Page, ACheckCaption, CheckBox, Label2);
  75. Result := Page;
  76. end;
  77. <event('InitializeWizard')>
  78. procedure IsCryptInitializeWizard;
  79. var
  80. ExistingFileName, Caption, SubCaption1, IconFileName, Label1Caption, Label2Caption, CheckCaption: String;
  81. begin
  82. if WizardForm.PrevAppDir <> '' then begin
  83. ExistingFileName := AddBackslash(WizardForm.PrevAppDir) + 'ISCrypt.dll';
  84. try
  85. if GetSHA256OfFile(ExistingFileName) = ISCryptHash then
  86. Exit;
  87. except
  88. end;
  89. end;
  90. Caption := 'Encryption Support';
  91. SubCaption1 := 'Would you like to download encryption support?';
  92. IconFileName := 'iscrypt.ico';
  93. Label1Caption :=
  94. 'Inno Setup supports encryption. However, because of encryption import/export laws in some countries, encryption support is not included in the main' +
  95. ' Inno Setup installer. Instead, it can be downloaded from a server located in the Netherlands now.';
  96. Label2Caption := 'Select whether you would like to download and install encryption support, then click Next.';
  97. CheckCaption := '&Download and install encryption support';
  98. ISCryptPage := CreateCustomOptionPage(wpSelectProgramGroup, Caption, SubCaption1, IconFileName, Label1Caption, Label2Caption, CheckCaption, ISCryptCheckBox);
  99. ISCryptCheckBox.Checked := ExpandConstant('{param:downloadiscrypt|0}') = '1';
  100. end;
  101. <event('NextButtonClick')>
  102. function IsCryptNextButtonClick(CurPageID: Integer): Boolean;
  103. var
  104. DownloadPage: TDownloadWizardPage;
  105. begin
  106. Result := True;
  107. if (CurPageID = wpReady) and (ISCryptCheckBox <> nil) and ISCryptCheckBox.Checked then begin
  108. DownloadPage := CreateDownloadPage(SetupMessage(msgWizardPreparing), SetupMessage(msgPreparingDesc), nil);
  109. DownloadPage.Clear;
  110. DownloadPage.Add('https://jrsoftware.org/download.php/iscrypt.dll', 'ISCrypt.dll', ISCryptHash);
  111. DownloadPage.Show;
  112. try
  113. try
  114. DownloadPage.Download;
  115. except
  116. if DownloadPage.AbortedByUser then
  117. Log('Aborted by user.')
  118. else
  119. SuppressibleMsgBox(AddPeriod(GetExceptionMessage), mbCriticalError, MB_OK, IDOK);
  120. end;
  121. finally
  122. DownloadPage.Hide;
  123. end;
  124. end;
  125. end;