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