From f6f441475698e47edf547412ccab7e7ef713f70a Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Tue, 8 Nov 2011 18:37:49 +0100 Subject: [PATCH] Installer: Move environment helper functions to a separate file Signed-off-by: Sebastian Schuberth --- .../{helpers.inc.iss => environment.inc.iss} | 63 ------ share/WinGit/helpers.inc.iss | 221 ++++++--------------- share/WinGit/install.iss | 1 + 3 files changed, 63 insertions(+), 222 deletions(-) copy share/WinGit/{helpers.inc.iss => environment.inc.iss} (66%) rewrite share/WinGit/helpers.inc.iss (69%) diff --git a/share/WinGit/helpers.inc.iss b/share/WinGit/environment.inc.iss similarity index 66% copy from share/WinGit/helpers.inc.iss copy to share/WinGit/environment.inc.iss index 41180481..7513d374 100644 --- a/share/WinGit/helpers.inc.iss +++ b/share/WinGit/environment.inc.iss @@ -1,48 +1,3 @@ -// Copies a NULL-terminated array of characters to a string. -function ArrayToString(Chars:array of Char):String; -var - Len,i:Longint; -begin - Len:=GetArrayLength(Chars); - SetLength(Result,Len); - - i:=0; - while (i#0) do begin - Result[i+1]:=Chars[i]; - Inc(i); - end; - - SetLength(Result,i); -end; - -// Copies a string to a NULL-terminated array of characters. -function StringToArray(Str:String):array of Char; -var - Len,i:Longint; -begin - Len:=Length(Str); - SetArrayLength(Result,Len+1); - - i:=0; - while i0); - end; -end; diff --git a/share/WinGit/helpers.inc.iss b/share/WinGit/helpers.inc.iss dissimilarity index 69% index 41180481..ff187bf5 100644 --- a/share/WinGit/helpers.inc.iss +++ b/share/WinGit/helpers.inc.iss @@ -1,159 +1,62 @@ -// Copies a NULL-terminated array of characters to a string. -function ArrayToString(Chars:array of Char):String; -var - Len,i:Longint; -begin - Len:=GetArrayLength(Chars); - SetLength(Result,Len); - - i:=0; - while (i#0) do begin - Result[i+1]:=Chars[i]; - Inc(i); - end; - - SetLength(Result,i); -end; - -// Copies a string to a NULL-terminated array of characters. -function StringToArray(Str:String):array of Char; -var - Len,i:Longint; -begin - Len:=Length(Str); - SetArrayLength(Result,Len+1); - - i:=0; - while i0 do begin - SetArrayLength(Result,i+1); - if p>1 then begin - Result[i]:=Copy(Path,1,p-1); - i:=i+1; - end; - Path:=Copy(Path,p+1,Length(Path)); - p:=Pos(';',Path); - end; -end; - -// Sets the contents of the specified environment variable for the current process. -function SetEnvironmentVariable(lpName,lpValue:String):Boolean; -#ifdef UNICODE -external 'SetEnvironmentVariableW@Kernel32.dll stdcall delayload'; -#else -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; -var - Path,KeyName:string; - i:Longint; -begin - // Merge all non-empty directory strings into a PATH variable. - Path:=''; - for i:=0 to GetArrayLength(DirStrings)-1 do begin - if Length(DirStrings[i])>0 then begin - if Length(Path)>0 then begin - Path:=Path+';'+DirStrings[i]; - end else begin - Path:=DirStrings[i]; - end; - end; - end; - - // See http://www.jrsoftware.org/isfaq.php#env - if AllUsers then begin - KeyName:='SYSTEM\CurrentControlSet\Control\Session Manager\Environment'; - if DeleteIfEmpty and (Length(Path)=0) then 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); - end; - end else begin - KeyName:='Environment'; - if DeleteIfEmpty and (Length(Path)=0) then 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); - end; - end; - - // Also update the environment of the current process. - SetEnvironmentVariable(VarName,Path); -end; - -// As IsComponentSelected() is not supported during uninstall, this work-around -// simply checks the Registry. This is unreliable if the user runs the installer -// twice, the first time selecting the component, the second deselecting it. -function IsComponentInstalled(Component:String):Boolean; -var - UninstallKey,UninstallValue:String; - Value:String; -begin - Result:=False; - - UninstallKey:='SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#APP_NAME}_is1'; - UninstallValue:='Inno Setup: Selected Components'; - - if RegQueryStringValue(HKEY_LOCAL_MACHINE,UninstallKey,UninstallValue,Value) then begin - Result:=(Pos(Component,Value)>0); - end; -end; +// Copies a NULL-terminated array of characters to a string. +function ArrayToString(Chars:array of Char):String; +var + Len,i:Longint; +begin + Len:=GetArrayLength(Chars); + SetLength(Result,Len); + + i:=0; + while (i#0) do begin + Result[i+1]:=Chars[i]; + Inc(i); + end; + + SetLength(Result,i); +end; + +// Copies a string to a NULL-terminated array of characters. +function StringToArray(Str:String):array of Char; +var + Len,i:Longint; +begin + Len:=Length(Str); + SetArrayLength(Result,Len+1); + + i:=0; + while i0); + end; +end; diff --git a/share/WinGit/install.iss b/share/WinGit/install.iss index c9712068..7766fe50 100644 --- a/share/WinGit/install.iss +++ b/share/WinGit/install.iss @@ -147,6 +147,7 @@ Type: dirifempty; Name: {app}\home [Code] #include "helpers.inc.iss" +#include "environment.inc.iss" #include "putty.inc.iss" #include "modules.inc.iss" -- 2.11.4.GIT