Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 6 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
Commits on May 08, 2012
@alonbl alonbl windows-nsis: use EnvVarUpdate.nsh instead of custom
Remove legacy StrStr.nsi, setpath.nsi in favor of system suppoted.

Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
5218d3e
@alonbl alonbl windows-nsis: install for all users
Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
0590d82
@alonbl alonbl windows-nsis: cleanup: minor directory handling
Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
e8faddc
@alonbl alonbl windows-nsis: cleanup registry
Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
749a449
@alonbl alonbl windows-nsi: install at appropreate program files
Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
d542e01
@alonbl alonbl windows-nsis: use 64bit registory hives if 64bit
Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
55a6337
View
327 windows-nsis/EnvVarUpdate.nsh
@@ -0,0 +1,327 @@
+/**
+ * EnvVarUpdate.nsh
+ * : Environmental Variables: append, prepend, and remove entries
+ *
+ * WARNING: If you use StrFunc.nsh header then include it before this file
+ * with all required definitions. This is to avoid conflicts
+ *
+ * Usage:
+ * ${EnvVarUpdate} "ResultVar" "EnvVarName" "Action" "RegLoc" "PathString"
+ *
+ * Credits:
+ * Version 1.0
+ * * Cal Turney (turnec2)
+ * * Amir Szekely (KiCHiK) and e-circ for developing the forerunners of this
+ * function: AddToPath, un.RemoveFromPath, AddToEnvVar, un.RemoveFromEnvVar,
+ * WriteEnvStr, and un.DeleteEnvStr
+ * * Diego Pedroso (deguix) for StrTok
+ * * Kevin English (kenglish_hi) for StrContains
+ * * Hendri Adriaens (Smile2Me), Diego Pedroso (deguix), and Dan Fuhry
+ * (dandaman32) for StrReplace
+ *
+ * Version 1.1 (compatibility with StrFunc.nsh)
+ * * techtonik
+ *
+ * http://nsis.sourceforge.net/Environmental_Variables:_append%2C_prepend%2C_and_remove_entries
+ *
+ */
+
+
+!ifndef ENVVARUPDATE_FUNCTION
+!define ENVVARUPDATE_FUNCTION
+!verbose push
+!verbose 3
+!include "LogicLib.nsh"
+!include "WinMessages.NSH"
+!include "StrFunc.nsh"
+
+; ---- Fix for conflict if StrFunc.nsh is already includes in main file -----------------------
+!macro _IncludeStrFunction StrFuncName
+ !ifndef ${StrFuncName}_INCLUDED
+ ${${StrFuncName}}
+ !endif
+ !ifndef Un${StrFuncName}_INCLUDED
+ ${Un${StrFuncName}}
+ !endif
+ !define un.${StrFuncName} "${Un${StrFuncName}}"
+!macroend
+
+!insertmacro _IncludeStrFunction StrTok
+!insertmacro _IncludeStrFunction StrStr
+!insertmacro _IncludeStrFunction StrRep
+
+; ---------------------------------- Macro Definitions ----------------------------------------
+!macro _EnvVarUpdateConstructor ResultVar EnvVarName Action Regloc PathString
+ Push "${EnvVarName}"
+ Push "${Action}"
+ Push "${RegLoc}"
+ Push "${PathString}"
+ Call EnvVarUpdate
+ Pop "${ResultVar}"
+!macroend
+!define EnvVarUpdate '!insertmacro "_EnvVarUpdateConstructor"'
+
+!macro _unEnvVarUpdateConstructor ResultVar EnvVarName Action Regloc PathString
+ Push "${EnvVarName}"
+ Push "${Action}"
+ Push "${RegLoc}"
+ Push "${PathString}"
+ Call un.EnvVarUpdate
+ Pop "${ResultVar}"
+!macroend
+!define un.EnvVarUpdate '!insertmacro "_unEnvVarUpdateConstructor"'
+; ---------------------------------- Macro Definitions end-------------------------------------
+
+;----------------------------------- EnvVarUpdate start----------------------------------------
+!define hklm_all_users 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
+!define hkcu_current_user 'HKCU "Environment"'
+
+!macro EnvVarUpdate UN
+
+Function ${UN}EnvVarUpdate
+
+ Push $0
+ Exch 4
+ Exch $1
+ Exch 3
+ Exch $2
+ Exch 2
+ Exch $3
+ Exch
+ Exch $4
+ Push $5
+ Push $6
+ Push $7
+ Push $8
+ Push $9
+ Push $R0
+
+ /* After this point:
+ -------------------------
+ $0 = ResultVar (returned)
+ $1 = EnvVarName (input)
+ $2 = Action (input)
+ $3 = RegLoc (input)
+ $4 = PathString (input)
+ $5 = Orig EnvVar (read from registry)
+ $6 = Len of $0 (temp)
+ $7 = tempstr1 (temp)
+ $8 = Entry counter (temp)
+ $9 = tempstr2 (temp)
+ $R0 = tempChar (temp) */
+
+ ; Step 1: Read contents of EnvVarName from RegLoc
+ ;
+ ; Check for empty EnvVarName
+ ${If} $1 == ""
+ SetErrors
+ DetailPrint "ERROR: EnvVarName is blank"
+ Goto EnvVarUpdate_Restore_Vars
+ ${EndIf}
+
+ ; Check for valid Action
+ ${If} $2 != "A"
+ ${AndIf} $2 != "P"
+ ${AndIf} $2 != "R"
+ SetErrors
+ DetailPrint "ERROR: Invalid Action - must be A, P, or R"
+ Goto EnvVarUpdate_Restore_Vars
+ ${EndIf}
+
+ ${If} $3 == HKLM
+ ReadRegStr $5 ${hklm_all_users} $1 ; Get EnvVarName from all users into $5
+ ${ElseIf} $3 == HKCU
+ ReadRegStr $5 ${hkcu_current_user} $1 ; Read EnvVarName from current user into $5
+ ${Else}
+ SetErrors
+ DetailPrint 'ERROR: Action is [$3] but must be "HKLM" or HKCU"'
+ Goto EnvVarUpdate_Restore_Vars
+ ${EndIf}
+
+ ; Check for empty PathString
+ ${If} $4 == ""
+ SetErrors
+ DetailPrint "ERROR: PathString is blank"
+ Goto EnvVarUpdate_Restore_Vars
+ ${EndIf}
+
+ ; Make sure we've got some work to do
+ ${If} $5 == ""
+ ${AndIf} $2 == "R"
+ SetErrors
+ DetailPrint "$1 is empty - Nothing to remove"
+ Goto EnvVarUpdate_Restore_Vars
+ ${EndIf}
+
+ ; Step 2: Scrub EnvVar
+ ;
+ StrCpy $0 $5 ; Copy the contents to $0
+ ; Remove spaces around semicolons (NOTE: spaces before the 1st entry or
+ ; after the last one are not removed here but instead in Step 3)
+ ${If} $0 != "" ; If EnvVar is not empty ...
+ ${Do}
+ ${${UN}StrStr} $7 $0 " ;"
+ ${If} $7 == ""
+ ${ExitDo}
+ ${EndIf}
+ ${${UN}StrRep} $0 $0 " ;" ";" ; Remove '<space>;'
+ ${Loop}
+ ${Do}
+ ${${UN}StrStr} $7 $0 "; "
+ ${If} $7 == ""
+ ${ExitDo}
+ ${EndIf}
+ ${${UN}StrRep} $0 $0 "; " ";" ; Remove ';<space>'
+ ${Loop}
+ ${Do}
+ ${${UN}StrStr} $7 $0 ";;"
+ ${If} $7 == ""
+ ${ExitDo}
+ ${EndIf}
+ ${${UN}StrRep} $0 $0 ";;" ";"
+ ${Loop}
+
+ ; Remove a leading or trailing semicolon from EnvVar
+ StrCpy $7 $0 1 0
+ ${If} $7 == ";"
+ StrCpy $0 $0 "" 1 ; Change ';<EnvVar>' to '<EnvVar>'
+ ${EndIf}
+ StrLen $6 $0
+ IntOp $6 $6 - 1
+ StrCpy $7 $0 1 $6
+ ${If} $7 == ";"
+ StrCpy $0 $0 $6 ; Change ';<EnvVar>' to '<EnvVar>'
+ ${EndIf}
+ ; DetailPrint "Scrubbed $1: [$0]" ; Uncomment to debug
+ ${EndIf}
+
+ /* Step 3. Remove all instances of the target path/string (even if "A" or "P")
+ $6 = bool flag (1 = found and removed PathString)
+ $7 = a string (e.g. path) delimited by semicolon(s)
+ $8 = entry counter starting at 0
+ $9 = copy of $0
+ $R0 = tempChar */
+
+ ${If} $5 != "" ; If EnvVar is not empty ...
+ StrCpy $9 $0
+ StrCpy $0 ""
+ StrCpy $8 0
+ StrCpy $6 0
+
+ ${Do}
+ ${${UN}StrTok} $7 $9 ";" $8 "0" ; $7 = next entry, $8 = entry counter
+
+ ${If} $7 == "" ; If we've run out of entries,
+ ${ExitDo} ; were done
+ ${EndIf} ;
+
+ ; Remove leading and trailing spaces from this entry (critical step for Action=Remove)
+ ${Do}
+ StrCpy $R0 $7 1
+ ${If} $R0 != " "
+ ${ExitDo}
+ ${EndIf}
+ StrCpy $7 $7 "" 1 ; Remove leading space
+ ${Loop}
+ ${Do}
+ StrCpy $R0 $7 1 -1
+ ${If} $R0 != " "
+ ${ExitDo}
+ ${EndIf}
+ StrCpy $7 $7 -1 ; Remove trailing space
+ ${Loop}
+ ${If} $7 == $4 ; If string matches, remove it by not appending it
+ StrCpy $6 1 ; Set 'found' flag
+ ${ElseIf} $7 != $4 ; If string does NOT match
+ ${AndIf} $0 == "" ; and the 1st string being added to $0,
+ StrCpy $0 $7 ; copy it to $0 without a prepended semicolon
+ ${ElseIf} $7 != $4 ; If string does NOT match
+ ${AndIf} $0 != "" ; and this is NOT the 1st string to be added to $0,
+ StrCpy $0 $0;$7 ; append path to $0 with a prepended semicolon
+ ${EndIf} ;
+
+ IntOp $8 $8 + 1 ; Bump counter
+ ${Loop} ; Check for duplicates until we run out of paths
+ ${EndIf}
+
+ ; Step 4: Perform the requested Action
+ ;
+ ${If} $2 != "R" ; If Append or Prepend
+ ${If} $6 == 1 ; And if we found the target
+ DetailPrint "Target is already present in $1. It will be removed and"
+ ${EndIf}
+ ${If} $0 == "" ; If EnvVar is (now) empty
+ StrCpy $0 $4 ; just copy PathString to EnvVar
+ ${If} $6 == 0 ; If found flag is either 0
+ ${OrIf} $6 == "" ; or blank (if EnvVarName is empty)
+ DetailPrint "$1 was empty and has been updated with the target"
+ ${EndIf}
+ ${ElseIf} $2 == "A" ; If Append (and EnvVar is not empty),
+ StrCpy $0 $0;$4 ; append PathString
+ ${If} $6 == 1
+ DetailPrint "appended to $1"
+ ${Else}
+ DetailPrint "Target was appended to $1"
+ ${EndIf}
+ ${Else} ; If Prepend (and EnvVar is not empty),
+ StrCpy $0 $4;$0 ; prepend PathString
+ ${If} $6 == 1
+ DetailPrint "prepended to $1"
+ ${Else}
+ DetailPrint "Target was prepended to $1"
+ ${EndIf}
+ ${EndIf}
+ ${Else} ; If Action = Remove
+ ${If} $6 == 1 ; and we found the target
+ DetailPrint "Target was found and removed from $1"
+ ${Else}
+ DetailPrint "Target was NOT found in $1 (nothing to remove)"
+ ${EndIf}
+ ${If} $0 == ""
+ DetailPrint "$1 is now empty"
+ ${EndIf}
+ ${EndIf}
+
+ ; Step 5: Update the registry at RegLoc with the updated EnvVar and announce the change
+ ;
+ ClearErrors
+ ${If} $3 == HKLM
+ WriteRegExpandStr ${hklm_all_users} $1 $0 ; Write it in all users section
+ ${ElseIf} $3 == HKCU
+ WriteRegExpandStr ${hkcu_current_user} $1 $0 ; Write it to current user section
+ ${EndIf}
+
+ IfErrors 0 +4
+ MessageBox MB_OK|MB_ICONEXCLAMATION "Could not write updated $1 to $3"
+ DetailPrint "Could not write updated $1 to $3"
+ Goto EnvVarUpdate_Restore_Vars
+
+ ; "Export" our change
+ SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
+
+ EnvVarUpdate_Restore_Vars:
+ ;
+ ; Restore the user's variables and return ResultVar
+ Pop $R0
+ Pop $9
+ Pop $8
+ Pop $7
+ Pop $6
+ Pop $5
+ Pop $4
+ Pop $3
+ Pop $2
+ Pop $1
+ Push $0 ; Push my $0 (ResultVar)
+ Exch
+ Pop $0 ; Restore his $0
+
+FunctionEnd
+
+!macroend ; EnvVarUpdate UN
+!insertmacro EnvVarUpdate ""
+!insertmacro EnvVarUpdate "un."
+;----------------------------------- EnvVarUpdate end----------------------------------------
+
+!verbose pop
+!endif
View
47 windows-nsis/StrStr.nsi
@@ -1,47 +0,0 @@
-;====================================================
-; StrStr - Finds a given string in another given string.
-; Returns -1 if not found and the pos if found.
-; Input: head of the stack - string to find
-; second in the stack - string to find in
-; Output: head of the stack
-;====================================================
-!macro StrStr un
-Function ${un}StrStr
- Push $0
- Exch
- Pop $0 ; $0 now have the string to find
- Push $1
- Exch 2
- Pop $1 ; $1 now have the string to find in
- Exch
- Push $2
- Push $3
- Push $4
- Push $5
-
- StrCpy $2 -1
- StrLen $3 $0
- StrLen $4 $1
- IntOp $4 $4 - $3
-
- StrStr_loop:
- IntOp $2 $2 + 1
- IntCmp $2 $4 0 0 StrStrReturn_notFound
- StrCpy $5 $1 $3 $2
- StrCmp $5 $0 StrStr_done StrStr_loop
-
- StrStrReturn_notFound:
- StrCpy $2 -1
-
- StrStr_done:
- Pop $5
- Pop $4
- Pop $3
- Exch $2
- Exch 2
- Pop $0
- Pop $1
-FunctionEnd
-!macroend
-!insertmacro StrStr ""
-!insertmacro StrStr "un."
View
1  windows-nsis/build
@@ -78,6 +78,7 @@ main() {
OUTPUT="${OUTPUT_DIR}/openvpn-install-${VERSION_STRING}-${ARCH}.exe"
"${MAKENSIS}" \
+ -DARCH="${ARCH}" \
-DPACKAGE_NAME="${OPENVPN_PACKAGE_NAME}" \
-DVERSION_STRING="${VERSION_STRING}" \
-DSPECIAL_BUILD="${SPECIAL_BUILD}" \
View
56 windows-nsis/openvpn.nsi
@@ -12,8 +12,7 @@ SetCompressor lzma
!include "MUI.nsh"
-!include "StrStr.nsi"
-!include "setpath.nsi"
+!include "EnvVarUpdate.nsh"
; Default service settings
!define OPENVPN_CONFIG_EXT "ovpn"
@@ -29,11 +28,8 @@ OutFile "${OUTPUT}"
ShowInstDetails show
ShowUninstDetails show
-;Folder selection page
-InstallDir "$PROGRAMFILES\${PACKAGE_NAME}"
-
;Remember install folder
-InstallDirRegKey HKCU "Software\${PACKAGE_NAME}" ""
+InstallDirRegKey HKLM "SOFTWARE\${PACKAGE_NAME}" ""
;--------------------------------
;Modern UI Configuration
@@ -149,11 +145,19 @@ ReserveFile "install-whirl.bmp"
Function .onInit
ClearErrors
+ SetShellVarContext all
!insertmacro IsAdmin
+ ${If} "${ARCH}" == "x86_64"
+ SetRegView 64
+ StrCpy $INSTDIR "$PROGRAMFILES64\${PACKAGE_NAME}"
+ ${Else}
+ StrCpy $INSTDIR "$PROGRAMFILES\${PACKAGE_NAME}"
+ ${EndIf}
+
# Delete previous start menu
- RMDir /r $SMPROGRAMS\${PACKAGE_NAME}
+ RMDir /r "$SMPROGRAMS\${PACKAGE_NAME}"
FunctionEnd
;--------------------
@@ -244,7 +248,7 @@ Section "TAP Virtual Ethernet Adapter" SecTAP
Delete "$TEMP\tap-windows.exe"
- WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PACKAGE_NAME}" "tap" "installed"
+ WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${PACKAGE_NAME}" "tap" "installed"
SectionEnd
!endif
@@ -332,20 +336,14 @@ SectionEnd
Section "Add ${PACKAGE_NAME} to PATH" SecAddPath
- ; remove previously set path (if any)
- Push "$INSTDIR\bin"
- Call RemoveFromPath
-
; append our bin directory to end of current user path
- Push "$INSTDIR\bin"
- Call AddToPath
+ ${EnvVarUpdate} $R0 "PATH" "A" "HKLM" "$INSTDIR\bin"
SectionEnd
Section "Add Shortcuts to Start Menu" SecAddShortcuts
SetOverwrite on
- CreateDirectory "$SMPROGRAMS\${PACKAGE_NAME}"
CreateDirectory "$SMPROGRAMS\${PACKAGE_NAME}\Documentation"
WriteINIStr "$SMPROGRAMS\${PACKAGE_NAME}\Documentation\${PACKAGE_NAME} Windows Notes.url" "InternetShortcut" "URL" "http://openvpn.net/INSTALL-win32.html"
WriteINIStr "$SMPROGRAMS\${PACKAGE_NAME}\Documentation\${PACKAGE_NAME} Manual Page.url" "InternetShortcut" "URL" "http://openvpn.net/man.html"
@@ -390,10 +388,10 @@ Section -post
WriteUninstaller "$INSTDIR\Uninstall.exe"
; Show up in Add/Remove programs
- WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PACKAGE_NAME}" "DisplayName" "${PACKAGE_NAME} ${VERSION_STRING} ${SPECIAL_BUILD}"
- WriteRegExpandStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PACKAGE_NAME}" "UninstallString" "$INSTDIR\Uninstall.exe"
- WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PACKAGE_NAME}" "DisplayIcon" "$INSTDIR\icon.ico"
- WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PACKAGE_NAME}" "DisplayVersion" "${VERSION_STRING}"
+ WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${PACKAGE_NAME}" "DisplayName" "${PACKAGE_NAME} ${VERSION_STRING} ${SPECIAL_BUILD}"
+ WriteRegExpandStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${PACKAGE_NAME}" "UninstallString" "$INSTDIR\Uninstall.exe"
+ WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${PACKAGE_NAME}" "DisplayIcon" "$INSTDIR\icon.ico"
+ WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${PACKAGE_NAME}" "DisplayVersion" "${VERSION_STRING}"
SectionEnd
@@ -426,7 +424,10 @@ SectionEnd
Function un.onInit
ClearErrors
-
+ SetShellVarContext all
+ ${If} "${ARCH}" == "x86_64"
+ SetRegView 64
+ ${EndIf}
!insertmacro IsAdmin
FunctionEnd
@@ -440,9 +441,9 @@ Section "Uninstall"
Sleep 3000
!ifdef USE_TAP_WINDOWS
- ReadRegStr $R0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PACKAGE_NAME}" "tap"
+ ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${PACKAGE_NAME}" "tap"
${If} $R0 == "installed"
- ReadRegStr $R0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\TAP-Windows" "UninstallString"
+ ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\TAP-Windows" "UninstallString"
${If} $R0 != ""
DetailPrint "TAP UNINSTALL"
nsExec::ExecToLog '"$R0" /S'
@@ -451,10 +452,7 @@ Section "Uninstall"
${EndIf}
!endif
- Push "$INSTDIR\bin"
- Call un.RemoveFromPath
-
- RMDir /r $SMPROGRAMS\${PACKAGE_NAME}
+ ${un.EnvVarUpdate} $R0 "PATH" "R" "HKLM" "$INSTDIR\bin"
!ifdef USE_OPENVPN_GUI
Delete "$INSTDIR\bin\openvpn-gui.exe"
@@ -505,11 +503,11 @@ Section "Uninstall"
RMDir "$INSTDIR\sample-config"
RMDir /r "$INSTDIR\log"
RMDir "$INSTDIR"
+ RMDir /r "$SMPROGRAMS\${PACKAGE_NAME}"
!insertmacro DelRegKeyIfUnchanged HKCR ".${OPENVPN_CONFIG_EXT}" "${PACKAGE_NAME}File"
DeleteRegKey HKCR "${PACKAGE_NAME}File"
- DeleteRegKey HKLM SOFTWARE\${PACKAGE_NAME}
- DeleteRegKey HKCU "Software\${PACKAGE_NAME}"
- DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PACKAGE_NAME}"
+ DeleteRegKey HKLM "SOFTWARE\${PACKAGE_NAME}"
+ DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${PACKAGE_NAME}"
SectionEnd
View
182 windows-nsis/setpath.nsi
@@ -1,182 +0,0 @@
-; Modify the user's PATH variable.
-;
-; Modified by JY to have both a RemoveFromPath
-; and an un.RemoveFromPath which are basically
-; copies of each other. Why does NSIS demand
-; this nonsense?
-;
-; Modified Feb 14, 2005 by Mathias Sundman:
-; Added code to remove the semicolon at the end of the path
-; when uninstalling.
-;
-; Added code to make sure we don't insert an extra semicolon
-; before our path if there already exist one at the end of
-; the original path.
-;
-; Removed duplicated "un. and install" functions and made
-; macros to duplicate the code instead.
-
-; example usage
-;
-;Section "Add to path"
-; Push $INSTDIR
-; Call AddToPath
-;SectionEnd
-;
-;# ...
-;
-;Section "uninstall"
-; # ...
-; Push $INSTDIR
-; Call un.RemoveFromPath
-; # ...
-;SectionEnd
-
-!verbose 3
-!include "WinMessages.NSH"
-!verbose 4
-
-;====================================================
-; AddToPath - Adds the given dir to the search path.
-; Input - head of the stack
-; Note - Win9x systems requires reboot
-;====================================================
-Function AddToPath
- Exch $0
- Push $1
- Push $2
-
- Call IsNT
- Pop $1
- StrCmp $1 1 AddToPath_NT
- ; Not on NT
- StrCpy $1 $WINDIR 2
- FileOpen $1 "$1\autoexec.bat" a
- FileSeek $1 0 END
- GetFullPathName /SHORT $0 $0
- FileWrite $1 "$\r$\nSET PATH=%PATH%;$0$\r$\n"
- FileClose $1
- Goto AddToPath_done
-
- AddToPath_NT:
- ReadRegStr $1 HKCU "Environment" "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"
- Goto AddToPath_NTdoIt
- AddToPath_NTdoIt:
- WriteRegExpandStr HKCU "Environment" "PATH" $0
- SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
-
- AddToPath_done:
- Pop $2
- Pop $1
- Pop $0
-FunctionEnd
-
-;====================================================
-; RemoveFromPath - Remove a given dir from the path
-; Input: head of the stack
-;====================================================
-!macro RemoveFromPath un
-Function ${un}RemoveFromPath
- Exch $0
- Push $1
- Push $2
- Push $3
- Push $4
- Push $5
-
- Call ${un}IsNT
- Pop $1
- StrCmp $1 1 RemoveFromPath_NT
- ; Not on NT
- StrCpy $1 $WINDIR 2
- FileOpen $1 "$1\autoexec.bat" r
- GetTempFileName $4
- FileOpen $2 $4 w
- GetFullPathName /SHORT $0 $0
- StrCpy $0 "SET PATH=%PATH%;$0"
- SetRebootFlag true
- Goto RemoveFromPath_dosLoop
-
- RemoveFromPath_dosLoop:
- FileRead $1 $3
- StrCmp $3 "$0$\r$\n" RemoveFromPath_dosLoop
- StrCmp $3 "$0$\n" RemoveFromPath_dosLoop
- StrCmp $3 "$0" RemoveFromPath_dosLoop
- StrCmp $3 "" RemoveFromPath_dosLoopEnd
- FileWrite $2 $3
- Goto RemoveFromPath_dosLoop
-
- RemoveFromPath_dosLoopEnd:
- FileClose $2
- FileClose $1
- StrCpy $1 $WINDIR 2
- Delete "$1\autoexec.bat"
- CopyFiles /SILENT $4 "$1\autoexec.bat"
- Delete $4
- Goto RemoveFromPath_done
-
- RemoveFromPath_NT:
- StrLen $2 $0
- ReadRegStr $1 HKCU "Environment" "PATH"
- Push $1
- Push $0
- Call ${un}StrStr ; Find $0 in $1
- Pop $0 ; pos of our dir
- IntCmp $0 -1 RemoveFromPath_done
- ; else, it is in path
- StrCpy $3 $1 $0 ; $3 now has the part of the path before our dir
- IntOp $2 $2 + $0 ; $2 now contains the pos after our dir in the path (';')
- IntOp $2 $2 + 1 ; $2 now containts the pos after our dir and the semicolon.
- StrLen $0 $1
- StrCpy $1 $1 $0 $2
- StrCpy $3 "$3$1"
-
- StrCpy $5 $3 1 -1 # copy last char
- StrCmp $5 ";" 0 +2 # if last char == ;
- StrCpy $3 $3 -1 # remove last char
-
- WriteRegExpandStr HKCU "Environment" "PATH" $3
- SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
-
- RemoveFromPath_done:
- Pop $5
- Pop $4
- Pop $3
- Pop $2
- Pop $1
- Pop $0
-FunctionEnd
-!macroend
-!insertmacro RemoveFromPath ""
-!insertmacro RemoveFromPath "un."
-
-;====================================================
-; IsNT - Returns 1 if the current system is NT, 0
-; otherwise.
-; Output: head of the stack
-;====================================================
-!macro IsNT un
-Function ${un}IsNT
- Push $0
- ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
- StrCmp $0 "" 0 IsNT_yes
- ; we are not NT.
- Pop $0
- Push 0
- Return
-
- IsNT_yes:
- ; NT!!!
- Pop $0
- Push 1
-FunctionEnd
-!macroend
-!insertmacro IsNT ""
-!insertmacro IsNT "un."
-

No commit comments for this range

Something went wrong with that request. Please try again.