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