]>
Commit | Line | Data |
---|---|---|
4d59bff9 GG |
1 | ; |
2 | ; installer.nsi - NSIS install script for smartmontools | |
3 | ; | |
4 | ; Copyright (C) 2006 Christian Franke <smartmontools-support@lists.sourceforge.net> | |
5 | ; | |
6 | ; Project home page is: http://smartmontools.sourceforge.net | |
7 | ; | |
8 | ; Download and install NSIS from: http://nsis.sourceforge.net/Download | |
9 | ; Process with makensis to create installer (tested with NSIS 2.17). | |
10 | ; | |
11 | ; $Id: installer.nsi,v 1.2 2006/07/17 20:51:22 chrfranke Exp $ | |
12 | ; | |
13 | ||
14 | ||
15 | ;-------------------------------------------------------------------- | |
16 | ; Command line arguments: | |
17 | ; makensis /DINPDIR=<input-dir> /DOUTFILE=<output-file> installer.nsi | |
18 | ||
19 | !ifndef INPDIR | |
20 | !define INPDIR "." | |
21 | !endif | |
22 | ||
23 | !ifndef OUTFILE | |
24 | !define OUTFILE "smartmontools.win32-setup.exe" | |
25 | !endif | |
26 | ||
27 | ;-------------------------------------------------------------------- | |
28 | ; General | |
29 | ||
30 | Name "smartmontools" | |
31 | OutFile "${OUTFILE}" | |
32 | ||
33 | SetCompressor /solid lzma | |
34 | ||
35 | XPStyle on | |
36 | InstallColors /windows | |
37 | ||
38 | InstallDir "$PROGRAMFILES\smartmontools" | |
39 | InstallDirRegKey HKLM "Software\smartmontools" "Install_Dir" | |
40 | ||
41 | LicenseData "${INPDIR}\doc\COPYING.txt" | |
42 | ||
43 | ;-------------------------------------------------------------------- | |
44 | ; Pages | |
45 | ||
46 | Page license | |
47 | Page components | |
48 | Page directory | |
49 | Page instfiles | |
50 | ||
51 | UninstPage uninstConfirm | |
52 | UninstPage instfiles | |
53 | ||
54 | InstType "Full" | |
55 | InstType "Extract files only" | |
56 | ||
57 | ||
58 | ;-------------------------------------------------------------------- | |
59 | ; Sections | |
60 | ||
61 | SectionGroup "Program files" | |
62 | ||
63 | Section "smartctl" | |
64 | ||
65 | SectionIn 1 2 | |
66 | ||
67 | SetOutPath "$INSTDIR\bin" | |
68 | File "${INPDIR}\bin\smartctl.exe" | |
69 | ||
70 | SectionEnd | |
71 | ||
72 | Section "smartd" | |
73 | ||
74 | SectionIn 1 2 | |
75 | ||
76 | SetOutPath "$INSTDIR\bin" | |
77 | File "${INPDIR}\bin\smartd.exe" | |
78 | ||
79 | IfFileExists "$INSTDIR\bin\smartd.conf" 0 +2 | |
80 | MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Replace existing configuration file$\n$INSTDIR\bin\smartd.conf ?" IDYES 0 IDNO +2 | |
81 | File "${INPDIR}\doc\smartd.conf" | |
82 | ||
83 | IfFileExists "$WINDIR\system32\cmd.exe" 0 +2 | |
84 | File /nonfatal "${INPDIR}\bin\syslogevt.exe" | |
85 | ||
86 | SectionEnd | |
87 | ||
88 | SectionGroupEnd | |
89 | ||
90 | Section "Documentation" | |
91 | ||
92 | SectionIn 1 2 | |
93 | ||
94 | SetOutPath "$INSTDIR\doc" | |
95 | File "${INPDIR}\doc\AUTHORS.txt" | |
96 | File "${INPDIR}\doc\CHANGELOG.txt" | |
97 | File "${INPDIR}\doc\COPYING.txt" | |
98 | File "${INPDIR}\doc\INSTALL.txt" | |
99 | File "${INPDIR}\doc\NEWS.txt" | |
100 | File "${INPDIR}\doc\README.txt" | |
101 | File "${INPDIR}\doc\TODO.txt" | |
102 | File "${INPDIR}\doc\WARNINGS.txt" | |
103 | File "${INPDIR}\doc\smartctl.8.html" | |
104 | File "${INPDIR}\doc\smartctl.8.txt" | |
105 | File "${INPDIR}\doc\smartd.8.html" | |
106 | File "${INPDIR}\doc\smartd.8.txt" | |
107 | File "${INPDIR}\doc\smartd.conf" | |
108 | File "${INPDIR}\doc\smartd.conf.5.html" | |
109 | File "${INPDIR}\doc\smartd.conf.5.txt" | |
110 | ||
111 | SectionEnd | |
112 | ||
113 | Section "Uninstaller" | |
114 | ||
115 | SectionIn 1 | |
116 | AddSize 35 | |
117 | ||
118 | CreateDirectory "$INSTDIR" | |
119 | ||
120 | ; Save installation location | |
121 | WriteRegStr HKLM "Software\smartmontools" "Install_Dir" "$INSTDIR" | |
122 | ||
123 | ; Write uninstall keys and program | |
124 | WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "DisplayName" "smartmontools" | |
125 | WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "UninstallString" '"$INSTDIR\uninst-smartmontools.exe"' | |
126 | WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "NoModify" 1 | |
127 | WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "NoRepair" 1 | |
128 | WriteUninstaller "uninst-smartmontools.exe" | |
129 | ||
130 | SectionEnd | |
131 | ||
132 | Section "Start Menu Shortcuts" | |
133 | ||
134 | SectionIn 1 | |
135 | ||
136 | CreateDirectory "$SMPROGRAMS\smartmontools" | |
137 | ||
138 | ; smartctl | |
139 | IfFileExists "$INSTDIR\bin\smartctl.exe" 0 noctl | |
140 | SetOutPath "$INSTDIR\bin" | |
141 | DetailPrint "Create file: $INSTDIR\bin\smartctl-run.bat" | |
142 | FileOpen $0 "$INSTDIR\bin\smartctl-run.bat" "w" | |
143 | FileWrite $0 "@echo off$\r$\necho smartctl %1 %2 %3 %4 %5$\r$\nsmartctl %1 %2 %3 %4 %5$\r$\npause$\r$\n" | |
144 | FileClose $0 | |
145 | CreateDirectory "$SMPROGRAMS\smartmontools\smartctl Examples" | |
146 | FileOpen $0 "$SMPROGRAMS\smartmontools\smartctl Examples\!Read this first!.txt" "w" | |
147 | FileWrite $0 "All the example commands in this directory$\r$\napply to the first IDE/ATA/SATA drive (hda).$\r$\n" | |
148 | FileClose $0 | |
149 | CreateShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\All info (-a).lnk" "$INSTDIR\bin\smartctl-run.bat" "-a hda" | |
150 | CreateShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\Identify drive (-i).lnk" "$INSTDIR\bin\smartctl-run.bat" "-i hda" | |
151 | CreateShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\SMART attributes (-A).lnk" "$INSTDIR\bin\smartctl-run.bat" "-A hda" | |
152 | CreateShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\SMART capabilities (-c).lnk" "$INSTDIR\bin\smartctl-run.bat" "-c hda" | |
153 | CreateShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\SMART health status (-H).lnk" "$INSTDIR\bin\smartctl-run.bat" "-H hda" | |
154 | CreateShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\SMART error log (-l error).lnk" "$INSTDIR\bin\smartctl-run.bat" "-l error hda" | |
155 | CreateShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\SMART selftest log (-l selftest).lnk" "$INSTDIR\bin\smartctl-run.bat" "-l selftest hda" | |
156 | CreateShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\Start long selftest (-t long).lnk" "$INSTDIR\bin\smartctl-run.bat" "-t long hda" | |
157 | CreateShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\Start offline test (-t offline).lnk" "$INSTDIR\bin\smartctl-run.bat" "-t offline hda" | |
158 | CreateShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\Start short selftest (-t short).lnk" "$INSTDIR\bin\smartctl-run.bat" "-t short hda" | |
159 | CreateShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\Stop(Abort) selftest (-X).lnk" "$INSTDIR\bin\smartctl-run.bat" "-X hda" | |
160 | CreateShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\Turn SMART off (-s off).lnk" "$INSTDIR\bin\smartctl-run.bat" "-s off hda" | |
161 | CreateShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\Turn SMART on (-s on).lnk" "$INSTDIR\bin\smartctl-run.bat" "-s on hda" | |
162 | noctl: | |
163 | ||
164 | ; smartd | |
165 | IfFileExists "$INSTDIR\bin\smartd.exe" 0 nod | |
166 | SetOutPath "$INSTDIR\bin" | |
167 | DetailPrint "Create file: $INSTDIR\bin\smartd-run.bat" | |
168 | FileOpen $0 "$INSTDIR\bin\smartd-run.bat" "w" | |
169 | FileWrite $0 "@echo off$\r$\necho smartd %1 %2 %3 %4 %5$\r$\nsmartd %1 %2 %3 %4 %5$\r$\npause$\r$\n" | |
170 | FileClose $0 | |
171 | CreateDirectory "$SMPROGRAMS\smartmontools\smartd Examples" | |
172 | CreateShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Daemon start, log to smartd.log.lnk" "$INSTDIR\bin\smartd-run.bat" "-l local0" | |
173 | IfFileExists "$WINDIR\system32\cmd.exe" 0 +2 | |
174 | CreateShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Daemon start, log to eventlog.lnk" "$INSTDIR\bin\smartd-run.bat" "" | |
175 | CreateShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Daemon stop.lnk" "$INSTDIR\bin\smartd-run.bat" "stop" | |
176 | CreateShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Do all tests once (-q onecheck).lnk" "$INSTDIR\bin\smartd-run.bat" "-q onecheck" | |
177 | CreateShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Debug mode (-d).lnk" "$INSTDIR\bin\smartd-run.bat" "-d" | |
178 | IfFileExists "$WINDIR\notepad.exe" 0 nopad | |
179 | CreateShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Edit smartd.conf.lnk" "$WINDIR\notepad.exe" "$INSTDIR\bin\smartd.conf" | |
180 | CreateShortCut "$SMPROGRAMS\smartmontools\smartd Examples\View smartd.log.lnk" "$WINDIR\notepad.exe" "$INSTDIR\bin\smartd.log" | |
181 | nopad: | |
182 | ||
183 | ; smartd service (not on 9x/ME) | |
184 | IfFileExists "$WINDIR\system32\cmd.exe" 0 nosvc | |
185 | CreateShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Service install, log to eventlog.lnk" "$INSTDIR\bin\smartd-run.bat" "install" | |
186 | CreateShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Service install, log to smartd.log.lnk" "$INSTDIR\bin\smartd-run.bat" "install -l local0" | |
187 | CreateShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Service remove.lnk" "$INSTDIR\bin\smartd-run.bat" "remove" | |
188 | DetailPrint "Create file: $INSTDIR\bin\net-run.bat" | |
189 | FileOpen $0 "$INSTDIR\bin\net-run.bat" "w" | |
190 | FileWrite $0 "@echo off$\r$\necho net %1 %2 %3 %4 %5$\r$\nnet %1 %2 %3 %4 %5$\r$\npause$\r$\n" | |
191 | FileClose $0 | |
192 | CreateShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Service start.lnk" "$INSTDIR\bin\net-run.bat" "start smartd" | |
193 | CreateShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Service stop.lnk" "$INSTDIR\bin\net-run.bat" "stop smartd" | |
194 | nosvc: | |
195 | nod: | |
196 | ||
197 | ; Documentation | |
198 | IfFileExists "$INSTDIR\doc\README.TXT" 0 nodoc | |
199 | SetOutPath "$INSTDIR\doc" | |
200 | CreateDirectory "$SMPROGRAMS\smartmontools\Documentation" | |
201 | CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\smartctl manual page (html).lnk" "$INSTDIR\doc\smartctl.8.html" | |
202 | CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\smartd manual page (html).lnk" "$INSTDIR\doc\smartd.8.html" | |
203 | CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\smartd.conf manual page (html).lnk" "$INSTDIR\doc\smartd.conf.5.html" | |
204 | CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\smartctl manual page (txt).lnk" "$INSTDIR\doc\smartctl.8.txt" | |
205 | CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\smartd manual page (txt).lnk" "$INSTDIR\doc\smartd.8.txt" | |
206 | CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\smartd.conf manual page (txt).lnk" "$INSTDIR\doc\smartd.conf.5.txt" | |
207 | IfFileExists "$WINDIR\notepad.exe" 0 +2 | |
208 | CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\smartd.conf sample.lnk" "$WINDIR\notepad.exe" "$INSTDIR\doc\smartd.conf" | |
209 | CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\AUTHORS.lnk" "$INSTDIR\doc\AUTHORS.txt" | |
210 | CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\CHANGELOG.lnk" "$INSTDIR\doc\CHANGELOG.txt" | |
211 | CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\COPYING.lnk" "$INSTDIR\doc\COPYING.txt" | |
212 | CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\INSTALL.lnk" "$INSTDIR\doc\INSTALL.txt" | |
213 | CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\NEWS.lnk" "$INSTDIR\doc\NEWS.txt" | |
214 | CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\README.lnk" "$INSTDIR\doc\README.txt" | |
215 | CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\TODO.lnk" "$INSTDIR\doc\TODO.txt" | |
216 | CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\WARNINGS.lnk" "$INSTDIR\doc\WARNINGS.txt" | |
217 | nodoc: | |
218 | ||
219 | ; Homepage | |
220 | CreateShortCut "$SMPROGRAMS\smartmontools\smartmontools Home Page.lnk" "http://smartmontools.sourceforge.net/" | |
221 | ||
222 | ; Uninstall | |
223 | IfFileExists "$INSTDIR\uninst-smartmontools.exe" 0 +2 | |
224 | CreateShortCut "$SMPROGRAMS\smartmontools\Uninstall smartmontools.lnk" "$INSTDIR\uninst-smartmontools.exe" | |
225 | ||
226 | SectionEnd | |
227 | ||
228 | Section "Add install dir to PATH" PATH_IDX | |
229 | ||
230 | SectionIn 1 | |
231 | ||
232 | IfFileExists "$WINDIR\system32\cmd.exe" 0 +3 | |
233 | Push "$INSTDIR\bin" | |
234 | Call AddToPath | |
235 | ||
236 | SectionEnd | |
237 | ||
238 | ;-------------------------------------------------------------------- | |
239 | ||
240 | Section "Uninstall" | |
241 | ||
242 | ; Remove registry keys | |
243 | DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" | |
244 | DeleteRegKey HKLM "Software\smartmontools" | |
245 | ||
246 | IfFileExists "$INSTDIR\bin\smartd.conf" 0 noconf | |
247 | ; Assume unchanged if timestamp is equal to sample file | |
248 | GetFileTime "$INSTDIR\bin\smartd.conf" $0 $1 | |
249 | GetFileTime "$INSTDIR\doc\smartd.conf" $2 $3 | |
250 | StrCmp "$0:$1" "$2:$3" +2 0 | |
251 | MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Delete configuration file$\n$INSTDIR\bin\smartd.conf ?" IDYES 0 IDNO noconf | |
252 | Delete "$INSTDIR\bin\smartd.conf" | |
253 | noconf: | |
254 | ||
255 | IfFileExists "$INSTDIR\bin\smartd.log" 0 +3 | |
256 | MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Delete log file$\n$INSTDIR\bin\smartd.log ?" IDYES 0 IDNO +2 | |
257 | Delete "$INSTDIR\bin\smartd.log" | |
258 | ||
259 | ; Remove files | |
260 | Delete "$INSTDIR\bin\smartctl.exe" | |
261 | Delete "$INSTDIR\bin\smartd.exe" | |
262 | Delete "$INSTDIR\bin\syslogevt.exe" | |
263 | Delete "$INSTDIR\bin\smartctl-run.bat" | |
264 | Delete "$INSTDIR\bin\smartd-run.bat" | |
265 | Delete "$INSTDIR\bin\net-run.bat" | |
266 | Delete "$INSTDIR\doc\AUTHORS.txt" | |
267 | Delete "$INSTDIR\doc\CHANGELOG.txt" | |
268 | Delete "$INSTDIR\doc\COPYING.txt" | |
269 | Delete "$INSTDIR\doc\INSTALL.txt" | |
270 | Delete "$INSTDIR\doc\NEWS.txt" | |
271 | Delete "$INSTDIR\doc\README.txt" | |
272 | Delete "$INSTDIR\doc\TODO.txt" | |
273 | Delete "$INSTDIR\doc\WARNINGS.txt" | |
274 | Delete "$INSTDIR\doc\smartctl.8.html" | |
275 | Delete "$INSTDIR\doc\smartctl.8.txt" | |
276 | Delete "$INSTDIR\doc\smartd.8.html" | |
277 | Delete "$INSTDIR\doc\smartd.8.txt" | |
278 | Delete "$INSTDIR\doc\smartd.conf" | |
279 | Delete "$INSTDIR\doc\smartd.conf.5.html" | |
280 | Delete "$INSTDIR\doc\smartd.conf.5.txt" | |
281 | Delete "$INSTDIR\uninst-smartmontools.exe" | |
282 | ||
283 | ; Remove shortcuts | |
284 | Delete "$SMPROGRAMS\smartmontools\*.*" | |
285 | Delete "$SMPROGRAMS\smartmontools\Documentation\*.*" | |
286 | Delete "$SMPROGRAMS\smartmontools\smartctl Examples\*.*" | |
287 | Delete "$SMPROGRAMS\smartmontools\smartd Examples\*.*" | |
288 | ||
289 | ; Remove folders | |
290 | RMDir "$SMPROGRAMS\smartmontools\Documentation" | |
291 | RMDir "$SMPROGRAMS\smartmontools\smartctl Examples\" | |
292 | RMDir "$SMPROGRAMS\smartmontools\smartd Examples\" | |
293 | RMDir "$SMPROGRAMS\smartmontools" | |
294 | RMDir "$INSTDIR\bin" | |
295 | RMDir "$INSTDIR\doc" | |
296 | RMDir "$INSTDIR" | |
297 | ||
298 | ; Remove install dir from PATH | |
299 | IfFileExists "$WINDIR\system32\cmd.exe" 0 +3 | |
300 | Push "$INSTDIR\bin" | |
301 | Call un.RemoveFromPath | |
302 | ||
303 | ; Check for still existing files | |
304 | IfFileExists "$INSTDIR\bin\smartd.exe" 0 +3 | |
305 | MessageBox MB_OK|MB_ICONEXCLAMATION "$INSTDIR\bin\smartd.exe could not be removed.$\nsmartd is possibly still running." | |
306 | Goto +3 | |
307 | IfFileExists "$INSTDIR" 0 +2 | |
308 | MessageBox MB_OK "Note: $INSTDIR could not be removed." | |
309 | ||
310 | SectionEnd | |
311 | ||
312 | ;-------------------------------------------------------------------- | |
313 | ||
314 | Function .onInit | |
315 | ||
316 | ; Hide "Add install dir to PATH" on 9x/ME | |
317 | IfFileExists "$WINDIR\system32\cmd.exe" +2 0 | |
318 | SectionSetText ${PATH_IDX} "" | |
319 | ||
320 | FunctionEnd | |
321 | ||
322 | ||
323 | ;-------------------------------------------------------------------- | |
324 | ; Utility functions | |
325 | ; | |
326 | ; Based on example from: | |
327 | ; http://nsis.sourceforge.net/Path_Manipulation | |
328 | ; | |
329 | ||
330 | ||
331 | !include "WinMessages.nsh" | |
332 | ||
333 | ; Registry Entry for environment (NT4,2000,XP) | |
334 | ; All users: | |
335 | ;!define Environ 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"' | |
336 | ; Current user only: | |
337 | !define Environ 'HKCU "Environment"' | |
338 | ||
339 | ||
340 | ; AddToPath - Appends dir to PATH | |
341 | ; (does not work on Win9x/ME) | |
342 | ; | |
343 | ; Usage: | |
344 | ; Push "dir" | |
345 | ; Call AddToPath | |
346 | ||
347 | Function AddToPath | |
348 | Exch $0 | |
349 | Push $1 | |
350 | Push $2 | |
351 | Push $3 | |
352 | ||
353 | ReadRegStr $1 ${Environ} "PATH" | |
354 | Push "$1;" | |
355 | Push "$0;" | |
356 | Call StrStr | |
357 | Pop $2 | |
358 | StrCmp $2 "" "" done | |
359 | Push "$1;" | |
360 | Push "$0\;" | |
361 | Call StrStr | |
362 | Pop $2 | |
363 | StrCmp $2 "" "" done | |
364 | ||
365 | DetailPrint "Add to PATH: $0" | |
366 | StrCpy $2 $1 1 -1 | |
367 | StrCmp $2 ";" 0 +2 | |
368 | StrCpy $1 $1 -1 ; remove trailing ';' | |
369 | StrCmp $1 "" +2 ; no leading ';' | |
370 | StrCpy $0 "$1;$0" | |
371 | WriteRegExpandStr ${Environ} "PATH" $0 | |
372 | SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000 | |
373 | ||
374 | done: | |
375 | Pop $3 | |
376 | Pop $2 | |
377 | Pop $1 | |
378 | Pop $0 | |
379 | FunctionEnd | |
380 | ||
381 | ||
382 | ; RemoveFromPath - Removes dir from PATH | |
383 | ; | |
384 | ; Usage: | |
385 | ; Push "dir" | |
386 | ; Call RemoveFromPath | |
387 | ||
388 | Function un.RemoveFromPath | |
389 | Exch $0 | |
390 | Push $1 | |
391 | Push $2 | |
392 | Push $3 | |
393 | Push $4 | |
394 | Push $5 | |
395 | Push $6 | |
396 | ||
397 | ReadRegStr $1 ${Environ} "PATH" | |
398 | StrCpy $5 $1 1 -1 | |
399 | StrCmp $5 ";" +2 | |
400 | StrCpy $1 "$1;" ; ensure trailing ';' | |
401 | Push $1 | |
402 | Push "$0;" | |
403 | Call un.StrStr | |
404 | Pop $2 ; pos of our dir | |
405 | StrCmp $2 "" done | |
406 | ||
407 | DetailPrint "Remove from PATH: $0" | |
408 | StrLen $3 "$0;" | |
409 | StrLen $4 $2 | |
410 | StrCpy $5 $1 -$4 ; $5 is now the part before the path to remove | |
411 | StrCpy $6 $2 "" $3 ; $6 is now the part after the path to remove | |
412 | StrCpy $3 "$5$6" | |
413 | StrCpy $5 $3 1 -1 | |
414 | StrCmp $5 ";" 0 +2 | |
415 | StrCpy $3 $3 -1 ; remove trailing ';' | |
416 | WriteRegExpandStr ${Environ} "PATH" $3 | |
417 | SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000 | |
418 | ||
419 | done: | |
420 | Pop $6 | |
421 | Pop $5 | |
422 | Pop $4 | |
423 | Pop $3 | |
424 | Pop $2 | |
425 | Pop $1 | |
426 | Pop $0 | |
427 | FunctionEnd | |
428 | ||
429 | ||
430 | ; StrStr - find substring in a string | |
431 | ; | |
432 | ; Usage: | |
433 | ; Push "this is some string" | |
434 | ; Push "some" | |
435 | ; Call StrStr | |
436 | ; Pop $0 ; "some string" | |
437 | ||
438 | !macro StrStr un | |
439 | Function ${un}StrStr | |
440 | Exch $R1 ; $R1=substring, stack=[old$R1,string,...] | |
441 | Exch ; stack=[string,old$R1,...] | |
442 | Exch $R2 ; $R2=string, stack=[old$R2,old$R1,...] | |
443 | Push $R3 | |
444 | Push $R4 | |
445 | Push $R5 | |
446 | StrLen $R3 $R1 | |
447 | StrCpy $R4 0 | |
448 | ; $R1=substring, $R2=string, $R3=strlen(substring) | |
449 | ; $R4=count, $R5=tmp | |
450 | loop: | |
451 | StrCpy $R5 $R2 $R3 $R4 | |
452 | StrCmp $R5 $R1 done | |
453 | StrCmp $R5 "" done | |
454 | IntOp $R4 $R4 + 1 | |
455 | Goto loop | |
456 | done: | |
457 | StrCpy $R1 $R2 "" $R4 | |
458 | Pop $R5 | |
459 | Pop $R4 | |
460 | Pop $R3 | |
461 | Pop $R2 | |
462 | Exch $R1 ; $R1=old$R1, stack=[result,...] | |
463 | FunctionEnd | |
464 | !macroend | |
465 | !insertmacro StrStr "" | |
466 | !insertmacro StrStr "un." |