raptorinstallerscript.nsi 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  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/uninstaller script
  15. # Set compression type - the advice in the NSIS user manual
  16. # is to have this at the top of the main .nsi file.
  17. SetCompressor /SOLID lzma
  18. # Standard NSIS Library includes
  19. !include "MUI2.nsh"
  20. !include "LogicLib.nsh"
  21. !include "WinMessages.nsh"
  22. !include "FileFunc.nsh"
  23. # Enable users to specify command line parameters and enable
  24. # the installer to process them
  25. !insertmacro GetParameters
  26. !insertmacro GetOptions
  27. # Extra plugin includes
  28. !include "nsDialogs.nsh"
  29. !include "Registry.nsh"
  30. !include "NSISpcre.nsh"
  31. !include "Time.nsh"
  32. # Define functions from NSISpcre.nsh
  33. !insertmacro REMatches
  34. !insertmacro un.REMatches
  35. !insertmacro REQuoteMeta
  36. # Variables
  37. Var DIALOG
  38. Var RESULT # Generic variable to obtain results, and immediately thrown away after
  39. Var RESULT2 # Generic variable to obtain results, and immediately thrown away after
  40. Var USERONLYINSTALL_HWND # HWND of radio button control for user-only installation
  41. Var ALLUSERSINSTALL_HWND # HWND of radio button control for system installation
  42. Var NOENVCHANGES_HWND # HWND of radio button control for file-only installation
  43. Var USERONLYINSTALL_STATE # State of user-only radio button
  44. Var ALLUSERSINSTALL_STATE # State of system radio button
  45. Var NOENVCHANGES_STATE # State of file-only installation radio button
  46. Var INSTALL_TYPE # Type of installer ("USR" or "SYS" or "NO_ENV")
  47. # Custom includes (depend on above variables so much be here)
  48. !include "raptorinstallerutils.nsh" # Functions and macros for handling environment variables
  49. # !include "raptorversion.nsh" # Define the RAPTOR_VERSION variable
  50. # Defines
  51. !define INSTALLER_NAME "Raptor v${RAPTOR_VERSION}"
  52. !define RAPTOR "sbs"
  53. !define INSTALLER_FILENAME "${RAPTOR}-${RAPTOR_VERSION}.exe"
  54. !define UNINSTALLER_FILENAME "${RAPTOR}-${RAPTOR_VERSION}-uninstaller.exe"
  55. ########################## Attributes ###########################
  56. # Name of installer executable to create!
  57. OutFile ${INSTALLER_FILENAME}
  58. # Name for the installer caption
  59. Name "Raptor v${RAPTOR_VERSION}"
  60. ####################### Generic Behaviour #######################
  61. # Vista support; use admin in case user decides to install Raptor for all users
  62. RequestExecutionLevel admin
  63. # Set XPStyle on
  64. XPStyle on
  65. ###################### Installer Behaviour ######################
  66. # Warn on Cancel
  67. !define MUI_ABORTWARNING
  68. # Abort warning text
  69. !define MUI_ABORTWARNING_TEXT "Are you sure you want to quit the ${INSTALLER_NAME} installer?"
  70. # Cancel is default button on cancel dialogue boxes.
  71. !define MUI_ABORTWARNING_CANCEL_DEFAULT
  72. # Don't just to final page
  73. !define MUI_FINISHPAGE_NOAUTOCLOSE
  74. # Show installer details
  75. ShowInstDetails show
  76. ##################### Pages in the installer #####################
  77. !define MUI_WELCOMEPAGE_TITLE_3LINES
  78. !insertmacro MUI_PAGE_WELCOME
  79. !insertmacro MUI_PAGE_LICENSE ${LICENSE_FILE}
  80. !define MUI_PAGE_HEADER_TEXT "Installation type"
  81. Page custom UserOrSysInstall UserOrSysInstallLeave
  82. !define MUI_PAGE_CUSTOMFUNCTION_LEAVE DirLeave # Directory page exit function - disallow spaces in $INSTDIR
  83. !insertmacro MUI_PAGE_DIRECTORY
  84. !insertmacro MUI_PAGE_INSTFILES
  85. !define MUI_FINISHPAGE_TITLE_3LINES
  86. !insertmacro MUI_PAGE_FINISH
  87. ######################## .onInit function ########################
  88. Function .onInit
  89. ${If} ${SILENT}
  90. ${GetParameters} $R0
  91. ClearErrors
  92. ${GetOptions} $R0 /INSTALL_TYPE= $INSTALL_TYPE
  93. ${Else}
  94. StrCpy $INSTDIR "C:\Apps\Raptor"
  95. ${EndIf}
  96. FunctionEnd
  97. #################### Sections in the installer ####################
  98. # "Sections" - i.e. components to install. This installer
  99. # only has Raptor, so there is no point giving options
  100. # to the user.
  101. Section "Install Raptor" INSTALLRAPTOR
  102. # Install Raptor
  103. SetOutPath "$INSTDIR\bin"
  104. File /r /x distribution.policy.s60 ${RAPTOR_LOCATION}\bin\*.*
  105. SetOutPath "$INSTDIR\examples"
  106. File /r /x distribution.policy.s60 ${RAPTOR_LOCATION}\examples\*.*
  107. SetOutPath "$INSTDIR\lib"
  108. File /r /x distribution.policy.s60 ${RAPTOR_LOCATION}\lib\*.*
  109. SetOutPath "$INSTDIR\python"
  110. File /r /x distribution.policy.s60 /x *.pyc /x *.pydevproject /x *.project ${RAPTOR_LOCATION}\python\*.*
  111. SetOutPath "$INSTDIR\raptor"
  112. File /r /x distribution.policy.s60 /x *.pyc /x *.pydevproject /x *.project ${RAPTOR_LOCATION}\raptor\*.*
  113. SetOutPath "$INSTDIR\schema"
  114. File /r /x distribution.policy.s60 ${RAPTOR_LOCATION}\schema\*.*
  115. SetOutPath "$INSTDIR\style"
  116. File /r /x distribution.policy.s60 ${RAPTOR_LOCATION}\style\*.*
  117. SetOutPath "$INSTDIR\win32\bin"
  118. File /r /x distribution.policy.s60 ${RAPTOR_LOCATION}\win32\bin\*.*
  119. !ifdef BV_LOCATION
  120. SetOutPath "$INSTDIR\win32\bv"
  121. File /r /x distribution.policy.s60 /x .hg ${BV_LOCATION}\*.*
  122. !endif
  123. SetOutPath "$INSTDIR\win32\cygwin"
  124. File /r /x distribution.policy.s60 /x .hg ${CYGWIN_LOCATION}\*.*
  125. SetOutPath "$INSTDIR\win32\mingw"
  126. File /r /x distribution.policy.s60 /x .hg ${MINGW_LOCATION}\*.*
  127. SetOutPath "$INSTDIR\win32\python27"
  128. File /r /x distribution.policy.s60 /x .hg ${PYTHON_LOCATION}\*.*
  129. SetOutPath "$INSTDIR"
  130. File ${RAPTOR_LOCATION}\RELEASE-NOTES.html
  131. SetOutPath "$INSTDIR\notes"
  132. File /r /x distribution.policy.s60 ${RAPTOR_LOCATION}\notes\*.*
  133. ${Unless} $INSTALL_TYPE == "NO_ENV"
  134. # Back up system and user environments before changing them.
  135. !insertmacro DefineDateStamp
  136. !define SYS_REG_BACKUP_FILE "$INSTDIR\SysEnvBackUpPreInstall-${DATE_STAMP}.reg"
  137. !define USR_REG_BACKUP_FILE "$INSTDIR\UsrEnvBackUpPreInstall-${DATE_STAMP}.reg"
  138. # Save System Environment just in case.
  139. ${registry::SaveKey} "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "${SYS_REG_BACKUP_FILE}" "" "$RESULT"
  140. ${If} $RESULT == 0
  141. DetailPrint "Successfully backed up system environment in ${SYS_REG_BACKUP_FILE}."
  142. ${Else}
  143. DetailPrint "Failed to back up system environment due to an unknown error."
  144. ${EndIf}
  145. # Save user Environment just in case.
  146. ${registry::SaveKey} "HKCU\Environment" "${USR_REG_BACKUP_FILE}" "" "$RESULT"
  147. ${If} $RESULT == 0
  148. DetailPrint "Successfully backed up user environment in ${USR_REG_BACKUP_FILE}."
  149. ${Else}
  150. DetailPrint "Failed to back up user environment due to an unknown error."
  151. ${EndIf}
  152. # Reset error flag
  153. ClearErrors
  154. # Prepend PATH with $INSTDIR\bin
  155. Push "$INSTDIR\bin" # First on stack
  156. call PrependToPath
  157. ${EndUnless}
  158. # Generate batch file to set environment variables for Raptor
  159. StrCpy $RESULT "@REM Environment variables for ${INSTALLER_NAME}$\r$\nset PATH=$INSTDIR\bin;%PATH%$\r$\n"
  160. SetOutPath "$INSTDIR"
  161. !insertmacro WriteFile "RaptorEnv.bat" "$RESULT"
  162. SectionEnd
  163. # Finishing up installation.
  164. Section
  165. ${Unless} $INSTALL_TYPE == "NO_ENV"
  166. # Refresh environment to get changes for PATH
  167. !insertmacro RefreshEnv
  168. ${EndUnless}
  169. # Write the uninstaller
  170. WriteUninstaller "$INSTDIR\${UNINSTALLER_FILENAME}"
  171. # Unload registry plug in
  172. ${registry::Unload}
  173. SectionEnd
  174. # Custom install page to select install type
  175. Function UserOrSysInstall
  176. !insertmacro MUI_HEADER_TEXT "Choose Installation Type" "Choose the type of installation \
  177. you would like for your computer."
  178. nsDialogs::Create 1018
  179. Pop $DIALOG
  180. # Exit is unable to create dialog
  181. ${If} $DIALOG == error
  182. Abort
  183. ${EndIf}
  184. # Create second radio button for system install
  185. #${NSD_CreateRadioButton} 0 10u 100% 33% "Install Raptor for all users on this computer. \
  186. #(Recommended).$\nThis option modifies system wide environment variables."
  187. #Pop $ALLUSERSINSTALL_HWND
  188. # Create first radio button for user install
  189. #${NSD_CreateRadioButton} 0 45u 100% 67% "Install Raptor just for me on this computer.\
  190. #$\nThis option modifies only user environment variables."
  191. #Pop $USERONLYINSTALL_HWND
  192. # Create first radio button for system install
  193. ${NSD_CreateRadioButton} 0 0% 100% 30% "Install Raptor for all users on this computer. \
  194. (Recommended).$\nThis option modifies system wide environment variables."
  195. Pop $ALLUSERSINSTALL_HWND
  196. # Create second radio button for user install
  197. ${NSD_CreateRadioButton} 0 25% 100% 30% "Install Raptor just for me on this computer.\
  198. $\nThis option modifies only user environment variables."
  199. Pop $USERONLYINSTALL_HWND
  200. # Create third radio button for file-only install
  201. ${NSD_CreateRadioButton} 0 50% 100% 40% "Install, but do not modify the environment.\
  202. $\nThis option only unpacks Raptor's files. A batch file in the installation \
  203. folder (RaptorEnv.bat) can be used to set Raptor's environment variables in a command prompt."
  204. Pop $NOENVCHANGES_HWND
  205. # Update page control with previous state, if set.
  206. # Initially these will be blank, so set system install to be on by default.
  207. ${If} $USERONLYINSTALL_STATE == ""
  208. ${AndIf} $ALLUSERSINSTALL_STATE == ""
  209. ${AndIf} $NOENVCHANGES_STATE == ""
  210. ${NSD_SetState} $ALLUSERSINSTALL_HWND ${BST_CHECKED}
  211. ${Else} # Previously set, user has returned to this page using "Back" button
  212. ${If} $USERONLYINSTALL_STATE == ${BST_CHECKED}
  213. ${NSD_SetState} $USERONLYINSTALL_HWND ${BST_CHECKED}
  214. ${ElseIf} $NOENVCHANGES_STATE == ${BST_CHECKED}
  215. ${NSD_SetState} $NOENVCHANGES_HWND ${BST_CHECKED}
  216. ${Else}
  217. ${NSD_SetState} $ALLUSERSINSTALL_HWND ${BST_CHECKED}
  218. ${EndIf}
  219. ${EndIf}
  220. nsDialogs::Show
  221. FunctionEnd
  222. # Store the states of the radio buttons once the user has left the page.
  223. Function UserOrSysInstallLeave
  224. ${NSD_GetState} $USERONLYINSTALL_HWND $USERONLYINSTALL_STATE
  225. ${NSD_GetState} $ALLUSERSINSTALL_HWND $ALLUSERSINSTALL_STATE
  226. ${NSD_GetState} $NOENVCHANGES_HWND $NOENVCHANGES_STATE
  227. # Set the ${INSTALL_TYPE} variable
  228. ${If} $USERONLYINSTALL_STATE == ${BST_CHECKED}
  229. StrCpy $INSTALL_TYPE "USR"
  230. ${EndIf}
  231. ${If} $ALLUSERSINSTALL_STATE == ${BST_CHECKED}
  232. StrCpy $INSTALL_TYPE "SYS"
  233. ${EndIf}
  234. ${If} $NOENVCHANGES_STATE == ${BST_CHECKED}
  235. StrCpy $INSTALL_TYPE "NO_ENV"
  236. ${EndIf}
  237. ${Unless} $INSTALL_TYPE == "USR"
  238. ${AndUnless} $INSTALL_TYPE == "SYS"
  239. ${AndUnless} $INSTALL_TYPE == "NO_ENV"
  240. Abort "Failed to determine installation type.\n\
  241. $$INSTALL_TYPE = $\"$INSTALL_TYPE$\"."
  242. ${EndUnless}
  243. FunctionEnd
  244. Function DirLeave
  245. StrCpy $0 " "
  246. ${REQuoteMeta} $9 $0 # $9 now contains the meta-quoted version of $0
  247. ${If} $INSTDIR =~ $9
  248. MessageBox MB_OK|MB_ICONSTOP "Please choose a directory without a space in it." /SD IDOK
  249. Abort
  250. ${EndIf}
  251. FunctionEnd
  252. ########################### Uninstaller #########################
  253. ######################## .onInit function ########################
  254. Function un.onInit
  255. !undef DATE_STAMP
  256. !insertmacro DefineDateStamp
  257. FunctionEnd
  258. ########################### Behaviour ###########################
  259. # Warn on Cancel
  260. !define MUI_UNABORTWARNING
  261. # Abort warning text
  262. !undef MUI_UNABORTWARNING_TEXT
  263. !define MUI_UNABORTWARNING_TEXT "Are you sure you want to quit the ${INSTALLER_NAME} uninstaller?"
  264. # Cancel is default button on cancel dialogue boxes.
  265. !define MUI_UNABORTWARNING_CANCEL_DEFAULT
  266. # Don't just to final page
  267. !define MUI_UNFINISHPAGE_NOAUTOCLOSE
  268. # Show uninstaller details
  269. ShowUninstDetails show
  270. #################### Pages in the uninstaller ####################
  271. !define MUI_WELCOMEPAGE_TITLE_3LINES
  272. !insertmacro MUI_UNPAGE_WELCOME
  273. !insertmacro MUI_UNPAGE_CONFIRM
  274. !insertmacro MUI_UNPAGE_INSTFILES
  275. !define MUI_FINISHPAGE_TITLE_3LINES
  276. !insertmacro MUI_UNPAGE_FINISH
  277. ################## Sections in the uninstaller ##################
  278. # There is only one section in the uninstaller.
  279. Section "Uninstall"
  280. # Delete Raptor
  281. RmDir /r $INSTDIR\bin
  282. RmDir /r $INSTDIR\examples
  283. RmDir /r $INSTDIR\lib
  284. RmDir /r $INSTDIR\python
  285. RmDir /r $INSTDIR\raptor
  286. RmDir /r $INSTDIR\schema
  287. RmDir /r $INSTDIR\style
  288. RmDir /r $INSTDIR\win32
  289. Delete $INSTDIR\RELEASE-NOTES.html
  290. RmDir /r $INSTDIR\notes
  291. Delete $INSTDIR\RaptorEnv.bat
  292. Delete $INSTDIR\${UNINSTALLER_FILENAME}
  293. !undef SYS_REG_BACKUP_FILE
  294. !undef USR_REG_BACKUP_FILE
  295. !define SYS_REG_BACKUP_FILE "$INSTDIR\SysEnvBackUpPreUninstall-${DATE_STAMP}.reg"
  296. !define USR_REG_BACKUP_FILE "$INSTDIR\UsrEnvBackUpPreUninstall-${DATE_STAMP}.reg"
  297. # Save System Environment just in case.
  298. ${registry::SaveKey} "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "${SYS_REG_BACKUP_FILE}" "" "$RESULT"
  299. ${If} $RESULT == 0
  300. DetailPrint "Successfully backed up system environment in ${SYS_REG_BACKUP_FILE}."
  301. ${Else}
  302. DetailPrint "Failed to back up system environment due to an unknown error."
  303. ${EndIf}
  304. # Save user Environment just in case.
  305. ${registry::SaveKey} "HKCU\Environment" "${USR_REG_BACKUP_FILE}" "" "$RESULT"
  306. ${If} $RESULT == 0
  307. DetailPrint "Successfully backed up user environment in ${USR_REG_BACKUP_FILE}."
  308. ${Else}
  309. DetailPrint "Failed to back up user environment due to an unknown error."
  310. ${EndIf}
  311. ################################# Clean up the path env vars #################################
  312. # Reset error flag
  313. ClearErrors
  314. # Read user path
  315. !insertmacro ReadUsrPath $RESULT
  316. DetailPrint "Read user Path: $RESULT"
  317. ${Unless} ${Errors} # No errors, so user Path exists
  318. ${If} $RESULT == "" # If it came back empty.
  319. DetailPrint "No user Path available - nothing to do."
  320. ${Else}
  321. ${If} $RESULT un.=~ "$INSTDIR\\bin;" # Only need to act if $INSTDIR\bin; is in the Path
  322. DetailPrint "Removing $INSTDIR\bin; from user path"
  323. # Reset error flag and clean user Path
  324. ClearErrors
  325. !insertmacro RemoveFromPathString $RESULT "$INSTDIR\bin;"
  326. DetailPrint "DEBUG: User path $$RESULT = "
  327. DetailPrint "DEBUG: User path $RESULT"
  328. ${If} $RESULT == ""
  329. !insertmacro RmUsrEnvVar "Path"
  330. ${Else}
  331. # Write cleaned Path to registry
  332. !insertmacro WriteUsrEnvVarExp "Path" $RESULT
  333. ${EndIf}
  334. ${If} ${Errors}
  335. DetailPrint "ERROR: The ${INSTALLER_NAME} uninstaller could not clean the user Path. Please clean it manually."
  336. ${EndIf}
  337. ${Else}
  338. DetailPrint "Nothing to remove from user path."
  339. ${EndIf}
  340. ${EndIf}
  341. ${Else} # No user path
  342. DetailPrint "Note: Unable to find user Path environment variable."
  343. DetailPrint "Please check that the variable exists and remove $INSTDIR\bin manually if required."
  344. ${EndUnless}
  345. # Read system path
  346. !insertmacro ReadSysPath $RESULT
  347. DetailPrint "Read system Path: $RESULT"
  348. ${Unless} ${Errors} # No errors, so system path read OK.
  349. ${If} $RESULT un.=~ "$INSTDIR\\bin;" # Only need to act if $INSTDIR\bin; is in the Path
  350. DetailPrint "Removing $INSTDIR\bin; from system path"
  351. # Reset error flag
  352. ClearErrors
  353. !insertmacro RemoveFromPathString $RESULT "$INSTDIR\bin;"
  354. DetailPrint "DEBUG: System Path $$RESULT = "
  355. DetailPrint "DEBUG: System Path $RESULT"
  356. ClearErrors
  357. # Write cleaned PATH to registry
  358. !insertmacro WriteSysEnvVarExp "Path" $RESULT
  359. ${If} ${Errors}
  360. DetailPrint "ERROR: The ${INSTALLER_NAME} uninstaller could not clean the PATH."
  361. DetailPrint "Please clean it manually."
  362. ${EndIf}
  363. ${Else}
  364. DetailPrint "Nothing to remove from system path."
  365. ${EndIf}
  366. ${Else} # Some error reading system path
  367. DetailPrint "Note: Unable to read the system Path environment variable."
  368. DetailPrint "Please check that the variable and remove $INSTDIR\bin manually if required."
  369. ${EndUnless}
  370. ##########################################################################
  371. # Refresh environment to get changes for PATH
  372. !insertmacro RefreshEnv
  373. # Unload registry plug in
  374. ${registry::Unload}
  375. SectionEnd
  376. # Languages
  377. !insertmacro MUI_LANGUAGE "English"
  378. ################################################ End ################################################