NSIS.template.in 29 KB

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