NSIS.template.in 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  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 "Albanian"
  491. !insertmacro MUI_LANGUAGE "Arabic"
  492. !insertmacro MUI_LANGUAGE "Basque"
  493. !insertmacro MUI_LANGUAGE "Belarusian"
  494. !insertmacro MUI_LANGUAGE "Bosnian"
  495. !insertmacro MUI_LANGUAGE "Breton"
  496. !insertmacro MUI_LANGUAGE "Bulgarian"
  497. !insertmacro MUI_LANGUAGE "Croatian"
  498. !insertmacro MUI_LANGUAGE "Czech"
  499. !insertmacro MUI_LANGUAGE "Danish"
  500. !insertmacro MUI_LANGUAGE "Dutch"
  501. !insertmacro MUI_LANGUAGE "Estonian"
  502. !insertmacro MUI_LANGUAGE "Farsi"
  503. !insertmacro MUI_LANGUAGE "Finnish"
  504. !insertmacro MUI_LANGUAGE "French"
  505. !insertmacro MUI_LANGUAGE "German"
  506. !insertmacro MUI_LANGUAGE "Greek"
  507. !insertmacro MUI_LANGUAGE "Hebrew"
  508. !insertmacro MUI_LANGUAGE "Hungarian"
  509. !insertmacro MUI_LANGUAGE "Icelandic"
  510. !insertmacro MUI_LANGUAGE "Indonesian"
  511. !insertmacro MUI_LANGUAGE "Irish"
  512. !insertmacro MUI_LANGUAGE "Italian"
  513. !insertmacro MUI_LANGUAGE "Japanese"
  514. !insertmacro MUI_LANGUAGE "Korean"
  515. !insertmacro MUI_LANGUAGE "Kurdish"
  516. !insertmacro MUI_LANGUAGE "Latvian"
  517. !insertmacro MUI_LANGUAGE "Lithuanian"
  518. !insertmacro MUI_LANGUAGE "Luxembourgish"
  519. !insertmacro MUI_LANGUAGE "Macedonian"
  520. !insertmacro MUI_LANGUAGE "Malay"
  521. !insertmacro MUI_LANGUAGE "Mongolian"
  522. !insertmacro MUI_LANGUAGE "Norwegian"
  523. !insertmacro MUI_LANGUAGE "Polish"
  524. !insertmacro MUI_LANGUAGE "Portuguese"
  525. !insertmacro MUI_LANGUAGE "PortugueseBR"
  526. !insertmacro MUI_LANGUAGE "Romanian"
  527. !insertmacro MUI_LANGUAGE "Russian"
  528. !insertmacro MUI_LANGUAGE "Serbian"
  529. !insertmacro MUI_LANGUAGE "SerbianLatin"
  530. !insertmacro MUI_LANGUAGE "SimpChinese"
  531. !insertmacro MUI_LANGUAGE "Slovak"
  532. !insertmacro MUI_LANGUAGE "Slovenian"
  533. !insertmacro MUI_LANGUAGE "Spanish"
  534. !insertmacro MUI_LANGUAGE "Swedish"
  535. !insertmacro MUI_LANGUAGE "Thai"
  536. !insertmacro MUI_LANGUAGE "TradChinese"
  537. !insertmacro MUI_LANGUAGE "Turkish"
  538. !insertmacro MUI_LANGUAGE "Ukrainian"
  539. !insertmacro MUI_LANGUAGE "Welsh"
  540. ;--------------------------------
  541. ;Reserve Files
  542. ;These files should be inserted before other files in the data block
  543. ;Keep these lines before any File command
  544. ;Only for solid compression (by default, solid compression is enabled for BZIP2 and LZMA)
  545. ReserveFile "NSIS.InstallOptions.ini"
  546. !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
  547. ;--------------------------------
  548. ;Installer Sections
  549. Section "-Core installation"
  550. ;Use the entire tree produced by the INSTALL target. Keep the
  551. ;list of directories here in sync with the RMDir commands below.
  552. SetOutPath "$INSTDIR"
  553. @CPACK_NSIS_EXTRA_PREINSTALL_COMMANDS@
  554. @CPACK_NSIS_FULL_INSTALL@
  555. ;Store installation folder
  556. WriteRegStr SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "" $INSTDIR
  557. ;Create uninstaller
  558. WriteUninstaller "$INSTDIR\Uninstall.exe"
  559. Push "DisplayName"
  560. Push "@CPACK_NSIS_DISPLAY_NAME@"
  561. Call ConditionalAddToRegistry
  562. Push "DisplayVersion"
  563. Push "@CPACK_PACKAGE_VERSION@"
  564. Call ConditionalAddToRegistry
  565. Push "Publisher"
  566. Push "@CPACK_PACKAGE_VENDOR@"
  567. Call ConditionalAddToRegistry
  568. Push "UninstallString"
  569. Push "$INSTDIR\Uninstall.exe"
  570. Call ConditionalAddToRegistry
  571. Push "NoRepair"
  572. Push "1"
  573. Call ConditionalAddToRegistry
  574. !ifdef CPACK_NSIS_ADD_REMOVE
  575. ;Create add/remove functionality
  576. Push "ModifyPath"
  577. Push "$INSTDIR\AddRemove.exe"
  578. Call ConditionalAddToRegistry
  579. !else
  580. Push "NoModify"
  581. Push "1"
  582. Call ConditionalAddToRegistry
  583. !endif
  584. ; Optional registration
  585. Push "DisplayIcon"
  586. Push "$INSTDIR\@CPACK_NSIS_INSTALLED_ICON_NAME@"
  587. Call ConditionalAddToRegistry
  588. Push "HelpLink"
  589. Push "@CPACK_NSIS_HELP_LINK@"
  590. Call ConditionalAddToRegistry
  591. Push "URLInfoAbout"
  592. Push "@CPACK_NSIS_URL_INFO_ABOUT@"
  593. Call ConditionalAddToRegistry
  594. Push "Contact"
  595. Push "@CPACK_NSIS_CONTACT@"
  596. Call ConditionalAddToRegistry
  597. !insertmacro MUI_INSTALLOPTIONS_READ $INSTALL_DESKTOP "NSIS.InstallOptions.ini" "Field 5" "State"
  598. !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
  599. ;Create shortcuts
  600. CreateDirectory "$SMPROGRAMS\$STARTMENU_FOLDER"
  601. @CPACK_NSIS_CREATE_ICONS@
  602. @CPACK_NSIS_CREATE_ICONS_EXTRA@
  603. CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Uninstall.lnk" "$INSTDIR\Uninstall.exe"
  604. ;Read a value from an InstallOptions INI file
  605. !insertmacro MUI_INSTALLOPTIONS_READ $DO_NOT_ADD_TO_PATH "NSIS.InstallOptions.ini" "Field 2" "State"
  606. !insertmacro MUI_INSTALLOPTIONS_READ $ADD_TO_PATH_ALL_USERS "NSIS.InstallOptions.ini" "Field 3" "State"
  607. !insertmacro MUI_INSTALLOPTIONS_READ $ADD_TO_PATH_CURRENT_USER "NSIS.InstallOptions.ini" "Field 4" "State"
  608. ; Write special uninstall registry entries
  609. Push "StartMenu"
  610. Push "$STARTMENU_FOLDER"
  611. Call ConditionalAddToRegistry
  612. Push "DoNotAddToPath"
  613. Push "$DO_NOT_ADD_TO_PATH"
  614. Call ConditionalAddToRegistry
  615. Push "AddToPathAllUsers"
  616. Push "$ADD_TO_PATH_ALL_USERS"
  617. Call ConditionalAddToRegistry
  618. Push "AddToPathCurrentUser"
  619. Push "$ADD_TO_PATH_CURRENT_USER"
  620. Call ConditionalAddToRegistry
  621. Push "InstallToDesktop"
  622. Push "$INSTALL_DESKTOP"
  623. Call ConditionalAddToRegistry
  624. !insertmacro MUI_STARTMENU_WRITE_END
  625. @CPACK_NSIS_EXTRA_INSTALL_COMMANDS@
  626. SectionEnd
  627. Section "-Add to path"
  628. Push $INSTDIR\bin
  629. StrCmp "@CPACK_NSIS_MODIFY_PATH@" "ON" 0 doNotAddToPath
  630. StrCmp $DO_NOT_ADD_TO_PATH "1" doNotAddToPath 0
  631. Call AddToPath
  632. doNotAddToPath:
  633. SectionEnd
  634. ;--------------------------------
  635. ; Create custom pages
  636. Function InstallOptionsPage
  637. !insertmacro MUI_HEADER_TEXT "Install Options" "Choose options for installing @CPACK_NSIS_PACKAGE_NAME@"
  638. !insertmacro MUI_INSTALLOPTIONS_DISPLAY "NSIS.InstallOptions.ini"
  639. FunctionEnd
  640. ;--------------------------------
  641. ; determine admin versus local install
  642. Function un.onInit
  643. ClearErrors
  644. UserInfo::GetName
  645. IfErrors noLM
  646. Pop $0
  647. UserInfo::GetAccountType
  648. Pop $1
  649. StrCmp $1 "Admin" 0 +3
  650. SetShellVarContext all
  651. ;MessageBox MB_OK 'User "$0" is in the Admin group'
  652. Goto done
  653. StrCmp $1 "Power" 0 +3
  654. SetShellVarContext all
  655. ;MessageBox MB_OK 'User "$0" is in the Power Users group'
  656. Goto done
  657. noLM:
  658. ;Get installation folder from registry if available
  659. done:
  660. FunctionEnd
  661. ;--- Add/Remove callback functions: ---
  662. !macro SectionList MacroName
  663. ;This macro used to perform operation on multiple sections.
  664. ;List all of your components in following manner here.
  665. @CPACK_NSIS_COMPONENT_SECTION_LIST@
  666. !macroend
  667. Section -FinishComponents
  668. ;Removes unselected components and writes component status to registry
  669. !insertmacro SectionList "FinishSection"
  670. !ifdef CPACK_NSIS_ADD_REMOVE
  671. ; Get the name of the installer executable
  672. System::Call 'kernel32::GetModuleFileNameA(i 0, t .R0, i 1024) i r1'
  673. StrCpy $R3 $R0
  674. ; Strip off the last 13 characters, to see if we have AddRemove.exe
  675. StrLen $R1 $R0
  676. IntOp $R1 $R0 - 13
  677. StrCpy $R2 $R0 13 $R1
  678. StrCmp $R2 "AddRemove.exe" addremove_installed
  679. ; We're not running AddRemove.exe, so install it
  680. CopyFiles $R3 $INSTDIR\AddRemove.exe
  681. addremove_installed:
  682. !endif
  683. SectionEnd
  684. ;--- End of Add/Remove callback functions ---
  685. ;--------------------------------
  686. ; Component dependencies
  687. Function .onSelChange
  688. !insertmacro SectionList MaybeSelectionChanged
  689. FunctionEnd
  690. ;--------------------------------
  691. ;Uninstaller Section
  692. Section "Uninstall"
  693. ReadRegStr $START_MENU SHCTX \
  694. "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "StartMenu"
  695. ;MessageBox MB_OK "Start menu is in: $START_MENU"
  696. ReadRegStr $DO_NOT_ADD_TO_PATH SHCTX \
  697. "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "DoNotAddToPath"
  698. ReadRegStr $ADD_TO_PATH_ALL_USERS SHCTX \
  699. "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "AddToPathAllUsers"
  700. ReadRegStr $ADD_TO_PATH_CURRENT_USER SHCTX \
  701. "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "AddToPathCurrentUser"
  702. ;MessageBox MB_OK "Add to path: $DO_NOT_ADD_TO_PATH all users: $ADD_TO_PATH_ALL_USERS"
  703. ReadRegStr $INSTALL_DESKTOP SHCTX \
  704. "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "InstallToDesktop"
  705. ;MessageBox MB_OK "Install to desktop: $INSTALL_DESKTOP "
  706. @CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS@
  707. ;Remove files we installed.
  708. ;Keep the list of directories here in sync with the File commands above.
  709. @CPACK_NSIS_DELETE_FILES@
  710. @CPACK_NSIS_DELETE_DIRECTORIES@
  711. !ifdef CPACK_NSIS_ADD_REMOVE
  712. ;Remove the add/remove program
  713. Delete "$INSTDIR\AddRemove.exe"
  714. !endif
  715. ;Remove the uninstaller itself.
  716. Delete "$INSTDIR\Uninstall.exe"
  717. DeleteRegKey SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
  718. ;Remove the installation directory if it is empty.
  719. RMDir "$INSTDIR"
  720. ; Remove the registry entries.
  721. DeleteRegKey SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
  722. ; Removes all optional components
  723. !insertmacro SectionList "RemoveSection_CPack"
  724. !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP
  725. Delete "$SMPROGRAMS\$MUI_TEMP\Uninstall.lnk"
  726. @CPACK_NSIS_DELETE_ICONS@
  727. @CPACK_NSIS_DELETE_ICONS_EXTRA@
  728. ;Delete empty start menu parent directories
  729. StrCpy $MUI_TEMP "$SMPROGRAMS\$MUI_TEMP"
  730. startMenuDeleteLoop:
  731. ClearErrors
  732. RMDir $MUI_TEMP
  733. GetFullPathName $MUI_TEMP "$MUI_TEMP\.."
  734. IfErrors startMenuDeleteLoopDone
  735. StrCmp "$MUI_TEMP" "$SMPROGRAMS" startMenuDeleteLoopDone startMenuDeleteLoop
  736. startMenuDeleteLoopDone:
  737. ; If the user changed the shortcut, then untinstall may not work. This should
  738. ; try to fix it.
  739. StrCpy $MUI_TEMP "$START_MENU"
  740. Delete "$SMPROGRAMS\$MUI_TEMP\Uninstall.lnk"
  741. @CPACK_NSIS_DELETE_ICONS_EXTRA@
  742. ;Delete empty start menu parent directories
  743. StrCpy $MUI_TEMP "$SMPROGRAMS\$MUI_TEMP"
  744. secondStartMenuDeleteLoop:
  745. ClearErrors
  746. RMDir $MUI_TEMP
  747. GetFullPathName $MUI_TEMP "$MUI_TEMP\.."
  748. IfErrors secondStartMenuDeleteLoopDone
  749. StrCmp "$MUI_TEMP" "$SMPROGRAMS" secondStartMenuDeleteLoopDone secondStartMenuDeleteLoop
  750. secondStartMenuDeleteLoopDone:
  751. DeleteRegKey /ifempty SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
  752. Push $INSTDIR\bin
  753. StrCmp $DO_NOT_ADD_TO_PATH_ "1" doNotRemoveFromPath 0
  754. Call un.RemoveFromPath
  755. doNotRemoveFromPath:
  756. SectionEnd
  757. ;--------------------------------
  758. ; determine admin versus local install
  759. ; Is install for "AllUsers" or "JustMe"?
  760. ; Default to "JustMe" - set to "AllUsers" if admin or on Win9x
  761. ; This function is used for the very first "custom page" of the installer.
  762. ; This custom page does not show up visibly, but it executes prior to the
  763. ; first visible page and sets up $INSTDIR properly...
  764. ; Choose different default installation folder based on SV_ALLUSERS...
  765. ; "Program Files" for AllUsers, "My Documents" for JustMe...
  766. Function .onInit
  767. StrCmp "@CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL@" "ON" 0 inst
  768. ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "UninstallString"
  769. StrCmp $0 "" inst
  770. MessageBox MB_YESNOCANCEL|MB_ICONEXCLAMATION \
  771. "@CPACK_NSIS_PACKAGE_NAME@ is already installed. $\n$\nDo you want to uninstall the old version before installing the new one?" \
  772. /SD IDYES IDYES uninst IDNO inst
  773. Abort
  774. ;Run the uninstaller
  775. uninst:
  776. ClearErrors
  777. StrLen $2 "\Uninstall.exe"
  778. StrCpy $3 $0 -$2 # remove "\Uninstall.exe" from UninstallString to get path
  779. ExecWait '"$0" /S _?=$3' ;Do not copy the uninstaller to a temp file
  780. IfErrors uninst_failed inst
  781. uninst_failed:
  782. MessageBox MB_OK|MB_ICONSTOP "Uninstall failed."
  783. Abort
  784. inst:
  785. ; Reads components status for registry
  786. !insertmacro SectionList "InitSection"
  787. ; check to see if /D has been used to change
  788. ; the install directory by comparing it to the
  789. ; install directory that is expected to be the
  790. ; default
  791. StrCpy $IS_DEFAULT_INSTALLDIR 0
  792. StrCmp "$INSTDIR" "@CPACK_NSIS_INSTALL_ROOT@\@CPACK_PACKAGE_INSTALL_DIRECTORY@" 0 +2
  793. StrCpy $IS_DEFAULT_INSTALLDIR 1
  794. StrCpy $SV_ALLUSERS "JustMe"
  795. ; if default install dir then change the default
  796. ; if it is installed for JustMe
  797. StrCmp "$IS_DEFAULT_INSTALLDIR" "1" 0 +2
  798. StrCpy $INSTDIR "$DOCUMENTS\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
  799. ClearErrors
  800. UserInfo::GetName
  801. IfErrors noLM
  802. Pop $0
  803. UserInfo::GetAccountType
  804. Pop $1
  805. StrCmp $1 "Admin" 0 +4
  806. SetShellVarContext all
  807. ;MessageBox MB_OK 'User "$0" is in the Admin group'
  808. StrCpy $SV_ALLUSERS "AllUsers"
  809. Goto done
  810. StrCmp $1 "Power" 0 +4
  811. SetShellVarContext all
  812. ;MessageBox MB_OK 'User "$0" is in the Power Users group'
  813. StrCpy $SV_ALLUSERS "AllUsers"
  814. Goto done
  815. noLM:
  816. StrCpy $SV_ALLUSERS "AllUsers"
  817. ;Get installation folder from registry if available
  818. done:
  819. StrCmp $SV_ALLUSERS "AllUsers" 0 +3
  820. StrCmp "$IS_DEFAULT_INSTALLDIR" "1" 0 +2
  821. StrCpy $INSTDIR "@CPACK_NSIS_INSTALL_ROOT@\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
  822. StrCmp "@CPACK_NSIS_MODIFY_PATH@" "ON" 0 noOptionsPage
  823. !insertmacro MUI_INSTALLOPTIONS_EXTRACT "NSIS.InstallOptions.ini"
  824. noOptionsPage:
  825. FunctionEnd