55#define MyAppExeName " cloudsqlctl.exe"
66
77[Setup]
8- ; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
9- ; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
108AppId = {{8A4B2C1D-E3F4-5678 -9012 -3456789ABCDE}
119AppName = {#MyAppName }
1210AppVersion = {#MyAppVersion}
13- ;AppVerName={#MyAppName} {#MyAppVersion}
1411AppPublisher = {#MyAppPublisher}
1512AppPublisherURL = {#MyAppURL}
1613AppSupportURL = {#MyAppURL}
1714AppUpdatesURL = {#MyAppURL}
1815DefaultDirName = {autopf}\{#MyAppName }
1916DisableProgramGroupPage = yes
20- ; Install for all users (requires admin)
2117PrivilegesRequired = admin
2218OutputDir = ..\dist
2319OutputBaseFilename = cloudsqlctl-setup
@@ -38,12 +34,20 @@ Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
3834; Add to System PATH
3935Root : HKLM; Subkey : " SYSTEM\CurrentControlSet\Control\Session Manager\Environment" ; ValueType : expandsz ; ValueName : " Path" ; ValueData : " {olddata};{app} " ; Check : NeedsAddPath(ExpandConstant(' {app} ' ))
4036
41- ; Optional: Set Environment Variables for Machine Scope
42- Root : HKLM; Subkey : " SYSTEM\CurrentControlSet\Control\Session Manager\Environment" ; ValueType : string ; ValueName : " CLOUDSQLCTL_HOME" ; ValueData : " {commonappdata} \CloudSQLCTL" ; Flags : createvalueifdoesntexist uninsdeletevalue
43- Root : HKLM; Subkey : " SYSTEM\CurrentControlSet\Control\Session Manager\Environment" ; ValueType : string ; ValueName : " CLOUDSQLCTL_LOGS" ; ValueData : " {commonappdata} \CloudSQLCTL\logs" ; Flags : createvalueifdoesntexist uninsdeletevalue
44- Root : HKLM; Subkey : " SYSTEM\CurrentControlSet\Control\Session Manager\Environment" ; ValueType : string ; ValueName : " CLOUDSQLCTL_PROXY_PATH" ; ValueData : " {commonappdata} \CloudSQLCTL\bin\cloud-sql-proxy.exe" ; Flags : createvalueifdoesntexist uninsdeletevalue
37+ ; Environment Variables (Machine Scope) - Logic handled in Code section for smart reuse
38+ Root : HKLM; Subkey : " SYSTEM\CurrentControlSet\Control\Session Manager\Environment" ; ValueType : string ; ValueName : " CLOUDSQLCTL_HOME" ; ValueData : " {code:GetHomeDir}" ; Flags : uninsdeletevalue
39+ Root : HKLM; Subkey : " SYSTEM\CurrentControlSet\Control\Session Manager\Environment" ; ValueType : string ; ValueName : " CLOUDSQLCTL_LOGS" ; ValueData : " {code:GetLogsDir}" ; Flags : uninsdeletevalue
40+ Root : HKLM; Subkey : " SYSTEM\CurrentControlSet\Control\Session Manager\Environment" ; ValueType : string ; ValueName : " CLOUDSQLCTL_PROXY_PATH" ; ValueData : " {code:GetProxyPath}" ; Flags : uninsdeletevalue
41+
42+ [Dirs]
43+ Name : " {commonappdata} \CloudSQLCTL" ; Permissions: users-modify
44+ Name : " {commonappdata} \CloudSQLCTL\logs" ; Permissions: users-modify
45+ Name : " {commonappdata} \CloudSQLCTL\bin" ; Permissions: users-modify
4546
4647[Code]
48+ var
49+ ProxyPath: string;
50+
4751function NeedsAddPath (Param: string): boolean;
4852var
4953 OrigPath: string;
5559 Result := True;
5660 exit;
5761 end ;
58- // look for the path with leading and trailing semicolon
59- // Pos() returns 0 if not found
6062 Result := Pos(' ;' + Param + ' ;' , ' ;' + OrigPath + ' ;' ) = 0 ;
6163end ;
64+
65+ function GetHomeDir (Param: string): string;
66+ var
67+ ExistingHome: string;
68+ begin
69+ // Reuse existing HOME if set
70+ if RegQueryStringValue(HKEY_LOCAL_MACHINE, ' SYSTEM\CurrentControlSet\Control\Session Manager\Environment' , ' CLOUDSQLCTL_HOME' , ExistingHome) then
71+ begin
72+ if DirExists(ExistingHome) then
73+ begin
74+ Result := ExistingHome;
75+ exit;
76+ end ;
77+ end ;
78+ Result := ExpandConstant(' {commonappdata}\CloudSQLCTL' );
79+ end ;
80+
81+ function GetLogsDir (Param: string): string;
82+ begin
83+ Result := ExpandConstant(' {commonappdata}\CloudSQLCTL\logs' );
84+ end ;
85+
86+ function GetProxyPath (Param: string): string;
87+ var
88+ ExistingProxy: string;
89+ CommonBin: string;
90+ UserBin: string;
91+ begin
92+ // 1. Check Registry for existing
93+ if RegQueryStringValue(HKEY_LOCAL_MACHINE, ' SYSTEM\CurrentControlSet\Control\Session Manager\Environment' , ' CLOUDSQLCTL_PROXY_PATH' , ExistingProxy) then
94+ begin
95+ if FileExists(ExistingProxy) then
96+ begin
97+ Result := ExistingProxy;
98+ exit;
99+ end ;
100+ end ;
101+
102+ CommonBin := ExpandConstant(' {commonappdata}\CloudSQLCTL\bin\cloud-sql-proxy.exe' );
103+
104+ // 2. Check if exists in Common AppData
105+ if FileExists(CommonBin) then
106+ begin
107+ Result := CommonBin;
108+ exit;
109+ end ;
110+
111+ // 3. Check User AppData (Migration scenario)
112+ UserBin := ExpandConstant(' {localappdata}\CloudSQLCTL\bin\cloud-sql-proxy.exe' );
113+ if FileExists(UserBin) then
114+ begin
115+ // Copy to Common AppData
116+ ForceDirectories(ExpandConstant(' {commonappdata}\CloudSQLCTL\bin' ));
117+ if FileCopy(UserBin, CommonBin, False) then
118+ begin
119+ Result := CommonBin;
120+ exit;
121+ end ;
122+ end ;
123+
124+ // 4. Default
125+ Result := CommonBin;
126+ end ;
0 commit comments