templates/installer: Refactor installer code for easier changes
This commit is contained in:
		
							parent
							
								
									e7ed40a69d
								
							
						
					
					
						commit
						569fa56b1d
					
				|  | @ -2,9 +2,11 @@ | ||||||
| ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! | ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! | ||||||
| 
 | 
 | ||||||
| #define MyAppName "@PROJECT_FULL_NAME@" | #define MyAppName "@PROJECT_FULL_NAME@" | ||||||
| #define MyAppVersion "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@.@PROJECT_VERSION_TWEAK@" | #define MyAppVersion "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@.@VERSION_TWEAK@" | ||||||
|  | #define MyAppVersionText "@VERSION_STRING@" | ||||||
| #define MyAppPublisher "Xaymars Technology Workshop" | #define MyAppPublisher "Xaymars Technology Workshop" | ||||||
| #define MyAppURL "https://www.xaymar.com/" | #define MyAppURL "https://xaymar.com/" | ||||||
|  | #define MyAppCopyright "@PROJECT_COPYRIGHT_YEARS@ @PROJECT_AUTHORS@" | ||||||
| 
 | 
 | ||||||
| [Setup] | [Setup] | ||||||
| ; NOTE: The value of AppId uniquely identifies this application. | ; NOTE: The value of AppId uniquely identifies this application. | ||||||
|  | @ -22,12 +24,17 @@ AppUpdatesURL={#MyAppURL} | ||||||
| AppMutex={#MyAppName} | AppMutex={#MyAppName} | ||||||
| 
 | 
 | ||||||
| ; Versioning | ; Versioning | ||||||
|  | VersionInfoProductName={#MyAppName} | ||||||
|  | VersionInfoProductVersion={#MyAppVersion} | ||||||
| VersionInfoVersion={#MyAppVersion} | VersionInfoVersion={#MyAppVersion} | ||||||
|  | VersionInfoProductTextVersion={#MyAppVersionText} | ||||||
|  | VersionInfoTextVersion={#MyAppVersionText} | ||||||
| VersionInfoCompany={#MyAppPublisher} | VersionInfoCompany={#MyAppPublisher} | ||||||
|  | VersionInfoCopyright={#MyAppCopyright} | ||||||
| VersionInfoDescription={#MyAppName} Setup | VersionInfoDescription={#MyAppName} Setup | ||||||
| 
 | 
 | ||||||
| ; Architecture (Platform is always Windows) | ; Architecture (Platform is always Windows) | ||||||
| ArchitecturesInstallIn64BitMode=@ARCH@ | ArchitecturesInstallIn64BitMode=x64 arm64 ia64 | ||||||
| ArchitecturesAllowed=@ARCH@ | ArchitecturesAllowed=@ARCH@ | ||||||
| 
 | 
 | ||||||
| ; Wizard Information | ; Wizard Information | ||||||
|  | @ -36,7 +43,8 @@ WizardResizable=yes | ||||||
| SetupIconFile="@PROJECT_SOURCE_DIR@/media/icon.ico" | SetupIconFile="@PROJECT_SOURCE_DIR@/media/icon.ico" | ||||||
| 
 | 
 | ||||||
| ; Other Information | ; Other Information | ||||||
| DefaultDirName={code:GetDirName} | UsePreviousAppDir=yes | ||||||
|  | DefaultDirName={code:GetDefaultDirectory} | ||||||
| DefaultGroupName={#MyAppName} | DefaultGroupName={#MyAppName} | ||||||
| AllowNoIcons=yes | AllowNoIcons=yes | ||||||
| LicenseFile="@ISS_SOURCE_DIR@/LICENSE" | LicenseFile="@ISS_SOURCE_DIR@/LICENSE" | ||||||
|  | @ -51,7 +59,7 @@ Name: "english"; MessagesFile: "compiler:Default.isl" | ||||||
| 
 | 
 | ||||||
| [Files] | [Files] | ||||||
| Source: "@ISS_FILES_DIR@/*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs | Source: "@ISS_FILES_DIR@/*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs | ||||||
| Source: "@PROJECT_SOURCE_DIR@/third-party/msvc-redist-helper.exe"; DestDir: "{app}"; DestName: "msvc-redist-helper.exe"; Flags: ignoreversion dontcopy noencryption | Source: "@PROJECT_SOURCE_DIR@/templates/msvc-redist-helper.exe"; DestDir: "{app}"; DestName: "msvc-redist-helper.exe"; Flags: ignoreversion dontcopy noencryption | ||||||
| ; NOTE: Don't use "Flags: ignoreversion" on any shared system files | ; NOTE: Don't use "Flags: ignoreversion" on any shared system files | ||||||
| 
 | 
 | ||||||
| [Icons] | [Icons] | ||||||
|  | @ -59,78 +67,104 @@ Name: "{group}\{cm:ProgramOnTheWeb,{#MyAppName}}"; Filename: "{#MyAppURL}" | ||||||
| Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}" | Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}" | ||||||
| 
 | 
 | ||||||
| [Code] | [Code] | ||||||
| function GetDirName(Value: string): string; | // ------------------------------------------------------------------------------------------------------------------ // | ||||||
| var | function FindRegistryKey(): String; | ||||||
|   InstallPath: string; |  | ||||||
| begin | begin | ||||||
|   // initialize default path, which will be returned when the following registry | 	Result := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#emit SetupSetting('AppId')}_is1');	 | ||||||
|   // key queries fail due to missing keys or for some different reason |  | ||||||
|   Result := ExpandConstant('{pf}\obs-studio'); |  | ||||||
|   // query the first registry value; if this succeeds, return the obtained value |  | ||||||
|   if RegQueryStringValue(HKLM32, 'SOFTWARE\OBS Studio', '', InstallPath) then |  | ||||||
|     Result := InstallPath |  | ||||||
| end; | end; | ||||||
| 
 | 
 | ||||||
| ///////////////////////////////////////////////////////////////////// | // ------------------------------------------------------------------------------------------------------------------ // | ||||||
| function GetUninstallString(): String; | function GetDefaultDirectory(Value: String): String; | ||||||
| var | var | ||||||
|   sUnInstPath: String; | 	sInstallPath: String; | ||||||
|   sUnInstallString: String; |  | ||||||
| begin | begin | ||||||
|   sUnInstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#emit SetupSetting("AppId")}_is1'); | 	// 1. Use the path we were given on call. | ||||||
|   sUnInstallString := ''; | 	sInstallPath := Value; | ||||||
|   if not RegQueryStringValue(HKLM, sUnInstPath, 'UninstallString', sUnInstallString) then | 
 | ||||||
|     RegQueryStringValue(HKCU, sUnInstPath, 'UninstallString', sUnInstallString); | 	// 2. If that was empty, try and find it ourselves from the registry. | ||||||
|   Result := sUnInstallString; | 	if (sInstallPath = '') then | ||||||
|  | 		RegQueryStringValue(HKA64, FindRegistryKey(), 'InstallLocation', sInstallPath); | ||||||
|  | 
 | ||||||
|  | 	// 2. If empty, try and find the "Local Machine" installation of OBS Studio. | ||||||
|  | 	if (sInstallPath = '') then  | ||||||
|  | 		RegQueryStringValue(HKLM64, 'SOFTWARE\OBS Studio', '', sInstallPath); | ||||||
|  | 
 | ||||||
|  | 	// 3. If empty, try and find the "Current User" installation of OBS Studio. | ||||||
|  | 	if (sInstallPath = '') then  | ||||||
|  | 		RegQueryStringValue(HKCU64, 'SOFTWARE\OBS Studio', '', sInstallPath); | ||||||
|  | 
 | ||||||
|  | 	// 4. If empty, try and find the 32-bit "Local Machine" installation of OBS Studio. | ||||||
|  | 	if (sInstallPath = '') then  | ||||||
|  | 		RegQueryStringValue(HKLM32, 'SOFTWARE\OBS Studio', '', sInstallPath); | ||||||
|  | 
 | ||||||
|  | 	// 5. If empty, try and find the 32-bit "Current User" installation of OBS Studio. | ||||||
|  | 	if (sInstallPath = '') then  | ||||||
|  | 		RegQueryStringValue(HKCU32, 'SOFTWARE\OBS Studio', '', sInstallPath); | ||||||
|  | 
 | ||||||
|  | 	// 6. If empty, just use the default path. | ||||||
|  | 	if (sInstallPath = '') then  | ||||||
|  | 		sInstallPath := ExpandConstant('{commonpf}\obs-studio'); | ||||||
|  | 	 | ||||||
|  | 	Result := sInstallPath | ||||||
| end; | end; | ||||||
| 
 | 
 | ||||||
| ///////////////////////////////////////////////////////////////////// | // ------------------------------------------------------------------------------------------------------------------ // | ||||||
|  | function GetUninstallerPath(): String; | ||||||
|  | var | ||||||
|  | 	sRegistryKey: String; | ||||||
|  | 	sUninstallerPath: String; | ||||||
|  | begin | ||||||
|  | 	sRegistryKey := FindRegistryKey(); | ||||||
|  | 
 | ||||||
|  | 	RegQueryStringValue(HKLM64, sRegistryKey, 'UninstallString', sUninstallerPath); | ||||||
|  | 
 | ||||||
|  | 	if (sUninstallerPath = '') then | ||||||
|  | 		RegQueryStringValue(HKCU64, sRegistryKey, 'UninstallString', sUninstallerPath); | ||||||
|  | 
 | ||||||
|  | 	if (sUninstallerPath = '') then | ||||||
|  | 		RegQueryStringValue(HKLM32, sRegistryKey, 'UninstallString', sUninstallerPath); | ||||||
|  | 
 | ||||||
|  | 	if (sUninstallerPath = '') then | ||||||
|  | 		RegQueryStringValue(HKCU32, sRegistryKey, 'UninstallString', sUninstallerPath); | ||||||
|  | 
 | ||||||
|  | 	Result := sUninstallerPath; | ||||||
|  | end; | ||||||
|  | 
 | ||||||
|  | // ------------------------------------------------------------------------------------------------------------------ // | ||||||
| function IsUpgrade(): Boolean; | function IsUpgrade(): Boolean; | ||||||
| begin | begin | ||||||
|   Result := (GetUninstallString() <> ''); | 	Result := (GetUninstallerPath() <> ''); | ||||||
| end; | end; | ||||||
| 
 | 
 | ||||||
| ///////////////////////////////////////////////////////////////////// | // ------------------------------------------------------------------------------------------------------------------ // | ||||||
| function UnInstallOldVersion(): Integer; | function UninstallOldVersion(): Integer; | ||||||
| var | var | ||||||
|   sUnInstallString: String; | 	sUninstallerPath: String; | ||||||
| 	iResultCode: Integer; | 	iResultCode: Integer; | ||||||
| begin | begin | ||||||
| // Return Values: |  | ||||||
| // 1 - uninstall string is empty |  | ||||||
| // 2 - error executing the UnInstallString |  | ||||||
| // 3 - successfully executed the UnInstallString |  | ||||||
| 
 |  | ||||||
|   // default return value |  | ||||||
| 	Result := 0; | 	Result := 0; | ||||||
| 
 | 	sUninstallerPath := GetUninstallerPath(); | ||||||
|   // get the uninstall string of the old app | 	if (sUninstallerPath <> '') then begin | ||||||
|   sUnInstallString := GetUninstallString(); | 		sUninstallerPath := RemoveQuotes(sUninstallerPath); | ||||||
|   if sUnInstallString <> '' then begin | 		if Exec(sUninstallerPath, '/VERYSILENT /NORESTART /SUPPRESSMSGBOXES', '', SW_HIDE, ewWaitUntilTerminated, iResultCode) then begin | ||||||
|     sUnInstallString := RemoveQuotes(sUnInstallString); | 			Result := iResultCode | ||||||
|     if Exec(sUnInstallString, '/VERYSILENT /NORESTART /SUPPRESSMSGBOXES','', SW_HIDE, ewWaitUntilTerminated, iResultCode) then | 		end else begin | ||||||
|       Result := 3 | 			Result := 1 | ||||||
|     else | 		end; | ||||||
|       Result := 2; | 	end; | ||||||
|   end else |  | ||||||
|     Result := 1; |  | ||||||
| end; | end; | ||||||
| 
 | 
 | ||||||
| ///////////////////////////////////////////////////////////////////// | // ------------------------------------------------------------------------------------------------------------------ // | ||||||
| procedure CurStepChanged(CurStep: TSetupStep); | function PrepareToInstall(var NeedsRestart: Boolean): String; | ||||||
| var | var | ||||||
|   ResultCode: Integer; | 	iResultCode: Integer; | ||||||
| begin | begin | ||||||
|   if (CurStep=ssInstall) then | 	// Attempt to remove old version if it exists. | ||||||
|   begin | 	if (IsUpgrade()) then begin | ||||||
|     if (IsUpgrade()) then | 		UninstallOldVersion(); | ||||||
|     begin |  | ||||||
|       UnInstallOldVersion(); |  | ||||||
| 	end; | 	end; | ||||||
|   end; | 
 | ||||||
|   if (CurStep=ssPostInstall) then | 	// Also ensure that we have the necessary prerequisites installed to run the program. | ||||||
|   begin |  | ||||||
|     ExtractTemporaryFile('msvc-redist-helper.exe'); |     ExtractTemporaryFile('msvc-redist-helper.exe'); | ||||||
|     Exec(ExpandConstant('{tmp}\msvc-redist-helper.exe'), '2019', '', SW_HIDE, ewWaitUntilTerminated, ResultCode); |     Exec(ExpandConstant('{tmp}\msvc-redist-helper.exe'), '2019', '', SW_HIDE, ewWaitUntilTerminated, iResultCode); | ||||||
|   end; |  | ||||||
| end; | end; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue