mixer/install/installer.nsi

265 lines
8.6 KiB
NSIS
Raw Blame History

;Auto versioning-------------------------------
!makensis "/DBUILDTYPE=${BUILDTYPE} version.nsi"
!system "GetVersion.exe"
!include "Version.txt"
;optional cleanup
!delfile "GetVersion.exe"
!delfile "Version.txt"
;Includes--------------------------------
!include "MUI2.nsh"
!include "nsDialogs.nsh"
!include "LogicLib.nsh"
!include "${NSISDIR}\Contrib\Language files\English.nsh"
!include "${NSISDIR}\Contrib\Language files\Spanish.nsh"
;!include "${NSISDIR}\Contrib\Language files\English.nsh"
;Defines----------------------------------
!define MUI_LANGDLL_ALLLANGUAGES
!define MUI_UNICON "..\assets\uninstaller.ico"
!define MUI_ICON "..\assets\installer.ico"
;--------------------------------
;General
;Name and file
!if ${BUILDTYPE} == "release"
Name "MixerQ"
!else
Name "MixerQd"
!endif
OutFile "..\build\bin\MixerQ-installer-${version}.exe"
;Get installation folder from registry if available
;InstallDirRegKey HKCU "Software\Modern UI Test" ""
Unicode True
Var Is_Admin
Var Install_Type
;Request application privileges for UAC. If admin is not available, only user-level install will be available
RequestExecutionLevel highest
;--------------------------------
;Interface Settings
!define MUI_ABORTWARNING
;--------------------------------
;Pages
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "..\LICENSE.txt"
;!insertmacro MULTIUSER_PAGE_INSTALLMODE
Page Custom InstallTargetPage
;!insertmacro MUI_PAGE_COMPONENTS
!define MUI_PAGE_CUSTOMFUNCTION_PRE Skip_Directory_Func
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "Spanish"
!insertmacro MUI_LANGUAGE "SpanishInternational"
;English----------------------------
LangString Header_Title ${LANG_ENGLISH} "Configure Install"
LangString Header_Subtitle ${LANG_ENGLISH} "Customize install settings"
LangString Option_Scope ${LANG_ENGLISH} "Select for whom will $(^Name) be installed: "
LangString Scope_Machine ${LANG_ENGLISH} "All users"
LangString Scope_User ${LANG_ENGLISH} "Current user"
;Spanish/SpanishInternational----------------------------
LangString Header_Title ${LANG_SPANISH} "Configurar instalaci<63>n"
LangString Header_Subtitle ${LANG_SPANISH} "Elija los ajustes de la instalaci<63>n"
LangString Option_Scope ${LANG_SPANISH} "$(^Name) ser<65> instalado para: "
LangString Scope_Machine ${LANG_SPANISH} "Todos los usuarios"
LangString Scope_User ${LANG_SPANISH} "Usuario actual"
LangString Header_Title ${LANG_SPANISHINTERNATIONAL} "Configurar instalaci<63>n"
LangString Header_Subtitle ${LANG_SPANISHINTERNATIONAL} "Elija los ajustes de la instalaci<63>n"
LangString Option_Scope ${LANG_SPANISHINTERNATIONAL} "$(^Name) ser<65> instalado para: "
LangString Scope_Machine ${LANG_SPANISHINTERNATIONAL} "Todos los usuarios"
LangString Scope_User ${LANG_SPANISHINTERNATIONAL} "Usuario actual"
;Functions------------------------------
Function Skip_Directory_Func
;StrCmp $Install_Type "user" dontSkip
Abort # skip the page
;dontSkip:
FunctionEnd
!macro ONINIT un
Function ${un}.onInit
; The value of SetShellVarContext detetmines whether SHCTX is HKLM or HKCU
; and whether SMPROGRAMS refers to all users or just the current
!insertmacro MUI_LANGDLL_DISPLAY
UserInfo::GetAccountType
Pop $0
${If} $0 == "Admin"
; If we're an admin, default to installing to C:\Program Files
SetShellVarContext all
; StrCpy $INSTDIR "$PROGRAMFILES64\$(^Name)"
StrCpy $Is_Admin "true"
${Else}
; If we're just a user, default to installing to ~\AppData\Local
SetShellVarContext current
; StrCpy $INSTDIR "$LOCALAPPDATA\$(^Name)"
StrCpy $Is_Admin "false"
${EndIf}
; ${If} $INSTDIR == ""
; ; This only happens in the installer, because the uninstaller already knows INSTDIR
; ReadRegStr $0 SHCTX "Software\${PRODUCT_NAME}" ""
; ${If} $0 != ""
; ; If we're already installed, use the existing directory
; StrCpy $INSTDIR "$0"
; ${Else}
; StrCpy $INSTDIR "$INSTDIR_BASE\${PRODUCT_NAME}"
; ${Endif}
; ${Endif}
FunctionEnd
!macroend
!insertmacro ONINIT ""
!insertmacro ONINIT "un"
;NSDialog InstallTarget Page definition---------------------------------
Function InstallTargetPage
!insertmacro MUI_HEADER_TEXT $(Header_Title) $(Header_Subtitle)
;MessageBox MB_OK "Install type $Install_Type"
;MessageBox MB_OK "Build type ${BUILDTYPE}"
nsDialogs::Create 1018
Pop $0
FindWindow $0 "#32770"
GetDlgItem $1 $0 1 ;next/install button
SendMessage $1 ${WM_SETTEXT} 1 "STR:$(^InstallBtn)"
Pop $0
${NSD_CreateLabel} 0 0 100% 10% $(Option_Scope)
Pop $3
${NSD_CreateFirstRadioButton} 0 12% 40% 6% $(Scope_Machine)
Pop $1
${If} $Is_Admin == "false"
EnableWindow $1 0
StrCpy $INSTDIR "$LOCALAPPDATA\$(^Name)"
${Else}
SendMessage $1 ${BM_CLICK} "" "" ;Set default
StrCpy $INSTDIR "$PROGRAMFILES64\$(^Name)"
${EndIf}
${NSD_OnClick} $1 All_Users_Click
${NSD_CreateAdditionalRadioButton} 0 24% 40% 6% $(Scope_User)
Pop $2
${IfThen} $Is_Admin == "false" ${|} SendMessage $2 ${BM_CLICK} "" "" ${|}
${NSD_OnClick} $2 Current_User_Click
nsDialogs::Show
FunctionEnd
Function All_Users_Click
Pop $0
SetShellVarContext all
StrCpy $INSTDIR "$PROGRAMFILES64\$(^Name)"
StrCpy $Install_Type "machine"
;${NSD_SetText} $0 "machine"
;FindWindow $0 "#32770"
;GetDlgItem $1 $0 1 ;next/install button
;SendMessage $1 ${WM_SETTEXT} 1 "STR:$(^InstallBtn)"
FunctionEnd
Function Current_User_Click
Pop $0
SetShellVarContext current
StrCpy $INSTDIR "$LOCALAPPDATA\$(^Name)"
StrCpy $Install_Type "user"
;${NSD_SetText} $0 "user"
;FindWindow $0 "#32770"
;GetDlgItem $1 $0 1 ;next/install button
;SendMessage $1 ${WM_SETTEXT} 1 "STR:$(^NextBtn)"
FunctionEnd
;Default section----------------------
Section
SetRegView 64
SetOutPath $INSTDIR
!if ${BUILDTYPE} == "release"
File "..\build\bin\MixerQ.exe"
!else
File "..\build\bin\MixerQd.exe"
!endif
File "..\LICENSE.txt"
;Start menu shortcut
createDirectory "$SMPROGRAMS\$(^Name)"
createShortCut "$SMPROGRAMS\$(^Name)\$(^Name).lnk" "$INSTDIR\$(^Name).exe"
createShortCut "$SMPROGRAMS\$(^Name)\Uninstall$(^Name).lnk" "$INSTDIR\Uninstall$(^Name).exe"
;Store installation folder
WriteRegStr SHCTX "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" "DisplayName" "$(^Name)"
WriteRegStr SHCTX "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" "UninstallString" '"$INSTDIR\Uninstall$(^Name).exe"'
WriteRegDWORD SHCTX "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" "NoModify" 1
WriteRegDWORD SHCTX "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" "NoRepair" 1
WriteRegStr SHCTX "SOFTWARE\Microsoft\Windows\CurrentVersion\Run" "$(^Name)" "$INSTDIR\$(^Name)"
;Create uninstaller
WriteUninstaller "$INSTDIR\Uninstall$(^Name).exe"
SectionEnd
;--------------------------------
;Descriptions
; ;Language strings
; LangString DESC_SecDummy ${LANG_ENGLISH} "A test section."
; ;Assign language strings to sections
; !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
; !insertmacro MUI_DESCRIPTION_TEXT ${SecDummy} $(DESC_SecDummy)
; !insertmacro MUI_FUNCTION_DESCRIPTION_END
;--------------------------------
;Uninstaller Section
Section "Uninstall"
SetRegView 64
SetShellVarContext current
DeleteRegValue HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Run" "$(^Name)"
DeleteRegKey HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)"
Delete "$SMPROGRAMS\$(^Name)\$(^Name).lnk"
Delete "$SMPROGRAMS\$(^Name)\Uninstall$(^Name).lnk"
RMDir "$SMPROGRAMS\$(^Name)"
${If} $Is_Admin == "true"
SetShellVarContext all
DeleteRegValue HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Run" "$(^Name)"
DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)"
Delete "$SMPROGRAMS\$(^Name)\$(^Name).lnk"
Delete "$SMPROGRAMS\$(^Name)\Uninstall$(^Name).lnk"
RMDir "$SMPROGRAMS\$(^Name)"
${EndIf}
Delete "$INSTDIR\$(^Name).exe"
Delete "$INSTDIR\LICENSE.txt"
Delete "$INSTDIR\Uninstall$(^Name).exe"
;!define PRODUCT_UNINST_ROOT_KEY "HKLM"
RMDir "$INSTDIR"
SectionEnd