remove previous installation
[fw/sdcc] / support / scripts / sdcc.nsi
1 # sdcc.nsi - NSIS installer script for SDCC
2 #
3 # Copyright (c) 2003,2004 Borut Razem
4 #
5 # This file is part of sdcc.
6 #
7 #  This software is provided 'as-is', without any express or implied
8 #  warranty.  In no event will the authors be held liable for any damages
9 #  arising from the use of this software.
10 #
11 #  Permission is granted to anyone to use this software for any purpose,
12 #  including commercial applications, and to alter it and redistribute it
13 #  freely, subject to the following restrictions:
14 #
15 #  1. The origin of this software must not be misrepresented; you must not
16 #     claim that you wrote the original software. If you use this software
17 #     in a product, an acknowledgment in the product documentation would be
18 #     appreciated but is not required.
19 #  2. Altered source versions must be plainly marked as such, and must not be
20 #     misrepresented as being the original software.
21 #  3. This notice may not be removed or altered from any source distribution.
22 #
23 #  Borut Razem
24 #  borut.razem@siol.net
25
26 !include "MUI.nsh"
27
28 SetCompressor lzma
29
30 !define SDCC_ROOT "..\.."
31
32 !define FROM_SNAPSHOT
33
34 !ifdef FROM_SNAPSHOT
35 !system "dir ${SDCC_ROOT}\device > NUL" <> 0
36 !define DEV_ROOT "${SDCC_ROOT}"
37 !else
38 !system "dir ${SDCC_ROOT}\device > NUL" = 0
39 !define DEV_ROOT "${SDCC_ROOT}\device"
40 !endif
41
42 !system "unix2dos ${SDCC_ROOT}\doc\ChangeLog_head.txt" = 0
43 !system "unix2dos ${SDCC_ROOT}\doc\README.TXT" = 0
44
45 InstType "Full (Bin, Doc, Lib, Src)"
46 InstType "Medium (Bin, Doc, Lib)"
47 InstType "Compact (Bin, Doc)"
48
49 ;--------------------------------
50 ;Variables
51
52 Var MUI_STARTMENUPAGE_VARIABLE
53
54 ;--------------------------------
55 !define MUI_ABORTWARNING
56
57 !insertmacro MUI_PAGE_WELCOME
58 !insertmacro MUI_PAGE_LICENSE "${SDCC_ROOT}\COPYING.TXT"
59 !define MUI_STARTMENUPAGE_DEFAULTFOLDER "SDCC"
60 !define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKLM"
61 !define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC"
62 !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "NSIS:StartMenuDir"
63 !define MUI_STARTMENUPAGE_NODISABLE
64 !insertmacro MUI_PAGE_STARTMENU Application $MUI_STARTMENUPAGE_VARIABLE
65 !insertmacro MUI_PAGE_COMPONENTS
66 !insertmacro MUI_PAGE_DIRECTORY
67 !insertmacro MUI_PAGE_INSTFILES
68 !insertmacro MUI_PAGE_FINISH
69
70 !insertmacro MUI_UNPAGE_INSTFILES
71
72 !insertmacro MUI_LANGUAGE "English"
73
74 Name "SDCC"
75 BrandingText ""
76 OutFile "setup.exe"
77 InstallDir "$PROGRAMFILES\SDCC"
78 ShowInstDetails show
79 ShowUnInstDetails show
80
81 Function .onInit
82   ;Uninstall the old version, if present
83   ReadRegStr $R0 HKLM \
84   "Software\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" \
85   "UninstallString"
86   StrCmp $R0 "" inst
87
88   MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
89   "$(^Name) is already installed. $\n$\nClick `OK` to remove the \
90   previous version or `Cancel` to cancel this upgrade." \
91   IDOK uninst
92   Abort
93
94 uninst:
95   ;Run the uninstaller
96   ClearErrors
97   ExecWait '$R0 _?=$INSTDIR' ;Do not copy the uninstaller to a temp file
98
99   ;IfErrors no_remove_uninstaller
100   ;  ;You can either use Delete /REBOOTOK in the uninstaller or add some code
101   ;  ;here to remove to remove the uninstaller. Use a registry key to check
102   ;  ;whether the user has chosen to uninstall. If you are using an uninstaller
103   ;  ;components page, make sure all sections are uninstalled.
104   ;no_remove_uninstaller:
105
106   Goto done
107 inst:
108
109   ; install the new version
110   MessageBox MB_YESNO|MB_ICONQUESTION "This will install $(^Name). Do you wish to continue?" IDYES +2
111   Abort
112
113 done:
114 FunctionEnd
115
116 Section -Common
117   SetOutPath "$INSTDIR"
118   File ".\sdcc.ico"
119   File "${SDCC_ROOT}\COPYING.TXT"
120 SectionEnd
121
122 Section "SDCC application files"
123   SectionIn 1 2 3 RO
124   SetOutPath "$INSTDIR\bin"
125   File "${SDCC_ROOT}\bin\*.exe"
126 SectionEnd
127
128 Section "SDCC documentation"
129   SectionIn 1 2 3
130   SetOutPath "$INSTDIR\doc"
131   File "${SDCC_ROOT}\doc\ChangeLog_head.txt"
132   File "${SDCC_ROOT}\doc\README.TXT"
133 SectionEnd
134
135 Section "SDCC include files"
136   SectionIn 1 2
137   SetOutPath "$INSTDIR\include\asm\default"
138   File "${DEV_ROOT}\include\asm\default\features.h"
139   SetOutPath "$INSTDIR\include\asm\gbz80"
140   File "${DEV_ROOT}\include\asm\gbz80\features.h"
141   SetOutPath "$INSTDIR\include\asm\z80"
142   File "${DEV_ROOT}\include\asm\z80\features.h"
143   SetOutPath "$INSTDIR\include"
144   File "${DEV_ROOT}\include\*.h"
145 SectionEnd
146
147 Section "SDCC DS390 library"
148   SectionIn 1 2
149   SetOutPath "$INSTDIR\lib\ds390"
150   File "${DEV_ROOT}\lib\ds390\*.asm"
151   File "${DEV_ROOT}\lib\ds390\*.rel"
152   File "${DEV_ROOT}\lib\ds390\*.lib"
153 SectionEnd
154
155 Section "SDCC DS400 library"
156   SectionIn 1 2
157   SetOutPath "$INSTDIR\lib\ds400"
158   File "${DEV_ROOT}\lib\ds400\*.asm"
159   File "${DEV_ROOT}\lib\ds400\*.rel"
160   File "${DEV_ROOT}\lib\ds400\*.lib"
161 SectionEnd
162
163 Section "SDCC GBZ80 library"
164   SectionIn 1 2
165   SetOutPath "$INSTDIR\lib\gbz80"
166   File "${DEV_ROOT}\lib\gbz80\*.asm"
167   File "${DEV_ROOT}\lib\gbz80\*.o"
168   File "${DEV_ROOT}\lib\gbz80\*.lib"
169 SectionEnd
170
171 Section "SDCC Z80 library"
172   SectionIn 1 2
173   SetOutPath "$INSTDIR\lib\z80"
174   File "${DEV_ROOT}\lib\z80\*.asm"
175   File "${DEV_ROOT}\lib\z80\*.o"
176   File "${DEV_ROOT}\lib\z80\*.lib"
177 SectionEnd
178
179 Section "SDCC large model library"
180   SectionIn 1 2
181   SetOutPath "$INSTDIR\lib\large"
182   File "${DEV_ROOT}\lib\large\*.asm"
183   File "${DEV_ROOT}\lib\large\*.rel"
184   File "${DEV_ROOT}\lib\large\*.lib"
185 SectionEnd
186
187 Section "SDCC small model library"
188   SectionIn 1 2
189   SetOutPath "$INSTDIR\lib\small"
190   File "${DEV_ROOT}\lib\small\*.asm"
191   File "${DEV_ROOT}\lib\small\*.rel"
192   File "${DEV_ROOT}\lib\small\*.lib"
193 SectionEnd
194
195 Section "SDCC HC08 library"
196   SectionIn 1 2
197   SetOutPath "$INSTDIR\lib\hc08"
198   File "${DEV_ROOT}\lib\hc08\*.asm"
199   File "${DEV_ROOT}\lib\hc08\*.rel"
200   File "${DEV_ROOT}\lib\hc08\*.lib"
201 SectionEnd
202
203 Section "SDCC library sources"
204   SectionIn 1
205   SetOutPath "$INSTDIR\lib\src\ds390\examples"
206   File "${DEV_ROOT}\lib\src\ds390\examples\MOVED"
207
208   SetOutPath "$INSTDIR\lib\src\ds390"
209   File "${DEV_ROOT}\lib\src\ds390\*.c"
210   File "${DEV_ROOT}\lib\src\ds390\libds390.lib"
211   File "${DEV_ROOT}\lib\src\ds390\Makefile"
212   File "${DEV_ROOT}\lib\src\ds390\Makefile.dep"
213
214   SetOutPath "$INSTDIR\lib\src\ds400"
215   File "${DEV_ROOT}\lib\src\ds400\*.c"
216   File "${DEV_ROOT}\lib\src\ds400\libds400.lib"
217   File "${DEV_ROOT}\lib\src\ds400\Makefile"
218   File "${DEV_ROOT}\lib\src\ds400\Makefile.dep"
219
220   SetOutPath "$INSTDIR\lib\src\gbz80"
221   File "${DEV_ROOT}\lib\src\gbz80\*.c"
222   File "${DEV_ROOT}\lib\src\gbz80\*.s"
223   File "${DEV_ROOT}\lib\src\gbz80\gbz80.lib"
224   File "${DEV_ROOT}\lib\src\gbz80\Makefile"
225   File "${DEV_ROOT}\lib\src\gbz80\README"
226
227   SetOutPath "$INSTDIR\lib\src\z80"
228   File "${DEV_ROOT}\lib\src\z80\*.c"
229   File "${DEV_ROOT}\lib\src\z80\*.s"
230   File "${DEV_ROOT}\lib\src\z80\Makefile"
231   File "${DEV_ROOT}\lib\src\z80\README"
232   File "${DEV_ROOT}\lib\src\z80\z80.lib"
233
234   SetOutPath "$INSTDIR\lib\src\hc08"
235   File "${DEV_ROOT}\lib\src\hc08\*.c"
236   File "${DEV_ROOT}\lib\src\hc08\Makefile"
237   File "${DEV_ROOT}\lib\src\hc08\hc08.lib"
238
239   SetOutPath "$INSTDIR\lib\src"
240   File "${DEV_ROOT}\lib\src\*.c"
241 SectionEnd
242
243 Section -Icons
244 !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
245   CreateDirectory "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE"
246   CreateShortCut "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\SDCC on the Web.lnk" "$INSTDIR\sdcc.url" 
247   CreateShortCut "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Uninstall SDCC.lnk" "$INSTDIR\uninstall.exe" 
248   CreateShortCut "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Documentation.lnk" "$INSTDIR\doc\README.TXT" "" "$INSTDIR\sdcc.ico" "" "" "" ""
249   CreateShortCut "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Change Log.lnk" "$INSTDIR\doc\ChangeLog_head.txt" "" "$INSTDIR\sdcc.ico" "" "" "" ""
250   CreateShortCut "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\GPL 2 License.lnk" "$INSTDIR\COPYING.TXT" 
251 !insertmacro MUI_STARTMENU_WRITE_END
252 SectionEnd
253
254 Section -INI
255   WriteIniStr "$INSTDIR\sdcc.url" "InternetShortcut" "URL" "http://sdcc.sourceforge.net/"
256 SectionEnd
257
258 Section -PostInstall
259   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC" "DisplayName" "SDCC"
260   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC" "UninstallString" "$INSTDIR\uninstall.exe"
261   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC" "Publisher" "sdcc.sourceforge.net"
262   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC" "URLInfoAbout" "http://sdcc.sourceforge.net/"
263   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC" "HelpLink" "http://sdcc.sourceforge.net/"
264   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC" "URLUpdateInfo" "http://sdcc.sourceforge.net/"
265   WriteUninstaller "$INSTDIR\uninstall.exe"
266 SectionEnd
267
268 Section -AddToPath
269   MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Do you want to add $INSTDIR\bin to the PATH?" IDNO +3
270     Push "$INSTDIR\bin"
271     Call AddToPath
272 SectionEnd
273
274
275 ;;;; Uninstaller code ;;;;
276
277 Function un.onInit
278   MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to completely remove $(^Name) and all of its components?" IDYES +2
279   Abort
280 FunctionEnd
281
282 Function un.onUninstSuccess
283   HideWindow
284   MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) was successfully removed from your computer."
285 FunctionEnd
286
287 Section Uninstall
288   !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_STARTMENUPAGE_VARIABLE
289
290   Delete "$INSTDIR\sdcc.url"
291
292   DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC" "NSIS:StartMenuDir"
293   DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC"
294
295   Delete "$INSTDIR\uninstall.exe"
296   Delete "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\GPL 2 License.lnk"
297   Delete "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Change Log.lnk"
298   Delete "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Documentation.lnk"
299   Delete "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Uninstall SDCC.lnk"
300   Delete "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\SDCC on the Web.lnk"
301
302   Delete "$INSTDIR\lib\src\hc08\*.c"
303   Delete "$INSTDIR\lib\src\hc08\hc08.lib"
304   Delete "$INSTDIR\lib\src\hc08\Makefile"
305
306   Delete "$INSTDIR\lib\src\z80\*.c"
307   Delete "$INSTDIR\lib\src\z80\*.s"
308   Delete "$INSTDIR\lib\src\z80\z80.lib"
309   Delete "$INSTDIR\lib\src\z80\README"
310   Delete "$INSTDIR\lib\src\z80\Makefile"
311
312   Delete "$INSTDIR\lib\src\gbz80\*.c"
313   Delete "$INSTDIR\lib\src\gbz80\*.s"
314   Delete "$INSTDIR\lib\src\gbz80\gbz80.lib"
315   Delete "$INSTDIR\lib\src\gbz80\README"
316   Delete "$INSTDIR\lib\src\gbz80\Makefile"
317
318   Delete "$INSTDIR\lib\src\ds390\*.c"
319   Delete "$INSTDIR\lib\src\ds390\libds390.lib"
320   Delete "$INSTDIR\lib\src\ds390\Makefile.dep"
321   Delete "$INSTDIR\lib\src\ds390\Makefile"
322   Delete "$INSTDIR\lib\src\ds390\examples\MOVED"
323
324   Delete "$INSTDIR\lib\src\ds400\*.c"
325   Delete "$INSTDIR\lib\src\ds400\libds400.lib"
326   Delete "$INSTDIR\lib\src\ds400\Makefile.dep"
327   Delete "$INSTDIR\lib\src\ds400\Makefile"
328
329   Delete "$INSTDIR\lib\src\*.c"
330
331   Delete "$INSTDIR\lib\hc08\*.rel"
332   Delete "$INSTDIR\lib\hc08\*.asm"
333   Delete "$INSTDIR\lib\hc08\*.lib"
334
335   Delete "$INSTDIR\lib\z80\*.o"
336   Delete "$INSTDIR\lib\z80\*.asm"
337   Delete "$INSTDIR\lib\z80\*.lib"
338
339   Delete "$INSTDIR\lib\small\*.asm"
340   Delete "$INSTDIR\lib\small\*.rel"
341   Delete "$INSTDIR\lib\small\*.lib"
342
343   Delete "$INSTDIR\lib\large\*.asm"
344   Delete "$INSTDIR\lib\large\*.rel"
345   Delete "$INSTDIR\lib\large\*.lib"
346
347   Delete "$INSTDIR\lib\gbz80\*.asm"
348   Delete "$INSTDIR\lib\gbz80\*.o"
349   Delete "$INSTDIR\lib\gbz80\*.lib"
350
351   Delete "$INSTDIR\lib\ds390\*.asm"
352   Delete "$INSTDIR\lib\ds390\*.rel"
353   Delete "$INSTDIR\lib\ds390\*.lib"
354
355   Delete "$INSTDIR\lib\ds400\*.asm"
356   Delete "$INSTDIR\lib\ds400\*.rel"
357   Delete "$INSTDIR\lib\ds400\*.lib"
358
359   Delete "$INSTDIR\include\asm\z80\*.h"
360   Delete "$INSTDIR\include\asm\gbz80\*.h"
361   Delete "$INSTDIR\include\asm\default\*.h"
362   Delete "$INSTDIR\include\*.h"
363
364   Delete "$INSTDIR\doc\README.TXT"
365   Delete "$INSTDIR\doc\ChangeLog_head.txt"
366
367   Delete "$INSTDIR\bin\*.exe"
368
369   Delete "$INSTDIR\COPYING.TXT"
370   Delete "$INSTDIR\sdcc.ico"
371
372   RMDir "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE"
373
374   RMDir "$INSTDIR\lib\src\z80"
375   RMDir "$INSTDIR\lib\src\gbz80"
376   RMDir "$INSTDIR\lib\src\ds390\examples"
377   RMDir "$INSTDIR\lib\src\ds390"
378   RMDir "$INSTDIR\lib\src\ds400"
379   RMDir "$INSTDIR\lib\src\hc08"
380   RMDir "$INSTDIR\lib\src"
381
382   RMDir "$INSTDIR\lib\z80"
383   RMDir "$INSTDIR\lib\small"
384   RMDir "$INSTDIR\lib\large"
385   RMDir "$INSTDIR\lib\gbz80"
386   RMDir "$INSTDIR\lib\ds390"
387   RMDir "$INSTDIR\lib\ds400"
388   RMDir "$INSTDIR\lib\hc08"
389   RMDir "$INSTDIR\lib"
390
391   RMDir "$INSTDIR\include\asm\z80"
392   RMDir "$INSTDIR\include\asm\gbz80"
393   RMDir "$INSTDIR\include\asm\default"
394   RMDir "$INSTDIR\include\asm"
395   RMDir "$INSTDIR\include"
396
397   RMDir "$INSTDIR\doc"
398
399   RMDir "$INSTDIR\bin"
400
401   RMDir "$INSTDIR"
402
403   Push "$INSTDIR\bin"
404   Call un.RemoveFromPath
405
406   SetAutoClose true
407 SectionEnd
408
409 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
410 ; Path Manipulation functions                                                 ;
411 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
412
413 !verbose 3
414 !include "WinMessages.NSH"
415 !verbose 4
416
417 ; AddToPath - Adds the given dir to the search path.
418 ;        Input - head of the stack
419 ;        Note - Win9x systems requires reboot
420
421 Function AddToPath
422   Exch $0
423   Push $1
424   Push $2
425   Push $3
426   Push $4
427
428   ; don't add if the path doesn't exist
429   IfFileExists $0 "" AddToPath_done
430
431   Call IsNT
432   Pop $4
433   StrCmp $4 1 +3
434     ; Not on NT: read PATH from environment variable
435     ReadEnvStr $1 PATH
436     Goto +2
437     ; On NT: read PATH from registry
438     ReadRegStr $1 HKCU "Environment" "PATH"
439   Push "$1;"
440   Push "$0;"
441   Call StrStr
442   Pop $2
443   StrCmp $2 "" "" AddToPath_done
444   Push "$1;"
445   Push "$0\;"
446   Call StrStr
447   Pop $2
448   StrCmp $2 "" "" AddToPath_done
449   GetFullPathName /SHORT $3 $0
450   Push "$1;"
451   Push "$3;"
452   Call StrStr
453   Pop $2
454   StrCmp $2 "" "" AddToPath_done
455   Push "$1;"
456   Push "$3\;"
457   Call StrStr
458   Pop $2
459   StrCmp $2 "" "" AddToPath_done
460
461   StrCmp $4 1 AddToPath_NT
462     ; Not on NT
463     StrCpy $1 $WINDIR 2
464     FileOpen $1 "$1\autoexec.bat" a
465     FileSeek $1 -1 END
466     FileReadByte $1 $2
467     IntCmp $2 26 0 +2 +2 ; DOS EOF
468       FileSeek $1 -1 END ; write over EOF
469     FileWrite $1 "$\r$\nSET PATH=%PATH%;$3$\r$\n"
470     FileClose $1
471     SetRebootFlag true
472     Goto AddToPath_done
473
474   AddToPath_NT:
475     ReadRegStr $1 HKCU "Environment" "PATH"
476     StrCpy $2 $1 1 -1  ; copy last char
477     StrCmp $2 ";" 0 +2 ; if last char == ;
478       StrCpy $1 $1 -1  ; remove last char
479     StrCmp $1 "" AddToPath_NTdoIt
480       StrCpy $0 "$1;$0"
481     AddToPath_NTdoIt:
482       WriteRegExpandStr HKCU "Environment" "PATH" $0
483       SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
484
485   AddToPath_done:
486     Pop $4
487     Pop $3
488     Pop $2
489     Pop $1
490     Pop $0
491 FunctionEnd
492
493 ; RemoveFromPath - Remove a given dir from the path
494 ;     Input: head of the stack
495
496 Function un.RemoveFromPath
497   Exch $0
498   Push $1
499   Push $2
500   Push $3
501   Push $4
502   Push $5
503   Push $6
504
505   IntFmt $6 "%c" 26 ; DOS EOF
506
507   Call un.IsNT
508   Pop $1
509   StrCmp $1 1 unRemoveFromPath_NT
510     ; Not on NT
511     StrCpy $1 $WINDIR 2
512     FileOpen $1 "$1\autoexec.bat" r
513     GetTempFileName $4
514     FileOpen $2 $4 w
515     GetFullPathName /SHORT $0 $0
516     StrCpy $0 "SET PATH=%PATH%;$0"
517     Goto unRemoveFromPath_dosLoop
518
519     unRemoveFromPath_dosLoop:
520       FileRead $1 $3
521       StrCpy $5 $3 1 -1 ; read last char
522       StrCmp $5 $6 0 +2 ; if DOS EOF
523         StrCpy $3 $3 -1 ; remove DOS EOF so we can compare
524       StrCmp $3 "$0$\r$\n" unRemoveFromPath_dosLoopRemoveLine
525       StrCmp $3 "$0$\n" unRemoveFromPath_dosLoopRemoveLine
526       StrCmp $3 "$0" unRemoveFromPath_dosLoopRemoveLine
527       StrCmp $3 "" unRemoveFromPath_dosLoopEnd
528       FileWrite $2 $3
529       Goto unRemoveFromPath_dosLoop
530       unRemoveFromPath_dosLoopRemoveLine:
531         SetRebootFlag true
532         Goto unRemoveFromPath_dosLoop
533
534     unRemoveFromPath_dosLoopEnd:
535       FileClose $2
536       FileClose $1
537       StrCpy $1 $WINDIR 2
538       Delete "$1\autoexec.bat"
539       CopyFiles /SILENT $4 "$1\autoexec.bat"
540       Delete $4
541       Goto unRemoveFromPath_done
542
543   unRemoveFromPath_NT:
544     ReadRegStr $1 HKCU "Environment" "PATH"
545     StrCpy $5 $1 1 -1 ; copy last char
546     StrCmp $5 ";" +2  ; if last char != ;
547       StrCpy $1 "$1;" ; append ;
548     Push $1
549     Push "$0;"
550     Call un.StrStr    ; Find `$0;` in $1
551     Pop $2            ; pos of our dir
552     StrCmp $2 "" unRemoveFromPath_done
553       ; else, it is in path
554       ; $0 - path to add
555       ; $1 - path var
556       StrLen $3 "$0;"
557       StrLen $4 $2
558       StrCpy $5 $1 -$4   ; $5 is now the part before the path to remove
559       StrCpy $6 $2 "" $3 ; $6 is now the part after the path to remove
560       StrCpy $3 $5$6
561
562       StrCpy $5 $3 1 -1  ; copy last char
563       StrCmp $5 ";" 0 +2 ; if last char == ;
564         StrCpy $3 $3 -1  ; remove last char
565
566       StrCmp $3 "" +3
567         ; New PATH not empty: update the registry
568         WriteRegExpandStr HKCU "Environment" "PATH" $3
569         Goto +2
570         ; New PATH empty: remove from the registry
571         DeleteRegValue HKCU "Environment" "PATH"
572       SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
573
574   unRemoveFromPath_done:
575     Pop $6
576     Pop $5
577     Pop $4
578     Pop $3
579     Pop $2
580     Pop $1
581     Pop $0
582 FunctionEnd
583
584 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
585 ;            Utility Functions            ;
586 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
587
588 ; IsNT
589 ; no input
590 ; output, top of the stack = 1 if NT or 0 if not
591 ;
592 ; Usage:
593 ;   Call IsNT
594 ;   Pop $R0
595 ;  ($R0 at this point is 1 or 0)
596
597 !macro IsNT un
598 Function ${un}IsNT
599   Push $0
600   ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
601   StrCmp $0 "" 0 IsNT_yes
602   ; we are not NT.
603   Pop $0
604   Push 0
605   Return
606
607   IsNT_yes:
608     ; NT!!!
609     Pop $0
610     Push 1
611 FunctionEnd
612 !macroend
613 !insertmacro IsNT ""
614 !insertmacro IsNT "un."
615
616 ; StrStr
617 ; input, top of stack = string to search for
618 ;        top of stack-1 = string to search in
619 ; output, top of stack (replaces with the portion of the string remaining)
620 ; modifies no other variables.
621 ;
622 ; Usage:
623 ;   Push "this is a long ass string"
624 ;   Push "ass"
625 ;   Call StrStr
626 ;   Pop $R0
627 ;  ($R0 at this point is "ass string")
628
629 !macro StrStr un
630 Function ${un}StrStr
631 Exch $R1   ; st=haystack,old$R1, $R1=needle
632   Exch     ; st=old$R1,haystack
633   Exch $R2 ; st=old$R1,old$R2, $R2=haystack
634   Push $R3
635   Push $R4
636   Push $R5
637   StrLen $R3 $R1
638   StrCpy $R4 0
639   ; $R1=needle
640   ; $R2=haystack
641   ; $R3=len(needle)
642   ; $R4=cnt
643   ; $R5=tmp
644   loop:
645     StrCpy $R5 $R2 $R3 $R4
646     StrCmp $R5 $R1 done
647     StrCmp $R5 "" done
648     IntOp $R4 $R4 + 1
649     Goto loop
650 done:
651   StrCpy $R1 $R2 "" $R4
652   Pop $R5
653   Pop $R4
654   Pop $R3
655   Pop $R2
656   Exch $R1
657 FunctionEnd
658 !macroend
659 !insertmacro StrStr ""
660 !insertmacro StrStr "un."
661