From: Sebastian Schuberth Date: Wed, 5 Feb 2014 13:16:35 +0000 (+0100) Subject: Installer: Write environment variables as expandable strings X-Git-Url: https://repo.or.cz/w/msysgit.git/commitdiff_plain/9c4b9cb734081908255793e54a67e0518de89a8a Installer: Write environment variables as expandable strings This allows to refer to other variables from within a variable. Signed-off-by: Sebastian Schuberth --- diff --git a/share/WinGit/environment.inc.iss b/share/WinGit/environment.inc.iss index dadf875e..50824ec6 100644 --- a/share/WinGit/environment.inc.iss +++ b/share/WinGit/environment.inc.iss @@ -54,10 +54,12 @@ external 'SetEnvironmentVariableA@Kernel32.dll stdcall delayload'; #endif // Sets the environment variable "VarName" to the concatenation of "DirStrings" -// using ";" as the delimiter. If "AllUsers" is true, a common variable is set, -// else a user-specific one. If "DeleteIfEmpty" is true and "DirStrings" is -// empty, "VarName" is deleted instead of set if it exists. -function SetEnvStrings(VarName:string;AllUsers,DeleteIfEmpty:Boolean;DirStrings:TArrayOfString):Boolean; +// using ";" as the delimiter. If "Expandable" is true, the "DirStrings" will be +// written as expandable strings, i.e. they may in turn contain environment variable +// names that are expanded at evaluation time. If "AllUsers" is true, a common +// variable is set, else a user-specific one. If "DeleteIfEmpty" is true and +// "DirStrings" is empty, "VarName" is deleted instead of set if it exists. +function SetEnvStrings(VarName:string;DirStrings:TArrayOfString;Expandable,AllUsers,DeleteIfEmpty:Boolean):Boolean; var Path,KeyName:string; i:Longint; @@ -81,7 +83,11 @@ begin Result:=(not RegValueExists(HKEY_LOCAL_MACHINE,KeyName,VarName)) or RegDeleteValue(HKEY_LOCAL_MACHINE,KeyName,VarName); end else begin - Result:=RegWriteStringValue(HKEY_LOCAL_MACHINE,KeyName,VarName,Path); + if Expandable then begin + Result:=RegWriteExpandStringValue(HKEY_LOCAL_MACHINE,KeyName,VarName,Path); + end else begin + Result:=RegWriteStringValue(HKEY_LOCAL_MACHINE,KeyName,VarName,Path); + end; end; end else begin KeyName:='Environment'; @@ -89,7 +95,11 @@ begin Result:=(not RegValueExists(HKEY_CURRENT_USER,KeyName,VarName)) or RegDeleteValue(HKEY_CURRENT_USER,KeyName,VarName); end else begin - Result:=RegWriteStringValue(HKEY_CURRENT_USER,KeyName,VarName,Path); + if Expandable then begin + Result:=RegWriteExpandStringValue(HKEY_CURRENT_USER,KeyName,VarName,Path); + end else begin + Result:=RegWriteStringValue(HKEY_CURRENT_USER,KeyName,VarName,Path); + end; end; end; diff --git a/share/WinGit/install.iss b/share/WinGit/install.iss index 4c4cb0a4..ba5b355c 100644 --- a/share/WinGit/install.iss +++ b/share/WinGit/install.iss @@ -354,7 +354,7 @@ begin end; end; -procedure SetAndMarkEnvString(Name,Value:String); +procedure SetAndMarkEnvString(Name,Value:String;Expandable:Boolean); var Env:TArrayOfString; FileName,Msg:String; @@ -363,7 +363,7 @@ begin Env[0]:=Value; // Try to set the variable as specified by the user. - if not SetEnvStrings(Name,IsAdminLoggedOn,True,Env) then begin + if not SetEnvStrings(Name,Env,Expandable,IsAdminLoggedOn,True) then begin Msg:='Line {#__LINE__}: Unable to set the '+Name+' environment variable.'; // This is not a critical error, so just notify the user and continue. @@ -392,7 +392,7 @@ begin if (GetArrayLength(Env)=1) and (CompareStr(RemoveQuotes(Env[0]),GetIniString('Environment',Name,'',FileName))=0) then begin - if not SetEnvStrings(Name,IsAdminLoggedOn,True,[]) then begin + if not SetEnvStrings(Name,[],False,IsAdminLoggedOn,True) then begin Msg:='Line {#__LINE__}: Unable to delete the '+Name+' environment variable.'; // This is not a critical error, so just notify the user and continue. @@ -1016,8 +1016,8 @@ begin DeleteMarkedEnvString('SVN_SSH'); if (PuTTYPage<>NIL) and RdbSSH[GS_Plink].Checked then begin - SetAndMarkEnvString('GIT_SSH',EdtPlink.Text); - SetAndMarkEnvString('SVN_SSH',EdtPlink.Text); + SetAndMarkEnvString('GIT_SSH',EdtPlink.Text,True); + SetAndMarkEnvString('SVN_SSH',EdtPlink.Text,True); end; // Get the current user's directories in PATH. @@ -1050,13 +1050,13 @@ begin EnvHome:=GetEnvStrings('HOME',IsAdminLoggedOn); i:=GetArrayLength(EnvHome); if (i=0) or ((i=1) and (Length(EnvHome[0])=0)) then begin - SetAndMarkEnvString('HOME',ExpandConstant('{%HOMEDRIVE}{%HOMEPATH}')); + SetAndMarkEnvString('HOME','%HOMEDRIVE%%HOMEPATH%',True); end; end; end; // Set the current user's PATH directories. - if not SetEnvStrings('PATH',IsAdminLoggedOn,True,EnvPath) then begin + if not SetEnvStrings('PATH',EnvPath,True,IsAdminLoggedOn,True) then begin Msg:='Line {#__LINE__}: Unable to set the PATH environment variable.'; // This is not a critical error, so just notify the user and continue. @@ -1361,7 +1361,7 @@ begin end; // Reset the current user's directories in PATH. - if not SetEnvStrings('PATH',IsAdminLoggedOn,True,EnvPath) then begin + if not SetEnvStrings('PATH',EnvPath,True,IsAdminLoggedOn,True) then begin Msg:='Line {#__LINE__}: Unable to revert any possible changes to PATH.'; // This is not a critical error, so just notify the user and continue.