NSIS.template.in 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  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. ;--------------------------------
  17. ;Include Modern UI
  18. !include "MUI.nsh"
  19. ;Default installation folder
  20. InstallDir "$PROGRAMFILES\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
  21. ;--------------------------------
  22. ; determine admin versus local install
  23. ; Is install for "AllUsers" or "JustMe"?
  24. ; Default to "JustMe" - set to "AllUsers" if admin or on Win9x
  25. ; This function is used for the very first "custom page" of the installer.
  26. ; This custom page does not show up visibly, but it executes prior to the
  27. ; first visible page and sets up $INSTDIR properly...
  28. ; Choose different default installation folder based on SV_ALLUSERS...
  29. ; "Program Files" for AllUsers, "My Documents" for JustMe...
  30. Function .onInit
  31. StrCpy $SV_ALLUSERS "JustMe"
  32. StrCpy $INSTDIR "$DOCUMENTS\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
  33. ClearErrors
  34. UserInfo::GetName
  35. IfErrors noLM
  36. Pop $0
  37. UserInfo::GetAccountType
  38. Pop $1
  39. StrCmp $1 "Admin" 0 +3
  40. SetShellVarContext all
  41. ;MessageBox MB_OK 'User "$0" is in the Admin group'
  42. StrCpy $SV_ALLUSERS "AllUsers"
  43. Goto done
  44. StrCmp $1 "Power" 0 +3
  45. SetShellVarContext all
  46. ;MessageBox MB_OK 'User "$0" is in the Power Users group'
  47. StrCpy $SV_ALLUSERS "AllUsers"
  48. Goto done
  49. noLM:
  50. StrCpy $SV_ALLUSERS "AllUsers"
  51. ;Get installation folder from registry if available
  52. done:
  53. StrCmp $SV_ALLUSERS "AllUsers" 0 +2
  54. StrCpy $INSTDIR "$PROGRAMFILES\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
  55. StrCmp "@CPACK_NSIS_MODIFY_PATH@" "ON" 0 noOptionsPage
  56. !insertmacro MUI_INSTALLOPTIONS_EXTRACT "NSIS.InstallOptions.ini"
  57. noOptionsPage:
  58. FunctionEnd
  59. ;--------------------------------
  60. ;General
  61. ;Name and file
  62. Name "@CPACK_PACKAGE_INSTALL_DIRECTORY@"
  63. OutFile "@CPACK_TOPLEVEL_DIRECTORY@/@CPACK_OUTPUT_FILE_NAME@"
  64. ;--------------------------------
  65. ;Interface Settings
  66. !define MUI_HEADERIMAGE
  67. !define MUI_ABORTWARNING
  68. ;--------------------------------
  69. ; path functions
  70. !verbose 3
  71. !include "WinMessages.NSH"
  72. !verbose 4
  73. ;----------------------------------------
  74. ; based upon a script of "Written by KiCHiK 2003-01-18 05:57:02"
  75. ;----------------------------------------
  76. !verbose 3
  77. !include "WinMessages.NSH"
  78. !verbose 4
  79. ;====================================================
  80. ; get_NT_environment
  81. ; Returns: the selected environment
  82. ; Output : head of the stack
  83. ;====================================================
  84. !macro select_NT_profile UN
  85. Function ${UN}select_NT_profile
  86. StrCmp $ADD_TO_PATH_ALL_USERS "1" 0 environment_single
  87. DetailPrint "Selected environment for all users"
  88. Push "all"
  89. Return
  90. environment_single:
  91. DetailPrint "Selected environment for current user only."
  92. Push "current"
  93. Return
  94. FunctionEnd
  95. !macroend
  96. !insertmacro select_NT_profile ""
  97. !insertmacro select_NT_profile "un."
  98. ;----------------------------------------------------
  99. !define NT_current_env 'HKCU "Environment"'
  100. !define NT_all_env 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
  101. ;====================================================
  102. ; AddToPath - Adds the given dir to the search path.
  103. ; Input - head of the stack
  104. ; Note - Win9x systems requires reboot
  105. ;====================================================
  106. Function AddToPath
  107. Exch $0
  108. Push $1
  109. Push $2
  110. Call IsNT
  111. Pop $1
  112. StrCmp $1 1 AddToPath_NT
  113. ; Not on NT
  114. StrCpy $1 $WINDIR 2
  115. FileOpen $1 "$1\autoexec.bat" a
  116. FileSeek $1 0 END
  117. GetFullPathName /SHORT $0 $0
  118. FileWrite $1 "$\r$\n\
  119. $\r$\n\
  120. SET PATH=%PATH%;$0$\r$\n\
  121. $\r$\n\
  122. "
  123. FileClose $1
  124. Goto AddToPath_done
  125. AddToPath_NT:
  126. Push $4
  127. Call select_NT_profile
  128. Pop $4
  129. AddToPath_NT_selection_done:
  130. StrCmp $4 "current" read_path_NT_current
  131. ReadRegStr $1 ${NT_all_env} "PATH"
  132. Goto read_path_NT_resume
  133. read_path_NT_current:
  134. ReadRegStr $1 ${NT_current_env} "PATH"
  135. read_path_NT_resume:
  136. StrCmp $1 "" AddToPath_NoCurrentPath
  137. StrCpy $2 "$0;$1"
  138. Goto AddToPath_NTdoIt
  139. AddToPath_NoCurrentPath:
  140. DetailPrint "No current path, so just use $0"
  141. StrCpy $2 $0
  142. Goto AddToPath_NTdoIt
  143. AddToPath_NTdoIt:
  144. StrCmp $4 "current" write_path_NT_current
  145. ClearErrors
  146. WriteRegExpandStr ${NT_all_env} "PATH" $2
  147. IfErrors 0 write_path_NT_resume
  148. MessageBox MB_YESNO|MB_ICONQUESTION "The path could not be set for all users$\n\
  149. $\n\
  150. Should I try for the current user?" \
  151. IDNO write_path_NT_failed
  152. ; change selection
  153. StrCpy $4 "current"
  154. Goto AddToPath_NT_selection_done
  155. write_path_NT_current:
  156. ClearErrors
  157. WriteRegExpandStr ${NT_current_env} "PATH" $2
  158. IfErrors 0 write_path_NT_resume
  159. MessageBox MB_OK|MB_ICONINFORMATION "The path could not be set for the current user."
  160. Goto write_path_NT_failed
  161. write_path_NT_resume:
  162. SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
  163. DetailPrint "Added path for user ($4), $0"
  164. DetailPrint "New path is: $2"
  165. write_path_NT_failed:
  166. Pop $4
  167. AddToPath_done:
  168. Pop $2
  169. Pop $1
  170. Pop $0
  171. FunctionEnd
  172. ;====================================================
  173. ; RemoveFromPath - Remove a given dir from the path
  174. ; Input: head of the stack
  175. ;====================================================
  176. Function un.RemoveFromPath
  177. Exch $0
  178. Push $1
  179. Push $2
  180. Push $3
  181. Push $4
  182. Call un.IsNT
  183. Pop $1
  184. StrCmp $1 1 unRemoveFromPath_NT
  185. ; Not on NT
  186. StrCpy $1 $WINDIR 2
  187. FileOpen $1 "$1\autoexec.bat" r
  188. GetTempFileName $4
  189. FileOpen $2 $4 w
  190. GetFullPathName /SHORT $0 $0
  191. StrCpy $0 "SET PATH=%PATH%;$0"
  192. SetRebootFlag true
  193. Goto unRemoveFromPath_dosLoop
  194. unRemoveFromPath_dosLoop:
  195. FileRead $1 $3
  196. StrCmp $3 "$0$$\r$\n\
  197. $\r$\n\
  198. " unRemoveFromPath_dosLoop
  199. StrCmp $3 "$0$\r$\n\
  200. " unRemoveFromPath_dosLoop
  201. StrCmp $3 "$0" unRemoveFromPath_dosLoop
  202. StrCmp $3 "" unRemoveFromPath_dosLoopEnd
  203. FileWrite $2 $3
  204. Goto unRemoveFromPath_dosLoop
  205. unRemoveFromPath_dosLoopEnd:
  206. FileClose $2
  207. FileClose $1
  208. StrCpy $1 $WINDIR 2
  209. Delete "$1\autoexec.bat"
  210. CopyFiles /SILENT $4 "$1\autoexec.bat"
  211. Delete $4
  212. Goto unRemoveFromPath_done
  213. unRemoveFromPath_NT:
  214. StrLen $2 $0
  215. Call un.select_NT_profile
  216. Pop $4
  217. StrCmp $4 "current" un_read_path_NT_current
  218. ReadRegStr $1 ${NT_all_env} "PATH"
  219. Goto un_read_path_NT_resume
  220. un_read_path_NT_current:
  221. ReadRegStr $1 ${NT_current_env} "PATH"
  222. un_read_path_NT_resume:
  223. StrCpy $8 $0
  224. Push $1
  225. Push $0
  226. Call un.StrStr ; Find $0 in $1
  227. Pop $0 ; pos of our dir
  228. IntCmp $0 -1 unRemoveFromPath_done
  229. ; else, it is in path
  230. StrLen $5 $1 ; Get the length of the original path
  231. StrLen $6 $0 ; get the length of path without the first path
  232. IntOp $5 $5 - $6
  233. IntOp $5 $5 - 1
  234. IntCmp $5 -1 unRemoveFromPath_nothingBefore
  235. StrCpy $3 $1 $5 ; $3 now has the part of the path before our dir
  236. Goto unRemoveFromPath_AfterBefore
  237. unRemoveFromPath_nothingBefore:
  238. StrCpy $3 ""
  239. unRemoveFromPath_AfterBefore:
  240. StrCpy $7 $0 "" $2 ; $3 now has the part of the path after our dir
  241. StrCpy $3 "$3$7"
  242. ; $3 now holds path, but there may be some stray semicolon at
  243. ; beginning. Let's remove it
  244. StrCpy $7 $3 1
  245. StrCmp $7 ";" 0 unRemoveFromPath_NoTrailingSemiColon
  246. StrCpy $3 $3 "" 1
  247. unRemoveFromPath_NoTrailingSemiColon:
  248. StrCmp $4 "current" un_write_path_NT_current
  249. WriteRegExpandStr ${NT_all_env} "PATH" $3
  250. Goto un_write_path_NT_resume
  251. un_write_path_NT_current:
  252. WriteRegExpandStr ${NT_current_env} "PATH" $3
  253. un_write_path_NT_resume:
  254. SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
  255. DetailPrint "Removed $8 from the path"
  256. DetailPrint "New path is: $3"
  257. unRemoveFromPath_done:
  258. Pop $4
  259. Pop $3
  260. Pop $2
  261. Pop $1
  262. Pop $0
  263. FunctionEnd
  264. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  265. ; Uninstall sutff
  266. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  267. ###########################################
  268. # Utility Functions #
  269. ###########################################
  270. ;====================================================
  271. ; IsNT - Returns 1 if the current system is NT, 0
  272. ; otherwise.
  273. ; Output: head of the stack
  274. ;====================================================
  275. ; IsNT
  276. ; no input
  277. ; output, top of the stack = 1 if NT or 0 if not
  278. ;
  279. ; Usage:
  280. ; Call IsNT
  281. ; Pop $R0
  282. ; ($R0 at this point is 1 or 0)
  283. !macro IsNT un
  284. Function ${un}IsNT
  285. Push $0
  286. ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
  287. StrCmp $0 "" 0 IsNT_yes
  288. ; we are not NT.
  289. Pop $0
  290. Push 0
  291. Return
  292. IsNT_yes:
  293. ; NT!!!
  294. Pop $0
  295. Push 1
  296. FunctionEnd
  297. !macroend
  298. !insertmacro IsNT ""
  299. !insertmacro IsNT "un."
  300. ; StrStr
  301. ; input, top of stack = string to search for
  302. ; top of stack-1 = string to search in
  303. ; output, top of stack (replaces with the portion of the string remaining)
  304. ; modifies no other variables.
  305. ;
  306. ; Usage:
  307. ; Push "this is a long ass string"
  308. ; Push "ass"
  309. ; Call StrStr
  310. ; Pop $R0
  311. ; ($R0 at this point is "ass string")
  312. !macro StrStr un
  313. Function ${un}StrStr
  314. Exch $R1 ; st=haystack,old$R1, $R1=needle
  315. Exch ; st=old$R1,haystack
  316. Exch $R2 ; st=old$R1,old$R2, $R2=haystack
  317. Push $R3
  318. Push $R4
  319. Push $R5
  320. StrLen $R3 $R1
  321. StrCpy $R4 0
  322. ; $R1=needle
  323. ; $R2=haystack
  324. ; $R3=len(needle)
  325. ; $R4=cnt
  326. ; $R5=tmp
  327. loop:
  328. StrCpy $R5 $R2 $R3 $R4
  329. StrCmp $R5 $R1 done
  330. StrCmp $R5 "" done
  331. IntOp $R4 $R4 + 1
  332. Goto loop
  333. done:
  334. StrCpy $R1 $R2 "" $R4
  335. Pop $R5
  336. Pop $R4
  337. Pop $R3
  338. Pop $R2
  339. Exch $R1
  340. FunctionEnd
  341. !macroend
  342. !insertmacro StrStr ""
  343. !insertmacro StrStr "un."
  344. Function ConditionalAddToRegisty
  345. Pop $0
  346. Pop $1
  347. StrCmp "$0" "" ConditionalAddToRegisty_EmptyString
  348. WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_DIRECTORY@" \
  349. "$1" "$0"
  350. ;MessageBox MB_OK "Set Registry: '$1' to '$0'"
  351. DetailPrint "Set install registry entry: '$1' to '$0'"
  352. ConditionalAddToRegisty_EmptyString:
  353. FunctionEnd
  354. ;--------------------------------
  355. ; Define some macro setting for the gui
  356. !define CPACK_PACKAGE_ICON@CPACK_PACKAGE_ICON@
  357. !ifndef CPACK_PACKAGE_ICON
  358. !define MUI_HEADERIMAGE_BITMAP "@CPACK_PACKAGE_ICON@"
  359. !endif
  360. ;--------------------------------
  361. ;Pages
  362. !insertmacro MUI_PAGE_WELCOME
  363. !insertmacro MUI_PAGE_LICENSE "@CPACK_RESOURCE_FILE_LICENSE@"
  364. Page custom InstallOptionsPage
  365. !insertmacro MUI_PAGE_DIRECTORY
  366. ;Start Menu Folder Page Configuration
  367. !define MUI_STARTMENUPAGE_REGISTRY_ROOT "SHCTX"
  368. !define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
  369. !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder"
  370. !insertmacro MUI_PAGE_STARTMENU Application $STARTMENU_FOLDER
  371. !insertmacro MUI_PAGE_INSTFILES
  372. !insertmacro MUI_PAGE_FINISH
  373. !insertmacro MUI_UNPAGE_CONFIRM
  374. !insertmacro MUI_UNPAGE_INSTFILES
  375. ;--------------------------------
  376. ;Languages
  377. !insertmacro MUI_LANGUAGE "English"
  378. ;--------------------------------
  379. ;Reserve Files
  380. ;These files should be inserted before other files in the data block
  381. ;Keep these lines before any File command
  382. ;Only for solid compression (by default, solid compression is enabled for BZIP2 and LZMA)
  383. ReserveFile "NSIS.InstallOptions.ini"
  384. !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
  385. ;--------------------------------
  386. ;Installer Sections
  387. Section "Add to path"
  388. Push $INSTDIR\bin
  389. ;Read a value from an InstallOptions INI file
  390. !insertmacro MUI_INSTALLOPTIONS_READ $DO_NOT_ADD_TO_PATH "NSIS.InstallOptions.ini" "Field 2" "State"
  391. !insertmacro MUI_INSTALLOPTIONS_READ $ADD_TO_PATH_ALL_USERS "NSIS.InstallOptions.ini" "Field 3" "State"
  392. !insertmacro MUI_INSTALLOPTIONS_READ $ADD_TO_PATH_CURRENT_USER "NSIS.InstallOptions.ini" "Field 4" "State"
  393. StrCmp $DO_NOT_ADD_TO_PATH "1" doNotAddToPath 0
  394. Call AddToPath
  395. doNotAddToPath:
  396. SectionEnd
  397. Section "Installer Section" InstSection
  398. ;Use the entire tree produced by the INSTALL target. Keep the
  399. ;list of directories here in sync with the RMDir commands below.
  400. SetOutPath "$INSTDIR"
  401. File /r "${INST_DIR}\*.*"
  402. ;Store installation folder
  403. WriteRegStr SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "" $INSTDIR
  404. ;Create uninstaller
  405. WriteUninstaller "$INSTDIR\Uninstall.exe"
  406. Push "DisplayName"
  407. Push "@CPACK_NSIS_DISPLAY_NAME@"
  408. Call ConditionalAddToRegisty
  409. Push "DisplayVersion"
  410. Push "@CPACK_PACKAGE_VERSION@"
  411. Call ConditionalAddToRegisty
  412. Push "Publisher"
  413. Push "@CPACK_PACKAGE_VENDOR@"
  414. Call ConditionalAddToRegisty
  415. Push "UninstallString"
  416. Push "$INSTDIR\Uninstall.exe"
  417. Call ConditionalAddToRegisty
  418. ; Optional registration
  419. Push "DisplayIcon"
  420. Push "$INSTDIR\@CPACK_NSIS_INSTALLED_ICON_NAME@"
  421. Call ConditionalAddToRegisty
  422. Push "HelpLink"
  423. Push "@CPACK_NSIS_HELP_LINK@"
  424. Call ConditionalAddToRegisty
  425. Push "URLInfoAbout"
  426. Push "@CPACK_NSIS_URL_INFO_ABOUT@"
  427. Call ConditionalAddToRegisty
  428. Push "Contact"
  429. Push "@CPACK_NSIS_CONTACT@"
  430. Call ConditionalAddToRegisty
  431. !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
  432. ;Create shortcuts
  433. CreateDirectory "$SMPROGRAMS\$STARTMENU_FOLDER"
  434. @CPACK_NSIS_CREATE_ICONS@
  435. CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Uninstall.lnk" "$INSTDIR\Uninstall.exe"
  436. ; Write special uninstall registry entries
  437. Push "StartMenu"
  438. Push "$STARTMENU_FOLDER"
  439. Call ConditionalAddToRegisty
  440. Push "DoNotAddToPath"
  441. Push "$DO_NOT_ADD_TO_PATH"
  442. Call ConditionalAddToRegisty
  443. Push "AddToPathAllUsers"
  444. Push "$ADD_TO_PATH_ALL_USERS"
  445. Call ConditionalAddToRegisty
  446. Push "AddToPathCurrentUser"
  447. Push "$ADD_TO_PATH_CURRENT_USER"
  448. Call ConditionalAddToRegisty
  449. @CPACK_NSIS_EXTRA_INSTALL_COMMANDS@
  450. !insertmacro MUI_STARTMENU_WRITE_END
  451. SectionEnd
  452. ;--------------------------------
  453. ; Create custom pages
  454. Function InstallOptionsPage
  455. !insertmacro MUI_HEADER_TEXT "Install Options" "Chose options for installing @CPACK_PACKAGE_INSTALL_DIRECTORY@"
  456. !insertmacro MUI_INSTALLOPTIONS_DISPLAY "NSIS.InstallOptions.ini"
  457. FunctionEnd
  458. ;--------------------------------
  459. ; determine admin versus local install
  460. Function un.onInit
  461. ClearErrors
  462. UserInfo::GetName
  463. IfErrors noLM
  464. Pop $0
  465. UserInfo::GetAccountType
  466. Pop $1
  467. StrCmp $1 "Admin" 0 +3
  468. SetShellVarContext all
  469. ;MessageBox MB_OK 'User "$0" is in the Admin group'
  470. Goto done
  471. StrCmp $1 "Power" 0 +3
  472. SetShellVarContext all
  473. ;MessageBox MB_OK 'User "$0" is in the Power Users group'
  474. Goto done
  475. noLM:
  476. ;Get installation folder from registry if available
  477. done:
  478. FunctionEnd
  479. ;--------------------------------
  480. ;Uninstaller Section
  481. Section "Uninstall"
  482. ReadRegStr $START_MENU SHCTX \
  483. "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_DIRECTORY@" "StartMenu"
  484. ;MessageBox MB_OK "Start menu is in: $START_MENU"
  485. ReadRegStr $DO_NOT_ADD_TO_PATH SHCTX \
  486. "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_DIRECTORY@" "DoNotAddToPath"
  487. ReadRegStr $ADD_TO_PATH_ALL_USERS SHCTX \
  488. "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_DIRECTORY@" "AddToPathAllUsers"
  489. ReadRegStr $ADD_TO_PATH_CURRENT_USER SHCTX \
  490. "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_DIRECTORY@" "AddToPathCurrentUser"
  491. ;MessageBox MB_OK "Add to path: $DO_NOT_ADD_TO_PATH all users: $ADD_TO_PATH_ALL_USERS"
  492. @CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS@
  493. ;Remove files we installed.
  494. ;Keep the list of directories here in sync with the File commands above.
  495. @CPACK_NSIS_DELETE_FILES@
  496. @CPACK_NSIS_DELETE_DIRECTORIES@
  497. ;Remove the uninstaller itself.
  498. Delete "$INSTDIR\Uninstall.exe"
  499. DeleteRegKey SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
  500. ;Remove the installation directory if it is empty.
  501. RMDir "$INSTDIR"
  502. ; Remove the registry entries.
  503. DeleteRegKey SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
  504. !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP
  505. Delete "$SMPROGRAMS\$MUI_TEMP\Uninstall.lnk"
  506. @CPACK_NSIS_DELETE_ICONS@
  507. ;Delete empty start menu parent diretories
  508. StrCpy $MUI_TEMP "$SMPROGRAMS\$MUI_TEMP"
  509. startMenuDeleteLoop:
  510. ClearErrors
  511. RMDir $MUI_TEMP
  512. GetFullPathName $MUI_TEMP "$MUI_TEMP\.."
  513. IfErrors startMenuDeleteLoopDone
  514. StrCmp "$MUI_TEMP" "$SMPROGRAMS" startMenuDeleteLoopDone startMenuDeleteLoop
  515. startMenuDeleteLoopDone:
  516. ; If the user changed the shortcut, then untinstall may not work. This should
  517. ; try to fix it.
  518. StrCpy $MUI_TEMP "$START_MENU"
  519. Delete "$SMPROGRAMS\$MUI_TEMP\Uninstall.lnk"
  520. @CPACK_NSIS_DELETE_ICONS@
  521. ;Delete empty start menu parent diretories
  522. StrCpy $MUI_TEMP "$SMPROGRAMS\$MUI_TEMP"
  523. secondStartMenuDeleteLoop:
  524. ClearErrors
  525. RMDir $MUI_TEMP
  526. GetFullPathName $MUI_TEMP "$MUI_TEMP\.."
  527. IfErrors secondStartMenuDeleteLoopDone
  528. StrCmp "$MUI_TEMP" "$SMPROGRAMS" secondStartMenuDeleteLoopDone secondStartMenuDeleteLoop
  529. secondStartMenuDeleteLoopDone:
  530. DeleteRegKey /ifempty SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
  531. Push $INSTDIR\bin
  532. StrCmp $DO_NOT_ADD_TO_PATH_ "1" doNotRemoveFromPath 0
  533. Call un.RemoveFromPath
  534. doNotRemoveFromPath:
  535. SectionEnd