NSIS.template.in 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  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_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"
  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 diretories
  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 diretories
  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. ; Reads components status for registry
  767. !insertmacro SectionList "InitSection"
  768. ; check to see if /D has been used to change
  769. ; the install directory by comparing it to the
  770. ; install directory that is expected to be the
  771. ; default
  772. StrCpy $IS_DEFAULT_INSTALLDIR 0
  773. StrCmp "$INSTDIR" "@CPACK_NSIS_INSTALL_ROOT@\@CPACK_PACKAGE_INSTALL_DIRECTORY@" 0 +2
  774. StrCpy $IS_DEFAULT_INSTALLDIR 1
  775. StrCpy $SV_ALLUSERS "JustMe"
  776. ; if default install dir then change the default
  777. ; if it is installed for JustMe
  778. StrCmp "$IS_DEFAULT_INSTALLDIR" "1" 0 +2
  779. StrCpy $INSTDIR "$DOCUMENTS\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
  780. ClearErrors
  781. UserInfo::GetName
  782. IfErrors noLM
  783. Pop $0
  784. UserInfo::GetAccountType
  785. Pop $1
  786. StrCmp $1 "Admin" 0 +4
  787. SetShellVarContext all
  788. ;MessageBox MB_OK 'User "$0" is in the Admin group'
  789. StrCpy $SV_ALLUSERS "AllUsers"
  790. Goto done
  791. StrCmp $1 "Power" 0 +4
  792. SetShellVarContext all
  793. ;MessageBox MB_OK 'User "$0" is in the Power Users group'
  794. StrCpy $SV_ALLUSERS "AllUsers"
  795. Goto done
  796. noLM:
  797. StrCpy $SV_ALLUSERS "AllUsers"
  798. ;Get installation folder from registry if available
  799. done:
  800. StrCmp $SV_ALLUSERS "AllUsers" 0 +3
  801. StrCmp "$IS_DEFAULT_INSTALLDIR" "1" 0 +2
  802. StrCpy $INSTDIR "@CPACK_NSIS_INSTALL_ROOT@\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
  803. StrCmp "@CPACK_NSIS_MODIFY_PATH@" "ON" 0 noOptionsPage
  804. !insertmacro MUI_INSTALLOPTIONS_EXTRACT "NSIS.InstallOptions.ini"
  805. noOptionsPage:
  806. FunctionEnd