; ThreadPilot Installer Script for Inno Setup ; Copyright (C) 2025 Prime Build #define MyAppName "ThreadPilot" #define MyAppPublisher "Prime Build" #define MyAppURL "https://github.com/PrimeBuild-pc/ThreadPilot" #define MyAppExeName "ThreadPilot.exe" #ifndef MyWizardStyle #define MyWizardStyle "modern dynamic windows11" #endif #ifndef MyAppVersion #define MyAppVersion "1.7.9" #endif #ifndef MyAppSourceDir #define MyAppSourceDir "..\\artifacts\\release\\singlefile" #endif [Setup] AppId={{E8F7A3B2-5C4D-4E6F-8A9B-1C2D3E4F5A6B} AppName={#MyAppName} AppVersion={#MyAppVersion} AppVerName={#MyAppName} AppPublisher={#MyAppPublisher} AppPublisherURL={#MyAppURL} AppSupportURL={#MyAppURL}/issues AppUpdatesURL={#MyAppURL}/releases DefaultDirName={autopf}\{#MyAppName} DefaultGroupName={#MyAppName} AllowNoIcons=yes LicenseFile=..\LICENSE PrivilegesRequired=admin OutputDir=..\artifacts\release\installer OutputBaseFilename=ThreadPilot_v{#MyAppVersion}_Setup SetupIconFile=..\assets\icons\ico.ico Compression=lzma2/ultra64 SolidCompression=yes WizardStyle={#MyWizardStyle} ArchitecturesInstallIn64BitMode=x64compatible ArchitecturesAllowed=x64compatible MinVersion=10.0.17763 UninstallDisplayIcon={app}\{#MyAppExeName} DisableReadyPage=yes ; Always Program Files: ThreadPilot runs elevated, and only there can a non-admin program not replace it. ; Installs in another folder move here on upgrade (see MovePreviousInstall below). DisableDirPage=yes UsePreviousAppDir=no [Languages] Name: "english"; MessagesFile: "compiler:Default.isl" [Tasks] Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked [Files] Source: "{#MyAppSourceDir}\ThreadPilot.exe"; DestDir: "{app}"; Flags: ignoreversion Source: "{#MyAppSourceDir}\*.dll"; DestDir: "{app}"; Flags: ignoreversion skipifsourcedoesntexist Source: "{#MyAppSourceDir}\*.pdb"; DestDir: "{app}"; Flags: ignoreversion skipifsourcedoesntexist [Icons] Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}" Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}" Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon ; Normal/package-manager installs stay unattended. In-app updates opt in through ; /THREADPILOTUPDATE=1 and relaunch ThreadPilot after the replacement completes. [Run] Filename: "{app}\{#MyAppExeName}"; Flags: nowait; Check: IsThreadPilotUpdate ; ThreadPilot user data is preserved during install/update. Inno removes installed ; files and shortcuts automatically only when the generated uninstaller runs. ; Per-user AppData cleanup is limited to the account context used by uninstall. [UninstallRun] Filename: "taskkill.exe"; Parameters: "/IM ""{#MyAppExeName}"" /F"; Flags: runhidden waituntilterminated; RunOnceId: "UninstallKillThreadPilot" Filename: "schtasks.exe"; Parameters: "/Delete /TN ""ThreadPilot_Launch"" /F"; Flags: runhidden waituntilterminated; RunOnceId: "UninstallRemoveThreadPilotLaunchTask" Filename: "schtasks.exe"; Parameters: "/Delete /TN ""ThreadPilot_Startup"" /F"; Flags: runhidden waituntilterminated; RunOnceId: "UninstallRemoveThreadPilotStartupTask" Filename: "reg.exe"; Parameters: "delete ""HKCU\Software\Microsoft\Windows\CurrentVersion\Run"" /v ""ThreadPilot"" /f"; Flags: runhidden waituntilterminated; RunOnceId: "UninstallRemoveThreadPilotRunEntry" [UninstallDelete] Type: filesandordirs; Name: "{userappdata}\ThreadPilot" [Code] const LegacyBetaUninstallKey = 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{A2A4C8B5-4A9A-4B1B-93F4-5F8B1C7E8C2A}_is1'; LegacyBetaDisplayName = 'ThreadPilot 0.1.0-beta'; CurrentUninstallKey = 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{E8F7A3B2-5C4D-4E6F-8A9B-1C2D3E4F5A6B}_is1'; var PreviousInstallDir: string; function IsLegacyThreadPilotInstallPath(InstallLocation: string): Boolean; var NormalizedLocation: string; ExpectedInstallRoot: string; begin NormalizedLocation := Lowercase(RemoveBackslashUnlessRoot(RemoveQuotes(InstallLocation))); ExpectedInstallRoot := Lowercase(RemoveBackslashUnlessRoot(ExpandConstant('{autopf}\ThreadPilot'))); Result := (NormalizedLocation = ExpectedInstallRoot); end; procedure DeleteLegacyBetaUninstallEntry(RootKey: Integer); var DisplayName: string; InstallLocation: string; begin if RegQueryStringValue(RootKey, LegacyBetaUninstallKey, 'DisplayName', DisplayName) and RegQueryStringValue(RootKey, LegacyBetaUninstallKey, 'InstallLocation', InstallLocation) and (DisplayName = LegacyBetaDisplayName) and IsLegacyThreadPilotInstallPath(InstallLocation) then begin RegDeleteKeyIncludingSubkeys(RootKey, LegacyBetaUninstallKey); end; end; function InitializeSetup(): Boolean; begin DeleteLegacyBetaUninstallEntry(HKLM); DeleteLegacyBetaUninstallEntry(HKCU); if not RegQueryStringValue(HKLM, CurrentUninstallKey, 'InstallLocation', PreviousInstallDir) then PreviousInstallDir := ''; Result := True; end; function GetFileAttributes(lpFileName: string): Cardinal; external 'GetFileAttributesW@kernel32.dll stdcall'; // True when the folder or any folder above it is a junction/symlink (or unreadable). function HasReparsePointOnPath(Dir: string): Boolean; var Attributes: Cardinal; Parent: string; begin Result := True; while True do begin Attributes := GetFileAttributes(Dir); if (Attributes = $FFFFFFFF) or ((Attributes and $400) <> 0) then exit; Parent := ExtractFileDir(Dir); if (Parent = '') or (Length(Parent) >= Length(Dir)) then break; Dir := Parent; end; Result := False; end; // An earlier install in another folder: remove only the program files ThreadPilot put there. // The old uninstaller is not run because it also deletes the user's settings in AppData. procedure MovePreviousInstall(); var OldDir: string; begin OldDir := RemoveBackslashUnlessRoot(RemoveQuotes(PreviousInstallDir)); if (OldDir = '') or (CompareText(OldDir, RemoveBackslashUnlessRoot(ExpandConstant('{app}'))) = 0) or not FileExists(AddBackslash(OldDir) + '{#MyAppExeName}') then exit; // The old folder may be user-writable: if it was swapped for a junction, admin deletes would land elsewhere. if HasReparsePointOnPath(OldDir) then exit; // A copy that is still closing (in-app update) holds the exe for a moment. DelayDeleteFile(AddBackslash(OldDir) + '{#MyAppExeName}', 40); if FileExists(AddBackslash(OldDir) + '{#MyAppExeName}') then exit; DeleteFile(AddBackslash(OldDir) + 'ThreadPilot.pdb'); DeleteFile(AddBackslash(OldDir) + 'D3DCompiler_47_cor3.dll'); DeleteFile(AddBackslash(OldDir) + 'PenImc_cor3.dll'); DeleteFile(AddBackslash(OldDir) + 'PresentationNative_cor3.dll'); DeleteFile(AddBackslash(OldDir) + 'vcruntime140_cor3.dll'); DeleteFile(AddBackslash(OldDir) + 'wpfgfx_cor3.dll'); DeleteFile(AddBackslash(OldDir) + 'unins000.exe'); DeleteFile(AddBackslash(OldDir) + 'unins000.dat'); DeleteFile(AddBackslash(OldDir) + 'unins000.msg'); RemoveDir(OldDir); end; procedure CurStepChanged(CurStep: TSetupStep); begin if CurStep = ssPostInstall then MovePreviousInstall(); end; function IsThreadPilotUpdate(): Boolean; begin Result := CompareText(ExpandConstant('{param:THREADPILOTUPDATE|0}'), '1') = 0; end;