Browse Source

Make the iscrypt download optional via the wizard instead of requiring a command line parameter. To avoid unexpected downloads the option is disabled by default. It still doesnt redownload if iscrypt.dll is already present (unlike ISPack did).

Martijn Laan 4 years ago
parent
commit
fed0153384
4 changed files with 168 additions and 35 deletions
  1. BIN
      iscrypt.ico
  2. 163 0
      iscrypt.iss
  3. 4 34
      setup.iss
  4. 1 1
      whatsnew.htm

BIN
iscrypt.ico


+ 163 - 0
iscrypt.iss

@@ -0,0 +1,163 @@
+// -- IsCrypt.iss --
+// Include file with support functions to download encryption support
+// Must be included before adding [Files] entries
+//
+[Files]
+Source: "iscrypt.ico"; Flags: dontcopy
+Source: "{tmp}\ISCrypt.dll"; DestDir: "{app}"; Flags: ignoreversion external skipifsourcedoesntexist touch
+
+[Code]
+const
+  ISCryptHash = '2f6294f9aa09f59a574b5dcd33be54e16b39377984f3d5658cda44950fa0f8fc';
+
+var
+  ISCryptPage: TWizardPage;
+  ISCryptCheckBox: TCheckBox;
+
+function GetModuleHandle(lpModuleName: LongInt): LongInt;
+external '[email protected] stdcall';
+function ExtractIcon(hInst: LongInt; lpszExeFileName: String; nIconIndex: LongInt): LongInt;
+external '[email protected] stdcall';
+function DrawIconEx(hdc: LongInt; xLeft, yTop: Integer; hIcon: LongInt; cxWidth, cyWidth: Integer; istepIfAniCur: LongInt; hbrFlickerFreeDraw, diFlags: LongInt): LongInt;
+external '[email protected] stdcall';
+function DestroyIcon(hIcon: LongInt): LongInt;
+external '[email protected] stdcall';
+
+const
+  DI_NORMAL = 3;
+  
+procedure CreateCustomOption(Page: TWizardPage; ACheckCaption: String; var CheckBox: TCheckBox; PreviousControl: TControl);
+begin
+  CheckBox := TCheckBox.Create(Page);
+  with CheckBox do begin
+    Top := PreviousControl.Top + PreviousControl.Height + ScaleY(12);
+    Width := Page.SurfaceWidth;
+    Height := ScaleY(Height);
+    Anchors := [akLeft, akTop, akRight];
+    Caption := ACheckCaption;
+    Parent := Page.Surface;
+  end;
+end;
+
+function CreateCustomOptionPage(AAfterId: Integer; ACaption, ASubCaption, AIconFileName, ALabel1Caption, ALabel2Caption,
+  ACheckCaption: String; var CheckBox: TCheckBox): TWizardPage;
+var
+  Page: TWizardPage;
+  Rect: TRect;
+  hIcon: LongInt;
+  Label1, Label2: TNewStaticText;
+begin
+  Page := CreateCustomPage(AAfterID, ACaption, ASubCaption);
+  
+  try
+    AIconFileName := ExpandConstant('{tmp}\' + AIconFileName);
+    if not FileExists(AIconFileName) then
+      ExtractTemporaryFile(ExtractFileName(AIconFileName));
+
+    Rect.Left := 0;
+    Rect.Top := 0;
+    Rect.Right := 32;
+    Rect.Bottom := 32;
+
+    hIcon := ExtractIcon(GetModuleHandle(0), AIconFileName, 0);
+    try
+      with TBitmapImage.Create(Page) do begin
+        with Bitmap do begin
+          Width := 32;
+          Height := 32;
+          Canvas.Brush.Color := Page.SurfaceColor;
+          Canvas.FillRect(Rect);
+          DrawIconEx(Canvas.Handle, 0, 0, hIcon, 32, 32, 0, 0, DI_NORMAL);
+        end;
+        Width := Bitmap.Width;
+        Height := Bitmap.Width;
+        Parent := Page.Surface;
+      end;
+    finally
+      DestroyIcon(hIcon);
+    end;
+  except
+  end;
+
+  Label1 := TNewStaticText.Create(Page);
+  with Label1 do begin
+    AutoSize := False;
+    Left := WizardForm.SelectDirLabel.Left;
+    Width := Page.SurfaceWidth - Left;
+    Anchors := [akLeft, akTop, akRight];
+    WordWrap := True;
+    Caption := ALabel1Caption;
+    Parent := Page.Surface;
+  end;
+  WizardForm.AdjustLabelHeight(Label1);
+
+  Label2 := TNewStaticText.Create(Page);
+  with Label2 do begin
+    Top := Label1.Top + Label1.Height + ScaleY(12);
+    Width := Page.SurfaceWidth;
+    Anchors := [akLeft, akTop, akRight];
+    WordWrap := True;
+    Caption := ALabel2Caption;
+    Parent := Page.Surface;
+  end;
+  WizardForm.AdjustLabelHeight(Label2);
+  
+  CreateCustomOption(Page, ACheckCaption, CheckBox, Label2);
+
+  Result := Page;
+end;
+
+<event('InitializeWizard')>
+procedure IsCryptInitializeWizard;
+var
+  ExistingFileName, Caption, SubCaption1, IconFileName, Label1Caption, Label2Caption, CheckCaption: String;
+begin
+  if WizardForm.PrevAppDir <> '' then begin
+    ExistingFileName := AddBackslash(WizardForm.PrevAppDir) + 'ISCrypt.dll';
+    try
+      if GetSHA256OfFile(ExistingFileName) = ISCryptHash then
+        Exit;
+    except
+    end;
+  end;
+
+  Caption := 'Encryption Support';
+  SubCaption1 := 'Would you like to download encryption support?';
+  IconFileName := 'iscrypt.ico';
+  Label1Caption :=
+    'Inno Setup supports encryption. However, because of encryption import/export laws in some countries, encryption support is not included in the main' +
+    ' Inno Setup installer. Instead, it can be downloaded from a server located in the Netherlands now.';
+  Label2Caption := 'Select whether you would like to download and install encryption support, then click Next.';
+  CheckCaption := '&Download and install encryption support';
+
+  ISCryptPage := CreateCustomOptionPage(wpSelectProgramGroup, Caption, SubCaption1, IconFileName, Label1Caption, Label2Caption, CheckCaption, ISCryptCheckBox);
+  
+  ISCryptCheckBox.Checked := ExpandConstant('{param:downloadiscrypt|0}') = '1';
+end;
+
+<event('NextButtonClick')>
+function IsCryptNextButtonClick(CurPageID: Integer): Boolean;
+var
+  DownloadPage: TDownloadWizardPage;
+begin
+  Result := True;
+  if (CurPageID = wpReady) and (ISCryptCheckBox <> nil) and ISCryptCheckBox.Checked then begin
+    if DownloadPage = nil then
+      DownloadPage := CreateDownloadPage(SetupMessage(msgWizardPreparing), SetupMessage(msgPreparingDesc), nil);
+    DownloadPage.Clear;
+    DownloadPage.Add('https://jrsoftware.org/download.php/iscrypt.dll', 'ISCrypt.dll', ISCryptHash);
+    DownloadPage.Show;
+    try
+      try
+        DownloadPage.Download;
+      except
+        if DownloadPage.AbortedByUser then
+          Log('Aborted by user.')
+        else
+          SuppressibleMsgBox(AddPeriod(GetExceptionMessage), mbCriticalError, MB_OK, IDOK);
+      end;
+    finally
+      DownloadPage.Hide;
+    end;
+  end;
+end;

+ 4 - 34
setup.iss

@@ -6,6 +6,8 @@
 ; Portions Copyright (C) 2000-2021 Martijn Laan. All rights reserved.
 ; For conditions of distribution and use, see LICENSE.TXT.
 
+#include "iscrypt.iss"
+
 #include "isdonateandmail.iss"
 
 #include "isportable.iss"
@@ -78,7 +80,7 @@ Name: english; MessagesFile: "files\Default.isl"
 #expr FindFiles("files\Languages\")
 
 [Messages]
-HelpTextNote=/PORTABLE=1%nEnable portable mode.%n/NODOWNLOAD=1%nDisable ISCrypt.dll download.
+HelpTextNote=/PORTABLE=1%nEnable portable mode.%n/DOWNLOADISCRYPT=1%nEnable ISCrypt.dll download.
 ; Two "Setup" on the same line looks weird, so put a line break in between
 english.WelcomeLabel1=Welcome to the Inno Setup%nSetup Wizard
 
@@ -184,7 +186,6 @@ Source: "files\ISPP.chm"; DestDir: "{app}"; Flags: ignoreversion touch
 #endif
 Source: "files\{#isppdll}"; DestName: "ISPP.dll"; DestDir: "{app}"; Flags: ignoreversion signonce touch
 Source: "files\ISPPBuiltins.iss"; DestDir: "{app}"; Flags: ignoreversion touch
-Source: "{tmp}\ISCrypt.dll"; DestDir: "{app}"; Flags: ignoreversion external skipifsourcedoesntexist touch
 
 [INI]
 Filename: "{app}\isfaq.url"; Section: "InternetShortcut"; Key: "URL"; String: "https://jrsoftware.org/isfaq.php" 
@@ -208,35 +209,4 @@ Filename: "{app}\Compil32.exe"; WorkingDir: "{app}"; Description: "{cm:LaunchPro
 
 [UninstallRun]
 ; The /UNASSOC line will be automatically skipped on portable mode, because of Uninstallable being set to no
-Filename: "{app}\Compil32.exe"; Parameters: "/UNASSOC"; RunOnceId: "RemoveISSAssoc"
-
-[Code]
-const
-  ISCryptHash = '2f6294f9aa09f59a574b5dcd33be54e16b39377984f3d5658cda44950fa0f8fc';
-
-function NextButtonClick(CurPageID: Integer): Boolean;
-var
-  DownloadPage: TDownloadWizardPage;
-  ExistingFileName: String;
-begin
-  Result := True;
-  try
-    if (CurPageID = wpReady) and not (ExpandConstant('{param:nodownload|0}') = '1') then begin
-      ExistingFileName := ExpandConstant('{app}\ISCrypt.dll');
-      if not FileExists(ExistingFileName) or (GetSHA256OfFile(ExistingFileName) <> ISCryptHash) then begin;
-        if DownloadPage = nil then
-          DownloadPage := CreateDownloadPage(SetupMessage(msgWizardPreparing), SetupMessage(msgPreparingDesc), nil);
-        DownloadPage.Clear;
-        DownloadPage.Add('https://jrsoftware.org/download.php/iscrypt.dll', 'ISCrypt.dll', ISCryptHash);
-        DownloadPage.Show;
-        try
-          DownloadPage.Download;
-        finally
-          DownloadPage.Hide;
-        end;
-      end;
-    end;
-  except
-    Log(GetExceptionMessage);
-  end;
-end;
+Filename: "{app}\Compil32.exe"; Parameters: "/UNASSOC"; RunOnceId: "RemoveISSAssoc"

+ 1 - 1
whatsnew.htm

@@ -31,7 +31,7 @@ For conditions of distribution and use, see <a href="https://jrsoftware.org/file
 <p><a name="6.1.3"></a><span class="ver">6.1.3-dev </span><span class="date">(?)</span></p>
 <ul>
   <li>The QuickStart Pack installer has been removed because of a lack of added value and a lack of downloads.</li>
-  <li>The standard Inno Setup installer now always tries to download the encryption module if it's missing, like the QuickStart Pack installer could download it before. This can be disabled using a /NODOWNLOAD=1 command line parameter.</li>
+  <li>The standard Inno Setup installer now offers to download encryption support if it's missing, like the QuickStart Pack installer did before.</li>
 </ul>
 </p>