// contribute: https://github.com/DomGries/InnoDependencyInstaller // official article: https://codeproject.com/Articles/20868/Inno-Setup-Dependency-Installer #define APP_ID "06F25DC8-71E2-44E2-805A-F15E15B51C74" #define MyAppSetupName "Remove Empty Directories" #define MyAppVersion "2.3" #define MyAppPublisher "Jonas John" #define MyAppCopyright 'Copyright (c) Jonas John' #define MyAppURL "https://www.jonasjohn.de/" #define MyAppSourceDir "" #define MyAppExeName "RED2.exe" #define SourceBinPathX86 "..\RED2\bin\x86\Release-x86\RED2.exe" #define SourceBinPathX64 "..\RED2\bin\x64\Release-x64\RED2.exe" ; DLL is the same for X86 & X64 #define SourceDLLPath "..\RED2\bin\x86\Release-x86\AlphaFS.dll" [Setup] ; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications. ; (To generate a new GUID, click Tools | Generate GUID inside the IDE.) AppId={{{#APP_ID}} AppName={#MyAppSetupName} AppVersion={#MyAppVersion} AppVerName={#MyAppSetupName} {#MyAppVersion} AppCopyright={#MyAppCopyright} VersionInfoVersion={#MyAppVersion} VersionInfoCompany={#MyAppPublisher} AppPublisher={#MyAppPublisher} AppPublisherURL={#MyAppURL} AppSupportURL={#MyAppURL} AppUpdatesURL={#MyAppURL} OutputBaseFilename=red-{#MyAppVersion}-setup DefaultGroupName={#MyAppSetupName} DefaultDirName={autopf}\{#MyAppSetupName} UninstallDisplayIcon={app}\{#MyAppExeName} ; SourceDir={#MyAppSourceDir} OutputDir={#SourcePath}\bin AllowNoIcons=yes LicenseFile=license.txt ; WizardStyle=modern ; Compression=lzma SolidCompression=yes MinVersion=6.0 PrivilegesRequired=admin // remove next line if you only deploy 32-bit binaries and dependencies ArchitecturesInstallIn64BitMode=x64 // dependency installation requires ready page and ready memo to be enabled (default behaviour) DisableReadyPage=no DisableReadyMemo=no // shared code for installing the dependencies [Code] // types and variables type TDependency = record Filename: String; Parameters: String; Title: String; URL: String; Checksum: String; ForceSuccess: Boolean; InstallClean: Boolean; RebootAfter: Boolean; end; InstallResult = (InstallSuccessful, InstallRebootRequired, InstallError); var MemoInstallInfo: String; Dependencies: array of TDependency; DelayedReboot, ForceX86: Boolean; DownloadPage: TDownloadWizardPage; procedure AddDependency(const Filename, Parameters, Title, URL, Checksum: String; const ForceSuccess, InstallClean, RebootAfter: Boolean); var Dependency: TDependency; I: Integer; begin MemoInstallInfo := MemoInstallInfo + #13#10 + '%1' + Title; Dependency.Filename := Filename; Dependency.Parameters := Parameters; Dependency.Title := Title; if FileExists(ExpandConstant('{tmp}{\}') + Filename) then begin Dependency.URL := ''; end else begin Dependency.URL := URL; end; Dependency.Checksum := Checksum; Dependency.ForceSuccess := ForceSuccess; Dependency.InstallClean := InstallClean; Dependency.RebootAfter := RebootAfter; I := GetArrayLength(Dependencies); SetArrayLength(Dependencies, I + 1); Dependencies[I] := Dependency; end; function IsPendingReboot: Boolean; var Value: String; begin Result := RegQueryMultiStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager', 'PendingFileRenameOperations', Value) or (RegQueryMultiStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager', 'SetupExecute', Value) and (Value <> '')); end; function InstallProducts: InstallResult; var ResultCode, I, ProductCount: Integer; begin Result := InstallSuccessful; ProductCount := GetArrayLength(Dependencies); MemoInstallInfo := SetupMessage(msgReadyMemoTasks); if ProductCount > 0 then begin DownloadPage.Show; for I := 0 to ProductCount - 1 do begin if Dependencies[I].InstallClean and (DelayedReboot or IsPendingReboot) then begin Result := InstallRebootRequired; break; end; DownloadPage.SetText(Dependencies[I].Title, ''); DownloadPage.SetProgress(I + 1, ProductCount); while True do begin ResultCode := 0; if ShellExec('', ExpandConstant('{tmp}{\}') + Dependencies[I].Filename, Dependencies[I].Parameters, '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode) then begin if Dependencies[I].RebootAfter then begin // delay reboot after install if we installed the last dependency anyways if I = ProductCount - 1 then begin DelayedReboot := True; end else begin Result := InstallRebootRequired; MemoInstallInfo := Dependencies[I].Title; end; break; end else if (ResultCode = 0) or Dependencies[I].ForceSuccess then begin break; end else if ResultCode = 3010 then begin // Windows Installer ResultCode 3010: ERROR_SUCCESS_REBOOT_REQUIRED DelayedReboot := True; break; end; end; case SuppressibleMsgBox(FmtMessage(SetupMessage(msgErrorFunctionFailed), [Dependencies[I].Title, IntToStr(ResultCode)]), mbError, MB_ABORTRETRYIGNORE, IDIGNORE) of IDABORT: begin Result := InstallError; MemoInstallInfo := MemoInstallInfo + #13#10 + ' ' + Dependencies[I].Title; break; end; IDIGNORE: begin MemoInstallInfo := MemoInstallInfo + #13#10 + ' ' + Dependencies[I].Title; break; end; end; end; if Result <> InstallSuccessful then begin break; end; end; DownloadPage.Hide; end; end; // Inno Setup event functions procedure InitializeWizard; begin DownloadPage := CreateDownloadPage(SetupMessage(msgWizardPreparing), SetupMessage(msgPreparingDesc), nil); end; function PrepareToInstall(var NeedsRestart: Boolean): String; var I: Integer; begin DelayedReboot := False; case InstallProducts of InstallError: begin Result := MemoInstallInfo; end; InstallRebootRequired: begin Result := MemoInstallInfo; NeedsRestart := True; // write into the registry that the installer needs to be executed again after restart RegWriteStringValue(HKEY_CURRENT_USER, 'SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce', 'InstallBootstrap', ExpandConstant('{srcexe}')); end; end; end; function NeedRestart: Boolean; begin Result := DelayedReboot; end; function UpdateReadyMemo(const Space, NewLine, MemoUserInfoInfo, MemoDirInfo, MemoTypeInfo, MemoComponentsInfo, MemoGroupInfo, MemoTasksInfo: String): String; begin Result := ''; if MemoUserInfoInfo <> '' then begin Result := Result + MemoUserInfoInfo + Newline + NewLine; end; if MemoDirInfo <> '' then begin Result := Result + MemoDirInfo + Newline + NewLine; end; if MemoTypeInfo <> '' then begin Result := Result + MemoTypeInfo + Newline + NewLine; end; if MemoComponentsInfo <> '' then begin Result := Result + MemoComponentsInfo + Newline + NewLine; end; if MemoGroupInfo <> '' then begin Result := Result + MemoGroupInfo + Newline + NewLine; end; if MemoTasksInfo <> '' then begin Result := Result + MemoTasksInfo; end; if MemoInstallInfo <> '' then begin if MemoTasksInfo = '' then begin Result := Result + SetupMessage(msgReadyMemoTasks); end; Result := Result + FmtMessage(MemoInstallInfo, [Space]); end; end; function NextButtonClick(const CurPageID: Integer): Boolean; var I, ProductCount: Integer; Retry: Boolean; begin Result := True; if (CurPageID = wpReady) and (MemoInstallInfo <> '') then begin DownloadPage.Show; ProductCount := GetArrayLength(Dependencies); for I := 0 to ProductCount - 1 do begin if Dependencies[I].URL <> '' then begin DownloadPage.Clear; DownloadPage.Add(Dependencies[I].URL, Dependencies[I].Filename, Dependencies[I].Checksum); Retry := True; while Retry do begin Retry := False; try DownloadPage.Download; except if GetExceptionMessage = SetupMessage(msgErrorDownloadAborted) then begin Result := False; I := ProductCount; end else begin case SuppressibleMsgBox(AddPeriod(GetExceptionMessage), mbError, MB_ABORTRETRYIGNORE, IDIGNORE) of IDABORT: begin Result := False; I := ProductCount; end; IDRETRY: begin Retry := True; end; end; end; end; end; end; end; DownloadPage.Hide; end; end; // architecture helper functions function IsX64: Boolean; begin Result := not ForceX86 and Is64BitInstallMode; end; function GetString(const x86, x64: String): String; begin if IsX64 then begin Result := x64; end else begin Result := x86; end; end; function GetArchitectureSuffix: String; begin Result := GetString('', '_x64'); end; function GetArchitectureTitle: String; begin Result := GetString(' (x86)', ' (x64)'); end; function CompareVersion(const Version1, Version2: String): Integer; var Position, Number1, Number2: Integer; begin Result := 0; while (Version1 <> '') or (Version2 <> '') do begin Position := Pos('.', Version1); if Position > 0 then begin Number1 := StrToIntDef(Copy(Version1, 1, Position - 1), 0); Delete(Version1, 1, Position); end else if Version1 <> '' then begin Number1 := StrToIntDef(Version1, 0); Version1 := ''; end else begin Number1 := 0; end; Position := Pos('.', Version2); if Position > 0 then begin Number2 := StrToIntDef(Copy(Version2, 1, Position - 1), 0); Delete(Version2, 1, Position); end else if Version2 <> '' then begin Number2 := StrToIntDef(Version2, 0); Version2 := ''; end else begin Number2 := 0; end; if Number1 < Number2 then begin Result := -1; break; end else if Number1 > Number2 then begin Result := 1; break; end; end; end; // custom setup content [Languages] // Name: en; MessagesFile: "compiler:Default.isl" // Name: nl; MessagesFile: "compiler:Languages\Dutch.isl" // Name: de; MessagesFile: "compiler:Languages\German.isl" Name: "english"; MessagesFile: "compiler:Default.isl" Name: "armenian"; MessagesFile: "compiler:Languages\Armenian.isl" Name: "brazilianportuguese"; MessagesFile: "compiler:Languages\BrazilianPortuguese.isl" Name: "catalan"; MessagesFile: "compiler:Languages\Catalan.isl" Name: "corsican"; MessagesFile: "compiler:Languages\Corsican.isl" Name: "czech"; MessagesFile: "compiler:Languages\Czech.isl" Name: "danish"; MessagesFile: "compiler:Languages\Danish.isl" Name: "dutch"; MessagesFile: "compiler:Languages\Dutch.isl" Name: "finnish"; MessagesFile: "compiler:Languages\Finnish.isl" Name: "french"; MessagesFile: "compiler:Languages\French.isl" Name: "german"; MessagesFile: "compiler:Languages\German.isl" Name: "hebrew"; MessagesFile: "compiler:Languages\Hebrew.isl" Name: "icelandic"; MessagesFile: "compiler:Languages\Icelandic.isl" Name: "italian"; MessagesFile: "compiler:Languages\Italian.isl" Name: "japanese"; MessagesFile: "compiler:Languages\Japanese.isl" Name: "norwegian"; MessagesFile: "compiler:Languages\Norwegian.isl" Name: "polish"; MessagesFile: "compiler:Languages\Polish.isl" Name: "portuguese"; MessagesFile: "compiler:Languages\Portuguese.isl" Name: "russian"; MessagesFile: "compiler:Languages\Russian.isl" Name: "slovak"; MessagesFile: "compiler:Languages\Slovak.isl" Name: "slovenian"; MessagesFile: "compiler:Languages\Slovenian.isl" Name: "spanish"; MessagesFile: "compiler:Languages\Spanish.isl" Name: "turkish"; MessagesFile: "compiler:Languages\Turkish.isl" Name: "ukrainian"; MessagesFile: "compiler:Languages\Ukrainian.isl" [Files] // TODO: .NET could be included in the installer // Source: "dotnetfx46.exe"; Flags: dontcopy noencryption Source: "{#SourceBinPathX64}"; DestDir: "{app}"; DestName: "{#MyAppExeName}"; Check: IsX64; Flags: ignoreversion Source: "{#SourceBinPathX86}"; DestDir: "{app}"; Check: not IsX64; Flags: ignoreversion Source: "{#SourceDLLPath}"; DestDir: "{app}"; Flags: ignoreversion ; NOTE: Don't use "Flags: ignoreversion" on any shared system files [Icons] Name: "{group}\{#MyAppSetupName}"; Filename: "{app}\{#MyAppExeName}" Name: "{group}\{cm:UninstallProgram,{#MyAppSetupName}}"; Filename: "{uninstallexe}" Name: "{commondesktop}\{#MyAppSetupName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon [Tasks] Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked [Registry] ; remove explorer context entry if it exists Root: HKCR; Subkey: Folder\shell\Remove empty dirs; ValueType: string; Flags: uninsdeletekey deletekey dontcreatekey; Tasks: ; Languages: [Run] Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#MyAppSetupName}}"; Flags: nowait postinstall skipifsilent [Code] function InitializeSetup: Boolean; var Version: String; UninstallerPath: String; // PrevVersion: String; ErrorCode: Integer; begin // Check whether application is already installed (legacy) if RegKeyExists(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Remove Empty Directories') then begin if MsgBox('The setup has detected that RED is already installed on your computer. Do you wish to uninstall the previous version and continue with a fresh installation?', mbConfirmation, MB_YESNO) = IDYES then begin RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Remove Empty Directories', 'UninstallString', UninstallerPath); // ShellExec('runas', uninstaller, '/SILENT', '', SW_HIDE, ewWaitUntilTerminated, ErrorCode); // use above statement if extra level security is required usually it is not req //ShellExec('open', UninstallerPath, '/S', '', SW_SHOW, ewWaitUntilTerminated, ErrorCode); ShellExec('runas', UninstallerPath, '/SILENT', '', SW_SHOW, ewWaitUntilTerminated, ErrorCode); //Exec(UninstallerPath, '/S', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ErrorCode); end; end; // Check whether application is already installed (new way with appId) if RegKeyExists(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{{#APP_ID}}_is1') then begin if MsgBox('The setup has detected that RED is already installed on your computer. Do you wish to uninstall the previous version and continue with a fresh installation?', mbConfirmation, MB_YESNO) = IDYES then begin RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{{#APP_ID}}_is1', 'UninstallString', UninstallerPath); // ShellExec('runas', uninstaller, '/SILENT', '', SW_HIDE, ewWaitUntilTerminated, ErrorCode); // use above statement if extra level security is required usually it is not req //ShellExec('open', UninstallerPath, '/S', '', SW_SHOW, ewWaitUntilTerminated, ErrorCode); ShellExec('runas', UninstallerPath, '/SILENT', '', SW_SHOW, ewWaitUntilTerminated, ErrorCode); //Exec(UninstallerPath, '/S', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ErrorCode); end; end; // Check whether application is already installed (new way with appId + WOW6432Node tree) if RegKeyExists(HKEY_LOCAL_MACHINE, 'SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{{#APP_ID}}_is1') then begin if MsgBox('The setup has detected that RED is already installed on your computer. Do you wish to uninstall the previous version and continue with a fresh installation?', mbConfirmation, MB_YESNO) = IDYES then begin RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{{#APP_ID}}_is1', 'UninstallString', UninstallerPath); // RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{{#APP_ID}}_is1', 'DisplayVersion', PrevVersion); // ShellExec('runas', uninstaller, '/SILENT', '', SW_HIDE, ewWaitUntilTerminated, ErrorCode); // use above statement if extra level security is required usually it is not req //ShellExec('open', UninstallerPath, '/S', '', SW_SHOW, ewWaitUntilTerminated, ErrorCode); ShellExec('runas', UninstallerPath, '/SILENT', '', SW_SHOW, ewWaitUntilTerminated, ErrorCode); //Exec(UninstallerPath, '/S', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ErrorCode); end; end; // Check for .NET Framework 4.6.2 // https://www.microsoft.com/en-US/download/details.aspx?id=53345 if not IsDotNetInstalled(net462, 0) then begin AddDependency('dotnetfx46.exe', '/lcid ' + IntToStr(GetUILanguage) + ' /passive /norestart', '.NET Framework 4.6.2', 'https://download.microsoft.com/download/D/5/C/D5C98AB0-35CC-45D9-9BA5-B18256BA2AE6/NDP462-KB3151802-Web.exe', '', False, False, False); end; Result := True; end;