1
0

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. @CPACK_NSIS_DEFINES@
  31. !include Sections.nsh
  32. ;--- Component support macros: ---
  33. ; The code for the add/remove functionality is from:
  34. ; http://nsis.sourceforge.net/Add/Remove_Functionality
  35. ; It has been modified slightly and extended to provide
  36. ; inter-component dependencies.
  37. Var AR_SecFlags
  38. Var AR_RegFlags
  39. @CPACK_NSIS_SECTION_SELECTED_VARS@
  40. ; Loads the "selected" flag for the section named SecName into the
  41. ; variable VarName.
  42. !macro LoadSectionSelectedIntoVar SecName VarName
  43. SectionGetFlags ${${SecName}} $${VarName}
  44. IntOp $${VarName} $${VarName} & ${SF_SELECTED} ;Turn off all other bits
  45. !macroend
  46. ; Loads the value of a variable... can we get around this?
  47. !macro LoadVar VarName
  48. IntOp $R0 0 + $${VarName}
  49. !macroend
  50. ; Sets the value of a variable
  51. !macro StoreVar VarName IntValue
  52. IntOp $${VarName} 0 + ${IntValue}
  53. !macroend
  54. !macro InitSection SecName
  55. ; This macro reads component installed flag from the registry and
  56. ;changes checked state of the section on the components page.
  57. ;Input: section index constant name specified in Section command.
  58. ClearErrors
  59. ;Reading component status from registry
  60. ReadRegDWORD $AR_RegFlags HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@\Components\${SecName}" "Installed"
  61. IfErrors "default_${SecName}"
  62. ;Status will stay default if registry value not found
  63. ;(component was never installed)
  64. IntOp $AR_RegFlags $AR_RegFlags & ${SF_SELECTED} ;Turn off all other bits
  65. SectionGetFlags ${${SecName}} $AR_SecFlags ;Reading default section flags
  66. IntOp $AR_SecFlags $AR_SecFlags & 0xFFFE ;Turn lowest (enabled) bit off
  67. IntOp $AR_SecFlags $AR_RegFlags | $AR_SecFlags ;Change lowest bit
  68. ; Note whether this component was installed before
  69. !insertmacro StoreVar ${SecName}_was_installed $AR_RegFlags
  70. IntOp $R0 $AR_RegFlags & $AR_RegFlags
  71. ;Writing modified flags
  72. SectionSetFlags ${${SecName}} $AR_SecFlags
  73. "default_${SecName}:"
  74. !insertmacro LoadSectionSelectedIntoVar ${SecName} ${SecName}_selected
  75. !macroend
  76. !macro FinishSection SecName
  77. ; This macro reads section flag set by user and removes the section
  78. ;if it is not selected.
  79. ;Then it writes component installed flag to registry
  80. ;Input: section index constant name specified in Section command.
  81. SectionGetFlags ${${SecName}} $AR_SecFlags ;Reading section flags
  82. ;Checking lowest bit:
  83. IntOp $AR_SecFlags $AR_SecFlags & ${SF_SELECTED}
  84. IntCmp $AR_SecFlags 1 "leave_${SecName}"
  85. ;Section is not selected:
  86. ;Calling Section uninstall macro and writing zero installed flag
  87. !insertmacro "Remove_${${SecName}}"
  88. WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@\Components\${SecName}" \
  89. "Installed" 0
  90. Goto "exit_${SecName}"
  91. "leave_${SecName}:"
  92. ;Section is selected:
  93. WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@\Components\${SecName}" \
  94. "Installed" 1
  95. "exit_${SecName}:"
  96. !macroend
  97. !macro RemoveSection SecName
  98. ; This macro is used to call section's Remove_... macro
  99. ;from the uninstaller.
  100. ;Input: section index constant name specified in Section command.
  101. !insertmacro "Remove_${${SecName}}"
  102. !macroend
  103. ; Determine whether the selection of SecName changed
  104. !macro MaybeSelectionChanged SecName
  105. !insertmacro LoadVar ${SecName}_selected
  106. SectionGetFlags ${${SecName}} $R1
  107. IntOp $R1 $R1 & ${SF_SELECTED} ;Turn off all other bits
  108. ; See if the status has changed:
  109. IntCmp $R0 $R1 "${SecName}_unchanged"
  110. !insertmacro LoadSectionSelectedIntoVar ${SecName} ${SecName}_selected
  111. IntCmp $R1 ${SF_SELECTED} "${SecName}_was_selected"
  112. !insertmacro "Deselect_required_by_${SecName}"
  113. goto "${SecName}_unchanged"
  114. "${SecName}_was_selected:"
  115. !insertmacro "Select_${SecName}_depends"
  116. "${SecName}_unchanged:"
  117. !macroend
  118. ;--- End of Add/Remove macros ---
  119. ;--------------------------------
  120. ;Interface Settings
  121. !define MUI_HEADERIMAGE
  122. !define MUI_ABORTWARNING
  123. ;--------------------------------
  124. ; path functions
  125. !verbose 3
  126. !include "WinMessages.NSH"
  127. !verbose 4
  128. ;----------------------------------------
  129. ; based upon a script of "Written by KiCHiK 2003-01-18 05:57:02"
  130. ;----------------------------------------
  131. !verbose 3
  132. !include "WinMessages.NSH"
  133. !verbose 4
  134. ;====================================================
  135. ; get_NT_environment
  136. ; Returns: the selected environment
  137. ; Output : head of the stack
  138. ;====================================================
  139. !macro select_NT_profile UN
  140. Function ${UN}select_NT_profile
  141. StrCmp $ADD_TO_PATH_ALL_USERS "1" 0 environment_single
  142. DetailPrint "Selected environment for all users"
  143. Push "all"
  144. Return
  145. environment_single:
  146. DetailPrint "Selected environment for current user only."
  147. Push "current"
  148. Return
  149. FunctionEnd
  150. !macroend
  151. !insertmacro select_NT_profile ""
  152. !insertmacro select_NT_profile "un."
  153. ;----------------------------------------------------
  154. !define NT_current_env 'HKCU "Environment"'
  155. !define NT_all_env 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
  156. !ifndef WriteEnvStr_RegKey
  157. !ifdef ALL_USERS
  158. !define WriteEnvStr_RegKey \
  159. 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
  160. !else
  161. !define WriteEnvStr_RegKey 'HKCU "Environment"'
  162. !endif
  163. !endif
  164. ; AddToPath - Adds the given dir to the search path.
  165. ; Input - head of the stack
  166. ; Note - Win9x systems requires reboot
  167. Function AddToPath
  168. Exch $0
  169. Push $1
  170. Push $2
  171. Push $3
  172. # don't add if the path doesn't exist
  173. IfFileExists "$0\*.*" "" AddToPath_done
  174. ReadEnvStr $1 PATH
  175. ; if the path is too long for a NSIS variable NSIS will return a 0
  176. ; length string. If we find that, then warn and skip any path
  177. ; modification as it will trash the existing path.
  178. StrLen $2 $1
  179. IntCmp $2 0 CheckPathLength_ShowPathWarning CheckPathLength_Done CheckPathLength_Done
  180. CheckPathLength_ShowPathWarning:
  181. Messagebox MB_OK|MB_ICONEXCLAMATION "Warning! PATH too long installer unable to modify PATH!"
  182. Goto AddToPath_done
  183. CheckPathLength_Done:
  184. Push "$1;"
  185. Push "$0;"
  186. Call StrStr
  187. Pop $2
  188. StrCmp $2 "" "" AddToPath_done
  189. Push "$1;"
  190. Push "$0\;"
  191. Call StrStr
  192. Pop $2
  193. StrCmp $2 "" "" AddToPath_done
  194. GetFullPathName /SHORT $3 $0
  195. Push "$1;"
  196. Push "$3;"
  197. Call StrStr
  198. Pop $2
  199. StrCmp $2 "" "" AddToPath_done
  200. Push "$1;"
  201. Push "$3\;"
  202. Call StrStr
  203. Pop $2
  204. StrCmp $2 "" "" AddToPath_done
  205. Call IsNT
  206. Pop $1
  207. StrCmp $1 1 AddToPath_NT
  208. ; Not on NT
  209. StrCpy $1 $WINDIR 2
  210. FileOpen $1 "$1\autoexec.bat" a
  211. FileSeek $1 -1 END
  212. FileReadByte $1 $2
  213. IntCmp $2 26 0 +2 +2 # DOS EOF
  214. FileSeek $1 -1 END # write over EOF
  215. FileWrite $1 "$\r$\nSET PATH=%PATH%;$3$\r$\n"
  216. FileClose $1
  217. SetRebootFlag true
  218. Goto AddToPath_done
  219. AddToPath_NT:
  220. StrCmp $ADD_TO_PATH_ALL_USERS "1" ReadAllKey
  221. ReadRegStr $1 ${NT_current_env} "PATH"
  222. Goto DoTrim
  223. ReadAllKey:
  224. ReadRegStr $1 ${NT_all_env} "PATH"
  225. DoTrim:
  226. StrCmp $1 "" AddToPath_NTdoIt
  227. Push $1
  228. Call Trim
  229. Pop $1
  230. StrCpy $0 "$1;$0"
  231. AddToPath_NTdoIt:
  232. StrCmp $ADD_TO_PATH_ALL_USERS "1" WriteAllKey
  233. WriteRegExpandStr ${NT_current_env} "PATH" $0
  234. Goto DoSend
  235. WriteAllKey:
  236. WriteRegExpandStr ${NT_all_env} "PATH" $0
  237. DoSend:
  238. SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
  239. AddToPath_done:
  240. Pop $3
  241. Pop $2
  242. Pop $1
  243. Pop $0
  244. FunctionEnd
  245. ; RemoveFromPath - Remove a given dir from the path
  246. ; Input: head of the stack
  247. Function un.RemoveFromPath
  248. Exch $0
  249. Push $1
  250. Push $2
  251. Push $3
  252. Push $4
  253. Push $5
  254. Push $6
  255. IntFmt $6 "%c" 26 # DOS EOF
  256. Call un.IsNT
  257. Pop $1
  258. StrCmp $1 1 unRemoveFromPath_NT
  259. ; Not on NT
  260. StrCpy $1 $WINDIR 2
  261. FileOpen $1 "$1\autoexec.bat" r
  262. GetTempFileName $4
  263. FileOpen $2 $4 w
  264. GetFullPathName /SHORT $0 $0
  265. StrCpy $0 "SET PATH=%PATH%;$0"
  266. Goto unRemoveFromPath_dosLoop
  267. unRemoveFromPath_dosLoop:
  268. FileRead $1 $3
  269. StrCpy $5 $3 1 -1 # read last char
  270. StrCmp $5 $6 0 +2 # if DOS EOF
  271. StrCpy $3 $3 -1 # remove DOS EOF so we can compare
  272. StrCmp $3 "$0$\r$\n" unRemoveFromPath_dosLoopRemoveLine
  273. StrCmp $3 "$0$\n" unRemoveFromPath_dosLoopRemoveLine
  274. StrCmp $3 "$0" unRemoveFromPath_dosLoopRemoveLine
  275. StrCmp $3 "" unRemoveFromPath_dosLoopEnd
  276. FileWrite $2 $3
  277. Goto unRemoveFromPath_dosLoop
  278. unRemoveFromPath_dosLoopRemoveLine:
  279. SetRebootFlag true
  280. Goto unRemoveFromPath_dosLoop
  281. unRemoveFromPath_dosLoopEnd:
  282. FileClose $2
  283. FileClose $1
  284. StrCpy $1 $WINDIR 2
  285. Delete "$1\autoexec.bat"
  286. CopyFiles /SILENT $4 "$1\autoexec.bat"
  287. Delete $4
  288. Goto unRemoveFromPath_done
  289. unRemoveFromPath_NT:
  290. StrCmp $ADD_TO_PATH_ALL_USERS "1" unReadAllKey
  291. ReadRegStr $1 ${NT_current_env} "PATH"
  292. Goto unDoTrim
  293. unReadAllKey:
  294. ReadRegStr $1 ${NT_all_env} "PATH"
  295. unDoTrim:
  296. StrCpy $5 $1 1 -1 # copy last char
  297. StrCmp $5 ";" +2 # if last char != ;
  298. StrCpy $1 "$1;" # append ;
  299. Push $1
  300. Push "$0;"
  301. Call un.StrStr ; Find `$0;` in $1
  302. Pop $2 ; pos of our dir
  303. StrCmp $2 "" unRemoveFromPath_done
  304. ; else, it is in path
  305. # $0 - path to add
  306. # $1 - path var
  307. StrLen $3 "$0;"
  308. StrLen $4 $2
  309. StrCpy $5 $1 -$4 # $5 is now the part before the path to remove
  310. StrCpy $6 $2 "" $3 # $6 is now the part after the path to remove
  311. StrCpy $3 $5$6
  312. StrCpy $5 $3 1 -1 # copy last char
  313. StrCmp $5 ";" 0 +2 # if last char == ;
  314. StrCpy $3 $3 -1 # remove last char
  315. StrCmp $ADD_TO_PATH_ALL_USERS "1" unWriteAllKey
  316. WriteRegExpandStr ${NT_current_env} "PATH" $3
  317. Goto unDoSend
  318. unWriteAllKey:
  319. WriteRegExpandStr ${NT_all_env} "PATH" $3
  320. unDoSend:
  321. SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
  322. unRemoveFromPath_done:
  323. Pop $6
  324. Pop $5
  325. Pop $4
  326. Pop $3
  327. Pop $2
  328. Pop $1
  329. Pop $0
  330. FunctionEnd
  331. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  332. ; Uninstall sutff
  333. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  334. ###########################################
  335. # Utility Functions #
  336. ###########################################
  337. ;====================================================
  338. ; IsNT - Returns 1 if the current system is NT, 0
  339. ; otherwise.
  340. ; Output: head of the stack
  341. ;====================================================
  342. ; IsNT
  343. ; no input
  344. ; output, top of the stack = 1 if NT or 0 if not
  345. ;
  346. ; Usage:
  347. ; Call IsNT
  348. ; Pop $R0
  349. ; ($R0 at this point is 1 or 0)
  350. !macro IsNT un
  351. Function ${un}IsNT
  352. Push $0
  353. ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
  354. StrCmp $0 "" 0 IsNT_yes
  355. ; we are not NT.
  356. Pop $0
  357. Push 0
  358. Return
  359. IsNT_yes:
  360. ; NT!!!
  361. Pop $0
  362. Push 1
  363. FunctionEnd
  364. !macroend
  365. !insertmacro IsNT ""
  366. !insertmacro IsNT "un."
  367. ; StrStr
  368. ; input, top of stack = string to search for
  369. ; top of stack-1 = string to search in
  370. ; output, top of stack (replaces with the portion of the string remaining)
  371. ; modifies no other variables.
  372. ;
  373. ; Usage:
  374. ; Push "this is a long ass string"
  375. ; Push "ass"
  376. ; Call StrStr
  377. ; Pop $R0
  378. ; ($R0 at this point is "ass string")
  379. !macro StrStr un
  380. Function ${un}StrStr
  381. Exch $R1 ; st=haystack,old$R1, $R1=needle
  382. Exch ; st=old$R1,haystack
  383. Exch $R2 ; st=old$R1,old$R2, $R2=haystack
  384. Push $R3
  385. Push $R4
  386. Push $R5
  387. StrLen $R3 $R1
  388. StrCpy $R4 0
  389. ; $R1=needle
  390. ; $R2=haystack
  391. ; $R3=len(needle)
  392. ; $R4=cnt
  393. ; $R5=tmp
  394. loop:
  395. StrCpy $R5 $R2 $R3 $R4
  396. StrCmp $R5 $R1 done
  397. StrCmp $R5 "" done
  398. IntOp $R4 $R4 + 1
  399. Goto loop
  400. done:
  401. StrCpy $R1 $R2 "" $R4
  402. Pop $R5
  403. Pop $R4
  404. Pop $R3
  405. Pop $R2
  406. Exch $R1
  407. FunctionEnd
  408. !macroend
  409. !insertmacro StrStr ""
  410. !insertmacro StrStr "un."
  411. Function Trim ; Added by Pelaca
  412. Exch $R1
  413. Push $R2
  414. Loop:
  415. StrCpy $R2 "$R1" 1 -1
  416. StrCmp "$R2" " " RTrim
  417. StrCmp "$R2" "$\n" RTrim
  418. StrCmp "$R2" "$\r" RTrim
  419. StrCmp "$R2" ";" RTrim
  420. GoTo Done
  421. RTrim:
  422. StrCpy $R1 "$R1" -1
  423. Goto Loop
  424. Done:
  425. Pop $R2
  426. Exch $R1
  427. FunctionEnd
  428. Function ConditionalAddToRegisty
  429. Pop $0
  430. Pop $1
  431. StrCmp "$0" "" ConditionalAddToRegisty_EmptyString
  432. WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" \
  433. "$1" "$0"
  434. ;MessageBox MB_OK "Set Registry: '$1' to '$0'"
  435. DetailPrint "Set install registry entry: '$1' to '$0'"
  436. ConditionalAddToRegisty_EmptyString:
  437. FunctionEnd
  438. ;--------------------------------
  439. !ifdef CPACK_USES_DOWNLOAD
  440. Function DownloadFile
  441. IfFileExists $INSTDIR\* +2
  442. CreateDirectory $INSTDIR
  443. Pop $0
  444. ; Skip if already downloaded
  445. IfFileExists $INSTDIR\$0 0 +2
  446. Return
  447. StrCpy $1 "@CPACK_DOWNLOAD_SITE@"
  448. try_again:
  449. NSISdl::download "$1/$0" "$INSTDIR\$0"
  450. Pop $1
  451. StrCmp $1 "success" success
  452. StrCmp $1 "Cancelled" cancel
  453. MessageBox MB_OK "Download failed: $1"
  454. cancel:
  455. Return
  456. success:
  457. FunctionEnd
  458. !endif
  459. ;--------------------------------
  460. ; Installation types
  461. @CPACK_NSIS_INSTALLATION_TYPES@
  462. ;--------------------------------
  463. ; Component sections
  464. @CPACK_NSIS_COMPONENT_SECTIONS@
  465. ;--------------------------------
  466. ; Define some macro setting for the gui
  467. @CPACK_NSIS_INSTALLER_MUI_ICON_CODE@
  468. @CPACK_NSIS_INSTALLER_ICON_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 ConditionalAddToRegisty
  562. Push "DisplayVersion"
  563. Push "@CPACK_PACKAGE_VERSION@"
  564. Call ConditionalAddToRegisty
  565. Push "Publisher"
  566. Push "@CPACK_PACKAGE_VENDOR@"
  567. Call ConditionalAddToRegisty
  568. Push "UninstallString"
  569. Push "$INSTDIR\Uninstall.exe"
  570. Call ConditionalAddToRegisty
  571. Push "NoRepair"
  572. Push "1"
  573. Call ConditionalAddToRegisty
  574. !ifdef CPACK_NSIS_ADD_REMOVE
  575. ;Create add/remove functionality
  576. Push "ModifyPath"
  577. Push "$INSTDIR\AddRemove.exe"
  578. Call ConditionalAddToRegisty
  579. !else
  580. Push "NoModify"
  581. Push "1"
  582. Call ConditionalAddToRegisty
  583. !endif
  584. ; Optional registration
  585. Push "DisplayIcon"
  586. Push "$INSTDIR\@CPACK_NSIS_INSTALLED_ICON_NAME@"
  587. Call ConditionalAddToRegisty
  588. Push "HelpLink"
  589. Push "@CPACK_NSIS_HELP_LINK@"
  590. Call ConditionalAddToRegisty
  591. Push "URLInfoAbout"
  592. Push "@CPACK_NSIS_URL_INFO_ABOUT@"
  593. Call ConditionalAddToRegisty
  594. Push "Contact"
  595. Push "@CPACK_NSIS_CONTACT@"
  596. Call ConditionalAddToRegisty
  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 ConditionalAddToRegisty
  612. Push "DoNotAddToPath"
  613. Push "$DO_NOT_ADD_TO_PATH"
  614. Call ConditionalAddToRegisty
  615. Push "AddToPathAllUsers"
  616. Push "$ADD_TO_PATH_ALL_USERS"
  617. Call ConditionalAddToRegisty
  618. Push "AddToPathCurrentUser"
  619. Push "$ADD_TO_PATH_CURRENT_USER"
  620. Call ConditionalAddToRegisty
  621. Push "InstallToDesktop"
  622. Push "$INSTALL_DESKTOP"
  623. Call ConditionalAddToRegisty
  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"
  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 diretories
  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 diretories
  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_NAME@" "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. IDYES uninst IDNO inst
  773. Abort
  774. ;Run the uninstaller
  775. uninst:
  776. ClearErrors
  777. ExecWait '$0 _?=$INSTDIR' ;Do not copy the uninstaller to a temp file
  778. IfErrors uninst_failed inst
  779. uninst_failed:
  780. MessageBox MB_OK|MB_ICONSTOP "Uninstall failed."
  781. Abort
  782. inst:
  783. ; Reads components status for registry
  784. !insertmacro SectionList "InitSection"
  785. ; check to see if /D has been used to change
  786. ; the install directory by comparing it to the
  787. ; install directory that is expected to be the
  788. ; default
  789. StrCpy $IS_DEFAULT_INSTALLDIR 0
  790. StrCmp "$INSTDIR" "@CPACK_NSIS_INSTALL_ROOT@\@CPACK_PACKAGE_INSTALL_DIRECTORY@" 0 +2
  791. StrCpy $IS_DEFAULT_INSTALLDIR 1
  792. StrCpy $SV_ALLUSERS "JustMe"
  793. ; if default install dir then change the default
  794. ; if it is installed for JustMe
  795. StrCmp "$IS_DEFAULT_INSTALLDIR" "1" 0 +2
  796. StrCpy $INSTDIR "$DOCUMENTS\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
  797. ClearErrors
  798. UserInfo::GetName
  799. IfErrors noLM
  800. Pop $0
  801. UserInfo::GetAccountType
  802. Pop $1
  803. StrCmp $1 "Admin" 0 +4
  804. SetShellVarContext all
  805. ;MessageBox MB_OK 'User "$0" is in the Admin group'
  806. StrCpy $SV_ALLUSERS "AllUsers"
  807. Goto done
  808. StrCmp $1 "Power" 0 +4
  809. SetShellVarContext all
  810. ;MessageBox MB_OK 'User "$0" is in the Power Users group'
  811. StrCpy $SV_ALLUSERS "AllUsers"
  812. Goto done
  813. noLM:
  814. StrCpy $SV_ALLUSERS "AllUsers"
  815. ;Get installation folder from registry if available
  816. done:
  817. StrCmp $SV_ALLUSERS "AllUsers" 0 +3
  818. StrCmp "$IS_DEFAULT_INSTALLDIR" "1" 0 +2
  819. StrCpy $INSTDIR "@CPACK_NSIS_INSTALL_ROOT@\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
  820. StrCmp "@CPACK_NSIS_MODIFY_PATH@" "ON" 0 noOptionsPage
  821. !insertmacro MUI_INSTALLOPTIONS_EXTRACT "NSIS.InstallOptions.ini"
  822. noOptionsPage:
  823. FunctionEnd