svn cleanup
[anytun.git] / openvpn / install-win32 / setpath.nsi
bloba9626c3dda75e52be5aab566aca5722143175846
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
6 ; this nonsense?
8 ; Modified Feb 14, 2005 by Mathias Sundman:
9 ; Added code to remove the semicolon at the end of the path
10 ; when uninstalling.
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
14 ; the original path.
16 ; Removed duplicated "un. and install" functions and made
17 ; macros to duplicate the code instead.
19 ; example usage
21 ;Section "Add to path"
22 ; Push $INSTDIR
23 ; Call AddToPath
24 ;SectionEnd
26 ;# ...
28 ;Section "uninstall"
29 ; # ...
30 ; Push $INSTDIR
31 ; Call un.RemoveFromPath
32 ; # ...
33 ;SectionEnd
35 !verbose 3
36 !include "WinMessages.NSH"
37 !verbose 4
39 ;====================================================
40 ; AddToPath - Adds the given dir to the search path.
41 ; Input - head of the stack
42 ; Note - Win9x systems requires reboot
43 ;====================================================
44 Function AddToPath
45 Exch $0
46 Push $1
47 Push $2
49 Call IsNT
50 Pop $1
51 StrCmp $1 1 AddToPath_NT
52 ; Not on NT
53 StrCpy $1 $WINDIR 2
54 FileOpen $1 "$1\autoexec.bat" a
55 FileSeek $1 0 END
56 GetFullPathName /SHORT $0 $0
57 FileWrite $1 "$\r$\nSET PATH=%PATH%;$0$\r$\n"
58 FileClose $1
59 Goto AddToPath_done
61 AddToPath_NT:
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
68 StrCpy $0 "$1;$0"
69 Goto AddToPath_NTdoIt
70 AddToPath_NTdoIt:
71 WriteRegExpandStr HKCU "Environment" "PATH" $0
72 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
74 AddToPath_done:
75 Pop $2
76 Pop $1
77 Pop $0
78 FunctionEnd
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
86 Exch $0
87 Push $1
88 Push $2
89 Push $3
90 Push $4
91 Push $5
93 Call ${un}IsNT
94 Pop $1
95 StrCmp $1 1 RemoveFromPath_NT
96 ; Not on NT
97 StrCpy $1 $WINDIR 2
98 FileOpen $1 "$1\autoexec.bat" r
99 GetTempFileName $4
100 FileOpen $2 $4 w
101 GetFullPathName /SHORT $0 $0
102 StrCpy $0 "SET PATH=%PATH%;$0"
103 SetRebootFlag true
104 Goto RemoveFromPath_dosLoop
106 RemoveFromPath_dosLoop:
107 FileRead $1 $3
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
112 FileWrite $2 $3
113 Goto RemoveFromPath_dosLoop
115 RemoveFromPath_dosLoopEnd:
116 FileClose $2
117 FileClose $1
118 StrCpy $1 $WINDIR 2
119 Delete "$1\autoexec.bat"
120 CopyFiles /SILENT $4 "$1\autoexec.bat"
121 Delete $4
122 Goto RemoveFromPath_done
124 RemoveFromPath_NT:
125 StrLen $2 $0
126 ReadRegStr $1 HKCU "Environment" "PATH"
127 Push $1
128 Push $0
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.
136 StrLen $0 $1
137 StrCpy $1 $1 $0 $2
138 StrCpy $3 "$3$1"
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
147 RemoveFromPath_done:
148 Pop $5
149 Pop $4
150 Pop $3
151 Pop $2
152 Pop $1
153 Pop $0
154 FunctionEnd
155 !macroend
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 ;====================================================
167 !macro StrStr un
168 Function ${un}StrStr
169 Push $0
170 Exch
171 Pop $0 ; $0 now have the string to find
172 Push $1
173 Exch 2
174 Pop $1 ; $1 now have the string to find in
175 Exch
176 Push $2
177 Push $3
178 Push $4
179 Push $5
181 StrCpy $2 -1
182 StrLen $3 $0
183 StrLen $4 $1
184 IntOp $4 $4 - $3
186 StrStr_loop:
187 IntOp $2 $2 + 1
188 IntCmp $2 $4 0 0 StrStrReturn_notFound
189 StrCpy $5 $1 $3 $2
190 StrCmp $5 $0 StrStr_done StrStr_loop
192 StrStrReturn_notFound:
193 StrCpy $2 -1
195 StrStr_done:
196 Pop $5
197 Pop $4
198 Pop $3
199 Exch $2
200 Exch 2
201 Pop $0
202 Pop $1
203 FunctionEnd
204 !macroend
205 !insertmacro StrStr ""
206 !insertmacro StrStr "un."
208 ;====================================================
209 ; IsNT - Returns 1 if the current system is NT, 0
210 ; otherwise.
211 ; Output: head of the stack
212 ;====================================================
213 !macro IsNT un
214 Function ${un}IsNT
215 Push $0
216 ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
217 StrCmp $0 "" 0 IsNT_yes
218 ; we are not NT.
219 Pop $0
220 Push 0
221 Return
223 IsNT_yes:
224 ; NT!!!
225 Pop $0
226 Push 1
227 FunctionEnd
228 !macroend
229 !insertmacro IsNT ""
230 !insertmacro IsNT "un."