NSIS.template.in 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. ; CPack install script designed for a nmake build
  2. ;--------------------------------
  3. ; You must define these values
  4. !define VERSION "@CPACK_PACKAGE_VERSION@"
  5. !define PATCH "@CPACK_PACKAGE_VERSION_PATCH@"
  6. !define INST_DIR "@CPACK_TEMPORARY_DIRECTORY@"
  7. ;--------------------------------
  8. ;Variables
  9. Var MUI_TEMP
  10. Var STARTMENU_FOLDER
  11. Var SV_ALLUSERS
  12. Var START_MENU
  13. Var DO_NOT_ADD_TO_PATH
  14. Var ADD_TO_PATH_ALL_USERS
  15. Var ADD_TO_PATH_CURRENT_USER
  16. Var INSTALL_DESKTOP
  17. ;--------------------------------
  18. ;Include Modern UI
  19. !include "MUI.nsh"
  20. ;Default installation folder
  21. InstallDir "$PROGRAMFILES\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
  22. ;--------------------------------
  23. ;General
  24. ;Name and file
  25. Name "@CPACK_PACKAGE_INSTALL_DIRECTORY@"
  26. OutFile "@CPACK_TOPLEVEL_DIRECTORY@/@CPACK_OUTPUT_FILE_NAME@"
  27. ;Set compression
  28. SetCompressor @CPACK_NSIS_COMPRESSOR@
  29. !include Sections.nsh
  30. ;--- Component support macros: ---
  31. ; The code for the add/remove functionality is from:
  32. ; http://nsis.sourceforge.net/Add/Remove_Functionality
  33. ; It has been modified slightly and extended to provide
  34. ; inter-component dependencies.
  35. Var AR_SecFlags
  36. Var AR_RegFlags
  37. @CPACK_NSIS_SECTION_SELECTED_VARS@
  38. ; Loads the "selected" flag for the section named SecName into the
  39. ; variable VarName.
  40. !macro LoadSectionSelectedIntoVar SecName VarName
  41. SectionGetFlags ${${SecName}} $${VarName}
  42. IntOp $${VarName} $${VarName} & ${SF_SELECTED} ;Turn off all other bits
  43. !macroend
  44. ; Loads the value of a variable... can we get around this?
  45. !macro LoadVar VarName
  46. IntOp $R0 0 + $${VarName}
  47. !macroend
  48. !macro InitSection SecName
  49. ; This macro reads component installed flag from the registry and
  50. ;changes checked state of the section on the components page.
  51. ;Input: section index constant name specified in Section command.
  52. ClearErrors
  53. ;Reading component status from registry
  54. ReadRegDWORD $AR_RegFlags HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_DIRECTORY@\Components\${SecName}" "Installed"
  55. IfErrors "default_${SecName}"
  56. ;Status will stay default if registry value not found
  57. ;(component was never installed)
  58. IntOp $AR_RegFlags $AR_RegFlags & ${SF_SELECTED} ;Turn off all other bits
  59. SectionGetFlags ${${SecName}} $AR_SecFlags ;Reading default section flags
  60. IntOp $AR_SecFlags $AR_SecFlags & 0xFFFE ;Turn lowest (enabled) bit off
  61. IntOp $AR_SecFlags $AR_RegFlags | $AR_SecFlags ;Change lowest bit
  62. ;Writing modified flags
  63. SectionSetFlags ${${SecName}} $AR_SecFlags
  64. "default_${SecName}:"
  65. !insertmacro LoadSectionSelectedIntoVar ${SecName} ${SecName}_selected
  66. !macroend
  67. !macro FinishSection SecName
  68. ; This macro reads section flag set by user and removes the section
  69. ;if it is not selected.
  70. ;Then it writes component installed flag to registry
  71. ;Input: section index constant name specified in Section command.
  72. SectionGetFlags ${${SecName}} $AR_SecFlags ;Reading section flags
  73. ;Checking lowest bit:
  74. IntOp $AR_SecFlags $AR_SecFlags & ${SF_SELECTED}
  75. IntCmp $AR_SecFlags 1 "leave_${SecName}"
  76. ;Section is not selected:
  77. ;Calling Section uninstall macro and writing zero installed flag
  78. !insertmacro "Remove_${${SecName}}"
  79. WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_DIRECTORY@\Components\${SecName}" \
  80. "Installed" 0
  81. Goto "exit_${SecName}"
  82. "leave_${SecName}:"
  83. ;Section is selected:
  84. WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_DIRECTORY@\Components\${SecName}" \
  85. "Installed" 1
  86. "exit_${SecName}:"
  87. !macroend
  88. !macro RemoveSection SecName
  89. ; This macro is used to call section's Remove_... macro
  90. ;from the uninstaller.
  91. ;Input: section index constant name specified in Section command.
  92. !insertmacro "Remove_${${SecName}}"
  93. !macroend
  94. ; Determine whether the selection of SecName changed
  95. !macro MaybeSelectionChanged SecName
  96. !insertmacro LoadVar ${SecName}_selected
  97. SectionGetFlags ${${SecName}} $R1
  98. IntOp $R1 $R1 & ${SF_SELECTED} ;Turn off all other bits
  99. ; See if the status has changed:
  100. IntCmp $R0 $R1 "${SecName}_unchanged"
  101. !insertmacro LoadSectionSelectedIntoVar ${SecName} ${SecName}_selected
  102. IntCmp $R1 ${SF_SELECTED} "${SecName}_was_selected"
  103. !insertmacro "Deselect_required_by_${SecName}"
  104. goto "${SecName}_unchanged"
  105. "${SecName}_was_selected:"
  106. !insertmacro "Select_${SecName}_depends"
  107. "${SecName}_unchanged:"
  108. !macroend
  109. ;--- End of Add/Remove macros ---
  110. ;--------------------------------
  111. ;Interface Settings
  112. !define MUI_HEADERIMAGE
  113. !define MUI_ABORTWARNING
  114. ;--------------------------------
  115. ; path functions
  116. !verbose 3
  117. !include "WinMessages.NSH"
  118. !verbose 4
  119. ;----------------------------------------
  120. ; based upon a script of "Written by KiCHiK 2003-01-18 05:57:02"
  121. ;----------------------------------------
  122. !verbose 3
  123. !include "WinMessages.NSH"
  124. !verbose 4
  125. ;====================================================
  126. ; get_NT_environment
  127. ; Returns: the selected environment
  128. ; Output : head of the stack
  129. ;====================================================
  130. !macro select_NT_profile UN
  131. Function ${UN}select_NT_profile
  132. StrCmp $ADD_TO_PATH_ALL_USERS "1" 0 environment_single
  133. DetailPrint "Selected environment for all users"
  134. Push "all"
  135. Return
  136. environment_single:
  137. DetailPrint "Selected environment for current user only."
  138. Push "current"
  139. Return
  140. FunctionEnd
  141. !macroend
  142. !insertmacro select_NT_profile ""
  143. !insertmacro select_NT_profile "un."
  144. ;----------------------------------------------------
  145. !define NT_current_env 'HKCU "Environment"'
  146. !define NT_all_env 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
  147. !ifndef WriteEnvStr_RegKey
  148. !ifdef ALL_USERS
  149. !define WriteEnvStr_RegKey \
  150. 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
  151. !else
  152. !define WriteEnvStr_RegKey 'HKCU "Environment"'
  153. !endif
  154. !endif
  155. ; AddToPath - Adds the given dir to the search path.
  156. ; Input - head of the stack
  157. ; Note - Win9x systems requires reboot
  158. Function AddToPath
  159. Exch $0
  160. Push $1
  161. Push $2
  162. Push $3
  163. # don't add if the path doesn't exist
  164. IfFileExists "$0\*.*" "" AddToPath_done
  165. ReadEnvStr $1 PATH
  166. Push "$1;"
  167. Push "$0;"
  168. Call StrStr
  169. Pop $2
  170. StrCmp $2 "" "" AddToPath_done
  171. Push "$1;"
  172. Push "$0\;"
  173. Call StrStr
  174. Pop $2
  175. StrCmp $2 "" "" AddToPath_done
  176. GetFullPathName /SHORT $3 $0
  177. Push "$1;"
  178. Push "$3;"
  179. Call StrStr
  180. Pop $2
  181. StrCmp $2 "" "" AddToPath_done
  182. Push "$1;"
  183. Push "$3\;"
  184. Call StrStr
  185. Pop $2
  186. StrCmp $2 "" "" AddToPath_done
  187. Call IsNT
  188. Pop $1
  189. StrCmp $1 1 AddToPath_NT
  190. ; Not on NT
  191. StrCpy $1 $WINDIR 2
  192. FileOpen $1 "$1\autoexec.bat" a
  193. FileSeek $1 -1 END
  194. FileReadByte $1 $2
  195. IntCmp $2 26 0 +2 +2 # DOS EOF
  196. FileSeek $1 -1 END # write over EOF
  197. FileWrite $1 "$\r$\nSET PATH=%PATH%;$3$\r$\n"
  198. FileClose $1
  199. SetRebootFlag true
  200. Goto AddToPath_done
  201. AddToPath_NT:
  202. ReadRegStr $1 ${WriteEnvStr_RegKey} "PATH"
  203. StrCmp $1 "" AddToPath_NTdoIt
  204. Push $1
  205. Call Trim
  206. Pop $1
  207. StrCpy $0 "$1;$0"
  208. AddToPath_NTdoIt:
  209. WriteRegExpandStr ${WriteEnvStr_RegKey} "PATH" $0
  210. SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
  211. AddToPath_done:
  212. Pop $3
  213. Pop $2
  214. Pop $1
  215. Pop $0
  216. FunctionEnd
  217. ; RemoveFromPath - Remove a given dir from the path
  218. ; Input: head of the stack
  219. Function un.RemoveFromPath
  220. Exch $0
  221. Push $1
  222. Push $2
  223. Push $3
  224. Push $4
  225. Push $5
  226. Push $6
  227. IntFmt $6 "%c" 26 # DOS EOF
  228. Call un.IsNT
  229. Pop $1
  230. StrCmp $1 1 unRemoveFromPath_NT
  231. ; Not on NT
  232. StrCpy $1 $WINDIR 2
  233. FileOpen $1 "$1\autoexec.bat" r
  234. GetTempFileName $4
  235. FileOpen $2 $4 w
  236. GetFullPathName /SHORT $0 $0
  237. StrCpy $0 "SET PATH=%PATH%;$0"
  238. Goto unRemoveFromPath_dosLoop
  239. unRemoveFromPath_dosLoop:
  240. FileRead $1 $3
  241. StrCpy $5 $3 1 -1 # read last char
  242. StrCmp $5 $6 0 +2 # if DOS EOF
  243. StrCpy $3 $3 -1 # remove DOS EOF so we can compare
  244. StrCmp $3 "$0$\r$\n" unRemoveFromPath_dosLoopRemoveLine
  245. StrCmp $3 "$0$\n" unRemoveFromPath_dosLoopRemoveLine
  246. StrCmp $3 "$0" unRemoveFromPath_dosLoopRemoveLine
  247. StrCmp $3 "" unRemoveFromPath_dosLoopEnd
  248. FileWrite $2 $3
  249. Goto unRemoveFromPath_dosLoop
  250. unRemoveFromPath_dosLoopRemoveLine:
  251. SetRebootFlag true
  252. Goto unRemoveFromPath_dosLoop
  253. unRemoveFromPath_dosLoopEnd:
  254. FileClose $2
  255. FileClose $1
  256. StrCpy $1 $WINDIR 2
  257. Delete "$1\autoexec.bat"
  258. CopyFiles /SILENT $4 "$1\autoexec.bat"
  259. Delete $4
  260. Goto unRemoveFromPath_done
  261. unRemoveFromPath_NT:
  262. ReadRegStr $1 ${WriteEnvStr_RegKey} "PATH"
  263. StrCpy $5 $1 1 -1 # copy last char
  264. StrCmp $5 ";" +2 # if last char != ;
  265. StrCpy $1 "$1;" # append ;
  266. Push $1
  267. Push "$0;"
  268. Call un.StrStr ; Find `$0;` in $1
  269. Pop $2 ; pos of our dir
  270. StrCmp $2 "" unRemoveFromPath_done
  271. ; else, it is in path
  272. # $0 - path to add
  273. # $1 - path var
  274. StrLen $3 "$0;"
  275. StrLen $4 $2
  276. StrCpy $5 $1 -$4 # $5 is now the part before the path to remove
  277. StrCpy $6 $2 "" $3 # $6 is now the part after the path to remove
  278. StrCpy $3 $5$6
  279. StrCpy $5 $3 1 -1 # copy last char
  280. StrCmp $5 ";" 0 +2 # if last char == ;
  281. StrCpy $3 $3 -1 # remove last char
  282. WriteRegExpandStr ${WriteEnvStr_RegKey} "PATH" $3
  283. SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
  284. unRemoveFromPath_done:
  285. Pop $6
  286. Pop $5
  287. Pop $4
  288. Pop $3
  289. Pop $2
  290. Pop $1
  291. Pop $0
  292. FunctionEnd
  293. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  294. ; Uninstall sutff
  295. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  296. ###########################################
  297. # Utility Functions #
  298. ###########################################
  299. ;====================================================
  300. ; IsNT - Returns 1 if the current system is NT, 0
  301. ; otherwise.
  302. ; Output: head of the stack
  303. ;====================================================
  304. ; IsNT
  305. ; no input
  306. ; output, top of the stack = 1 if NT or 0 if not
  307. ;
  308. ; Usage:
  309. ; Call IsNT
  310. ; Pop $R0
  311. ; ($R0 at this point is 1 or 0)
  312. !macro IsNT un
  313. Function ${un}IsNT
  314. Push $0
  315. ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
  316. StrCmp $0 "" 0 IsNT_yes
  317. ; we are not NT.
  318. Pop $0
  319. Push 0
  320. Return
  321. IsNT_yes:
  322. ; NT!!!
  323. Pop $0
  324. Push 1
  325. FunctionEnd
  326. !macroend
  327. !insertmacro IsNT ""
  328. !insertmacro IsNT "un."
  329. ; StrStr
  330. ; input, top of stack = string to search for
  331. ; top of stack-1 = string to search in
  332. ; output, top of stack (replaces with the portion of the string remaining)
  333. ; modifies no other variables.
  334. ;
  335. ; Usage:
  336. ; Push "this is a long ass string"
  337. ; Push "ass"
  338. ; Call StrStr
  339. ; Pop $R0
  340. ; ($R0 at this point is "ass string")
  341. !macro StrStr un
  342. Function ${un}StrStr
  343. Exch $R1 ; st=haystack,old$R1, $R1=needle
  344. Exch ; st=old$R1,haystack
  345. Exch $R2 ; st=old$R1,old$R2, $R2=haystack
  346. Push $R3
  347. Push $R4
  348. Push $R5
  349. StrLen $R3 $R1
  350. StrCpy $R4 0
  351. ; $R1=needle
  352. ; $R2=haystack
  353. ; $R3=len(needle)
  354. ; $R4=cnt
  355. ; $R5=tmp
  356. loop:
  357. StrCpy $R5 $R2 $R3 $R4
  358. StrCmp $R5 $R1 done
  359. StrCmp $R5 "" done
  360. IntOp $R4 $R4 + 1
  361. Goto loop
  362. done:
  363. StrCpy $R1 $R2 "" $R4
  364. Pop $R5
  365. Pop $R4
  366. Pop $R3
  367. Pop $R2
  368. Exch $R1
  369. FunctionEnd
  370. !macroend
  371. !insertmacro StrStr ""
  372. !insertmacro StrStr "un."
  373. Function Trim ; Added by Pelaca
  374. Exch $R1
  375. Push $R2
  376. Loop:
  377. StrCpy $R2 "$R1" 1 -1
  378. StrCmp "$R2" " " RTrim
  379. StrCmp "$R2" "$\n" RTrim
  380. StrCmp "$R2" "$\r" RTrim
  381. StrCmp "$R2" ";" RTrim
  382. GoTo Done
  383. RTrim:
  384. StrCpy $R1 "$R1" -1
  385. Goto Loop
  386. Done:
  387. Pop $R2
  388. Exch $R1
  389. FunctionEnd
  390. Function ConditionalAddToRegisty
  391. Pop $0
  392. Pop $1
  393. StrCmp "$0" "" ConditionalAddToRegisty_EmptyString
  394. WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_DIRECTORY@" \
  395. "$1" "$0"
  396. ;MessageBox MB_OK "Set Registry: '$1' to '$0'"
  397. DetailPrint "Set install registry entry: '$1' to '$0'"
  398. ConditionalAddToRegisty_EmptyString:
  399. FunctionEnd
  400. ;--------------------------------
  401. ; Installation types
  402. @CPACK_NSIS_INSTALLATION_TYPES@
  403. ;--------------------------------
  404. ; Component sections
  405. @CPACK_NSIS_COMPONENT_SECTIONS@
  406. ;--------------------------------
  407. ; Define some macro setting for the gui
  408. @CPACK_NSIS_INSTALLER_MUI_ICON_CODE@
  409. @CPACK_NSIS_INSTALLER_ICON_CODE@
  410. @CPACK_NSIS_INSTALLER_MUI_COMPONENTS_DESC@
  411. ;--------------------------------
  412. ;Pages
  413. !insertmacro MUI_PAGE_WELCOME
  414. !insertmacro MUI_PAGE_LICENSE "@CPACK_RESOURCE_FILE_LICENSE@"
  415. Page custom InstallOptionsPage
  416. !insertmacro MUI_PAGE_DIRECTORY
  417. ;Start Menu Folder Page Configuration
  418. !define MUI_STARTMENUPAGE_REGISTRY_ROOT "SHCTX"
  419. !define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
  420. !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder"
  421. !insertmacro MUI_PAGE_STARTMENU Application $STARTMENU_FOLDER
  422. @CPACK_NSIS_PAGE_COMPONENTS@
  423. !insertmacro MUI_PAGE_INSTFILES
  424. !insertmacro MUI_PAGE_FINISH
  425. !insertmacro MUI_UNPAGE_CONFIRM
  426. !insertmacro MUI_UNPAGE_INSTFILES
  427. ;--------------------------------
  428. ;Languages
  429. !insertmacro MUI_LANGUAGE "English"
  430. ;--------------------------------
  431. ;Reserve Files
  432. ;These files should be inserted before other files in the data block
  433. ;Keep these lines before any File command
  434. ;Only for solid compression (by default, solid compression is enabled for BZIP2 and LZMA)
  435. ReserveFile "NSIS.InstallOptions.ini"
  436. !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
  437. ;--------------------------------
  438. ;Installer Sections
  439. Section "-Core installation"
  440. ;Use the entire tree produced by the INSTALL target. Keep the
  441. ;list of directories here in sync with the RMDir commands below.
  442. SetOutPath "$INSTDIR"
  443. @CPACK_NSIS_FULL_INSTALL@
  444. ;Store installation folder
  445. WriteRegStr SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "" $INSTDIR
  446. ;Create uninstaller
  447. WriteUninstaller "$INSTDIR\Uninstall.exe"
  448. Push "DisplayName"
  449. Push "@CPACK_NSIS_DISPLAY_NAME@"
  450. Call ConditionalAddToRegisty
  451. Push "DisplayVersion"
  452. Push "@CPACK_PACKAGE_VERSION@"
  453. Call ConditionalAddToRegisty
  454. Push "Publisher"
  455. Push "@CPACK_PACKAGE_VENDOR@"
  456. Call ConditionalAddToRegisty
  457. Push "UninstallString"
  458. Push "$INSTDIR\Uninstall.exe"
  459. Call ConditionalAddToRegisty
  460. Push "ModifyPath"
  461. ; Optional registration
  462. Push "DisplayIcon"
  463. Push "$INSTDIR\@CPACK_NSIS_INSTALLED_ICON_NAME@"
  464. Call ConditionalAddToRegisty
  465. Push "HelpLink"
  466. Push "@CPACK_NSIS_HELP_LINK@"
  467. Call ConditionalAddToRegisty
  468. Push "URLInfoAbout"
  469. Push "@CPACK_NSIS_URL_INFO_ABOUT@"
  470. Call ConditionalAddToRegisty
  471. Push "Contact"
  472. Push "@CPACK_NSIS_CONTACT@"
  473. Call ConditionalAddToRegisty
  474. !insertmacro MUI_INSTALLOPTIONS_READ $INSTALL_DESKTOP "NSIS.InstallOptions.ini" "Field 5" "State"
  475. !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
  476. ;Create shortcuts
  477. CreateDirectory "$SMPROGRAMS\$STARTMENU_FOLDER"
  478. @CPACK_NSIS_CREATE_ICONS@
  479. @CPACK_NSIS_CREATE_ICONS_EXTRA@
  480. CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Uninstall.lnk" "$INSTDIR\Uninstall.exe"
  481. ; Write special uninstall registry entries
  482. Push "StartMenu"
  483. Push "$STARTMENU_FOLDER"
  484. Call ConditionalAddToRegisty
  485. Push "DoNotAddToPath"
  486. Push "$DO_NOT_ADD_TO_PATH"
  487. Call ConditionalAddToRegisty
  488. Push "AddToPathAllUsers"
  489. Push "$ADD_TO_PATH_ALL_USERS"
  490. Call ConditionalAddToRegisty
  491. Push "AddToPathCurrentUser"
  492. Push "$ADD_TO_PATH_CURRENT_USER"
  493. Call ConditionalAddToRegisty
  494. Push "InstallToDesktop"
  495. Push "$INSTALL_DESKTOP"
  496. Call ConditionalAddToRegisty
  497. @CPACK_NSIS_EXTRA_INSTALL_COMMANDS@
  498. !insertmacro MUI_STARTMENU_WRITE_END
  499. SectionEnd
  500. Section "-Add to path"
  501. Push $INSTDIR\bin
  502. ;Read a value from an InstallOptions INI file
  503. !insertmacro MUI_INSTALLOPTIONS_READ $DO_NOT_ADD_TO_PATH "NSIS.InstallOptions.ini" "Field 2" "State"
  504. !insertmacro MUI_INSTALLOPTIONS_READ $ADD_TO_PATH_ALL_USERS "NSIS.InstallOptions.ini" "Field 3" "State"
  505. !insertmacro MUI_INSTALLOPTIONS_READ $ADD_TO_PATH_CURRENT_USER "NSIS.InstallOptions.ini" "Field 4" "State"
  506. StrCmp "@CPACK_NSIS_MODIFY_PATH@" "ON" 0 doNotAddToPath
  507. StrCmp $DO_NOT_ADD_TO_PATH "1" doNotAddToPath 0
  508. Call AddToPath
  509. doNotAddToPath:
  510. SectionEnd
  511. ;--------------------------------
  512. ; Create custom pages
  513. Function InstallOptionsPage
  514. !insertmacro MUI_HEADER_TEXT "Install Options" "Chose options for installing @CPACK_PACKAGE_INSTALL_DIRECTORY@"
  515. !insertmacro MUI_INSTALLOPTIONS_DISPLAY "NSIS.InstallOptions.ini"
  516. FunctionEnd
  517. ;--------------------------------
  518. ; determine admin versus local install
  519. Function un.onInit
  520. ClearErrors
  521. UserInfo::GetName
  522. IfErrors noLM
  523. Pop $0
  524. UserInfo::GetAccountType
  525. Pop $1
  526. StrCmp $1 "Admin" 0 +3
  527. SetShellVarContext all
  528. ;MessageBox MB_OK 'User "$0" is in the Admin group'
  529. Goto done
  530. StrCmp $1 "Power" 0 +3
  531. SetShellVarContext all
  532. ;MessageBox MB_OK 'User "$0" is in the Power Users group'
  533. Goto done
  534. noLM:
  535. ;Get installation folder from registry if available
  536. done:
  537. FunctionEnd
  538. ;--- Add/Remove callback functions: ---
  539. !macro SectionList MacroName
  540. ;This macro used to perform operation on multiple sections.
  541. ;List all of your components in following manner here.
  542. @CPACK_NSIS_COMPONENT_SECTION_LIST@
  543. !macroend
  544. Section -FinishComponents
  545. ;Removes unselected components and writes component status to registry
  546. !insertmacro SectionList "FinishSection"
  547. SectionEnd
  548. ;--- End of Add/Remove callback functions ---
  549. ;--------------------------------
  550. ; Component dependencies
  551. Function .onSelChange
  552. !insertmacro SectionList MaybeSelectionChanged
  553. FunctionEnd
  554. ;--------------------------------
  555. ;Uninstaller Section
  556. Section "Uninstall"
  557. ReadRegStr $START_MENU SHCTX \
  558. "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_DIRECTORY@" "StartMenu"
  559. ;MessageBox MB_OK "Start menu is in: $START_MENU"
  560. ReadRegStr $DO_NOT_ADD_TO_PATH SHCTX \
  561. "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_DIRECTORY@" "DoNotAddToPath"
  562. ReadRegStr $ADD_TO_PATH_ALL_USERS SHCTX \
  563. "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_DIRECTORY@" "AddToPathAllUsers"
  564. ReadRegStr $ADD_TO_PATH_CURRENT_USER SHCTX \
  565. "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_DIRECTORY@" "AddToPathCurrentUser"
  566. ;MessageBox MB_OK "Add to path: $DO_NOT_ADD_TO_PATH all users: $ADD_TO_PATH_ALL_USERS"
  567. ReadRegStr $INSTALL_DESKTOP SHCTX \
  568. "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_DIRECTORY@" "InstallToDesktop"
  569. ;MessageBox MB_OK "Install to desktop: $INSTALL_DESKTOP "
  570. @CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS@
  571. ;Remove files we installed.
  572. ;Keep the list of directories here in sync with the File commands above.
  573. @CPACK_NSIS_DELETE_FILES@
  574. @CPACK_NSIS_DELETE_DIRECTORIES@
  575. ;Remove the uninstaller itself.
  576. Delete "$INSTDIR\Uninstall.exe"
  577. DeleteRegKey SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
  578. ;Remove the installation directory if it is empty.
  579. RMDir "$INSTDIR"
  580. ; Remove the registry entries.
  581. DeleteRegKey SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
  582. ; Removes all optional components
  583. !insertmacro SectionList "RemoveSection"
  584. !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP
  585. Delete "$SMPROGRAMS\$MUI_TEMP\Uninstall.lnk"
  586. @CPACK_NSIS_DELETE_ICONS@
  587. @CPACK_NSIS_DELETE_ICONS_EXTRA@
  588. ;Delete empty start menu parent diretories
  589. StrCpy $MUI_TEMP "$SMPROGRAMS\$MUI_TEMP"
  590. startMenuDeleteLoop:
  591. ClearErrors
  592. RMDir $MUI_TEMP
  593. GetFullPathName $MUI_TEMP "$MUI_TEMP\.."
  594. IfErrors startMenuDeleteLoopDone
  595. StrCmp "$MUI_TEMP" "$SMPROGRAMS" startMenuDeleteLoopDone startMenuDeleteLoop
  596. startMenuDeleteLoopDone:
  597. ; If the user changed the shortcut, then untinstall may not work. This should
  598. ; try to fix it.
  599. StrCpy $MUI_TEMP "$START_MENU"
  600. Delete "$SMPROGRAMS\$MUI_TEMP\Uninstall.lnk"
  601. @CPACK_NSIS_DELETE_ICONS_EXTRA@
  602. ;Delete empty start menu parent diretories
  603. StrCpy $MUI_TEMP "$SMPROGRAMS\$MUI_TEMP"
  604. secondStartMenuDeleteLoop:
  605. ClearErrors
  606. RMDir $MUI_TEMP
  607. GetFullPathName $MUI_TEMP "$MUI_TEMP\.."
  608. IfErrors secondStartMenuDeleteLoopDone
  609. StrCmp "$MUI_TEMP" "$SMPROGRAMS" secondStartMenuDeleteLoopDone secondStartMenuDeleteLoop
  610. secondStartMenuDeleteLoopDone:
  611. DeleteRegKey /ifempty SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
  612. Push $INSTDIR\bin
  613. StrCmp $DO_NOT_ADD_TO_PATH_ "1" doNotRemoveFromPath 0
  614. Call un.RemoveFromPath
  615. doNotRemoveFromPath:
  616. SectionEnd
  617. ;--------------------------------
  618. ; determine admin versus local install
  619. ; Is install for "AllUsers" or "JustMe"?
  620. ; Default to "JustMe" - set to "AllUsers" if admin or on Win9x
  621. ; This function is used for the very first "custom page" of the installer.
  622. ; This custom page does not show up visibly, but it executes prior to the
  623. ; first visible page and sets up $INSTDIR properly...
  624. ; Choose different default installation folder based on SV_ALLUSERS...
  625. ; "Program Files" for AllUsers, "My Documents" for JustMe...
  626. Function .onInit
  627. ; Reads components status for registry
  628. !insertmacro SectionList "InitSection"
  629. StrCpy $SV_ALLUSERS "JustMe"
  630. StrCpy $INSTDIR "$DOCUMENTS\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
  631. ClearErrors
  632. UserInfo::GetName
  633. IfErrors noLM
  634. Pop $0
  635. UserInfo::GetAccountType
  636. Pop $1
  637. StrCmp $1 "Admin" 0 +3
  638. SetShellVarContext all
  639. ;MessageBox MB_OK 'User "$0" is in the Admin group'
  640. StrCpy $SV_ALLUSERS "AllUsers"
  641. Goto done
  642. StrCmp $1 "Power" 0 +3
  643. SetShellVarContext all
  644. ;MessageBox MB_OK 'User "$0" is in the Power Users group'
  645. StrCpy $SV_ALLUSERS "AllUsers"
  646. Goto done
  647. noLM:
  648. StrCpy $SV_ALLUSERS "AllUsers"
  649. ;Get installation folder from registry if available
  650. done:
  651. StrCmp $SV_ALLUSERS "AllUsers" 0 +2
  652. StrCpy $INSTDIR "$PROGRAMFILES\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
  653. StrCmp "@CPACK_NSIS_MODIFY_PATH@" "ON" 0 noOptionsPage
  654. !insertmacro MUI_INSTALLOPTIONS_EXTRACT "NSIS.InstallOptions.ini"
  655. noOptionsPage:
  656. FunctionEnd