From 1cf7d13873956a6d0685064e684602c878f505ce Mon Sep 17 00:00:00 2001
From: chylex <contact@chylex.com>
Date: Mon, 13 Jun 2022 22:50:25 +0200
Subject: [PATCH] Update installers to Inno Setup 6 & remove references to .NET
 Framework

---
 README.md        | 10 +++++-----
 bld/gen_full.iss | 31 ++++---------------------------
 bld/gen_port.iss | 31 ++++---------------------------
 bld/gen_upd.iss  | 27 +++------------------------
 4 files changed, 16 insertions(+), 83 deletions(-)

diff --git a/README.md b/README.md
index 20c04784..3aafbcbf 100644
--- a/README.md
+++ b/README.md
@@ -66,15 +66,15 @@ Icons and logos were designed in [Affinity Designer](https://affinity.serif.com/
 > If you don't want to build installers using the existing foundations, you can skip this section.
 
 Official Windows installers are built using [InnoSetup](https://jrsoftware.org/isinfo.php) and [Inno Download Plugin](https://mitrichsoftware.wordpress.com/inno-setup-tools/inno-download-plugin/), specifically:
-* [InnoSetup 5.6.1](https://files.jrsoftware.org/is/5/innosetup-5.6.1.exe) with Preprocessor support
-* [Inno Download Plugin 1.5.0](https://drive.google.com/folderview?id=0Bzw1xBVt0mokSXZrUEFIanV4azA&usp=sharing#list)
+* [InnoSetup 6.2.1](https://files.jrsoftware.org/is/6/innosetup-6.2.1.exe)
+* [Inno Download Plugin 1.5.1](https://drive.google.com/folderview?id=0Bzw1xBVt0mokSXZrUEFIanV4azA&usp=sharing#list)
 
-When installing InnoSetup, you can choose to include Inno Script Studio which I recommend for editing and testing installer configuration files in the `bld` folder (`.iss` extension).
+During installation, the download plugin will ask whether to add its include path to `ISPPBuiltins.iss`. Note that this option does not work with InnoSetup 6, so TweetDuck installers don't need it.
 
 Scripts for building installers require the `PATH` environment variable to include the InnoSetup installation folder. You can either edit `PATH` manually, or use a program like [Rapid Environment Editor](https://www.rapidee.com/en/about) to simplify the process. For example, this is the installation folder I added to `PATH` under **User variables**:
-* `C:\Program Files (x86)\Inno Setup 5`
+* `C:\Program Files (x86)\Inno Setup 6`
 
-You may need to restart Visual Studio after changing `PATH` for the change to take place.
+You may need to restart Visual Studio or Rider after changing `PATH` for the change to take place.
 
 ## Solution Overview
 
diff --git a/bld/gen_full.iss b/bld/gen_full.iss
index 553034e0..ad23f013 100644
--- a/bld/gen_full.iss
+++ b/bld/gen_full.iss
@@ -9,6 +9,8 @@
 
 #define MyAppVersion GetFileVersion("..\windows\TweetDuck\bin\x86\Release\TweetDuck.exe")
 
+#include ReadReg(HKLM, "Software\Mitrich Software\Inno Download Plugin", "InstallDir") + "\idp.iss"
+
 [Setup]
 AppId={{8C25A716-7E11-4AAD-9992-8B5D0C78AE06}
 AppName={#MyAppName}
@@ -29,13 +31,11 @@ Uninstallable=TDIsUninstallable
 UninstallDisplayName={#MyAppName}
 UninstallDisplayIcon={app}\{#MyAppExeName}
 Compression=lzma2/ultra
-LZMADictionarySize=15360
+LZMADictionarySize=32768
 SolidCompression=yes
 InternalCompressLevel=normal
 MinVersion=0,6.1
 
-#include <idp.iss>
-
 [Languages]
 Name: "english"; MessagesFile: "compiler:Default.isl"
 
@@ -68,20 +68,11 @@ AdditionalTasks=Additional shortcuts and components:
 var UpdatePath: String;
 var VisitedTasksPage: Boolean;
 
-function TDGetNetFrameworkVersion: Cardinal; forward;
-
-{ Check .NET Framework version on startup, ask user if they want to proceed if older than 4.7.2. }
+{ Prepare installation variables. }
 function InitializeSetup: Boolean;
 begin
   UpdatePath := ExpandConstant('{param:UPDATEPATH}')
   VisitedTasksPage := False
-  
-  if (TDGetNetFrameworkVersion() < 461808) and (MsgBox('{#MyAppName} requires .NET Framework 4.7.2 or newer,'+#13+#10+'please visit {#MyAppShortURL} for a download link.'+#13+#10+#13+#10'Do you want to proceed with the setup anyway?', mbCriticalError, MB_YESNO or MB_DEFBUTTON2) = IDNO) then
-  begin
-    Result := False
-    Exit
-  end;
-  
   Result := True
 end;
 
@@ -140,17 +131,3 @@ function TDIsUninstallable: Boolean;
 begin
   Result := (UpdatePath = '')
 end;
-
-{ Return DWORD value containing the build version of .NET Framework. }
-function TDGetNetFrameworkVersion: Cardinal;
-var FrameworkVersion: Cardinal;
-
-begin
-  if RegQueryDWordValue(HKEY_LOCAL_MACHINE, 'Software\Microsoft\NET Framework Setup\NDP\v4\Full', 'Release', FrameworkVersion) then
-  begin
-    Result := FrameworkVersion
-    Exit
-  end;
-  
-  Result := 0
-end;
diff --git a/bld/gen_port.iss b/bld/gen_port.iss
index 918304bc..66294ee7 100644
--- a/bld/gen_port.iss
+++ b/bld/gen_port.iss
@@ -9,6 +9,8 @@
 
 #define MyAppVersion GetFileVersion("..\windows\TweetDuck\bin\x86\Release\TweetDuck.exe")
 
+#include ReadReg(HKLM, "Software\Mitrich Software\Inno Download Plugin", "InstallDir") + "\idp.iss"
+
 [Setup]
 AppId={{8C25A716-7E11-4AAD-9992-8B5D0C78AE06}
 AppName={#MyAppName} Portable
@@ -29,13 +31,11 @@ Uninstallable=no
 UsePreviousAppDir=no
 PrivilegesRequired=lowest
 Compression=lzma2/ultra
-LZMADictionarySize=15360
+LZMADictionarySize=32768
 SolidCompression=yes
 InternalCompressLevel=normal
 MinVersion=0,6.1
 
-#include <idp.iss>
-
 [Languages]
 Name: "english"; MessagesFile: "compiler:Default.isl"
 
@@ -52,19 +52,10 @@ AdditionalTasks=Additional components:
 [Code]
 var UpdatePath: String;
 
-function TDGetNetFrameworkVersion: Cardinal; forward;
-
-{ Check .NET Framework version on startup, ask user if they want to proceed if older than 4.7.2. }
+{ Prepare installation variables. }
 function InitializeSetup: Boolean;
 begin
   UpdatePath := ExpandConstant('{param:UPDATEPATH}')
-  
-  if (TDGetNetFrameworkVersion() < 461808) and (MsgBox('{#MyAppName} requires .NET Framework 4.7.2 or newer,'+#13+#10+'please visit {#MyAppShortURL} for a download link.'+#13+#10+#13+#10'Do you want to proceed with the setup anyway?', mbCriticalError, MB_YESNO or MB_DEFBUTTON2) = IDNO) then
-  begin
-    Result := False
-    Exit
-  end;
-  
   Result := True
 end;
 
@@ -102,17 +93,3 @@ begin
     end;
   end;
 end;
-
-{ Return DWORD value containing the build version of .NET Framework. }
-function TDGetNetFrameworkVersion: Cardinal;
-var FrameworkVersion: Cardinal;
-
-begin
-  if RegQueryDWordValue(HKEY_LOCAL_MACHINE, 'Software\Microsoft\NET Framework Setup\NDP\v4\Full', 'Release', FrameworkVersion) then
-  begin
-    Result := FrameworkVersion
-    Exit
-  end;
-  
-  Result := 0
-end;
diff --git a/bld/gen_upd.iss b/bld/gen_upd.iss
index 4a3d805e..9c584383 100644
--- a/bld/gen_upd.iss
+++ b/bld/gen_upd.iss
@@ -11,6 +11,8 @@
 #define MyAppVersion GetFileVersion("..\windows\TweetDuck\bin\x86\Release\TweetDuck.exe")
 #define CefVersion GetFileVersion("..\windows\TweetDuck\bin\x86\Release\libcef.dll")
 
+#include ReadReg(HKLM, "Software\Mitrich Software\Inno Download Plugin", "InstallDir") + "\idp.iss"
+
 [Setup]
 AppId={{{#MyAppID}}
 AppName={#MyAppName}
@@ -37,8 +39,6 @@ SolidCompression=True
 InternalCompressLevel=normal
 MinVersion=0,6.1
 
-#include <idp.iss>
-
 [Languages]
 Name: "english"; MessagesFile: "compiler:Default.isl"
 
@@ -84,7 +84,6 @@ Type: filesandordirs; Name: "{app}\scripts"
 function TDIsUninstallable: Boolean; forward;
 function TDGetRunArgs(Param: String): String; forward;
 function TDFindUpdatePath: String; forward;
-function TDGetNetFrameworkVersion: Cardinal; forward;
 function TDGetAppVersionClean: String; forward;
 function TDGetFullDownloadFileName: String; forward;
 function TDIsMatchingCEFVersion: Boolean; forward;
@@ -93,7 +92,7 @@ procedure TDExecuteFullDownload; forward;
 var IsPortable: Boolean;
 var UpdatePath: String;
 
-{ Check .NET Framework version on startup, ask user if they want to proceed if older than 4.7.2. Prepare full download package if required. }
+{ Prepare update installation, and the full download package if required. }
 function InitializeSetup: Boolean;
 begin
   IsPortable := ExpandConstant('{param:PORTABLE}') = '1'
@@ -111,12 +110,6 @@ begin
     idpAddFile('https://github.com/{#MyAppPublisher}/{#MyAppName}/releases/download/'+TDGetAppVersionClean()+'/'+TDGetFullDownloadFileName(), ExpandConstant('{tmp}\{#MyAppName}.Full.exe'))
   end;
   
-  if (TDGetNetFrameworkVersion() < 461808) and (MsgBox('{#MyAppName} requires .NET Framework 4.7.2 or newer,'+#13+#10+'please visit {#MyAppShortURL} for a download link.'+#13+#10+#13+#10'Do you want to proceed with the setup anyway?', mbCriticalError, MB_YESNO or MB_DEFBUTTON2) = IDNO) then
-  begin
-    Result := False
-    Exit
-  end;
-  
   Result := True
 end;
 
@@ -211,20 +204,6 @@ begin
   Result := Path
 end;
 
-{ Return DWORD value containing the build version of .NET Framework. }
-function TDGetNetFrameworkVersion: Cardinal;
-var FrameworkVersion: Cardinal;
-
-begin
-  if RegQueryDWordValue(HKEY_LOCAL_MACHINE, 'Software\Microsoft\NET Framework Setup\NDP\v4\Full', 'Release', FrameworkVersion) then
-  begin
-    Result := FrameworkVersion
-    Exit
-  end;
-  
-  Result := 0
-end;
-
 { Return the name of the full installer file to download from GitHub. }
 function TDGetFullDownloadFileName: String;
 begin