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