From 9e76f88c8f8db8de24597830606629127bb3ec7f Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Wed, 30 Jul 2025 11:44:39 -0500 Subject: [PATCH] Create Windows installer #53 --- repertory.iss.in | 130 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 112 insertions(+), 18 deletions(-) diff --git a/repertory.iss.in b/repertory.iss.in index 1f425ed4..06653412 100644 --- a/repertory.iss.in +++ b/repertory.iss.in @@ -12,38 +12,137 @@ ; (To generate a new GUID, click Tools | Generate GUID inside the IDE.) AppId={{BD165823-1DEF-4D23-87DC-3D7A9BB73A00} AppName={#MyAppName} -AppVersion={#MyAppVersion} AppPublisher={#MyAppPublisher} AppPublisherURL={#MyAppURL} AppSupportURL={#MyAppURL} AppUpdatesURL={#MyAppURL} -DefaultDirName={autopf}\{#MyAppName} -UninstallDisplayIcon={app}\{#MyAppExeName} +AppVersion={#MyAppVersion} ArchitecturesAllowed=x64compatible ArchitecturesInstallIn64BitMode=x64compatible +DefaultDirName={autopf}\{#MyAppName} DefaultGroupName={#MyAppName} DisableProgramGroupPage=yes LicenseFile=repertory\LICENSE.md OutputBaseFilename=repertory_{#MyAppVersion}_windows_@PROJECT_MARCH@_setup +PrivilegesRequired=admin SolidCompression=yes +UninstallDisplayIcon={app}\{#MyAppExeName} WizardStyle=modern [code] -function CheckAddPath(Param: string): boolean; +procedure RefreshEnvironment(); var - CurPath: string; - PathPos: Integer; + R: Cardinal; begin - if RegQueryStringValue(HKEY_LOCAL_MACHINE, + SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, + LPARAM(PChar('Environment')), SMTO_ABORTIFHUNG, 5000, R); +end; + +function NormalizeSemicolons(S: string): string; +begin + while Pos(';;', S) > 0 do + StringChange(S, ';;', ';'); + Result := S; +end; + +function CheckAddPath(NewPath: string): Boolean; +var + OldPath: string; +begin + if not RegQueryStringValue(HKLM, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', - 'PATH', CurPath) - then begin - PathPos := Pos(';' + Param + ';', ';' + CurPath + ';'); - Result := PathPos = 0; - exit; + 'Path', OldPath) + then + OldPath := ''; + + Result := Pos(LowerCase(NewPath), LowerCase(OldPath)) = 0; +end; + +procedure AddAppToPath(); +var + OldPath, NewPath, FinalPath: string; +begin + if not RegQueryStringValue(HKLM, + 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', + 'Path', OldPath) + then + OldPath := ''; + + NewPath := ExpandConstant('{app}'); + if Pos(LowerCase(NewPath), LowerCase(OldPath)) = 0 then + begin + if (OldPath <> '') and (Copy(OldPath, Length(OldPath), 1) <> ';') then + OldPath := OldPath + ';'; + + FinalPath := NormalizeSemicolons(OldPath + NewPath + ';'); + RegWriteExpandStringValue(HKLM, + 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', + 'Path', FinalPath); + + RefreshEnvironment(); + end; +end; + +procedure CurStepChanged(CurStep: TSetupStep); +begin + if CurStep = ssPostInstall then + begin + AddAppToPath(); + end; +end; + +procedure RemoveAppFromPath(); +var + OldPath, NewPath, Token, Remainder, FinalPath: string; + p: Integer; +begin + if not RegQueryStringValue(HKLM, + 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', + 'Path', OldPath) then + Exit; + + NewPath := ExpandConstant('{app}'); + Remainder := OldPath; + FinalPath := ''; + + while Length(Remainder) > 0 do + begin + p := Pos(';', Remainder); + if p = 0 then + begin + Token := Remainder; + Remainder := ''; + end + else + begin + Token := Copy(Remainder, 1, p - 1); + Delete(Remainder, 1, p); + end; + + Token := Trim(Token); + if (Token <> '') and (CompareText(Token, NewPath) <> 0) then + begin + if (FinalPath <> '') and (FinalPath[Length(FinalPath)] <> ';') then + FinalPath := FinalPath + ';'; + FinalPath := FinalPath + Token; + end; end; - Result := True; + while Pos(';;', FinalPath) > 0 do + StringChange(FinalPath, ';;', ';'); + if (FinalPath <> '') and (FinalPath[Length(FinalPath)] = ';') then + Delete(FinalPath, Length(FinalPath), 1); + + RegWriteExpandStringValue(HKLM, + 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', + 'Path', FinalPath); + + RefreshEnvironment(); +end; + +procedure DeinitializeUninstall(); +begin + RemoveAppFromPath(); end; [Languages] @@ -64,8 +163,3 @@ Name: "{commonstartup}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Paramet [Run] Filename: "msiexec.exe"; WorkingDir: "{app}"; Parameters: "/a winfsp-@WINFSP_VERSION@.msi /norestart"; \ Flags: 64bit waituntilterminated; Components: winfsp - -[Registry] -Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; \ - ValueType: expandsz; ValueName: "Path"; ValueData: "{olddata};{app};"; \ - Check: CheckAddPath(ExpandConstant('{app}'))