1 ; Modify the user's PATH variable.
3 ; Modified by JY to have both a RemoveFromPath
4 ; and an un.RemoveFromPath which are basically
5 ; copies of each other. Why does NSIS demand
8 ; Modified Feb 14, 2005 by Mathias Sundman:
9 ; Added code to remove the semicolon at the end of the path
12 ; Added code to make sure we don't insert an extra semicolon
13 ; before our path if there already exist one at the end of
16 ; Removed duplicated "un. and install" functions and made
17 ; macros to duplicate the code instead.
21 ;Section "Add to path"
31 ; Call un.RemoveFromPath
36 !include "WinMessages.NSH"
39 ;====================================================
40 ; AddToPath - Adds the given dir to the search path.
41 ; Input - head of the stack
42 ; Note - Win9x systems requires reboot
43 ;====================================================
51 StrCmp $1 1 AddToPath_NT
54 FileOpen $1 "$1\autoexec.bat" a
56 GetFullPathName /SHORT
$0 $0
57 FileWrite $1 "$\r$\nSET PATH=%PATH%;$0$\r$\n"
62 ReadRegStr $1 HKCU "Environment" "PATH"
63 StrCpy $2 $1 1 -1 # copy last char
64 StrCmp $2 ";" 0 +2 # if last char == ;
65 StrCpy $1 $1 -1 # remove last char
67 StrCmp $1 "" AddToPath_NTdoIt
71 WriteRegExpandStr HKCU "Environment" "PATH" $0
72 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=
5000
80 ;====================================================
81 ; RemoveFromPath - Remove a given dir from the path
82 ; Input: head of the stack
83 ;====================================================
84 !macro RemoveFromPath un
85 Function ${un}RemoveFromPath
95 StrCmp $1 1 RemoveFromPath_NT
98 FileOpen $1 "$1\autoexec.bat" r
101 GetFullPathName /SHORT
$0 $0
102 StrCpy $0 "SET PATH=%PATH%;$0"
104 Goto RemoveFromPath_dosLoop
106 RemoveFromPath_dosLoop:
108 StrCmp $3 "$0$\r$\n" RemoveFromPath_dosLoop
109 StrCmp $3 "$0$\n" RemoveFromPath_dosLoop
110 StrCmp $3 "$0" RemoveFromPath_dosLoop
111 StrCmp $3 "" RemoveFromPath_dosLoopEnd
113 Goto RemoveFromPath_dosLoop
115 RemoveFromPath_dosLoopEnd:
119 Delete "$1\autoexec.bat"
120 CopyFiles /SILENT
$4 "$1\autoexec.bat"
122 Goto RemoveFromPath_done
126 ReadRegStr $1 HKCU "Environment" "PATH"
129 Call ${un}StrStr
; Find $0 in $1
130 Pop $0 ; pos of our dir
131 IntCmp $0 -1 RemoveFromPath_done
132 ; else, it is in path
133 StrCpy $3 $1 $0 ; $3 now has the part of the path before our dir
134 IntOp $2 $2 + $0 ; $2 now contains the pos after our dir in the path (';')
135 IntOp $2 $2 + 1 ; $2 now containts the pos after our dir and the semicolon.
140 StrCpy $5 $3 1 -1 # copy last char
141 StrCmp $5 ";" 0 +2 # if last char == ;
142 StrCpy $3 $3 -1 # remove last char
144 WriteRegExpandStr HKCU "Environment" "PATH" $3
145 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=
5000
156 !insertmacro RemoveFromPath
""
157 !insertmacro RemoveFromPath
"un."
160 ;====================================================
161 ; StrStr - Finds a given string in another given string.
162 ; Returns -1 if not found and the pos if found.
163 ; Input: head of the stack - string to find
164 ; second in the stack - string to find in
165 ; Output: head of the stack
166 ;====================================================
171 Pop $0 ; $0 now have the string to find
174 Pop $1 ; $1 now have the string to find in
188 IntCmp $2 $4 0 0 StrStrReturn_notFound
190 StrCmp $5 $0 StrStr_done StrStr_loop
192 StrStrReturn_notFound:
205 !insertmacro StrStr
""
206 !insertmacro StrStr
"un."
208 ;====================================================
209 ; IsNT - Returns 1 if the current system is NT, 0
211 ; Output: head of the stack
212 ;====================================================
216 ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
217 StrCmp $0 "" 0 IsNT_yes
230 !insertmacro IsNT
"un."