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