raptorinstallerutils.nsh 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. # Copyright (c) 2009-2011 Nokia Corporation and/or its subsidiary(-ies).
  2. # All rights reserved.
  3. # This component and the accompanying materials are made available
  4. # under the terms of the License "Eclipse Public License v1.0"
  5. # which accompanies this distribution, and is available
  6. # at the URL "http://www.eclipse.org/legal/epl-v10.html".
  7. #
  8. # Initial Contributors:
  9. # Nokia Corporation - initial contribution.
  10. #
  11. # Contributors:
  12. #
  13. # Description:
  14. # Raptor installer header file
  15. !include "WordFunc.nsh"
  16. # Time macros
  17. !macro DefineDateStamp
  18. ${time::GetLocalTime} $RESULT
  19. ${time::TimeString} "$RESULT" $0 $1 $2 $3 $4 $5
  20. !define DATE_STAMP "$2-$1-$0-$3-$4-$5"
  21. !macroend
  22. # Env var manipulation macros
  23. # Macro to refresh the computer's environment by sending Windows the
  24. # WM_WININICHANGE message so that it re-reads the environment changes
  25. # the installer has made.
  26. !macro RefreshEnv
  27. DetailPrint "Refreshing your computer's environment..."
  28. SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" $RESULT /TIMEOUT=5000
  29. DetailPrint "Done."
  30. !macroend
  31. # Sets ${RESULT} to value of user env var named ${VARNAME}
  32. !macro ReadUsrEnvVar VARNAME RESULT
  33. ReadRegStr ${RESULT} HKCU "Environment" ${VARNAME}
  34. !macroend
  35. # Sets ${RESULT} to value of system env var named ${VARNAME}
  36. !macro ReadSysEnvVar VARNAME RESULT
  37. ReadRegStr ${RESULT} HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" ${VARNAME}
  38. !macroend
  39. # Read the env var from the appropriate place
  40. !macro ReadEnvVar VARNAME RESULT
  41. ${If} $USERONLYINSTALL_STATE == ${BST_CHECKED}
  42. # User env var
  43. !insertmacro ReadUsrEnvVar ${VARNAME} ${RESULT}
  44. ${ElseIf} $ALLUSERSINSTALL_STATE == ${BST_CHECKED}
  45. # System env var
  46. !insertmacro ReadSysEnvVar ${VARNAME} ${RESULT}
  47. ${Else}
  48. # Something has gone wrong!
  49. MessageBox MB_OK|MB_ICONSTOP "Failed to determine installation type (Current User or All Users)." /SD IDOK
  50. ${EndIf}
  51. !macroend
  52. # Read the user Path
  53. !macro ReadUsrPath OUTPUT
  54. # Reset error flag
  55. ClearErrors
  56. !insertmacro ReadUsrEnvVar "Path" ${OUTPUT}
  57. ${If} ${Errors}
  58. DetailPrint "User has no Path variable."
  59. StrCpy "${OUTPUT}" ""
  60. ${EndIf}
  61. !macroend
  62. # Read the user Path
  63. !macro ReadSysPath OUTPUT
  64. # Reset error flag
  65. ClearErrors
  66. !insertmacro ReadSysEnvVar "Path" ${OUTPUT}
  67. !macroend
  68. # Read the Path (installer only).
  69. !macro ReadPath OUTPUT
  70. ${If} $USERONLYINSTALL_STATE == ${BST_CHECKED}
  71. # User env var
  72. !insertmacro ReadUsrPath ${OUTPUT}
  73. ${ElseIf} $ALLUSERSINSTALL_STATE == ${BST_CHECKED}
  74. # System env var
  75. !insertmacro ReadSysPath ${OUTPUT}
  76. ${Else}
  77. # Something has gone wrong!
  78. MessageBox MB_OK|MB_ICONSTOP "Failed to determine installation type (Current User or All Users)." /SD IDOK
  79. ${EndIf}
  80. !macroend
  81. # Writes a string user environment variable to the Registry
  82. # DO NOT USE FOR WRITING THE PATH ENVIRONMENT VARIABLE. USE THE BELOW MARCOS!
  83. !macro WriteUsrEnvVar VARNAME VALUE
  84. WriteRegStr HKCU "Environment" ${VARNAME} ${VALUE}
  85. !macroend
  86. # Writes a string system environment variable to the Registry
  87. # DO NOT USE FOR WRITING THE PATH ENVIRONMENT VARIABLE. USE THE BELOW MARCOS!
  88. !macro WriteSysEnvVar VARNAME VALUE
  89. WriteRegStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" ${VARNAME} ${VALUE}
  90. !macroend
  91. # Use the following for PATH env var that can expand variables it contains, e.g.
  92. # Something like
  93. # %SBS_HOME%;C:\Windows...
  94. # should be written to the registry
  95. # SBS_HOME must NOT be an "expandable string"; in fact expandable strings don't work recursively
  96. # Writes an expandable string user environment variable to the Registry; mostly used for PATH
  97. !macro WriteUsrEnvVarExp VARNAME VALUE
  98. WriteRegExpandStr HKCU "Environment" ${VARNAME} ${VALUE}
  99. !macroend
  100. # Writes an expandable string system environment variable to the Registry; mostly used for PATH
  101. !macro WriteSysEnvVarExp VARNAME VALUE
  102. WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" ${VARNAME} ${VALUE}
  103. !macroend
  104. # Deletes a user environment variable from the Registry
  105. !macro RmUsrEnvVar VARNAME
  106. DeleteRegValue HKCU "Environment" ${VARNAME}
  107. !macroend
  108. # Deletes a system environment variable from the Registry
  109. !macro RmSysEnvVar VARNAME
  110. DeleteRegValue HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" ${VARNAME}
  111. !macroend
  112. # Push env var name, value of env var, and either "" (for normal string env var)
  113. # or "exp" (for expandable env var) onto stack before calling this function
  114. # in this order
  115. Function WriteEnvVar
  116. pop $2 # Expandable string or not?
  117. pop $1 # Env var value
  118. pop $0 # Env var name
  119. DetailPrint "Going to write evn var $0, with value $1, expandable: $2."
  120. # Reset error flag
  121. ClearErrors
  122. ${If} $2 == "exp" # Expandable string env var
  123. # Write the env var to the appropriate place
  124. ${If} $USERONLYINSTALL_STATE == ${BST_CHECKED}
  125. DetailPrint "DEBUG $$0 $$1 = $0 $1"
  126. # User env var
  127. !insertmacro WriteUsrEnvVarExp $0 $1
  128. ${ElseIf} $ALLUSERSINSTALL_STATE == ${BST_CHECKED}
  129. DetailPrint "DEBUG $$0 $$1 = $0 $1"
  130. # System env var
  131. !insertmacro WriteSysEnvVarExp $0 $1
  132. ${Else}
  133. # Something has gone wrong!
  134. MessageBox MB_OK|MB_ICONSTOP "Failed to determine installation type (Current User or All Users)." /SD IDOK
  135. ${EndIf}
  136. ${Else} # Normal string env var
  137. # Write the env var to the appropriate place
  138. ${If} $USERONLYINSTALL_STATE == ${BST_CHECKED}
  139. DetailPrint "DEBUG $$0 $$1 = $0 $1"
  140. # User env var
  141. !insertmacro WriteUsrEnvVar $0 $1
  142. ${ElseIf} $ALLUSERSINSTALL_STATE == ${BST_CHECKED}
  143. DetailPrint "DEBUG $$0 $$1 = $0 $1"
  144. # System env var
  145. !insertmacro WriteSysEnvVar $0 $1
  146. ${Else}
  147. # Something has gone wrong!
  148. MessageBox MB_OK|MB_ICONSTOP "Failed to determine installation type (Current User or All Users)." /SD IDOK
  149. ${EndIf}
  150. ${EndIf}
  151. FunctionEnd
  152. # Prepend the PATH env var with the given string. User/system path is determined using
  153. # other function.
  154. Function PrependToPath
  155. pop $0 # String to prepend to PATH
  156. DetailPrint "Going to prepend PATH with $0."
  157. # Reset error flag
  158. ClearErrors
  159. # Read Path
  160. !insertmacro ReadPath $RESULT
  161. ${Unless} ${Errors} # If no errors
  162. ${REQuoteMeta} $9 $0 # $9 now contains the meta-quoted version of $0
  163. ${If} $RESULT !~ $9 # If Path doesn't contain string to add
  164. StrLen $RESULT2 "$0;$RESULT"
  165. # Warn is Path might be "too" long for the Windows registry.
  166. ${If} $RESULT2 > 1023
  167. DetailPrint "Note: adding %SBS_HOME%\bin; to the start of your Path..."
  168. DetailPrint "... will result in a string longer than 1023 characters..."
  169. DetailPrint "... being written to your registry. Certain versions of Windows..."
  170. DetailPrint "... cannot handle a string that long in the registry. The installer..."
  171. DetailPrint "... will continue writing to the registry. However, a back up of..."
  172. DetailPrint "... your full environment has been created in your installation directory ..."
  173. DetailPrint "... should anything go wrong which can be used to restore your previous Path."
  174. ${EndIf}
  175. Push "Path" # Third on stack
  176. Push "$0;$RESULT" # Second on stack
  177. Push "exp" # First on stack
  178. # Write expandable string to registry
  179. call WriteEnvVar
  180. ${EndIf}
  181. ${Else}
  182. DetailPrint "Error: failed to read Path environment variable."
  183. ${EndUnless}
  184. FunctionEnd
  185. # Remove the string STR from the string PATH.
  186. !macro RemoveFromPathString PATH STR
  187. DetailPrint "Going to remove ${STR} from ${PATH}."
  188. ${WordReplace} "${PATH}" "${STR}" "" "+" $RESULT2
  189. DetailPrint "Debug: Replaced ${STR} in RESULT2 = [$RESULT2]"
  190. StrCpy ${PATH} "$RESULT2"
  191. ${WordReplace} "${PATH}" ";;" ";" "+" $RESULT2
  192. DetailPrint "Debug: Replaced ;; in RESULT2 = [$RESULT2]"
  193. StrCpy ${PATH} $RESULT2
  194. !macroend
  195. ################### Miscellaneous utilities
  196. # WriteFile - writes a file with given contents
  197. # FILENAME - full path to file (all directories in path must exist)
  198. # CONTENTS - string to write to the file.
  199. !macro WriteFile FILENAME CONTENTS
  200. DetailPrint "Creating batch file for setting Raptor's environment..."
  201. ClearErrors
  202. FileOpen $0 ${FILENAME} w
  203. ${Unless} ${Errors}
  204. FileWrite $0 "${CONTENTS}"
  205. FileClose $0
  206. DetailPrint "Done."
  207. ${Else}
  208. DetailPrint "Error: failed to write RaptorEnv.bat."
  209. ${EndUnless}
  210. !macroend
  211. ################################################ End ################################################