mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 20:51:30 +00:00
164 lines
3.6 KiB
NSIS
164 lines
3.6 KiB
NSIS
!ifndef _AddToPath_nsh
|
|
!define _AddToPath_nsh
|
|
|
|
!verbose 3
|
|
!include "WinMessages.NSH"
|
|
!verbose 4
|
|
|
|
!ifndef WriteEnvStr_RegKey
|
|
!ifdef ALL_USERS
|
|
!define WriteEnvStr_RegKey \
|
|
'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
|
|
!else
|
|
!define WriteEnvStr_RegKey 'HKCU "Environment"'
|
|
!endif
|
|
!endif
|
|
|
|
; AddToPath - Adds the given dir to the search path.
|
|
; Input - head of the stack
|
|
|
|
Function AddToPath
|
|
Exch $0
|
|
Push $1
|
|
Push $2
|
|
Push $3
|
|
|
|
# don't add if the path doesn't exist
|
|
IfFileExists "$0\*.*" "" AddToPath_done
|
|
|
|
ReadEnvStr $1 PATH
|
|
Push "$1;"
|
|
Push "$0;"
|
|
Call StrStr
|
|
Pop $2
|
|
StrCmp $2 "" "" AddToPath_done
|
|
Push "$1;"
|
|
Push "$0\;"
|
|
Call StrStr
|
|
Pop $2
|
|
StrCmp $2 "" "" AddToPath_done
|
|
GetFullPathName /SHORT $3 $0
|
|
Push "$1;"
|
|
Push "$3;"
|
|
Call StrStr
|
|
Pop $2
|
|
StrCmp $2 "" "" AddToPath_done
|
|
Push "$1;"
|
|
Push "$3\;"
|
|
Call StrStr
|
|
Pop $2
|
|
StrCmp $2 "" "" AddToPath_done
|
|
|
|
ReadRegStr $1 ${WriteEnvStr_RegKey} "PATH"
|
|
StrCpy $2 $1 1 -1 # copy last char
|
|
StrCmp $2 ";" 0 +2 # if last char == ;
|
|
StrCpy $1 $1 -1 # remove last char
|
|
StrCmp $1 "" AddToPath_NTdoIt
|
|
StrCpy $0 "$1;$0"
|
|
AddToPath_NTdoIt:
|
|
WriteRegExpandStr ${WriteEnvStr_RegKey} "PATH" $0
|
|
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
|
|
|
|
AddToPath_done:
|
|
Pop $3
|
|
Pop $2
|
|
Pop $1
|
|
Pop $0
|
|
FunctionEnd
|
|
|
|
; RemoveFromPath - Remove a given dir from the path
|
|
; Input: head of the stack
|
|
|
|
Function un.RemoveFromPath
|
|
Exch $0
|
|
Push $1
|
|
Push $2
|
|
Push $3
|
|
Push $4
|
|
Push $5
|
|
Push $6
|
|
|
|
IntFmt $6 "%c" 26 # DOS EOF
|
|
|
|
ReadRegStr $1 ${WriteEnvStr_RegKey} "PATH"
|
|
StrCpy $5 $1 1 -1 # copy last char
|
|
StrCmp $5 ";" +2 # if last char != ;
|
|
StrCpy $1 "$1;" # append ;
|
|
Push $1
|
|
Push "$0;"
|
|
Call un.StrStr ; Find `$0;` in $1
|
|
Pop $2 ; pos of our dir
|
|
StrCmp $2 "" unRemoveFromPath_done
|
|
; else, it is in path
|
|
# $0 - path to add
|
|
# $1 - path var
|
|
StrLen $3 "$0;"
|
|
StrLen $4 $2
|
|
StrCpy $5 $1 -$4 # $5 is now the part before the path to remove
|
|
StrCpy $6 $2 "" $3 # $6 is now the part after the path to remove
|
|
StrCpy $3 $5$6
|
|
|
|
StrCpy $5 $3 1 -1 # copy last char
|
|
StrCmp $5 ";" 0 +2 # if last char == ;
|
|
StrCpy $3 $3 -1 # remove last char
|
|
|
|
WriteRegExpandStr ${WriteEnvStr_RegKey} "PATH" $3
|
|
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
|
|
|
|
unRemoveFromPath_done:
|
|
Pop $6
|
|
Pop $5
|
|
Pop $4
|
|
Pop $3
|
|
Pop $2
|
|
Pop $1
|
|
Pop $0
|
|
FunctionEnd
|
|
|
|
; StrStr
|
|
; input, top of stack = string to search for
|
|
; top of stack-1 = string to search in
|
|
; output, top of stack (replaces with the portion of the string remaining)
|
|
; modifies no other variables.
|
|
;
|
|
; Usage:
|
|
; Push "this is a long ass string"
|
|
; Push "ass"
|
|
; Call StrStr
|
|
; Pop $R0
|
|
; ($R0 at this point is "ass string")
|
|
|
|
!macro StrStr un
|
|
Function ${un}StrStr
|
|
Exch $R1 ; st=haystack,old$R1, $R1=needle
|
|
Exch ; st=old$R1,haystack
|
|
Exch $R2 ; st=old$R1,old$R2, $R2=haystack
|
|
Push $R3
|
|
Push $R4
|
|
Push $R5
|
|
StrLen $R3 $R1
|
|
StrCpy $R4 0
|
|
; $R1=needle
|
|
; $R2=haystack
|
|
; $R3=len(needle)
|
|
; $R4=cnt
|
|
; $R5=tmp
|
|
loop:
|
|
StrCpy $R5 $R2 $R3 $R4
|
|
StrCmp $R5 $R1 done
|
|
StrCmp $R5 "" done
|
|
IntOp $R4 $R4 + 1
|
|
Goto loop
|
|
done:
|
|
StrCpy $R1 $R2 "" $R4
|
|
Pop $R5
|
|
Pop $R4
|
|
Pop $R3
|
|
Pop $R2
|
|
Exch $R1
|
|
FunctionEnd
|
|
!macroend
|
|
!insertmacro StrStr ""
|
|
!insertmacro StrStr "un."
|
|
|
|
!endif ; _AddToPath_nsh |