2 !include "WinMessages.NSH"
5 ; AddToPath - Adds the given dir to the search path.
6 ; Input - head of the stack
7 ; Note - Win9x systems requires reboot
9 ; Push "directory" or ".ext"
10 ; Push "true" or "false"
11 ; Push "PATH" or "PATHEXT"
15 Pop $R8 ; env variable; PATH or PATHEXT
16 Pop $R7 ; "true" or "false" if admin user
22 StrCpy $4 "$0" ;save install directory in $4
23 ; don't add if the new item already exists in the registry value
24 StrCmp $R7 "true" ReadPath_AllUsers
25 ReadRegStr $1 HKCU "Environment" "$R8"
26 Goto ReadPath_UserCont
28 ReadRegStr $1 HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "$R8"
34 StrCmp $2 "" "" AddToPath_done
39 StrCmp $2 "" "" AddToPath_done
41 ; Only compare shortpath if PATH env variable
43 StrCmp $R8 "PATH" "" AddToPath_Not_PATH
44 GetFullPathName /SHORT $3 $0
49 StrCmp $2 "" "" AddToPath_done
54 StrCmp $2 "" "" AddToPath_done
61 StrCmp $1 1 AddToPath_NT
64 FileOpen $1 "$1\autoexec.bat" a
67 IntCmp $2 26 0 +2 +2 # DOS EOF
68 FileSeek $1 -1 END # write over EOF
69 FileWrite $1 "$\r$\nSET $R8=%$R8%;$3$\r$\n"
75 StrCmp $R7 "true" AddToPath_AllUsers
76 ReadRegStr $1 HKCU "Environment" "$R8"
77 Goto AddToPath_UserCont
79 ReadRegStr $1 HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "$R8"
81 StrCpy $2 $1 1 -1 # copy last char
82 StrCmp $2 ";" 0 +2 # if last char == ;
83 StrCpy $1 $1 -1 # remove last char
84 StrCmp $1 "" AddToPath_NTdoIt ; if current value is blank, do not prepend existing value
87 StrCmp $R7 "true" AddToPath_AllUsers_doit
88 ; writing registry for current user
89 WriteRegExpandStr HKCU "Environment" "$R8" $0
90 DetailPrint "$4 added to $R8 for Current User"
91 Goto AddToPath_UserCont_doit
92 AddToPath_AllUsers_doit:
93 ; writing registry for all users
94 WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "$R8" $0
95 DetailPrint "$4 added to $R8 for All Users"
96 AddToPath_UserCont_doit:
97 SendMessage ${HWND_BROADCAST} ${WM_SETTINGCHANGE} 0 "STR:Environment" /TIMEOUT=10000
106 ; RemoveFromPath - Remove a given dir from the path
107 ; Input: head of the stack
109 ; Push "directory" or ".ext"
110 ; Push "true" or "false"
111 ; Push "PATH" or "PATHEXT"
112 ; Call un.RemoveFromPath
114 Function un.RemoveFromPath
115 Pop $R8 ; env variable; PATH or PATHEXT
116 Pop $R7 ; "true" or "false" if admin user
125 IntFmt $6 "%c" 26 # DOS EOF
129 StrCmp $1 1 unRemoveFromPath_NT
132 FileOpen $1 "$1\autoexec.bat" r
136 ; Only compare shortpath if PATH env variable
138 StrCmp $R8 "PATH" "" unRemoveFromPath_Not_PATH
139 GetFullPathName /SHORT $0 $0
140 unRemoveFromPath_Not_PATH:
141 StrCpy $0 "SET $R8=%$R8%;$0"
142 Goto unRemoveFromPath_dosLoop
144 unRemoveFromPath_dosLoop:
146 StrCpy $5 $3 1 -1 # read last char
147 StrCmp $5 $6 0 +2 # if DOS EOF
148 StrCpy $3 $3 -1 # remove DOS EOF so we can compare
149 StrCmp $3 "$0$\r$\n" unRemoveFromPath_dosLoopRemoveLine
150 StrCmp $3 "$0$\n" unRemoveFromPath_dosLoopRemoveLine
151 StrCmp $3 "$0" unRemoveFromPath_dosLoopRemoveLine
152 StrCmp $3 "" unRemoveFromPath_dosLoopEnd
154 Goto unRemoveFromPath_dosLoop
155 unRemoveFromPath_dosLoopRemoveLine:
157 Goto unRemoveFromPath_dosLoop
159 unRemoveFromPath_dosLoopEnd:
163 Delete "$1\autoexec.bat"
164 CopyFiles /SILENT $4 "$1\autoexec.bat"
166 Goto unRemoveFromPath_done
169 StrCmp $R7 "true" unRemoveFromPath_AllUsers
170 ReadRegStr $1 HKCU "Environment" "$R8"
171 Goto unRemoveFromPath_UserCont
172 unRemoveFromPath_AllUsers:
173 ReadRegStr $1 HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "$R8"
174 unRemoveFromPath_UserCont:
175 StrCpy $5 $1 1 -1 # copy last char
176 StrCmp $5 ";" +2 # if last char != ;
177 StrCpy $1 "$1;" # append ;
180 Call un.StrStr ; Find `$0;` in $1
181 Pop $2 ; pos of our dir
182 StrCmp $2 "" unRemoveFromPath_done
183 ; else, it is in path
188 StrCpy $5 $1 -$4 # $5 is now the part before the path to remove
189 StrCpy $6 $2 "" $3 # $6 is now the part after the path to remove
192 StrCpy $5 $3 1 -1 # copy last char
193 StrCmp $5 ";" 0 +2 # if last char == ;
194 StrCpy $3 $3 -1 # remove last char
196 ; If the value is now empty, delete it
198 StrCmp $3 "" "" unRemoveFromPath_rewrite
199 ; we need to delete the value
200 StrCmp $R7 "true" unRemoveFromPath_AllUsers_delete
201 DeleteRegValue HKCU "Environment" "$R8"
202 DetailPrint "$0 removed from $R8 for Current User"
203 Goto unRemoveFromPath_UserCont_doit
204 unRemoveFromPath_AllUsers_delete:
205 DeleteRegValue HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "$R8"
206 DetailPrint "$0 removed from $R8 for All Users"
207 Goto unRemoveFromPath_UserCont_doit
208 unRemoveFromPath_rewrite:
209 StrCmp $R7 "true" unRemoveFromPath_AllUsers_rewrite
210 WriteRegExpandStr HKCU "Environment" "$R8" $3
211 DetailPrint "$0 removed from $R8 for Current User"
212 Goto unRemoveFromPath_UserCont_doit
213 unRemoveFromPath_AllUsers_rewrite:
214 WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "$R8" $3
215 DetailPrint "$0 removed from $R8 for All Users"
216 unRemoveFromPath_UserCont_doit:
217 SendMessage ${HWND_BROADCAST} ${WM_SETTINGCHANGE} 0 "STR:Environment" /TIMEOUT=10000
219 unRemoveFromPath_done:
229 ;====================================================
230 ; EmptyDirectory - Determines if directory passed is empty
231 ; and deletes it and from PATH if not empty
234 ; - "true" or "false"
235 ;====================================================
236 Function un.EmptyDirectory
237 Pop $R7 ; "true" or "false" if admin user
239 FindFirst $2 $1 "$5\*.*"
250 ; to get here we have a real file, so get out now
253 ; Remove the directory from PATH
257 Call un.RemoveFromPath
262 ###########################################
263 # Utility Functions #
264 ###########################################
268 ; input, top of stack = string to search for
269 ; top of stack-1 = string to search in
270 ; output, top of stack (replaces with the portion of the string remaining)
271 ; modifies no other variables.
274 ; Push "this is a long ass string"
278 ; ($R0 at this point is "ass string")
282 Exch $R1 ; st=haystack,old$R1, $R1=needle
283 Exch ; st=old$R1,haystack
284 Exch $R2 ; st=old$R1,old$R2, $R2=haystack
296 StrCpy $R5 $R2 $R3 $R4
302 StrCpy $R1 $R2 "" $R4
310 !insertmacro StrStr ""
311 !insertmacro StrStr "un."