Skip to content

Commit c62cd6e

Browse files
committed
don't add path to environment variable if it already exists
1 parent 0e5e80a commit c62cd6e

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

OctoPrint Setup.iss

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ AppendDefaultGroupName=False
4444
UsePreviousLanguage=no
4545
UninstallDisplayName=OctoPrint on port {code:GetOctoPrintPort}
4646
RestartIfNeededByRun=no
47+
ChangesEnvironment=yes
4748

4849
[Run]
4950
Filename: "{app}\vs_BuildTools.exe"; Parameters: "--add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Component.VC.CMake.Project --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.Windows11SDK.22621 --quiet --nocache --wait --norestart"; WorkingDir: "{app}"; Flags: runascurrentuser; Description: "Install Visual Studio Build Tools (required for some plugin installs, ie OctoLapse)"; StatusMsg: "Installing Visual Studio Build Tools, this process can take a considerable amount of time."; Components: initial_instance
@@ -73,7 +74,7 @@ Filename: "{sys}\netsh.exe"; Parameters: "advfirewall firewall delete rule name=
7374
[Registry]
7475
Root: "HKLM"; Subkey: "Software\{#MyAppName}\Instances"; ValueType: string; ValueName: "{code:GetOctoPrintPort}"; ValueData: "{code:GetServiceWrapperPath}"; Flags: uninsdeletekeyifempty uninsdeletevalue
7576
Root: "HKLM"; Subkey: "Software\{#MyAppName}"; ValueType: string; ValueName: "InstallPath"; ValueData: "{app}"
76-
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType: string; ValueName: "Path"; ValueData: "{olddata};{app}"; Flags: preservestringtype
77+
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType: string; ValueName: "Path"; ValueData: "{olddata};{app}"; Flags: preservestringtype; Check: NeedsAddPath(ExpandConstant('{app}'))
7778

7879
[Components]
7980
Name: "initial_instance"; Description: "Initial Install"; Flags: exclusive; Check: not InstalledOnce
@@ -526,8 +527,7 @@ var
526527
DirName: String;
527528
begin
528529
DirName:= 'C:\{#MyAppName}';
529-
if RegQueryStringValue(HKEY_LOCAL_MACHINE, 'Software\{#MyAppName}\',
530-
'InstallPath', DirName) then
530+
if RegQueryStringValue(HKEY_LOCAL_MACHINE, 'Software\{#MyAppName}\', 'InstallPath', DirName) then
531531
begin
532532
// Successfully read the value
533533
end;
@@ -555,6 +555,20 @@ begin
555555
end;
556556
end;
557557
558+
function NeedsAddPathHKLM(Param: string): boolean;
559+
var
560+
OrigPath: string;
561+
begin
562+
if not RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'Path', OrigPath) then
563+
begin
564+
Result := True;
565+
exit;
566+
end;
567+
// look for the path with leading and trailing semicolon
568+
// Pos() returns 0 if not found
569+
Result := Pos(';' + Param + ';', ';' + OrigPath + ';') = 0;
570+
end;
571+
558572
[Languages]
559573
Name: "english"; MessagesFile: "compiler:Default.isl"
560574

0 commit comments

Comments
 (0)