NSIS.template.in 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982
  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. Var IS_DEFAULT_INSTALLDIR
  18. ;--------------------------------
  19. ;Include Modern UI
  20. Unicode True
  21. !include "MUI.nsh"
  22. ;Default installation folder
  23. InstallDir "@CPACK_NSIS_INSTALL_ROOT@\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
  24. ;--------------------------------
  25. ;General
  26. ;Name and file
  27. Name "@CPACK_NSIS_PACKAGE_NAME@"
  28. OutFile "@CPACK_TOPLEVEL_DIRECTORY@/@CPACK_OUTPUT_FILE_NAME@"
  29. ;Set compression
  30. SetCompressor @CPACK_NSIS_COMPRESSOR@
  31. ;Require administrator access
  32. RequestExecutionLevel admin
  33. @CPACK_NSIS_DEFINES@
  34. !include Sections.nsh
  35. ;--- Component support macros: ---
  36. ; The code for the add/remove functionality is from:
  37. ; http://nsis.sourceforge.net/Add/Remove_Functionality
  38. ; It has been modified slightly and extended to provide
  39. ; inter-component dependencies.
  40. Var AR_SecFlags
  41. Var AR_RegFlags
  42. @CPACK_NSIS_SECTION_SELECTED_VARS@
  43. ; Loads the "selected" flag for the section named SecName into the
  44. ; variable VarName.
  45. !macro LoadSectionSelectedIntoVar SecName VarName
  46. SectionGetFlags ${${SecName}} $${VarName}
  47. IntOp $${VarName} $${VarName} & ${SF_SELECTED} ;Turn off all other bits
  48. !macroend
  49. ; Loads the value of a variable... can we get around this?
  50. !macro LoadVar VarName
  51. IntOp $R0 0 + $${VarName}
  52. !macroend
  53. ; Sets the value of a variable
  54. !macro StoreVar VarName IntValue
  55. IntOp $${VarName} 0 + ${IntValue}
  56. !macroend
  57. !macro InitSection SecName
  58. ; This macro reads component installed flag from the registry and
  59. ;changes checked state of the section on the components page.
  60. ;Input: section index constant name specified in Section command.
  61. ClearErrors
  62. ;Reading component status from registry
  63. ReadRegDWORD $AR_RegFlags HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@\Components\${SecName}" "Installed"
  64. IfErrors "default_${SecName}"
  65. ;Status will stay default if registry value not found
  66. ;(component was never installed)
  67. IntOp $AR_RegFlags $AR_RegFlags & ${SF_SELECTED} ;Turn off all other bits
  68. SectionGetFlags ${${SecName}} $AR_SecFlags ;Reading default section flags
  69. IntOp $AR_SecFlags $AR_SecFlags & 0xFFFE ;Turn lowest (enabled) bit off
  70. IntOp $AR_SecFlags $AR_RegFlags | $AR_SecFlags ;Change lowest bit
  71. ; Note whether this component was installed before
  72. !insertmacro StoreVar ${SecName}_was_installed $AR_RegFlags
  73. IntOp $R0 $AR_RegFlags & $AR_RegFlags
  74. ;Writing modified flags
  75. SectionSetFlags ${${SecName}} $AR_SecFlags
  76. "default_${SecName}:"
  77. !insertmacro LoadSectionSelectedIntoVar ${SecName} ${SecName}_selected
  78. !macroend
  79. !macro FinishSection SecName
  80. ; This macro reads section flag set by user and removes the section
  81. ;if it is not selected.
  82. ;Then it writes component installed flag to registry
  83. ;Input: section index constant name specified in Section command.
  84. SectionGetFlags ${${SecName}} $AR_SecFlags ;Reading section flags
  85. ;Checking lowest bit:
  86. IntOp $AR_SecFlags $AR_SecFlags & ${SF_SELECTED}
  87. IntCmp $AR_SecFlags 1 "leave_${SecName}"
  88. ;Section is not selected:
  89. ;Calling Section uninstall macro and writing zero installed flag
  90. !insertmacro "Remove_${${SecName}}"
  91. WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@\Components\${SecName}" \
  92. "Installed" 0
  93. Goto "exit_${SecName}"
  94. "leave_${SecName}:"
  95. ;Section is selected:
  96. WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@\Components\${SecName}" \
  97. "Installed" 1
  98. "exit_${SecName}:"
  99. !macroend
  100. !macro RemoveSection_CPack SecName
  101. ; This macro is used to call section's Remove_... macro
  102. ;from the uninstaller.
  103. ;Input: section index constant name specified in Section command.
  104. !insertmacro "Remove_${${SecName}}"
  105. !macroend
  106. ; Determine whether the selection of SecName changed
  107. !macro MaybeSelectionChanged SecName
  108. !insertmacro LoadVar ${SecName}_selected
  109. SectionGetFlags ${${SecName}} $R1
  110. IntOp $R1 $R1 & ${SF_SELECTED} ;Turn off all other bits
  111. ; See if the status has changed:
  112. IntCmp $R0 $R1 "${SecName}_unchanged"
  113. !insertmacro LoadSectionSelectedIntoVar ${SecName} ${SecName}_selected
  114. IntCmp $R1 ${SF_SELECTED} "${SecName}_was_selected"
  115. !insertmacro "Deselect_required_by_${SecName}"
  116. goto "${SecName}_unchanged"
  117. "${SecName}_was_selected:"
  118. !insertmacro "Select_${SecName}_depends"
  119. "${SecName}_unchanged:"
  120. !macroend
  121. ;--- End of Add/Remove macros ---
  122. ;--------------------------------
  123. ;Interface Settings
  124. !define MUI_HEADERIMAGE
  125. !define MUI_ABORTWARNING
  126. ;----------------------------------------
  127. ; based upon a script of "Written by KiCHiK 2003-01-18 05:57:02"
  128. ;----------------------------------------
  129. !verbose 3
  130. !include "WinMessages.NSH"
  131. !verbose 4
  132. ;====================================================
  133. ; get_NT_environment
  134. ; Returns: the selected environment
  135. ; Output : head of the stack
  136. ;====================================================
  137. !macro select_NT_profile UN
  138. Function ${UN}select_NT_profile
  139. StrCmp $ADD_TO_PATH_ALL_USERS "1" 0 environment_single
  140. DetailPrint "Selected environment for all users"
  141. Push "all"
  142. Return
  143. environment_single:
  144. DetailPrint "Selected environment for current user only."
  145. Push "current"
  146. Return
  147. FunctionEnd
  148. !macroend
  149. !insertmacro select_NT_profile ""
  150. !insertmacro select_NT_profile "un."
  151. ;----------------------------------------------------
  152. !define NT_current_env 'HKCU "Environment"'
  153. !define NT_all_env 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
  154. !ifndef WriteEnvStr_RegKey
  155. !ifdef ALL_USERS
  156. !define WriteEnvStr_RegKey \
  157. 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
  158. !else
  159. !define WriteEnvStr_RegKey 'HKCU "Environment"'
  160. !endif
  161. !endif
  162. ; AddToPath - Adds the given dir to the search path.
  163. ; Input - head of the stack
  164. ; Note - Win9x systems requires reboot
  165. Function AddToPath
  166. Exch $0
  167. Push $1
  168. Push $2
  169. Push $3
  170. # don't add if the path doesn't exist
  171. IfFileExists "$0\*.*" "" AddToPath_done
  172. ReadEnvStr $1 PATH
  173. ; if the path is too long for a NSIS variable NSIS will return a 0
  174. ; length string. If we find that, then warn and skip any path
  175. ; modification as it will trash the existing path.
  176. StrLen $2 $1
  177. IntCmp $2 0 CheckPathLength_ShowPathWarning CheckPathLength_Done CheckPathLength_Done
  178. CheckPathLength_ShowPathWarning:
  179. Messagebox MB_OK|MB_ICONEXCLAMATION "Warning! PATH too long installer unable to modify PATH!"
  180. Goto AddToPath_done
  181. CheckPathLength_Done:
  182. Push "$1;"
  183. Push "$0;"
  184. Call StrStr
  185. Pop $2
  186. StrCmp $2 "" "" AddToPath_done
  187. Push "$1;"
  188. Push "$0\;"
  189. Call StrStr
  190. Pop $2
  191. StrCmp $2 "" "" AddToPath_done
  192. GetFullPathName /SHORT $3 $0
  193. Push "$1;"
  194. Push "$3;"
  195. Call StrStr
  196. Pop $2
  197. StrCmp $2 "" "" AddToPath_done
  198. Push "$1;"
  199. Push "$3\;"
  200. Call StrStr
  201. Pop $2
  202. StrCmp $2 "" "" AddToPath_done
  203. Call IsNT
  204. Pop $1
  205. StrCmp $1 1 AddToPath_NT
  206. ; Not on NT
  207. StrCpy $1 $WINDIR 2
  208. FileOpen $1 "$1\autoexec.bat" a
  209. FileSeek $1 -1 END
  210. FileReadByte $1 $2
  211. IntCmp $2 26 0 +2 +2 # DOS EOF
  212. FileSeek $1 -1 END # write over EOF
  213. FileWrite $1 "$\r$\nSET PATH=%PATH%;$3$\r$\n"
  214. FileClose $1
  215. SetRebootFlag true
  216. Goto AddToPath_done
  217. AddToPath_NT:
  218. StrCmp $ADD_TO_PATH_ALL_USERS "1" ReadAllKey
  219. ReadRegStr $1 ${NT_current_env} "PATH"
  220. Goto DoTrim
  221. ReadAllKey:
  222. ReadRegStr $1 ${NT_all_env} "PATH"
  223. DoTrim:
  224. StrCmp $1 "" AddToPath_NTdoIt
  225. Push $1
  226. Call Trim
  227. Pop $1
  228. StrCpy $0 "$1;$0"
  229. AddToPath_NTdoIt:
  230. StrCmp $ADD_TO_PATH_ALL_USERS "1" WriteAllKey
  231. WriteRegExpandStr ${NT_current_env} "PATH" $0
  232. Goto DoSend
  233. WriteAllKey:
  234. WriteRegExpandStr ${NT_all_env} "PATH" $0
  235. DoSend:
  236. SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
  237. AddToPath_done:
  238. Pop $3
  239. Pop $2
  240. Pop $1
  241. Pop $0
  242. FunctionEnd
  243. ; RemoveFromPath - Remove a given dir from the path
  244. ; Input: head of the stack
  245. Function un.RemoveFromPath
  246. Exch $0
  247. Push $1
  248. Push $2
  249. Push $3
  250. Push $4
  251. Push $5
  252. Push $6
  253. IntFmt $6 "%c" 26 # DOS EOF
  254. Call un.IsNT
  255. Pop $1
  256. StrCmp $1 1 unRemoveFromPath_NT
  257. ; Not on NT
  258. StrCpy $1 $WINDIR 2
  259. FileOpen $1 "$1\autoexec.bat" r
  260. GetTempFileName $4
  261. FileOpen $2 $4 w
  262. GetFullPathName /SHORT $0 $0
  263. StrCpy $0 "SET PATH=%PATH%;$0"
  264. Goto unRemoveFromPath_dosLoop
  265. unRemoveFromPath_dosLoop:
  266. FileRead $1 $3
  267. StrCpy $5 $3 1 -1 # read last char
  268. StrCmp $5 $6 0 +2 # if DOS EOF
  269. StrCpy $3 $3 -1 # remove DOS EOF so we can compare
  270. StrCmp $3 "$0$\r$\n" unRemoveFromPath_dosLoopRemoveLine
  271. StrCmp $3 "$0$\n" unRemoveFromPath_dosLoopRemoveLine
  272. StrCmp $3 "$0" unRemoveFromPath_dosLoopRemoveLine
  273. StrCmp $3 "" unRemoveFromPath_dosLoopEnd
  274. FileWrite $2 $3
  275. Goto unRemoveFromPath_dosLoop
  276. unRemoveFromPath_dosLoopRemoveLine:
  277. SetRebootFlag true
  278. Goto unRemoveFromPath_dosLoop
  279. unRemoveFromPath_dosLoopEnd:
  280. FileClose $2
  281. FileClose $1
  282. StrCpy $1 $WINDIR 2
  283. Delete "$1\autoexec.bat"
  284. CopyFiles /SILENT $4 "$1\autoexec.bat"
  285. Delete $4
  286. Goto unRemoveFromPath_done
  287. unRemoveFromPath_NT:
  288. StrCmp $ADD_TO_PATH_ALL_USERS "1" unReadAllKey
  289. ReadRegStr $1 ${NT_current_env} "PATH"
  290. Goto unDoTrim
  291. unReadAllKey:
  292. ReadRegStr $1 ${NT_all_env} "PATH"
  293. unDoTrim:
  294. StrCpy $5 $1 1 -1 # copy last char
  295. StrCmp $5 ";" +2 # if last char != ;
  296. StrCpy $1 "$1;" # append ;
  297. Push $1
  298. Push "$0;"
  299. Call un.StrStr ; Find `$0;` in $1
  300. Pop $2 ; pos of our dir
  301. StrCmp $2 "" unRemoveFromPath_done
  302. ; else, it is in path
  303. # $0 - path to add
  304. # $1 - path var
  305. StrLen $3 "$0;"
  306. StrLen $4 $2
  307. StrCpy $5 $1 -$4 # $5 is now the part before the path to remove
  308. StrCpy $6 $2 "" $3 # $6 is now the part after the path to remove
  309. StrCpy $3 $5$6
  310. StrCpy $5 $3 1 -1 # copy last char
  311. StrCmp $5 ";" 0 +2 # if last char == ;
  312. StrCpy $3 $3 -1 # remove last char
  313. StrCmp $ADD_TO_PATH_ALL_USERS "1" unWriteAllKey
  314. WriteRegExpandStr ${NT_current_env} "PATH" $3
  315. Goto unDoSend
  316. unWriteAllKey:
  317. WriteRegExpandStr ${NT_all_env} "PATH" $3
  318. unDoSend:
  319. SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
  320. unRemoveFromPath_done:
  321. Pop $6
  322. Pop $5
  323. Pop $4
  324. Pop $3
  325. Pop $2
  326. Pop $1
  327. Pop $0
  328. FunctionEnd
  329. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  330. ; Uninstall sutff
  331. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  332. ###########################################
  333. # Utility Functions #
  334. ###########################################
  335. ;====================================================
  336. ; IsNT - Returns 1 if the current system is NT, 0
  337. ; otherwise.
  338. ; Output: head of the stack
  339. ;====================================================
  340. ; IsNT
  341. ; no input
  342. ; output, top of the stack = 1 if NT or 0 if not
  343. ;
  344. ; Usage:
  345. ; Call IsNT
  346. ; Pop $R0
  347. ; ($R0 at this point is 1 or 0)
  348. !macro IsNT un
  349. Function ${un}IsNT
  350. Push $0
  351. ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
  352. StrCmp $0 "" 0 IsNT_yes
  353. ; we are not NT.
  354. Pop $0
  355. Push 0
  356. Return
  357. IsNT_yes:
  358. ; NT!!!
  359. Pop $0
  360. Push 1
  361. FunctionEnd
  362. !macroend
  363. !insertmacro IsNT ""
  364. !insertmacro IsNT "un."
  365. ; StrStr
  366. ; input, top of stack = string to search for
  367. ; top of stack-1 = string to search in
  368. ; output, top of stack (replaces with the portion of the string remaining)
  369. ; modifies no other variables.
  370. ;
  371. ; Usage:
  372. ; Push "this is a long ass string"
  373. ; Push "ass"
  374. ; Call StrStr
  375. ; Pop $R0
  376. ; ($R0 at this point is "ass string")
  377. !macro StrStr un
  378. Function ${un}StrStr
  379. Exch $R1 ; st=haystack,old$R1, $R1=needle
  380. Exch ; st=old$R1,haystack
  381. Exch $R2 ; st=old$R1,old$R2, $R2=haystack
  382. Push $R3
  383. Push $R4
  384. Push $R5
  385. StrLen $R3 $R1
  386. StrCpy $R4 0
  387. ; $R1=needle
  388. ; $R2=haystack
  389. ; $R3=len(needle)
  390. ; $R4=cnt
  391. ; $R5=tmp
  392. loop:
  393. StrCpy $R5 $R2 $R3 $R4
  394. StrCmp $R5 $R1 done
  395. StrCmp $R5 "" done
  396. IntOp $R4 $R4 + 1
  397. Goto loop
  398. done:
  399. StrCpy $R1 $R2 "" $R4
  400. Pop $R5
  401. Pop $R4
  402. Pop $R3
  403. Pop $R2
  404. Exch $R1
  405. FunctionEnd
  406. !macroend
  407. !insertmacro StrStr ""
  408. !insertmacro StrStr "un."
  409. Function Trim ; Added by Pelaca
  410. Exch $R1
  411. Push $R2
  412. Loop:
  413. StrCpy $R2 "$R1" 1 -1
  414. StrCmp "$R2" " " RTrim
  415. StrCmp "$R2" "$\n" RTrim
  416. StrCmp "$R2" "$\r" RTrim
  417. StrCmp "$R2" ";" RTrim
  418. GoTo Done
  419. RTrim:
  420. StrCpy $R1 "$R1" -1
  421. Goto Loop
  422. Done:
  423. Pop $R2
  424. Exch $R1
  425. FunctionEnd
  426. Function ConditionalAddToRegistry
  427. Pop $0
  428. Pop $1
  429. StrCmp "$0" "" ConditionalAddToRegistry_EmptyString
  430. WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" \
  431. "$1" "$0"
  432. ;MessageBox MB_OK "Set Registry: '$1' to '$0'"
  433. DetailPrint "Set install registry entry: '$1' to '$0'"
  434. ConditionalAddToRegistry_EmptyString:
  435. FunctionEnd
  436. ;--------------------------------
  437. !ifdef CPACK_USES_DOWNLOAD
  438. Function DownloadFile
  439. IfFileExists $INSTDIR\* +2
  440. CreateDirectory $INSTDIR
  441. Pop $0
  442. ; Skip if already downloaded
  443. IfFileExists $INSTDIR\$0 0 +2
  444. Return
  445. StrCpy $1 "@CPACK_DOWNLOAD_SITE@"
  446. try_again:
  447. NSISdl::download "$1/$0" "$INSTDIR\$0"
  448. Pop $1
  449. StrCmp $1 "success" success
  450. StrCmp $1 "Cancelled" cancel
  451. MessageBox MB_OK "Download failed: $1"
  452. cancel:
  453. Return
  454. success:
  455. FunctionEnd
  456. !endif
  457. ;--------------------------------
  458. ; Installation types
  459. @CPACK_NSIS_INSTALLATION_TYPES@
  460. ;--------------------------------
  461. ; Component sections
  462. @CPACK_NSIS_COMPONENT_SECTIONS@
  463. ;--------------------------------
  464. ; Define some macro setting for the gui
  465. @CPACK_NSIS_INSTALLER_MUI_ICON_CODE@
  466. @CPACK_NSIS_INSTALLER_ICON_CODE@
  467. @CPACK_NSIS_INSTALLER_MUI_WELCOMEFINISH_CODE@
  468. @CPACK_NSIS_INSTALLER_MUI_UNWELCOMEFINISH_CODE@
  469. @CPACK_NSIS_INSTALLER_MUI_COMPONENTS_DESC@
  470. @CPACK_NSIS_INSTALLER_MUI_FINISHPAGE_RUN_CODE@
  471. ;--------------------------------
  472. ;Pages
  473. !insertmacro MUI_PAGE_WELCOME
  474. !insertmacro MUI_PAGE_LICENSE "@CPACK_RESOURCE_FILE_LICENSE@"
  475. Page custom InstallOptionsPage
  476. !insertmacro MUI_PAGE_DIRECTORY
  477. ;Start Menu Folder Page Configuration
  478. !define MUI_STARTMENUPAGE_REGISTRY_ROOT "SHCTX"
  479. !define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
  480. !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder"
  481. !insertmacro MUI_PAGE_STARTMENU Application $STARTMENU_FOLDER
  482. @CPACK_NSIS_PAGE_COMPONENTS@
  483. !insertmacro MUI_PAGE_INSTFILES
  484. !insertmacro MUI_PAGE_FINISH
  485. !insertmacro MUI_UNPAGE_CONFIRM
  486. !insertmacro MUI_UNPAGE_INSTFILES
  487. ;--------------------------------
  488. ;Languages
  489. !insertmacro MUI_LANGUAGE "English" ;first language is the default language
  490. !insertmacro MUI_LANGUAGE "Czech"
  491. !insertmacro MUI_LANGUAGE "SimpChinese"
  492. !insertmacro MUI_LANGUAGE "Finnish"
  493. !insertmacro MUI_LANGUAGE "French"
  494. !insertmacro MUI_LANGUAGE "German"
  495. !insertmacro MUI_LANGUAGE "Hungarian"
  496. !insertmacro MUI_LANGUAGE "Italian"
  497. !insertmacro MUI_LANGUAGE "Korean"
  498. !insertmacro MUI_LANGUAGE "Polish"
  499. !insertmacro MUI_LANGUAGE "Portuguese"
  500. !insertmacro MUI_LANGUAGE "Russian"
  501. !insertmacro MUI_LANGUAGE "Spanish"
  502. !insertmacro MUI_LANGUAGE "Swedish"
  503. !insertmacro MUI_LANGUAGE "Turkish"
  504. !insertmacro MUI_LANGUAGE "Ukrainian"
  505. !insertmacro MUI_LANGUAGE "Vietnamese"
  506. ;!insertmacro MUI_LANGUAGE "Albanian"
  507. ;!insertmacro MUI_LANGUAGE "Arabic"
  508. ;!insertmacro MUI_LANGUAGE "Basque"
  509. ;!insertmacro MUI_LANGUAGE "Belarusian"
  510. ;!insertmacro MUI_LANGUAGE "Bosnian"
  511. ;!insertmacro MUI_LANGUAGE "Breton"
  512. ;!insertmacro MUI_LANGUAGE "Bulgarian"
  513. ;!insertmacro MUI_LANGUAGE "Croatian"
  514. ;!insertmacro MUI_LANGUAGE "Danish"
  515. ;!insertmacro MUI_LANGUAGE "Dutch"
  516. ;!insertmacro MUI_LANGUAGE "Estonian"
  517. ;!insertmacro MUI_LANGUAGE "Farsi"
  518. ;!insertmacro MUI_LANGUAGE "Greek"
  519. ;!insertmacro MUI_LANGUAGE "Hebrew"
  520. ;!insertmacro MUI_LANGUAGE "Icelandic"
  521. ;!insertmacro MUI_LANGUAGE "Indonesian"
  522. ;!insertmacro MUI_LANGUAGE "Irish"
  523. ;!insertmacro MUI_LANGUAGE "Japanese"
  524. ;!insertmacro MUI_LANGUAGE "Kurdish"
  525. ;!insertmacro MUI_LANGUAGE "Latvian"
  526. ;!insertmacro MUI_LANGUAGE "Lithuanian"
  527. ;!insertmacro MUI_LANGUAGE "Luxembourgish"
  528. ;!insertmacro MUI_LANGUAGE "Macedonian"
  529. ;!insertmacro MUI_LANGUAGE "Malay"
  530. ;!insertmacro MUI_LANGUAGE "Mongolian"
  531. ;!insertmacro MUI_LANGUAGE "Norwegian"
  532. ;!insertmacro MUI_LANGUAGE "PortugueseBR"
  533. ;!insertmacro MUI_LANGUAGE "Romanian"
  534. ;!insertmacro MUI_LANGUAGE "Serbian"
  535. ;!insertmacro MUI_LANGUAGE "SerbianLatin"
  536. ;!insertmacro MUI_LANGUAGE "Slovak"
  537. ;!insertmacro MUI_LANGUAGE "Slovenian"
  538. ;!insertmacro MUI_LANGUAGE "Thai"
  539. ;!insertmacro MUI_LANGUAGE "TradChinese"
  540. ;!insertmacro MUI_LANGUAGE "Welsh"
  541. ; Language Selection Dialog
  542. !define MUI_LANGDLL_DISPLAY
  543. ;--------------------------------
  544. ;Reserve Files
  545. ;These files should be inserted before other files in the data block
  546. ;Keep these lines before any File command
  547. ;Only for solid compression (by default, solid compression is enabled for BZIP2 and LZMA)
  548. ReserveFile "NSIS.InstallOptions.ini"
  549. !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
  550. ;--------------------------------
  551. ;Installer Sections
  552. Section "-Core installation"
  553. ;Use the entire tree produced by the INSTALL target. Keep the
  554. ;list of directories here in sync with the RMDir commands below.
  555. SetOutPath "$INSTDIR"
  556. @CPACK_NSIS_EXTRA_PREINSTALL_COMMANDS@
  557. @CPACK_NSIS_FULL_INSTALL@
  558. ;Store installation folder
  559. WriteRegStr SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "" $INSTDIR
  560. ;Create uninstaller
  561. WriteUninstaller "$INSTDIR\Uninstall.exe"
  562. Push "DisplayName"
  563. Push "@CPACK_NSIS_DISPLAY_NAME@"
  564. Call ConditionalAddToRegistry
  565. Push "DisplayVersion"
  566. Push "@CPACK_PACKAGE_VERSION@"
  567. Call ConditionalAddToRegistry
  568. Push "Publisher"
  569. Push "@CPACK_PACKAGE_VENDOR@"
  570. Call ConditionalAddToRegistry
  571. Push "UninstallString"
  572. Push "$INSTDIR\Uninstall.exe"
  573. Call ConditionalAddToRegistry
  574. Push "NoRepair"
  575. Push "1"
  576. Call ConditionalAddToRegistry
  577. !ifdef CPACK_NSIS_ADD_REMOVE
  578. ;Create add/remove functionality
  579. Push "ModifyPath"
  580. Push "$INSTDIR\AddRemove.exe"
  581. Call ConditionalAddToRegistry
  582. !else
  583. Push "NoModify"
  584. Push "1"
  585. Call ConditionalAddToRegistry
  586. !endif
  587. ; Optional registration
  588. Push "DisplayIcon"
  589. Push "$INSTDIR\@CPACK_NSIS_INSTALLED_ICON_NAME@"
  590. Call ConditionalAddToRegistry
  591. Push "HelpLink"
  592. Push "@CPACK_NSIS_HELP_LINK@"
  593. Call ConditionalAddToRegistry
  594. Push "URLInfoAbout"
  595. Push "@CPACK_NSIS_URL_INFO_ABOUT@"
  596. Call ConditionalAddToRegistry
  597. Push "Contact"
  598. Push "@CPACK_NSIS_CONTACT@"
  599. Call ConditionalAddToRegistry
  600. !insertmacro MUI_INSTALLOPTIONS_READ $INSTALL_DESKTOP "NSIS.InstallOptions.ini" "Field 5" "State"
  601. !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
  602. ;Create shortcuts
  603. CreateDirectory "$SMPROGRAMS\$STARTMENU_FOLDER"
  604. @CPACK_NSIS_CREATE_ICONS@
  605. @CPACK_NSIS_CREATE_ICONS_EXTRA@
  606. CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Uninstall.lnk" "$INSTDIR\Uninstall.exe"
  607. ;Read a value from an InstallOptions INI file
  608. !insertmacro MUI_INSTALLOPTIONS_READ $DO_NOT_ADD_TO_PATH "NSIS.InstallOptions.ini" "Field 2" "State"
  609. !insertmacro MUI_INSTALLOPTIONS_READ $ADD_TO_PATH_ALL_USERS "NSIS.InstallOptions.ini" "Field 3" "State"
  610. !insertmacro MUI_INSTALLOPTIONS_READ $ADD_TO_PATH_CURRENT_USER "NSIS.InstallOptions.ini" "Field 4" "State"
  611. ; Write special uninstall registry entries
  612. Push "StartMenu"
  613. Push "$STARTMENU_FOLDER"
  614. Call ConditionalAddToRegistry
  615. Push "DoNotAddToPath"
  616. Push "$DO_NOT_ADD_TO_PATH"
  617. Call ConditionalAddToRegistry
  618. Push "AddToPathAllUsers"
  619. Push "$ADD_TO_PATH_ALL_USERS"
  620. Call ConditionalAddToRegistry
  621. Push "AddToPathCurrentUser"
  622. Push "$ADD_TO_PATH_CURRENT_USER"
  623. Call ConditionalAddToRegistry
  624. Push "InstallToDesktop"
  625. Push "$INSTALL_DESKTOP"
  626. Call ConditionalAddToRegistry
  627. !insertmacro MUI_STARTMENU_WRITE_END
  628. @CPACK_NSIS_EXTRA_INSTALL_COMMANDS@
  629. SectionEnd
  630. Section "-Add to path"
  631. Push $INSTDIR\bin
  632. StrCmp "@CPACK_NSIS_MODIFY_PATH@" "ON" 0 doNotAddToPath
  633. StrCmp $DO_NOT_ADD_TO_PATH "1" doNotAddToPath 0
  634. Call AddToPath
  635. doNotAddToPath:
  636. SectionEnd
  637. ;--------------------------------
  638. ; Create custom pages
  639. Function InstallOptionsPage
  640. !insertmacro MUI_HEADER_TEXT "Install Options" "Choose options for installing @CPACK_NSIS_PACKAGE_NAME@"
  641. !insertmacro MUI_INSTALLOPTIONS_DISPLAY "NSIS.InstallOptions.ini"
  642. FunctionEnd
  643. ;--------------------------------
  644. ; determine admin versus local install
  645. Function un.onInit
  646. ClearErrors
  647. UserInfo::GetName
  648. IfErrors noLM
  649. Pop $0
  650. UserInfo::GetAccountType
  651. Pop $1
  652. StrCmp $1 "Admin" 0 +3
  653. SetShellVarContext all
  654. ;MessageBox MB_OK 'User "$0" is in the Admin group'
  655. Goto done
  656. StrCmp $1 "Power" 0 +3
  657. SetShellVarContext all
  658. ;MessageBox MB_OK 'User "$0" is in the Power Users group'
  659. Goto done
  660. noLM:
  661. ;Get installation folder from registry if available
  662. done:
  663. FunctionEnd
  664. ;--- Add/Remove callback functions: ---
  665. !macro SectionList MacroName
  666. ;This macro used to perform operation on multiple sections.
  667. ;List all of your components in following manner here.
  668. @CPACK_NSIS_COMPONENT_SECTION_LIST@
  669. !macroend
  670. Section -FinishComponents
  671. ;Removes unselected components and writes component status to registry
  672. !insertmacro SectionList "FinishSection"
  673. !ifdef CPACK_NSIS_ADD_REMOVE
  674. ; Get the name of the installer executable
  675. System::Call 'kernel32::GetModuleFileNameA(i 0, t .R0, i 1024) i r1'
  676. StrCpy $R3 $R0
  677. ; Strip off the last 13 characters, to see if we have AddRemove.exe
  678. StrLen $R1 $R0
  679. IntOp $R1 $R0 - 13
  680. StrCpy $R2 $R0 13 $R1
  681. StrCmp $R2 "AddRemove.exe" addremove_installed
  682. ; We're not running AddRemove.exe, so install it
  683. CopyFiles $R3 $INSTDIR\AddRemove.exe
  684. addremove_installed:
  685. !endif
  686. SectionEnd
  687. ;--- End of Add/Remove callback functions ---
  688. ;--------------------------------
  689. ; Component dependencies
  690. Function .onSelChange
  691. !insertmacro SectionList MaybeSelectionChanged
  692. FunctionEnd
  693. ;--------------------------------
  694. ;Uninstaller Section
  695. Section "Uninstall"
  696. ReadRegStr $START_MENU SHCTX \
  697. "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "StartMenu"
  698. ;MessageBox MB_OK "Start menu is in: $START_MENU"
  699. ReadRegStr $DO_NOT_ADD_TO_PATH SHCTX \
  700. "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "DoNotAddToPath"
  701. ReadRegStr $ADD_TO_PATH_ALL_USERS SHCTX \
  702. "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "AddToPathAllUsers"
  703. ReadRegStr $ADD_TO_PATH_CURRENT_USER SHCTX \
  704. "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "AddToPathCurrentUser"
  705. ;MessageBox MB_OK "Add to path: $DO_NOT_ADD_TO_PATH all users: $ADD_TO_PATH_ALL_USERS"
  706. ReadRegStr $INSTALL_DESKTOP SHCTX \
  707. "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "InstallToDesktop"
  708. ;MessageBox MB_OK "Install to desktop: $INSTALL_DESKTOP "
  709. @CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS@
  710. ;Remove files we installed.
  711. ;Keep the list of directories here in sync with the File commands above.
  712. @CPACK_NSIS_DELETE_FILES@
  713. @CPACK_NSIS_DELETE_DIRECTORIES@
  714. !ifdef CPACK_NSIS_ADD_REMOVE
  715. ;Remove the add/remove program
  716. Delete "$INSTDIR\AddRemove.exe"
  717. !endif
  718. ;Remove the uninstaller itself.
  719. Delete "$INSTDIR\Uninstall.exe"
  720. DeleteRegKey SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
  721. ;Remove the installation directory if it is empty.
  722. RMDir "$INSTDIR"
  723. ; Remove the registry entries.
  724. DeleteRegKey SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
  725. ; Removes all optional components
  726. !insertmacro SectionList "RemoveSection_CPack"
  727. !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP
  728. Delete "$SMPROGRAMS\$MUI_TEMP\Uninstall.lnk"
  729. @CPACK_NSIS_DELETE_ICONS@
  730. @CPACK_NSIS_DELETE_ICONS_EXTRA@
  731. ;Delete empty start menu parent directories
  732. StrCpy $MUI_TEMP "$SMPROGRAMS\$MUI_TEMP"
  733. startMenuDeleteLoop:
  734. ClearErrors
  735. RMDir $MUI_TEMP
  736. GetFullPathName $MUI_TEMP "$MUI_TEMP\.."
  737. IfErrors startMenuDeleteLoopDone
  738. StrCmp "$MUI_TEMP" "$SMPROGRAMS" startMenuDeleteLoopDone startMenuDeleteLoop
  739. startMenuDeleteLoopDone:
  740. ; If the user changed the shortcut, then untinstall may not work. This should
  741. ; try to fix it.
  742. StrCpy $MUI_TEMP "$START_MENU"
  743. Delete "$SMPROGRAMS\$MUI_TEMP\Uninstall.lnk"
  744. @CPACK_NSIS_DELETE_ICONS_EXTRA@
  745. ;Delete empty start menu parent directories
  746. StrCpy $MUI_TEMP "$SMPROGRAMS\$MUI_TEMP"
  747. secondStartMenuDeleteLoop:
  748. ClearErrors
  749. RMDir $MUI_TEMP
  750. GetFullPathName $MUI_TEMP "$MUI_TEMP\.."
  751. IfErrors secondStartMenuDeleteLoopDone
  752. StrCmp "$MUI_TEMP" "$SMPROGRAMS" secondStartMenuDeleteLoopDone secondStartMenuDeleteLoop
  753. secondStartMenuDeleteLoopDone:
  754. DeleteRegKey /ifempty SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
  755. Push $INSTDIR\bin
  756. StrCmp $DO_NOT_ADD_TO_PATH_ "1" doNotRemoveFromPath 0
  757. Call un.RemoveFromPath
  758. doNotRemoveFromPath:
  759. SectionEnd
  760. ;--------------------------------
  761. ; determine admin versus local install
  762. ; Is install for "AllUsers" or "JustMe"?
  763. ; Default to "JustMe" - set to "AllUsers" if admin or on Win9x
  764. ; This function is used for the very first "custom page" of the installer.
  765. ; This custom page does not show up visibly, but it executes prior to the
  766. ; first visible page and sets up $INSTDIR properly...
  767. ; Choose different default installation folder based on SV_ALLUSERS...
  768. ; "Program Files" for AllUsers, "My Documents" for JustMe...
  769. Function .onInit
  770. !insertmacro MUI_LANGDLL_DISPLAY
  771. StrCmp "@CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL@" "ON" 0 inst
  772. ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "UninstallString"
  773. StrCmp $0 "" inst
  774. MessageBox MB_YESNOCANCEL|MB_ICONEXCLAMATION \
  775. "@CPACK_NSIS_PACKAGE_NAME@ is already installed. $\n$\nDo you want to uninstall the old version before installing the new one?" \
  776. /SD IDYES IDYES uninst IDNO inst
  777. Abort
  778. ;Run the uninstaller
  779. uninst:
  780. ClearErrors
  781. StrLen $2 "\Uninstall.exe"
  782. StrCpy $3 $0 -$2 # remove "\Uninstall.exe" from UninstallString to get path
  783. ExecWait '"$0" /S _?=$3' ;Do not copy the uninstaller to a temp file
  784. IfErrors uninst_failed inst
  785. uninst_failed:
  786. MessageBox MB_OK|MB_ICONSTOP "Uninstall failed."
  787. Abort
  788. inst:
  789. ; Reads components status for registry
  790. !insertmacro SectionList "InitSection"
  791. ; check to see if /D has been used to change
  792. ; the install directory by comparing it to the
  793. ; install directory that is expected to be the
  794. ; default
  795. StrCpy $IS_DEFAULT_INSTALLDIR 0
  796. StrCmp "$INSTDIR" "@CPACK_NSIS_INSTALL_ROOT@\@CPACK_PACKAGE_INSTALL_DIRECTORY@" 0 +2
  797. StrCpy $IS_DEFAULT_INSTALLDIR 1
  798. StrCpy $SV_ALLUSERS "JustMe"
  799. ; if default install dir then change the default
  800. ; if it is installed for JustMe
  801. StrCmp "$IS_DEFAULT_INSTALLDIR" "1" 0 +2
  802. StrCpy $INSTDIR "$DOCUMENTS\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
  803. ClearErrors
  804. UserInfo::GetName
  805. IfErrors noLM
  806. Pop $0
  807. UserInfo::GetAccountType
  808. Pop $1
  809. StrCmp $1 "Admin" 0 +4
  810. SetShellVarContext all
  811. ;MessageBox MB_OK 'User "$0" is in the Admin group'
  812. StrCpy $SV_ALLUSERS "AllUsers"
  813. Goto done
  814. StrCmp $1 "Power" 0 +4
  815. SetShellVarContext all
  816. ;MessageBox MB_OK 'User "$0" is in the Power Users group'
  817. StrCpy $SV_ALLUSERS "AllUsers"
  818. Goto done
  819. noLM:
  820. StrCpy $SV_ALLUSERS "AllUsers"
  821. ;Get installation folder from registry if available
  822. done:
  823. StrCmp $SV_ALLUSERS "AllUsers" 0 +3
  824. StrCmp "$IS_DEFAULT_INSTALLDIR" "1" 0 +2
  825. StrCpy $INSTDIR "@CPACK_NSIS_INSTALL_ROOT@\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
  826. StrCmp "@CPACK_NSIS_MODIFY_PATH@" "ON" 0 noOptionsPage
  827. !insertmacro MUI_INSTALLOPTIONS_EXTRACT "NSIS.InstallOptions.ini"
  828. noOptionsPage:
  829. FunctionEnd