NSIS.template.in 28 KB

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