root/trunk/install_scripts/windows/umit_compiled.nsi @ 2998

Revision 2998, 12.8 kB (checked in by luis, 5 years ago)

Added path variable to system ( Windows )

Line 
1; Added Path var
2; From: http://nsis.sourceforge.net/Path_Manipulation
3!ifndef _AddToPath_nsh
4!define _AddToPath_nsh
5 
6!verbose 3
7!include "WinMessages.NSH"
8!verbose 4
9 
10!ifndef WriteEnvStr_RegKey
11  !ifdef ALL_USERS
12    !define WriteEnvStr_RegKey \
13       'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
14  !else
15    !define WriteEnvStr_RegKey 'HKCU "Environment"'
16  !endif
17!endif
18 
19; AddToPath - Adds the given dir to the search path.
20;        Input - head of the stack
21;        Note - Win9x systems requires reboot
22 
23Function AddToPath
24  Exch $0
25  Push $1
26  Push $2
27  Push $3
28 
29  # don't add if the path doesn't exist
30  IfFileExists "$0\*.*" "" AddToPath_done
31 
32  ReadEnvStr $1 PATH
33  Push "$1;"
34  Push "$0;"
35  Call StrStr
36  Pop $2
37  StrCmp $2 "" "" AddToPath_done
38  Push "$1;"
39  Push "$0\;"
40  Call StrStr
41  Pop $2
42  StrCmp $2 "" "" AddToPath_done
43  GetFullPathName /SHORT $3 $0
44  Push "$1;"
45  Push "$3;"
46  Call StrStr
47  Pop $2
48  StrCmp $2 "" "" AddToPath_done
49  Push "$1;"
50  Push "$3\;"
51  Call StrStr
52  Pop $2
53  StrCmp $2 "" "" AddToPath_done
54 
55  Call IsNT
56  Pop $1
57  StrCmp $1 1 AddToPath_NT
58    ; Not on NT
59    StrCpy $1 $WINDIR 2
60    FileOpen $1 "$1\autoexec.bat" a
61    FileSeek $1 -1 END
62    FileReadByte $1 $2
63    IntCmp $2 26 0 +2 +2 # DOS EOF
64      FileSeek $1 -1 END # write over EOF
65    FileWrite $1 "$\r$\nSET PATH=%PATH%;$3$\r$\n"
66    FileClose $1
67    SetRebootFlag true
68    Goto AddToPath_done
69 
70  AddToPath_NT:
71    ReadRegStr $1 ${WriteEnvStr_RegKey} "PATH"
72    StrCmp $1 "" AddToPath_NTdoIt
73      Push $1
74      Call Trim
75      Pop $1
76      StrCpy $0 "$1;$0"
77    AddToPath_NTdoIt:
78      WriteRegExpandStr ${WriteEnvStr_RegKey} "PATH" $0
79      SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
80 
81  AddToPath_done:
82    Pop $3
83    Pop $2
84    Pop $1
85    Pop $0
86FunctionEnd
87 
88; RemoveFromPath - Remove a given dir from the path
89;     Input: head of the stack
90 
91Function un.RemoveFromPath
92  Exch $0
93  Push $1
94  Push $2
95  Push $3
96  Push $4
97  Push $5
98  Push $6
99 
100  IntFmt $6 "%c" 26 # DOS EOF
101 
102  Call un.IsNT
103  Pop $1
104  StrCmp $1 1 unRemoveFromPath_NT
105    ; Not on NT
106    StrCpy $1 $WINDIR 2
107    FileOpen $1 "$1\autoexec.bat" r
108    GetTempFileName $4
109    FileOpen $2 $4 w
110    GetFullPathName /SHORT $0 $0
111    StrCpy $0 "SET PATH=%PATH%;$0"
112    Goto unRemoveFromPath_dosLoop
113 
114    unRemoveFromPath_dosLoop:
115      FileRead $1 $3
116      StrCpy $5 $3 1 -1 # read last char
117      StrCmp $5 $6 0 +2 # if DOS EOF
118        StrCpy $3 $3 -1 # remove DOS EOF so we can compare
119      StrCmp $3 "$0$\r$\n" unRemoveFromPath_dosLoopRemoveLine
120      StrCmp $3 "$0$\n" unRemoveFromPath_dosLoopRemoveLine
121      StrCmp $3 "$0" unRemoveFromPath_dosLoopRemoveLine
122      StrCmp $3 "" unRemoveFromPath_dosLoopEnd
123      FileWrite $2 $3
124      Goto unRemoveFromPath_dosLoop
125      unRemoveFromPath_dosLoopRemoveLine:
126        SetRebootFlag true
127        Goto unRemoveFromPath_dosLoop
128 
129    unRemoveFromPath_dosLoopEnd:
130      FileClose $2
131      FileClose $1
132      StrCpy $1 $WINDIR 2
133      Delete "$1\autoexec.bat"
134      CopyFiles /SILENT $4 "$1\autoexec.bat"
135      Delete $4
136      Goto unRemoveFromPath_done
137 
138  unRemoveFromPath_NT:
139    ReadRegStr $1 ${WriteEnvStr_RegKey} "PATH"
140    StrCpy $5 $1 1 -1 # copy last char
141    StrCmp $5 ";" +2 # if last char != ;
142      StrCpy $1 "$1;" # append ;
143    Push $1
144    Push "$0;"
145    Call un.StrStr ; Find `$0;` in $1
146    Pop $2 ; pos of our dir
147    StrCmp $2 "" unRemoveFromPath_done
148      ; else, it is in path
149      # $0 - path to add
150      # $1 - path var
151      StrLen $3 "$0;"
152      StrLen $4 $2
153      StrCpy $5 $1 -$4 # $5 is now the part before the path to remove
154      StrCpy $6 $2 "" $3 # $6 is now the part after the path to remove
155      StrCpy $3 $5$6
156 
157      StrCpy $5 $3 1 -1 # copy last char
158      StrCmp $5 ";" 0 +2 # if last char == ;
159        StrCpy $3 $3 -1 # remove last char
160 
161      WriteRegExpandStr ${WriteEnvStr_RegKey} "PATH" $3
162      SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
163 
164  unRemoveFromPath_done:
165    Pop $6
166    Pop $5
167    Pop $4
168    Pop $3
169    Pop $2
170    Pop $1
171    Pop $0
172FunctionEnd
173 
174 
175 
176; AddToEnvVar - Adds the given value to the given environment var
177;        Input - head of the stack $0 environement variable $1=value to add
178;        Note - Win9x systems requires reboot
179 
180Function AddToEnvVar
181 
182  Exch $1 ; $1 has environment variable value
183  Exch
184  Exch $0 ; $0 has environment variable name
185 
186  DetailPrint "Adding $1 to $0"
187  Push $2
188  Push $3
189  Push $4
190 
191 
192  ReadEnvStr $2 $0
193  Push "$2;"
194  Push "$1;"
195  Call StrStr
196  Pop $3
197  StrCmp $3 "" "" AddToEnvVar_done
198 
199  Push "$2;"
200  Push "$1\;"
201  Call StrStr
202  Pop $3
203  StrCmp $3 "" "" AddToEnvVar_done
204 
205 
206  Call IsNT
207  Pop $2
208  StrCmp $2 1 AddToEnvVar_NT
209    ; Not on NT
210    StrCpy $2 $WINDIR 2
211    FileOpen $2 "$2\autoexec.bat" a
212    FileSeek $2 -1 END
213    FileReadByte $2 $3
214    IntCmp $3 26 0 +2 +2 # DOS EOF
215      FileSeek $2 -1 END # write over EOF
216    FileWrite $2 "$\r$\nSET $0=%$0%;$4$\r$\n"
217    FileClose $2
218    SetRebootFlag true
219    Goto AddToEnvVar_done
220 
221  AddToEnvVar_NT:
222    ReadRegStr $2 ${WriteEnvStr_RegKey} $0
223    StrCpy $3 $2 1 -1 # copy last char
224    StrCmp $3 ";" 0 +2 # if last char == ;
225      StrCpy $2 $2 -1 # remove last char
226    StrCmp $2 "" AddToEnvVar_NTdoIt
227      StrCpy $1 "$2;$1"
228    AddToEnvVar_NTdoIt:
229      WriteRegExpandStr ${WriteEnvStr_RegKey} $0 $1
230      SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
231 
232  AddToEnvVar_done:
233    Pop $4
234    Pop $3
235    Pop $2
236    Pop $0
237    Pop $1
238 
239FunctionEnd
240 
241; RemoveFromEnvVar - Remove a given value from a environment var
242;     Input: head of the stack
243 
244Function un.RemoveFromEnvVar
245 
246  Exch $1 ; $1 has environment variable value
247  Exch
248  Exch $0 ; $0 has environment variable name
249 
250  DetailPrint "Removing $1 from $0"
251  Push $2
252  Push $3
253  Push $4
254  Push $5
255  Push $6
256  Push $7
257 
258  IntFmt $7 "%c" 26 # DOS EOF
259 
260  Call un.IsNT
261  Pop $2
262  StrCmp $2 1 unRemoveFromEnvVar_NT
263    ; Not on NT
264    StrCpy $2 $WINDIR 2
265    FileOpen $2 "$2\autoexec.bat" r
266    GetTempFileName $5
267    FileOpen $3 $5 w
268    GetFullPathName /SHORT $1 $1
269    StrCpy $1 "SET $0=%$0%;$1"
270    Goto unRemoveFromEnvVar_dosLoop
271 
272    unRemoveFromEnvVar_dosLoop:
273      FileRead $2 $4
274      StrCpy $6 $4 1 -1 # read last char
275      StrCmp $6 $7 0 +2 # if DOS EOF
276        StrCpy $4 $4 -1 # remove DOS EOF so we can compare
277      StrCmp $4 "$1$\r$\n" unRemoveFromEnvVar_dosLoopRemoveLine
278      StrCmp $4 "$1$\n" unRemoveFromEnvVar_dosLoopRemoveLine
279      StrCmp $4 "$1" unRemoveFromEnvVar_dosLoopRemoveLine
280      StrCmp $4 "" unRemoveFromEnvVar_dosLoopEnd
281      FileWrite $3 $4
282      Goto unRemoveFromEnvVar_dosLoop
283      unRemoveFromEnvVar_dosLoopRemoveLine:
284        SetRebootFlag true
285        Goto unRemoveFromEnvVar_dosLoop
286 
287    unRemoveFromEnvVar_dosLoopEnd:
288      FileClose $3
289      FileClose $2
290      StrCpy $2 $WINDIR 2
291      Delete "$2\autoexec.bat"
292      CopyFiles /SILENT $5 "$2\autoexec.bat"
293      Delete $5
294      Goto unRemoveFromEnvVar_done
295 
296  unRemoveFromEnvVar_NT:
297    ReadRegStr $2 ${WriteEnvStr_RegKey} $0
298    StrCpy $6 $2 1 -1 # copy last char
299    StrCmp $6 ";" +2 # if last char != ;
300      StrCpy $2 "$2;" # append ;
301    Push $2
302    Push "$1;"
303    Call un.StrStr ; Find `$1;` in $2
304    Pop $3 ; pos of our dir
305    StrCmp $3 "" unRemoveFromEnvVar_done
306      ; else, it is in path
307      # $1 - path to add
308      # $2 - path var
309      StrLen $4 "$1;"
310      StrLen $5 $3
311      StrCpy $6 $2 -$5 # $6 is now the part before the path to remove
312      StrCpy $7 $3 "" $4 # $7 is now the part after the path to remove
313      StrCpy $4 $6$7
314 
315      StrCpy $6 $4 1 -1 # copy last char
316      StrCmp $6 ";" 0 +2 # if last char == ;
317      StrCpy $4 $4 -1 # remove last char
318 
319      WriteRegExpandStr ${WriteEnvStr_RegKey} $0 $4
320 
321      ; delete reg value if null
322      StrCmp $4 "" 0 +2 # if null delete reg
323      DeleteRegValue ${WriteEnvStr_RegKey} $0
324 
325      SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
326 
327  unRemoveFromEnvVar_done:
328    Pop $7
329    Pop $6
330    Pop $5
331    Pop $4
332    Pop $3
333    Pop $2
334    Pop $1
335    Pop $0
336FunctionEnd
337 
338 
339 
340 
341!ifndef IsNT_KiCHiK
342!define IsNT_KiCHiK
343 
344###########################################
345#            Utility Functions            #
346###########################################
347 
348; IsNT
349; no input
350; output, top of the stack = 1 if NT or 0 if not
351;
352; Usage:
353;   Call IsNT
354;   Pop $R0
355;  ($R0 at this point is 1 or 0)
356 
357!macro IsNT un
358Function ${un}IsNT
359  Push $0
360  ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
361  StrCmp $0 "" 0 IsNT_yes
362  ; we are not NT.
363  Pop $0
364  Push 0
365  Return
366 
367  IsNT_yes:
368    ; NT!!!
369    Pop $0
370    Push 1
371FunctionEnd
372!macroend
373!insertmacro IsNT ""
374!insertmacro IsNT "un."
375 
376!endif ; IsNT_KiCHiK
377 
378; StrStr
379; input, top of stack = string to search for
380;        top of stack-1 = string to search in
381; output, top of stack (replaces with the portion of the string remaining)
382; modifies no other variables.
383;
384; Usage:
385;   Push "this is a long ass string"
386;   Push "ass"
387;   Call StrStr
388;   Pop $R0
389;  ($R0 at this point is "ass string")
390 
391!macro StrStr un
392Function ${un}StrStr
393Exch $R1 ; st=haystack,old$R1, $R1=needle
394  Exch    ; st=old$R1,haystack
395  Exch $R2 ; st=old$R1,old$R2, $R2=haystack
396  Push $R3
397  Push $R4
398  Push $R5
399  StrLen $R3 $R1
400  StrCpy $R4 0
401  ; $R1=needle
402  ; $R2=haystack
403  ; $R3=len(needle)
404  ; $R4=cnt
405  ; $R5=tmp
406  loop:
407    StrCpy $R5 $R2 $R3 $R4
408    StrCmp $R5 $R1 done
409    StrCmp $R5 "" done
410    IntOp $R4 $R4 + 1
411    Goto loop
412done:
413  StrCpy $R1 $R2 "" $R4
414  Pop $R5
415  Pop $R4
416  Pop $R3
417  Pop $R2
418  Exch $R1
419FunctionEnd
420!macroend
421!insertmacro StrStr ""
422!insertmacro StrStr "un."
423 
424!endif ; _AddToPath_nsh
425 
426Function Trim ; Added by Pelaca
427        Exch $R1
428        Push $R2
429Loop:
430        StrCpy $R2 "$R1" 1 -1
431        StrCmp "$R2" " " RTrim
432        StrCmp "$R2" "$\n" RTrim
433        StrCmp "$R2" "$\r" RTrim
434        StrCmp "$R2" ";" RTrim
435        GoTo Done
436RTrim: 
437        StrCpy $R1 "$R1" -1
438        Goto Loop
439Done:
440        Pop $R2
441        Exch $R1
442FunctionEnd
443
444; end path var
445
446!include "MUI.nsh"
447; MUI Settings:
448;
449;!define MUI_ICON "share\icons\umit_32.ico" # Installer icon
450;!define MUI_UNICON "share\icons\trash_32.ico" # Uninstaller icon
451!define MUI_HEADERIMAGE
452!define MUI_HEADERIMAGE_BITMAP "share\pixmaps\umit\splash.bmp"
453!define MUI_HEADERIMAGE_UNBITMAP "share\pixmaps\umit\splash.bmp"
454!define MUI_ABORTWARNING
455!define MUI_UNABORTWARNING
456
457!define APPLICATION_NAME "Umit"
458!define APPLICATION_VERSION "0.9.5RC2"
459!define WINPCAP "winpcap-nmap-4.01.exe"
460
461Name "${APPLICATION_NAME}"
462InstallDir "$PROGRAMFILES\${APPLICATION_NAME}\"
463
464; Pages definitions
465;!define MUI_PAGE_HEADER_TEXT "Umit, Take the red pill"
466!define MUI_PAGE_HEADER_SUBTEXT "Umit"
467
468; Finish page definitions
469!define MUI_FINISHPAGE_LINK "Don't forget to visit Umit's website!"
470!define MUI_FINISHPAGE_LINK_LOCATION "http://www.umitproject.org/"
471
472Outfile ${APPLICATION_NAME}-${APPLICATION_VERSION}.exe
473
474; MUI Installer Pages
475!insertmacro MUI_PAGE_WELCOME
476!insertmacro MUI_PAGE_LICENSE "COPYING"
477!insertmacro MUI_PAGE_LICENSE "COPYING_HIGWIDGETS"
478!insertmacro MUI_PAGE_LICENSE "COPYING_NMAP"
479!insertmacro MUI_PAGE_LICENSE "COPYING_WINPCAP"
480;!insertmacro MUI_PAGE_COMPONENTS
481!insertmacro MUI_PAGE_DIRECTORY
482!insertmacro MUI_PAGE_INSTFILES
483!insertmacro MUI_PAGE_FINISH
484
485; MUI Uninstaller Pages
486!insertmacro MUI_UNPAGE_WELCOME
487!insertmacro MUI_UNPAGE_CONFIRM
488!insertmacro MUI_UNPAGE_INSTFILES
489!insertmacro MUI_UNPAGE_FINISH
490
491; Language
492!insertmacro MUI_LANGUAGE "English"
493
494Section "Umit" SecUmit
495  SetOutPath $INSTDIR
496  File COPYING
497  File COPYING_HIGWIDGETS
498  File COPYING_NMAP
499  File COPYING_WINPCAP
500  File README
501  File share\icons\umit\umit_*.ico
502
503  File /r dist\*.*
504
505  File "install_scripts\windows\win_dependencies\${WINPCAP}"
506  ExecWait "$INSTDIR\${WINPCAP}"
507  Delete "$INSTDIR\${WINPCAP}"
508
509  CreateDirectory "$SMPROGRAMS\Umit"
510  CreateShortCut "$SMPROGRAMS\Umit\Umit.lnk" "$INSTDIR\umit.exe" "" $INSTDIR\umit_48.ico
511  CreateShortCut "$SMPROGRAMS\Umit\Umit-Uninstaller.lnk" "$INSTDIR\Umit-Uninstaller.exe" "" $INSTDIR\Umit-Uninstaller.exe
512
513  WriteUninstaller "$INSTDIR\Umit-Uninstaller.exe"
514SectionEnd
515Section "Add to path"
516;likewise AddToPath could be
517  Push "PATH"
518  Push "$INSTDIR\Nmap"
519  Call AddToEnvVar
520SectionEnd
521
522 
523
524
525
526; Components descriptions
527!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
528        !insertmacro MUI_DESCRIPTION_TEXT SecUmit "Install Umit and its dependencies"
529!insertmacro MUI_FUNCTION_DESCRIPTION_END
530
531Section "Uninstall"
532    RMDir /r "$SMPROGRAMS\Umit"
533    RMDir /r "$INSTDIR"
534    Push "PATH"
535    Push "$INSTDIR\Nmap"
536    Call un.RemoveFromEnvVar
537SectionEnd
Note: See TracBrowser for help on using the browser.