NSIS.template.in 18 KB

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