* support/scripts/sdcc.nsi: added include/pic16/*.h to the setup package
[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\gbz80"
158   File "${DEV_ROOT}\include\asm\gbz80\features.h"
159   SetOutPath "$INSTDIR\include\asm\pic16"
160   File "${DEV_ROOT}\include\asm\pic16\features.h"
161   SetOutPath "$INSTDIR\include\asm\z80"
162   File "${DEV_ROOT}\include\asm\z80\features.h"
163   SetOutPath "$INSTDIR\include\pic16"
164   File "${DEV_ROOT}\include\pic16\*.h"
165   SetOutPath "$INSTDIR\include"
166   File "${DEV_ROOT}\include\*.h"
167 SectionEnd
168
169 Section "SDCC DS390 library"
170   SectionIn 1 2
171   SetOutPath "$INSTDIR\lib\ds390"
172   File "${DEV_ROOT}\lib\ds390\*.asm"
173   File "${DEV_ROOT}\lib\ds390\*.rel"
174   File "${DEV_ROOT}\lib\ds390\*.lib"
175 SectionEnd
176
177 Section "SDCC DS400 library"
178   SectionIn 1 2
179   SetOutPath "$INSTDIR\lib\ds400"
180   File "${DEV_ROOT}\lib\ds400\*.asm"
181   File "${DEV_ROOT}\lib\ds400\*.rel"
182   File "${DEV_ROOT}\lib\ds400\*.lib"
183 SectionEnd
184
185 Section "SDCC GBZ80 library"
186   SectionIn 1 2
187   SetOutPath "$INSTDIR\lib\gbz80"
188   File "${DEV_ROOT}\lib\gbz80\*.asm"
189   File "${DEV_ROOT}\lib\gbz80\*.o"
190   File "${DEV_ROOT}\lib\gbz80\*.lib"
191 SectionEnd
192
193 Section "SDCC Z80 library"
194   SectionIn 1 2
195   SetOutPath "$INSTDIR\lib\z80"
196   File "${DEV_ROOT}\lib\z80\*.asm"
197   File "${DEV_ROOT}\lib\z80\*.o"
198   File "${DEV_ROOT}\lib\z80\*.lib"
199 SectionEnd
200
201 Section "SDCC large model library"
202   SectionIn 1 2
203   SetOutPath "$INSTDIR\lib\large"
204   File "${DEV_ROOT}\lib\large\*.asm"
205   File "${DEV_ROOT}\lib\large\*.rel"
206   File "${DEV_ROOT}\lib\large\*.lib"
207 SectionEnd
208
209 Section "SDCC small model library"
210   SectionIn 1 2
211   SetOutPath "$INSTDIR\lib\small"
212   File "${DEV_ROOT}\lib\small\*.asm"
213   File "${DEV_ROOT}\lib\small\*.rel"
214   File "${DEV_ROOT}\lib\small\*.lib"
215 SectionEnd
216
217 Section "SDCC HC08 library"
218   SectionIn 1 2
219   SetOutPath "$INSTDIR\lib\hc08"
220   File "${DEV_ROOT}\lib\hc08\*.asm"
221   File "${DEV_ROOT}\lib\hc08\*.rel"
222   File "${DEV_ROOT}\lib\hc08\*.lib"
223 SectionEnd
224
225 Section "SDCC library sources"
226   SectionIn 1
227   SetOutPath "$INSTDIR\lib\src\ds390\examples"
228   File "${DEV_ROOT}\lib\src\ds390\examples\MOVED"
229
230   SetOutPath "$INSTDIR\lib\src\ds390"
231   File "${DEV_ROOT}\lib\src\ds390\*.c"
232   File "${DEV_ROOT}\lib\src\ds390\libds390.lib"
233   File "${DEV_ROOT}\lib\src\ds390\Makefile"
234   File "${DEV_ROOT}\lib\src\ds390\Makefile.dep"
235
236   SetOutPath "$INSTDIR\lib\src\ds400"
237   File "${DEV_ROOT}\lib\src\ds400\*.c"
238   File "${DEV_ROOT}\lib\src\ds400\libds400.lib"
239   File "${DEV_ROOT}\lib\src\ds400\Makefile"
240   File "${DEV_ROOT}\lib\src\ds400\Makefile.dep"
241
242   SetOutPath "$INSTDIR\lib\src\gbz80"
243   File "${DEV_ROOT}\lib\src\gbz80\*.c"
244   File "${DEV_ROOT}\lib\src\gbz80\*.s"
245   File "${DEV_ROOT}\lib\src\gbz80\gbz80.lib"
246   File "${DEV_ROOT}\lib\src\gbz80\Makefile"
247   File "${DEV_ROOT}\lib\src\gbz80\README"
248
249   SetOutPath "$INSTDIR\lib\src\z80"
250   File "${DEV_ROOT}\lib\src\z80\*.c"
251   File "${DEV_ROOT}\lib\src\z80\*.s"
252   File "${DEV_ROOT}\lib\src\z80\Makefile"
253   File "${DEV_ROOT}\lib\src\z80\README"
254   File "${DEV_ROOT}\lib\src\z80\z80.lib"
255
256   SetOutPath "$INSTDIR\lib\src\hc08"
257   File "${DEV_ROOT}\lib\src\hc08\*.c"
258   File "${DEV_ROOT}\lib\src\hc08\Makefile"
259   File "${DEV_ROOT}\lib\src\hc08\hc08.lib"
260
261   SetOutPath "$INSTDIR\lib\src"
262   File "${DEV_ROOT}\lib\src\*.c"
263 SectionEnd
264
265 Section -Icons
266 !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
267   CreateDirectory "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE"
268   CreateShortCut "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\SDCC on the Web.lnk" "$INSTDIR\sdcc.url" 
269   CreateShortCut "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Uninstall SDCC.lnk" "$INSTDIR\uninstall.exe" 
270   CreateShortCut "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Documentation.lnk" "$INSTDIR\doc\README.TXT" "" "$INSTDIR\sdcc.ico" "" "" "" ""
271   CreateShortCut "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Change Log.lnk" "$INSTDIR\doc\ChangeLog_head.txt" "" "$INSTDIR\sdcc.ico" "" "" "" ""
272   CreateShortCut "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\GPL 2 License.lnk" "$INSTDIR\COPYING.TXT" 
273 !insertmacro MUI_STARTMENU_WRITE_END
274 SectionEnd
275
276 Section -INI
277   WriteIniStr "$INSTDIR\sdcc.url" "InternetShortcut" "URL" "http://sdcc.sourceforge.net/"
278 SectionEnd
279
280 Section -PostInstall
281   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC" "DisplayName" "SDCC"
282   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC" "UninstallString" "$INSTDIR\uninstall.exe"
283   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC" "Publisher" "sdcc.sourceforge.net"
284   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC" "URLInfoAbout" "http://sdcc.sourceforge.net/"
285   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC" "HelpLink" "http://sdcc.sourceforge.net/"
286   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC" "URLUpdateInfo" "http://sdcc.sourceforge.net/"
287   WriteUninstaller "$INSTDIR\uninstall.exe"
288 SectionEnd
289
290 Section -AddToPath
291   MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Do you want to add $INSTDIR\bin to the PATH?" IDNO +3
292     Push "$INSTDIR\bin"
293     Call AddToPath
294 SectionEnd
295
296
297 ;;;; Uninstaller code ;;;;
298
299 Function un.onInit
300   MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to completely remove $(^Name) and all of its components?" IDYES +2
301   Abort
302 FunctionEnd
303
304 Function un.onUninstSuccess
305   HideWindow
306   MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) was successfully removed from your computer."
307 FunctionEnd
308
309 Section Uninstall
310   !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_STARTMENUPAGE_VARIABLE
311
312   Delete "$INSTDIR\sdcc.url"
313
314   DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC" "NSIS:StartMenuDir"
315   DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC"
316
317   Delete "$INSTDIR\uninstall.exe"
318   Delete "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\GPL 2 License.lnk"
319   Delete "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Change Log.lnk"
320   Delete "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Documentation.lnk"
321   Delete "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Uninstall SDCC.lnk"
322   Delete "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\SDCC on the Web.lnk"
323
324   Delete "$INSTDIR\lib\src\hc08\*.c"
325   Delete "$INSTDIR\lib\src\hc08\hc08.lib"
326   Delete "$INSTDIR\lib\src\hc08\Makefile"
327
328   Delete "$INSTDIR\lib\src\z80\*.c"
329   Delete "$INSTDIR\lib\src\z80\*.s"
330   Delete "$INSTDIR\lib\src\z80\z80.lib"
331   Delete "$INSTDIR\lib\src\z80\README"
332   Delete "$INSTDIR\lib\src\z80\Makefile"
333
334   Delete "$INSTDIR\lib\src\gbz80\*.c"
335   Delete "$INSTDIR\lib\src\gbz80\*.s"
336   Delete "$INSTDIR\lib\src\gbz80\gbz80.lib"
337   Delete "$INSTDIR\lib\src\gbz80\README"
338   Delete "$INSTDIR\lib\src\gbz80\Makefile"
339
340   Delete "$INSTDIR\lib\src\ds390\*.c"
341   Delete "$INSTDIR\lib\src\ds390\libds390.lib"
342   Delete "$INSTDIR\lib\src\ds390\Makefile.dep"
343   Delete "$INSTDIR\lib\src\ds390\Makefile"
344   Delete "$INSTDIR\lib\src\ds390\examples\MOVED"
345
346   Delete "$INSTDIR\lib\src\ds400\*.c"
347   Delete "$INSTDIR\lib\src\ds400\libds400.lib"
348   Delete "$INSTDIR\lib\src\ds400\Makefile.dep"
349   Delete "$INSTDIR\lib\src\ds400\Makefile"
350
351   Delete "$INSTDIR\lib\src\*.c"
352
353   Delete "$INSTDIR\lib\hc08\*.rel"
354   Delete "$INSTDIR\lib\hc08\*.asm"
355   Delete "$INSTDIR\lib\hc08\*.lib"
356
357   Delete "$INSTDIR\lib\z80\*.o"
358   Delete "$INSTDIR\lib\z80\*.asm"
359   Delete "$INSTDIR\lib\z80\*.lib"
360
361   Delete "$INSTDIR\lib\small\*.asm"
362   Delete "$INSTDIR\lib\small\*.rel"
363   Delete "$INSTDIR\lib\small\*.lib"
364
365   Delete "$INSTDIR\lib\large\*.asm"
366   Delete "$INSTDIR\lib\large\*.rel"
367   Delete "$INSTDIR\lib\large\*.lib"
368
369   Delete "$INSTDIR\lib\gbz80\*.asm"
370   Delete "$INSTDIR\lib\gbz80\*.o"
371   Delete "$INSTDIR\lib\gbz80\*.lib"
372
373   Delete "$INSTDIR\lib\ds390\*.asm"
374   Delete "$INSTDIR\lib\ds390\*.rel"
375   Delete "$INSTDIR\lib\ds390\*.lib"
376
377   Delete "$INSTDIR\lib\ds400\*.asm"
378   Delete "$INSTDIR\lib\ds400\*.rel"
379   Delete "$INSTDIR\lib\ds400\*.lib"
380
381   Delete "$INSTDIR\include\asm\z80\*.h"
382   Delete "$INSTDIR\include\asm\pic16\*.h"
383   Delete "$INSTDIR\include\asm\gbz80\*.h"
384   Delete "$INSTDIR\include\asm\default\*.h"
385   Delete "$INSTDIR\include\pic16\*.h"
386   Delete "$INSTDIR\include\*.h"
387
388   Delete "$INSTDIR\doc\README.TXT"
389   Delete "$INSTDIR\doc\ChangeLog_head.txt"
390
391   Delete "$INSTDIR\bin\*.exe"
392
393   Delete "$INSTDIR\COPYING.TXT"
394   Delete "$INSTDIR\sdcc.ico"
395
396   RMDir "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE"
397
398   RMDir "$INSTDIR\lib\src\z80"
399   RMDir "$INSTDIR\lib\src\gbz80"
400   RMDir "$INSTDIR\lib\src\ds390\examples"
401   RMDir "$INSTDIR\lib\src\ds390"
402   RMDir "$INSTDIR\lib\src\ds400"
403   RMDir "$INSTDIR\lib\src\hc08"
404   RMDir "$INSTDIR\lib\src"
405
406   RMDir "$INSTDIR\lib\z80"
407   RMDir "$INSTDIR\lib\small"
408   RMDir "$INSTDIR\lib\large"
409   RMDir "$INSTDIR\lib\gbz80"
410   RMDir "$INSTDIR\lib\ds390"
411   RMDir "$INSTDIR\lib\ds400"
412   RMDir "$INSTDIR\lib\hc08"
413   RMDir "$INSTDIR\lib"
414
415   RMDir "$INSTDIR\include\asm\z80"
416   RMDir "$INSTDIR\include\asm\pic16"
417   RMDir "$INSTDIR\include\asm\gbz80"
418   RMDir "$INSTDIR\include\asm\default"
419   RMDir "$INSTDIR\include\asm"
420   RMDir "$INSTDIR\include\pic16"
421   RMDir "$INSTDIR\include"
422
423   RMDir "$INSTDIR\doc"
424
425   RMDir "$INSTDIR\bin"
426
427   RMDir "$INSTDIR"
428
429   Push "$INSTDIR\bin"
430   Call un.RemoveFromPath
431
432   SetAutoClose true
433 SectionEnd
434
435 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
436 ; Path Manipulation functions                                                 ;
437 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
438
439 !verbose 3
440 !include "WinMessages.nsh"
441 !verbose 4
442
443 ; AddToPath - Adds the given dir to the search path.
444 ;        Input - head of the stack
445 ;        Note - Win9x systems requires reboot
446
447 Function AddToPath
448   Exch $0
449   Push $1
450   Push $2
451   Push $3
452   Push $4
453
454   ; don't add if the path doesn't exist
455   IfFileExists $0 "" AddToPath_done
456
457   Call IsNT
458   Pop $4
459   StrCmp $4 1 +3
460     ; Not on NT: read PATH from environment variable
461     ReadEnvStr $1 PATH
462     Goto +2
463     ; On NT: read PATH from registry
464     ReadRegStr $1 HKCU "Environment" "PATH"
465   Push "$1;"
466   Push "$0;"
467   Call StrStr
468   Pop $2
469   StrCmp $2 "" "" AddToPath_done
470   Push "$1;"
471   Push "$0\;"
472   Call StrStr
473   Pop $2
474   StrCmp $2 "" "" AddToPath_done
475   GetFullPathName /SHORT $3 $0
476   Push "$1;"
477   Push "$3;"
478   Call StrStr
479   Pop $2
480   StrCmp $2 "" "" AddToPath_done
481   Push "$1;"
482   Push "$3\;"
483   Call StrStr
484   Pop $2
485   StrCmp $2 "" "" AddToPath_done
486
487   StrCmp $4 1 AddToPath_NT
488     ; Not on NT
489     StrCpy $1 $WINDIR 2
490     FileOpen $1 "$1\autoexec.bat" a
491     FileSeek $1 -1 END
492     FileReadByte $1 $2
493     IntCmp $2 26 0 +2 +2 ; DOS EOF
494       FileSeek $1 -1 END ; write over EOF
495     FileWrite $1 "$\r$\nSET PATH=%PATH%;$3$\r$\n"
496     FileClose $1
497     SetRebootFlag true
498     Goto AddToPath_done
499
500   AddToPath_NT:
501     ReadRegStr $1 HKCU "Environment" "PATH"
502     StrCpy $2 $1 1 -1  ; copy last char
503     StrCmp $2 ";" 0 +2 ; if last char == ;
504       StrCpy $1 $1 -1  ; remove last char
505     StrCmp $1 "" AddToPath_NTdoIt
506       StrCpy $0 "$1;$0"
507     AddToPath_NTdoIt:
508       WriteRegExpandStr HKCU "Environment" "PATH" $0
509       SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
510
511   AddToPath_done:
512     Pop $4
513     Pop $3
514     Pop $2
515     Pop $1
516     Pop $0
517 FunctionEnd
518
519 ; RemoveFromPath - Remove a given dir from the path
520 ;     Input: head of the stack
521
522 Function un.RemoveFromPath
523   Exch $0
524   Push $1
525   Push $2
526   Push $3
527   Push $4
528   Push $5
529   Push $6
530
531   IntFmt $6 "%c" 26 ; DOS EOF
532
533   Call un.IsNT
534   Pop $1
535   StrCmp $1 1 unRemoveFromPath_NT
536     ; Not on NT
537     StrCpy $1 $WINDIR 2
538     FileOpen $1 "$1\autoexec.bat" r
539     GetTempFileName $4
540     FileOpen $2 $4 w
541     GetFullPathName /SHORT $0 $0
542     StrCpy $0 "SET PATH=%PATH%;$0"
543     Goto unRemoveFromPath_dosLoop
544
545     unRemoveFromPath_dosLoop:
546       FileRead $1 $3
547       StrCpy $5 $3 1 -1 ; read last char
548       StrCmp $5 $6 0 +2 ; if DOS EOF
549         StrCpy $3 $3 -1 ; remove DOS EOF so we can compare
550       StrCmp $3 "$0$\r$\n" unRemoveFromPath_dosLoopRemoveLine
551       StrCmp $3 "$0$\n" unRemoveFromPath_dosLoopRemoveLine
552       StrCmp $3 "$0" unRemoveFromPath_dosLoopRemoveLine
553       StrCmp $3 "" unRemoveFromPath_dosLoopEnd
554       FileWrite $2 $3
555       Goto unRemoveFromPath_dosLoop
556       unRemoveFromPath_dosLoopRemoveLine:
557         SetRebootFlag true
558         Goto unRemoveFromPath_dosLoop
559
560     unRemoveFromPath_dosLoopEnd:
561       FileClose $2
562       FileClose $1
563       StrCpy $1 $WINDIR 2
564       Delete "$1\autoexec.bat"
565       CopyFiles /SILENT $4 "$1\autoexec.bat"
566       Delete $4
567       Goto unRemoveFromPath_done
568
569   unRemoveFromPath_NT:
570     ReadRegStr $1 HKCU "Environment" "PATH"
571     StrCpy $5 $1 1 -1 ; copy last char
572     StrCmp $5 ";" +2  ; if last char != ;
573       StrCpy $1 "$1;" ; append ;
574     Push $1
575     Push "$0;"
576     Call un.StrStr    ; Find `$0;` in $1
577     Pop $2            ; pos of our dir
578     StrCmp $2 "" unRemoveFromPath_done
579       ; else, it is in path
580       ; $0 - path to add
581       ; $1 - path var
582       StrLen $3 "$0;"
583       StrLen $4 $2
584       StrCpy $5 $1 -$4   ; $5 is now the part before the path to remove
585       StrCpy $6 $2 "" $3 ; $6 is now the part after the path to remove
586       StrCpy $3 $5$6
587
588       StrCpy $5 $3 1 -1  ; copy last char
589       StrCmp $5 ";" 0 +2 ; if last char == ;
590         StrCpy $3 $3 -1  ; remove last char
591
592       StrCmp $3 "" +3
593         ; New PATH not empty: update the registry
594         WriteRegExpandStr HKCU "Environment" "PATH" $3
595         Goto +2
596         ; New PATH empty: remove from the registry
597         DeleteRegValue HKCU "Environment" "PATH"
598       SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
599
600   unRemoveFromPath_done:
601     Pop $6
602     Pop $5
603     Pop $4
604     Pop $3
605     Pop $2
606     Pop $1
607     Pop $0
608 FunctionEnd
609
610 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
611 ;            Utility Functions            ;
612 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
613
614 ; IsNT
615 ; no input
616 ; output, top of the stack = 1 if NT or 0 if not
617 ;
618 ; Usage:
619 ;   Call IsNT
620 ;   Pop $R0
621 ;  ($R0 at this point is 1 or 0)
622
623 !macro IsNT un
624 Function ${un}IsNT
625   Push $0
626   ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
627   StrCmp $0 "" 0 IsNT_yes
628   ; we are not NT.
629   Pop $0
630   Push 0
631   Return
632
633   IsNT_yes:
634     ; NT!!!
635     Pop $0
636     Push 1
637 FunctionEnd
638 !macroend
639 !insertmacro IsNT ""
640 !insertmacro IsNT "un."
641
642 ; StrStr
643 ; input, top of stack = string to search for
644 ;        top of stack-1 = string to search in
645 ; output, top of stack (replaces with the portion of the string remaining)
646 ; modifies no other variables.
647 ;
648 ; Usage:
649 ;   Push "this is a long ass string"
650 ;   Push "ass"
651 ;   Call StrStr
652 ;   Pop $R0
653 ;  ($R0 at this point is "ass string")
654
655 !macro StrStr un
656 Function ${un}StrStr
657 Exch $R1   ; st=haystack,old$R1, $R1=needle
658   Exch     ; st=old$R1,haystack
659   Exch $R2 ; st=old$R1,old$R2, $R2=haystack
660   Push $R3
661   Push $R4
662   Push $R5
663   StrLen $R3 $R1
664   StrCpy $R4 0
665   ; $R1=needle
666   ; $R2=haystack
667   ; $R3=len(needle)
668   ; $R4=cnt
669   ; $R5=tmp
670   loop:
671     StrCpy $R5 $R2 $R3 $R4
672     StrCmp $R5 $R1 done
673     StrCmp $R5 "" done
674     IntOp $R4 $R4 + 1
675     Goto loop
676 done:
677   StrCpy $R1 $R2 "" $R4
678   Pop $R5
679   Pop $R4
680   Pop $R3
681   Pop $R2
682   Exch $R1
683 FunctionEnd
684 !macroend
685 !insertmacro StrStr ""
686 !insertmacro StrStr "un."