1 ; CPack install script designed for a nmake build
3 ;--------------------------------
4 ; You must define these values
6 !define VERSION "@CPACK_PACKAGE_VERSION@"
7 !define PATCH "@CPACK_PACKAGE_VERSION_PATCH@"
8 !define INST_DIR "@CPACK_TEMPORARY_DIRECTORY@"
10 ;--------------------------------
17 Var DO_NOT_ADD_TO_PATH
18 Var ADD_TO_PATH_ALL_USERS
19 Var ADD_TO_PATH_CURRENT_USER
21 Var IS_DEFAULT_INSTALLDIR
22 ;--------------------------------
27 ;Default installation folder
28 InstallDir "@CPACK_NSIS_INSTALL_ROOT@\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
30 ;--------------------------------
34 Name "@CPACK_NSIS_PACKAGE_NAME@"
35 OutFile "@CPACK_TOPLEVEL_DIRECTORY@/@CPACK_OUTPUT_FILE_NAME@"
38 SetCompressor @CPACK_NSIS_COMPRESSOR@
44 ;--- Component support macros: ---
45 ; The code for the add/remove functionality is from:
46 ; http://nsis.sourceforge.net/Add/Remove_Functionality
47 ; It has been modified slightly and extended to provide
48 ; inter-component dependencies.
51 @CPACK_NSIS_SECTION_SELECTED_VARS@
53 ; Loads the "selected" flag for the section named SecName into the
55 !macro LoadSectionSelectedIntoVar SecName VarName
56 SectionGetFlags ${${SecName}} $${VarName}
57 IntOp $${VarName} $${VarName} & ${SF_SELECTED} ;Turn off all other bits
60 ; Loads the value of a variable... can we get around this?
61 !macro LoadVar VarName
62 IntOp $R0 0 + $${VarName}
65 ; Sets the value of a variable
66 !macro StoreVar VarName IntValue
67 IntOp $${VarName} 0 + ${IntValue}
70 !macro InitSection SecName
71 ; This macro reads component installed flag from the registry and
72 ;changes checked state of the section on the components page.
73 ;Input: section index constant name specified in Section command.
76 ;Reading component status from registry
77 ReadRegDWORD $AR_RegFlags HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@\Components\${SecName}" "Installed"
78 IfErrors "default_${SecName}"
79 ;Status will stay default if registry value not found
80 ;(component was never installed)
81 IntOp $AR_RegFlags $AR_RegFlags & ${SF_SELECTED} ;Turn off all other bits
82 SectionGetFlags ${${SecName}} $AR_SecFlags ;Reading default section flags
83 IntOp $AR_SecFlags $AR_SecFlags & 0xFFFE ;Turn lowest (enabled) bit off
84 IntOp $AR_SecFlags $AR_RegFlags | $AR_SecFlags ;Change lowest bit
86 ; Note whether this component was installed before
87 !insertmacro StoreVar ${SecName}_was_installed $AR_RegFlags
88 IntOp $R0 $AR_RegFlags & $AR_RegFlags
90 ;Writing modified flags
91 SectionSetFlags ${${SecName}} $AR_SecFlags
94 !insertmacro LoadSectionSelectedIntoVar ${SecName} ${SecName}_selected
97 !macro FinishSection SecName
98 ; This macro reads section flag set by user and removes the section
99 ;if it is not selected.
100 ;Then it writes component installed flag to registry
101 ;Input: section index constant name specified in Section command.
103 SectionGetFlags ${${SecName}} $AR_SecFlags ;Reading section flags
104 ;Checking lowest bit:
105 IntOp $AR_SecFlags $AR_SecFlags & ${SF_SELECTED}
106 IntCmp $AR_SecFlags 1 "leave_${SecName}"
107 ;Section is not selected:
108 ;Calling Section uninstall macro and writing zero installed flag
109 !insertmacro "Remove_${${SecName}}"
110 WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@\Components\${SecName}" \
112 Goto "exit_${SecName}"
115 ;Section is selected:
116 WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@\Components\${SecName}" \
122 !macro RemoveSection SecName
123 ; This macro is used to call section's Remove_... macro
124 ;from the uninstaller.
125 ;Input: section index constant name specified in Section command.
127 !insertmacro "Remove_${${SecName}}"
130 ; Determine whether the selection of SecName changed
131 !macro MaybeSelectionChanged SecName
132 !insertmacro LoadVar ${SecName}_selected
133 SectionGetFlags ${${SecName}} $R1
134 IntOp $R1 $R1 & ${SF_SELECTED} ;Turn off all other bits
136 ; See if the status has changed:
137 IntCmp $R0 $R1 "${SecName}_unchanged"
138 !insertmacro LoadSectionSelectedIntoVar ${SecName} ${SecName}_selected
140 IntCmp $R1 ${SF_SELECTED} "${SecName}_was_selected"
141 !insertmacro "Deselect_required_by_${SecName}"
142 goto "${SecName}_unchanged"
144 "${SecName}_was_selected:"
145 !insertmacro "Select_${SecName}_depends"
147 "${SecName}_unchanged:"
149 ;--- End of Add/Remove macros ---
151 ;--------------------------------
154 !define MUI_HEADERIMAGE
155 !define MUI_ABORTWARNING
157 ;--------------------------------
161 !include "WinMessages.NSH"
164 ;----------------------------------------
165 ; based upon a script of "Written by KiCHiK 2003-01-18 05:57:02"
166 ;----------------------------------------
168 !include "WinMessages.NSH"
170 ;====================================================
172 ; Returns: the selected environment
173 ; Output : head of the stack
174 ;====================================================
175 !macro select_NT_profile UN
176 Function ${UN}select_NT_profile
177 StrCmp $ADD_TO_PATH_ALL_USERS "1" 0 environment_single
178 DetailPrint "Selected environment for all users"
182 DetailPrint "Selected environment for current user only."
187 !insertmacro select_NT_profile ""
188 !insertmacro select_NT_profile "un."
189 ;----------------------------------------------------
190 !define NT_current_env 'HKCU "Environment"'
191 !define NT_all_env 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
193 !ifndef WriteEnvStr_RegKey
195 !define WriteEnvStr_RegKey \
196 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
198 !define WriteEnvStr_RegKey 'HKCU "Environment"'
202 ; AddToPath - Adds the given dir to the search path.
203 ; Input - head of the stack
204 ; Note - Win9x systems requires reboot
212 # don't add if the path doesn't exist
213 IfFileExists "$0\*.*" "" AddToPath_done
216 ; if the path is too long for a NSIS variable NSIS will return a 0
217 ; length string. If we find that, then warn and skip any path
218 ; modification as it will trash the existing path.
220 IntCmp $2 0 CheckPathLength_ShowPathWarning CheckPathLength_Done CheckPathLength_Done
221 CheckPathLength_ShowPathWarning:
222 Messagebox MB_OK|MB_ICONEXCLAMATION "Warning! PATH too long installer unable to modify PATH!"
224 CheckPathLength_Done:
229 StrCmp $2 "" "" AddToPath_done
234 StrCmp $2 "" "" AddToPath_done
235 GetFullPathName /SHORT $3 $0
240 StrCmp $2 "" "" AddToPath_done
245 StrCmp $2 "" "" AddToPath_done
249 StrCmp $1 1 AddToPath_NT
252 FileOpen $1 "$1\autoexec.bat" a
255 IntCmp $2 26 0 +2 +2 # DOS EOF
256 FileSeek $1 -1 END # write over EOF
257 FileWrite $1 "$\r$\nSET PATH=%PATH%;$3$\r$\n"
263 StrCmp $ADD_TO_PATH_ALL_USERS "1" ReadAllKey
264 ReadRegStr $1 ${NT_current_env} "PATH"
267 ReadRegStr $1 ${NT_all_env} "PATH"
269 StrCmp $1 "" AddToPath_NTdoIt
275 StrCmp $ADD_TO_PATH_ALL_USERS "1" WriteAllKey
276 WriteRegExpandStr ${NT_current_env} "PATH" $0
279 WriteRegExpandStr ${NT_all_env} "PATH" $0
281 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
291 ; RemoveFromPath - Remove a given dir from the path
292 ; Input: head of the stack
294 Function un.RemoveFromPath
303 IntFmt $6 "%c" 26 # DOS EOF
307 StrCmp $1 1 unRemoveFromPath_NT
310 FileOpen $1 "$1\autoexec.bat" r
313 GetFullPathName /SHORT $0 $0
314 StrCpy $0 "SET PATH=%PATH%;$0"
315 Goto unRemoveFromPath_dosLoop
317 unRemoveFromPath_dosLoop:
319 StrCpy $5 $3 1 -1 # read last char
320 StrCmp $5 $6 0 +2 # if DOS EOF
321 StrCpy $3 $3 -1 # remove DOS EOF so we can compare
322 StrCmp $3 "$0$\r$\n" unRemoveFromPath_dosLoopRemoveLine
323 StrCmp $3 "$0$\n" unRemoveFromPath_dosLoopRemoveLine
324 StrCmp $3 "$0" unRemoveFromPath_dosLoopRemoveLine
325 StrCmp $3 "" unRemoveFromPath_dosLoopEnd
327 Goto unRemoveFromPath_dosLoop
328 unRemoveFromPath_dosLoopRemoveLine:
330 Goto unRemoveFromPath_dosLoop
332 unRemoveFromPath_dosLoopEnd:
336 Delete "$1\autoexec.bat"
337 CopyFiles /SILENT $4 "$1\autoexec.bat"
339 Goto unRemoveFromPath_done
342 StrCmp $ADD_TO_PATH_ALL_USERS "1" unReadAllKey
343 ReadRegStr $1 ${NT_current_env} "PATH"
346 ReadRegStr $1 ${NT_all_env} "PATH"
348 StrCpy $5 $1 1 -1 # copy last char
349 StrCmp $5 ";" +2 # if last char != ;
350 StrCpy $1 "$1;" # append ;
353 Call un.StrStr ; Find `$0;` in $1
354 Pop $2 ; pos of our dir
355 StrCmp $2 "" unRemoveFromPath_done
356 ; else, it is in path
361 StrCpy $5 $1 -$4 # $5 is now the part before the path to remove
362 StrCpy $6 $2 "" $3 # $6 is now the part after the path to remove
365 StrCpy $5 $3 1 -1 # copy last char
366 StrCmp $5 ";" 0 +2 # if last char == ;
367 StrCpy $3 $3 -1 # remove last char
369 StrCmp $ADD_TO_PATH_ALL_USERS "1" unWriteAllKey
370 WriteRegExpandStr ${NT_current_env} "PATH" $3
373 WriteRegExpandStr ${NT_all_env} "PATH" $3
375 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
377 unRemoveFromPath_done:
387 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
389 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
391 ###########################################
392 # Utility Functions #
393 ###########################################
395 ;====================================================
396 ; IsNT - Returns 1 if the current system is NT, 0
398 ; Output: head of the stack
399 ;====================================================
402 ; output, top of the stack = 1 if NT or 0 if not
407 ; ($R0 at this point is 1 or 0)
412 ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
413 StrCmp $0 "" 0 IsNT_yes
426 !insertmacro IsNT "un."
429 ; input, top of stack = string to search for
430 ; top of stack-1 = string to search in
431 ; output, top of stack (replaces with the portion of the string remaining)
432 ; modifies no other variables.
435 ; Push "this is a long ass string"
439 ; ($R0 at this point is "ass string")
443 Exch $R1 ; st=haystack,old$R1, $R1=needle
444 Exch ; st=old$R1,haystack
445 Exch $R2 ; st=old$R1,old$R2, $R2=haystack
457 StrCpy $R5 $R2 $R3 $R4
463 StrCpy $R1 $R2 "" $R4
471 !insertmacro StrStr ""
472 !insertmacro StrStr "un."
474 Function Trim ; Added by Pelaca
478 StrCpy $R2 "$R1" 1 -1
479 StrCmp "$R2" " " RTrim
480 StrCmp "$R2" "$\n" RTrim
481 StrCmp "$R2" "$\r" RTrim
482 StrCmp "$R2" ";" RTrim
492 Function ConditionalAddToRegisty
495 StrCmp "$0" "" ConditionalAddToRegisty_EmptyString
496 WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" \
498 ;MessageBox MB_OK "Set Registry: '$1' to '$0'"
499 DetailPrint "Set install registry entry: '$1' to '$0'"
500 ConditionalAddToRegisty_EmptyString:
503 ;--------------------------------
505 !ifdef CPACK_USES_DOWNLOAD
506 Function DownloadFile
507 IfFileExists $INSTDIR\* +2
508 CreateDirectory $INSTDIR
511 ; Skip if already downloaded
512 IfFileExists $INSTDIR\$0 0 +2
515 StrCpy $1 "@CPACK_DOWNLOAD_SITE@"
518 NSISdl::download "$1/$0" "$INSTDIR\$0"
521 StrCmp $1 "success" success
522 StrCmp $1 "Cancelled" cancel
523 MessageBox MB_OK "Download failed: $1"
530 ;--------------------------------
532 @CPACK_NSIS_INSTALLATION_TYPES@
534 ;--------------------------------
536 @CPACK_NSIS_COMPONENT_SECTIONS@
538 ;--------------------------------
539 ; Define some macro setting for the gui
540 @CPACK_NSIS_INSTALLER_MUI_ICON_CODE@
541 @CPACK_NSIS_INSTALLER_ICON_CODE@
542 @CPACK_NSIS_INSTALLER_MUI_COMPONENTS_DESC@
543 @CPACK_NSIS_INSTALLER_MUI_FINISHPAGE_RUN_CODE@
545 ;--------------------------------
547 !insertmacro MUI_PAGE_WELCOME
549 !insertmacro MUI_PAGE_LICENSE "@CPACK_RESOURCE_FILE_LICENSE@"
550 Page custom InstallOptionsPage
551 !insertmacro MUI_PAGE_DIRECTORY
553 ;Start Menu Folder Page Configuration
554 !define MUI_STARTMENUPAGE_REGISTRY_ROOT "SHCTX"
555 !define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
556 !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder"
557 !insertmacro MUI_PAGE_STARTMENU Application $STARTMENU_FOLDER
559 @CPACK_NSIS_PAGE_COMPONENTS@
561 !insertmacro MUI_PAGE_INSTFILES
562 !insertmacro MUI_PAGE_FINISH
564 !insertmacro MUI_UNPAGE_CONFIRM
565 !insertmacro MUI_UNPAGE_INSTFILES
567 ;--------------------------------
570 !insertmacro MUI_LANGUAGE "English" ;first language is the default language
571 !insertmacro MUI_LANGUAGE "Albanian"
572 !insertmacro MUI_LANGUAGE "Arabic"
573 !insertmacro MUI_LANGUAGE "Basque"
574 !insertmacro MUI_LANGUAGE "Belarusian"
575 !insertmacro MUI_LANGUAGE "Bosnian"
576 !insertmacro MUI_LANGUAGE "Breton"
577 !insertmacro MUI_LANGUAGE "Bulgarian"
578 !insertmacro MUI_LANGUAGE "Croatian"
579 !insertmacro MUI_LANGUAGE "Czech"
580 !insertmacro MUI_LANGUAGE "Danish"
581 !insertmacro MUI_LANGUAGE "Dutch"
582 !insertmacro MUI_LANGUAGE "Estonian"
583 !insertmacro MUI_LANGUAGE "Farsi"
584 !insertmacro MUI_LANGUAGE "Finnish"
585 !insertmacro MUI_LANGUAGE "French"
586 !insertmacro MUI_LANGUAGE "German"
587 !insertmacro MUI_LANGUAGE "Greek"
588 !insertmacro MUI_LANGUAGE "Hebrew"
589 !insertmacro MUI_LANGUAGE "Hungarian"
590 !insertmacro MUI_LANGUAGE "Icelandic"
591 !insertmacro MUI_LANGUAGE "Indonesian"
592 !insertmacro MUI_LANGUAGE "Irish"
593 !insertmacro MUI_LANGUAGE "Italian"
594 !insertmacro MUI_LANGUAGE "Japanese"
595 !insertmacro MUI_LANGUAGE "Korean"
596 !insertmacro MUI_LANGUAGE "Kurdish"
597 !insertmacro MUI_LANGUAGE "Latvian"
598 !insertmacro MUI_LANGUAGE "Lithuanian"
599 !insertmacro MUI_LANGUAGE "Luxembourgish"
600 !insertmacro MUI_LANGUAGE "Macedonian"
601 !insertmacro MUI_LANGUAGE "Malay"
602 !insertmacro MUI_LANGUAGE "Mongolian"
603 !insertmacro MUI_LANGUAGE "Norwegian"
604 !insertmacro MUI_LANGUAGE "Polish"
605 !insertmacro MUI_LANGUAGE "Portuguese"
606 !insertmacro MUI_LANGUAGE "PortugueseBR"
607 !insertmacro MUI_LANGUAGE "Romanian"
608 !insertmacro MUI_LANGUAGE "Russian"
609 !insertmacro MUI_LANGUAGE "Serbian"
610 !insertmacro MUI_LANGUAGE "SerbianLatin"
611 !insertmacro MUI_LANGUAGE "SimpChinese"
612 !insertmacro MUI_LANGUAGE "Slovak"
613 !insertmacro MUI_LANGUAGE "Slovenian"
614 !insertmacro MUI_LANGUAGE "Spanish"
615 !insertmacro MUI_LANGUAGE "Swedish"
616 !insertmacro MUI_LANGUAGE "Thai"
617 !insertmacro MUI_LANGUAGE "TradChinese"
618 !insertmacro MUI_LANGUAGE "Turkish"
619 !insertmacro MUI_LANGUAGE "Ukrainian"
620 !insertmacro MUI_LANGUAGE "Welsh"
623 ;--------------------------------
626 ;These files should be inserted before other files in the data block
627 ;Keep these lines before any File command
628 ;Only for solid compression (by default, solid compression is enabled for BZIP2 and LZMA)
630 ReserveFile "NSIS.InstallOptions.ini"
631 !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
633 ;--------------------------------
636 Section "-Core installation"
637 ;Use the entire tree produced by the INSTALL target. Keep the
638 ;list of directories here in sync with the RMDir commands below.
639 SetOutPath "$INSTDIR"
640 @CPACK_NSIS_EXTRA_PREINSTALL_COMMANDS@
641 @CPACK_NSIS_FULL_INSTALL@
643 ;Store installation folder
644 WriteRegStr SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "" $INSTDIR
647 WriteUninstaller "$INSTDIR\Uninstall.exe"
649 Push "@CPACK_NSIS_DISPLAY_NAME@"
650 Call ConditionalAddToRegisty
651 Push "DisplayVersion"
652 Push "@CPACK_PACKAGE_VERSION@"
653 Call ConditionalAddToRegisty
655 Push "@CPACK_PACKAGE_VENDOR@"
656 Call ConditionalAddToRegisty
657 Push "UninstallString"
658 Push "$INSTDIR\Uninstall.exe"
659 Call ConditionalAddToRegisty
662 Call ConditionalAddToRegisty
664 !ifdef CPACK_NSIS_ADD_REMOVE
665 ;Create add/remove functionality
667 Push "$INSTDIR\AddRemove.exe"
668 Call ConditionalAddToRegisty
672 Call ConditionalAddToRegisty
675 ; Optional registration
677 Push "$INSTDIR\@CPACK_NSIS_INSTALLED_ICON_NAME@"
678 Call ConditionalAddToRegisty
680 Push "@CPACK_NSIS_HELP_LINK@"
681 Call ConditionalAddToRegisty
683 Push "@CPACK_NSIS_URL_INFO_ABOUT@"
684 Call ConditionalAddToRegisty
686 Push "@CPACK_NSIS_CONTACT@"
687 Call ConditionalAddToRegisty
688 !insertmacro MUI_INSTALLOPTIONS_READ $INSTALL_DESKTOP "NSIS.InstallOptions.ini" "Field 5" "State"
689 !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
692 CreateDirectory "$SMPROGRAMS\$STARTMENU_FOLDER"
693 @CPACK_NSIS_CREATE_ICONS@
694 @CPACK_NSIS_CREATE_ICONS_EXTRA@
695 CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Uninstall.lnk" "$INSTDIR\Uninstall.exe"
697 ;Read a value from an InstallOptions INI file
698 !insertmacro MUI_INSTALLOPTIONS_READ $DO_NOT_ADD_TO_PATH "NSIS.InstallOptions.ini" "Field 2" "State"
699 !insertmacro MUI_INSTALLOPTIONS_READ $ADD_TO_PATH_ALL_USERS "NSIS.InstallOptions.ini" "Field 3" "State"
700 !insertmacro MUI_INSTALLOPTIONS_READ $ADD_TO_PATH_CURRENT_USER "NSIS.InstallOptions.ini" "Field 4" "State"
702 ; Write special uninstall registry entries
704 Push "$STARTMENU_FOLDER"
705 Call ConditionalAddToRegisty
706 Push "DoNotAddToPath"
707 Push "$DO_NOT_ADD_TO_PATH"
708 Call ConditionalAddToRegisty
709 Push "AddToPathAllUsers"
710 Push "$ADD_TO_PATH_ALL_USERS"
711 Call ConditionalAddToRegisty
712 Push "AddToPathCurrentUser"
713 Push "$ADD_TO_PATH_CURRENT_USER"
714 Call ConditionalAddToRegisty
715 Push "InstallToDesktop"
716 Push "$INSTALL_DESKTOP"
717 Call ConditionalAddToRegisty
719 !insertmacro MUI_STARTMENU_WRITE_END
721 @CPACK_NSIS_EXTRA_INSTALL_COMMANDS@
725 Section "-Add to path"
727 StrCmp "@CPACK_NSIS_MODIFY_PATH@" "ON" 0 doNotAddToPath
728 StrCmp $DO_NOT_ADD_TO_PATH "1" doNotAddToPath 0
733 ;--------------------------------
734 ; Create custom pages
735 Function InstallOptionsPage
736 !insertmacro MUI_HEADER_TEXT "Install Options" "Choose options for installing @CPACK_NSIS_PACKAGE_NAME@"
737 !insertmacro MUI_INSTALLOPTIONS_DISPLAY "NSIS.InstallOptions.ini"
741 ;--------------------------------
742 ; determine admin versus local install
749 UserInfo::GetAccountType
751 StrCmp $1 "Admin" 0 +3
752 SetShellVarContext all
753 ;MessageBox MB_OK 'User "$0" is in the Admin group'
755 StrCmp $1 "Power" 0 +3
756 SetShellVarContext all
757 ;MessageBox MB_OK 'User "$0" is in the Power Users group'
761 ;Get installation folder from registry if available
767 ;--- Add/Remove callback functions: ---
768 !macro SectionList MacroName
769 ;This macro used to perform operation on multiple sections.
770 ;List all of your components in following manner here.
771 @CPACK_NSIS_COMPONENT_SECTION_LIST@
774 Section -FinishComponents
775 ;Removes unselected components and writes component status to registry
776 !insertmacro SectionList "FinishSection"
778 !ifdef CPACK_NSIS_ADD_REMOVE
779 ; Get the name of the installer executable
780 System::Call 'kernel32::GetModuleFileNameA(i 0, t .R0, i 1024) i r1'
783 ; Strip off the last 13 characters, to see if we have AddRemove.exe
786 StrCpy $R2 $R0 13 $R1
787 StrCmp $R2 "AddRemove.exe" addremove_installed
789 ; We're not running AddRemove.exe, so install it
790 CopyFiles $R3 $INSTDIR\AddRemove.exe
795 ;--- End of Add/Remove callback functions ---
797 ;--------------------------------
798 ; Component dependencies
799 Function .onSelChange
800 !insertmacro SectionList MaybeSelectionChanged
803 ;--------------------------------
807 ReadRegStr $START_MENU SHCTX \
808 "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "StartMenu"
809 ;MessageBox MB_OK "Start menu is in: $START_MENU"
810 ReadRegStr $DO_NOT_ADD_TO_PATH SHCTX \
811 "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "DoNotAddToPath"
812 ReadRegStr $ADD_TO_PATH_ALL_USERS SHCTX \
813 "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "AddToPathAllUsers"
814 ReadRegStr $ADD_TO_PATH_CURRENT_USER SHCTX \
815 "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "AddToPathCurrentUser"
816 ;MessageBox MB_OK "Add to path: $DO_NOT_ADD_TO_PATH all users: $ADD_TO_PATH_ALL_USERS"
817 ReadRegStr $INSTALL_DESKTOP SHCTX \
818 "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "InstallToDesktop"
819 ;MessageBox MB_OK "Install to desktop: $INSTALL_DESKTOP "
821 @CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS@
823 ;Remove files we installed.
824 ;Keep the list of directories here in sync with the File commands above.
825 @CPACK_NSIS_DELETE_FILES@
826 @CPACK_NSIS_DELETE_DIRECTORIES@
828 !ifdef CPACK_NSIS_ADD_REMOVE
829 ;Remove the add/remove program
830 Delete "$INSTDIR\AddRemove.exe"
833 ;Remove the uninstaller itself.
834 Delete "$INSTDIR\Uninstall.exe"
835 DeleteRegKey SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
837 ;Remove the installation directory if it is empty.
840 ; Remove the registry entries.
841 DeleteRegKey SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
843 ; Removes all optional components
844 !insertmacro SectionList "RemoveSection"
846 !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP
848 Delete "$SMPROGRAMS\$MUI_TEMP\Uninstall.lnk"
849 @CPACK_NSIS_DELETE_ICONS@
850 @CPACK_NSIS_DELETE_ICONS_EXTRA@
852 ;Delete empty start menu parent diretories
853 StrCpy $MUI_TEMP "$SMPROGRAMS\$MUI_TEMP"
858 GetFullPathName $MUI_TEMP "$MUI_TEMP\.."
860 IfErrors startMenuDeleteLoopDone
862 StrCmp "$MUI_TEMP" "$SMPROGRAMS" startMenuDeleteLoopDone startMenuDeleteLoop
863 startMenuDeleteLoopDone:
865 ; If the user changed the shortcut, then untinstall may not work. This should
867 StrCpy $MUI_TEMP "$START_MENU"
868 Delete "$SMPROGRAMS\$MUI_TEMP\Uninstall.lnk"
869 @CPACK_NSIS_DELETE_ICONS_EXTRA@
871 ;Delete empty start menu parent diretories
872 StrCpy $MUI_TEMP "$SMPROGRAMS\$MUI_TEMP"
874 secondStartMenuDeleteLoop:
877 GetFullPathName $MUI_TEMP "$MUI_TEMP\.."
879 IfErrors secondStartMenuDeleteLoopDone
881 StrCmp "$MUI_TEMP" "$SMPROGRAMS" secondStartMenuDeleteLoopDone secondStartMenuDeleteLoop
882 secondStartMenuDeleteLoopDone:
884 DeleteRegKey /ifempty SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
887 StrCmp $DO_NOT_ADD_TO_PATH_ "1" doNotRemoveFromPath 0
888 Call un.RemoveFromPath
892 ;--------------------------------
893 ; determine admin versus local install
894 ; Is install for "AllUsers" or "JustMe"?
895 ; Default to "JustMe" - set to "AllUsers" if admin or on Win9x
896 ; This function is used for the very first "custom page" of the installer.
897 ; This custom page does not show up visibly, but it executes prior to the
898 ; first visible page and sets up $INSTDIR properly...
899 ; Choose different default installation folder based on SV_ALLUSERS...
900 ; "Program Files" for AllUsers, "My Documents" for JustMe...
903 StrCmp "@CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL@" "ON" 0 inst
905 ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "UninstallString"
908 MessageBox MB_YESNOCANCEL|MB_ICONEXCLAMATION \
909 "@CPACK_NSIS_PACKAGE_NAME@ is already installed. $\n$\nDo you want to uninstall the old version before installing the new one?" \
910 IDYES uninst IDNO inst
916 ExecWait '$0 _?=$INSTDIR' ;Do not copy the uninstaller to a temp file
918 IfErrors uninst_failed inst
920 MessageBox MB_OK|MB_ICONSTOP "Uninstall failed."
925 ; Reads components status for registry
926 !insertmacro SectionList "InitSection"
928 ; check to see if /D has been used to change
929 ; the install directory by comparing it to the
930 ; install directory that is expected to be the
932 StrCpy $IS_DEFAULT_INSTALLDIR 0
933 StrCmp "$INSTDIR" "@CPACK_NSIS_INSTALL_ROOT@\@CPACK_PACKAGE_INSTALL_DIRECTORY@" 0 +2
934 StrCpy $IS_DEFAULT_INSTALLDIR 1
936 StrCpy $SV_ALLUSERS "JustMe"
937 ; if default install dir then change the default
938 ; if it is installed for JustMe
939 StrCmp "$IS_DEFAULT_INSTALLDIR" "1" 0 +2
940 StrCpy $INSTDIR "$DOCUMENTS\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
946 UserInfo::GetAccountType
948 StrCmp $1 "Admin" 0 +4
949 SetShellVarContext all
950 ;MessageBox MB_OK 'User "$0" is in the Admin group'
951 StrCpy $SV_ALLUSERS "AllUsers"
953 StrCmp $1 "Power" 0 +4
954 SetShellVarContext all
955 ;MessageBox MB_OK 'User "$0" is in the Power Users group'
956 StrCpy $SV_ALLUSERS "AllUsers"
960 StrCpy $SV_ALLUSERS "AllUsers"
961 ;Get installation folder from registry if available
964 StrCmp $SV_ALLUSERS "AllUsers" 0 +3
965 StrCmp "$IS_DEFAULT_INSTALLDIR" "1" 0 +2
966 StrCpy $INSTDIR "@CPACK_NSIS_INSTALL_ROOT@\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
968 StrCmp "@CPACK_NSIS_MODIFY_PATH@" "ON" 0 noOptionsPage
969 !insertmacro MUI_INSTALLOPTIONS_EXTRACT "NSIS.InstallOptions.ini"