| 1 |
// ---------------------------------------------------------------------------- |
| 2 |
// |
| 3 |
// Inno Setup Ver: 5.4.2 |
| 4 |
// Script Version: 1.4.2 |
| 5 |
// Author: Jared Breland <[email protected]> |
| 6 |
// Homepage: http://www.legroom.net/software |
| 7 |
// License: GNU Lesser General Public License (LGPL), version 3 |
| 8 |
// http://www.gnu.org/licenses/lgpl.html |
| 9 |
// |
| 10 |
// Script Function: |
| 11 |
// Allow modification of environmental path directly from Inno Setup installers |
| 12 |
// |
| 13 |
// Instructions: |
| 14 |
// Copy modpath.iss to the same directory as your setup script |
| 15 |
// |
| 16 |
// Add this statement to your [Setup] section |
| 17 |
// ChangesEnvironment=true |
| 18 |
// |
| 19 |
// Add this statement to your [Tasks] section |
| 20 |
// You can change the Description or Flags |
| 21 |
// You can change the Name, but it must match the ModPathName setting below |
| 22 |
// Name: modifypath; Description: &Add application directory to your environmental path; Flags: unchecked |
| 23 |
// |
| 24 |
// Add the following to the end of your [Code] section |
| 25 |
// ModPathName defines the name of the task defined above |
| 26 |
// ModPathType defines whether the 'user' or 'system' path will be modified; |
| 27 |
// this will default to user if anything other than system is set |
| 28 |
// setArrayLength must specify the total number of dirs to be added |
| 29 |
// Result[0] contains first directory, Result[1] contains second, etc. |
| 30 |
// const |
| 31 |
// ModPathName = 'modifypath'; |
| 32 |
// ModPathType = 'user'; |
| 33 |
// |
| 34 |
// function ModPathDir(): TArrayOfString; |
| 35 |
// begin |
| 36 |
// setArrayLength(Result, 1); |
| 37 |
// Result[0] := ExpandConstant('{app}'); |
| 38 |
// end; |
| 39 |
// #include "modpath.iss" |
| 40 |
// ---------------------------------------------------------------------------- |
| 41 |
|
| 42 |
procedure ModPath(); |
| 43 |
var |
| 44 |
oldpath: String; |
| 45 |
newpath: String; |
| 46 |
updatepath: Boolean; |
| 47 |
pathArr: TArrayOfString; |
| 48 |
aExecFile: String; |
| 49 |
aExecArr: TArrayOfString; |
| 50 |
i, d: Integer; |
| 51 |
pathdir: TArrayOfString; |
| 52 |
regroot: Integer; |
| 53 |
regpath: String; |
| 54 |
|
| 55 |
begin |
| 56 |
// Get constants from main script and adjust behavior accordingly |
| 57 |
// ModPathType MUST be 'system' or 'user'; force 'user' if invalid |
| 58 |
if ModPathType = 'system' then begin |
| 59 |
regroot := HKEY_LOCAL_MACHINE; |
| 60 |
regpath := 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment'; |
| 61 |
end else begin |
| 62 |
regroot := HKEY_CURRENT_USER; |
| 63 |
regpath := 'Environment'; |
| 64 |
end; |
| 65 |
|
| 66 |
// Get array of new directories and act on each individually |
| 67 |
pathdir := ModPathDir(); |
| 68 |
for d := 0 to GetArrayLength(pathdir)-1 do begin |
| 69 |
updatepath := true; |
| 70 |
|
| 71 |
// Get current path, split into an array |
| 72 |
RegQueryStringValue(regroot, regpath, 'Path', oldpath); |
| 73 |
oldpath := oldpath + ';'; |
| 74 |
i := 0; |
| 75 |
|
| 76 |
while (Pos(';', oldpath) > 0) do begin |
| 77 |
SetArrayLength(pathArr, i+1); |
| 78 |
pathArr[i] := Copy(oldpath, 0, Pos(';', oldpath)-1); |
| 79 |
oldpath := Copy(oldpath, Pos(';', oldpath)+1, Length(oldpath)); |
| 80 |
i := i + 1; |
| 81 |
|
| 82 |
// Check if current directory matches app dir |
| 83 |
if pathdir[d] = pathArr[i-1] then begin |
| 84 |
// if uninstalling, remove dir from path |
| 85 |
if IsUninstaller() = true then begin |
| 86 |
continue; |
| 87 |
// if installing, flag that dir already exists in path |
| 88 |
end else begin |
| 89 |
updatepath := false; |
| 90 |
end; |
| 91 |
end; |
| 92 |
|
| 93 |
// Add current directory to new path |
| 94 |
if i = 1 then begin |
| 95 |
newpath := pathArr[i-1]; |
| 96 |
end else begin |
| 97 |
newpath := newpath + ';' + pathArr[i-1]; |
| 98 |
end; |
| 99 |
end; |
| 100 |
|
| 101 |
// Append app dir to path if not already included |
| 102 |
if (IsUninstaller() = false) AND (updatepath = true) then |
| 103 |
newpath := newpath + ';' + pathdir[d]; |
| 104 |
|
| 105 |
// Write new path |
| 106 |
RegWriteStringValue(regroot, regpath, 'Path', newpath); |
| 107 |
end; |
| 108 |
end; |
| 109 |
|
| 110 |
// Split a string into an array using passed delimeter |
| 111 |
procedure MPExplode(var Dest: TArrayOfString; Text: String; Separator: String); |
| 112 |
var |
| 113 |
i: Integer; |
| 114 |
begin |
| 115 |
i := 0; |
| 116 |
repeat |
| 117 |
SetArrayLength(Dest, i+1); |
| 118 |
if Pos(Separator,Text) > 0 then begin |
| 119 |
Dest[i] := Copy(Text, 1, Pos(Separator, Text)-1); |
| 120 |
Text := Copy(Text, Pos(Separator,Text) + Length(Separator), Length(Text)); |
| 121 |
i := i + 1; |
| 122 |
end else begin |
| 123 |
Dest[i] := Text; |
| 124 |
Text := ''; |
| 125 |
end; |
| 126 |
until Length(Text)=0; |
| 127 |
end; |
| 128 |
|
| 129 |
|
| 130 |
procedure CurStepChanged(CurStep: TSetupStep); |
| 131 |
var |
| 132 |
taskname: String; |
| 133 |
begin |
| 134 |
taskname := ModPathName; |
| 135 |
if CurStep = ssPostInstall then |
| 136 |
if IsTaskSelected(taskname) then |
| 137 |
ModPath(); |
| 138 |
end; |
| 139 |
|
| 140 |
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep); |
| 141 |
var |
| 142 |
aSelectedTasks: TArrayOfString; |
| 143 |
i: Integer; |
| 144 |
taskname: String; |
| 145 |
regpath: String; |
| 146 |
regstring: String; |
| 147 |
appid: String; |
| 148 |
begin |
| 149 |
// only run during actual uninstall |
| 150 |
if CurUninstallStep = usUninstall then begin |
| 151 |
// get list of selected tasks saved in registry at install time |
| 152 |
appid := '{#emit SetupSetting("AppId")}'; |
| 153 |
if appid = '' then appid := '{#emit SetupSetting("AppName")}'; |
| 154 |
regpath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\'+appid+'_is1'); |
| 155 |
RegQueryStringValue(HKLM, regpath, 'Inno Setup: Selected Tasks', regstring); |
| 156 |
if regstring = '' then RegQueryStringValue(HKCU, regpath, 'Inno Setup: Selected Tasks', regstring); |
| 157 |
|
| 158 |
// check each task; if matches modpath taskname, trigger patch removal |
| 159 |
if regstring <> '' then begin |
| 160 |
taskname := ModPathName; |
| 161 |
MPExplode(aSelectedTasks, regstring, ','); |
| 162 |
if GetArrayLength(aSelectedTasks) > 0 then begin |
| 163 |
for i := 0 to GetArrayLength(aSelectedTasks)-1 do begin |
| 164 |
if comparetext(aSelectedTasks[i], taskname) = 0 then |
| 165 |
ModPath(); |
| 166 |
end; |
| 167 |
end; |
| 168 |
end; |
| 169 |
end; |
| 170 |
end; |
| 171 |
|
| 172 |
function NeedRestart(): Boolean; |
| 173 |
begin |
| 174 |
Result := False; |
| 175 |
end; |