diff --git a/.gitignore b/.gitignore index 9eec94c..a4ce7f0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ build *.rdbg *.pdb *.ps1 +*.exe Makefile Makefile.Debug Makefile.Release \ No newline at end of file diff --git a/install/installer.nsi b/install/installer.nsi new file mode 100644 index 0000000..b2e29eb --- /dev/null +++ b/install/installer.nsi @@ -0,0 +1,210 @@ +;Auto versioning------------------------------- + +!makensis "version.nsi" +!system "GetVersion.exe" +!include "Version.txt" +; optional cleanup +!delfile "GetVersion.exe" +!delfile "Version.txt" + +;Defines--------------- +;!define MULTIUSER_EXECUTIONLEVEL Highest + + +;Includes-------------------------------- + + !include "MUI2.nsh" + !include "nsDialogs.nsh" + !include "LogicLib.nsh" + ;!include "MultiUser.nsh" + +;-------------------------------- +;General + + ;Name and file + Name "MixerQ" + OutFile "mixerq-installer-${version}.exe" + Unicode True + + ;Default installation folder + ;InstallDir "$LOCALAPPDATA\Modern UI Test" + + ;Get installation folder from registry if available + ;InstallDirRegKey HKCU "Software\Modern UI Test" "" + + 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 + + !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 user + UserInfo::GetAccountType + Pop $0 + ${If} $0 == "Admin" + ; If we're an admin, default to installing to C:\Program Files + ;SetShellVarContext all + ;StrCpy $INSTDIR_BASE "$PROGRAMFILES64" + StrCpy $Is_Admin "true" + StrCpy $Install_Type "machine" + ${Else} + ; If we're just a user, default to installing to ~\AppData\Local + ;SetShellVarContext current + ;StrCpy $INSTDIR_BASE "$LOCALAPPDATA" + StrCpy $Is_Admin "false" + StrCpy $Install_Type "user" + ${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" + +;-------------------------------- +;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 + !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" + +;NSDialog InstallTarget Page definition--------------------------------- + +Function InstallTargetPage + !insertmacro MUI_HEADER_TEXT "Configure Install" "Customize install settings" + + nsDialogs::Create 1018 + Pop $0 + + ${NSD_CreateLabel} 0 0 100% 10% "Select for whom will $(^Name) be installed: " + Pop $3 + + ${NSD_CreateFirstRadioButton} 0 12% 40% 6% "All users" + 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% "Current 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 + StrCpy $INSTDIR "$PROGRAMFILES64\$(^Name)" + StrCpy $Install_Type "machine" + ;${NSD_SetText} $0 "machine" +FunctionEnd + +Function Current_User_Click + Pop $0 + StrCpy $INSTDIR "$LOCALAPPDATA\$(^Name)" + StrCpy $Install_Type "user" + ;${NSD_SetText} $0 "user" +FunctionEnd + +;Default section---------------------- +Section + SetRegView 64 + SetOutPath $INSTDIR + + ;File "..\build\debug\qtest.exe" + File "..\LICENSE.txt" + + ;Store installation folder + + ${If} $Install_Type == "user" + WriteRegStr HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" "DisplayName" "$(^Name)" + WriteRegStr HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" "UninstallString" '"$INSTDIR\Uninstall.exe"' + WriteRegDWORD HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" "NoModify" 1 + WriteRegDWORD HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" "NoRepair" 1 + WriteRegStr HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Run" "$(^Name)" "$INSTDIR\$(^Name)" + ${Else} + WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" "DisplayName" "$(^Name)" + WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" "UninstallString" '"$INSTDIR\Uninstall.exe"' + WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" "NoModify" 1 + WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" "NoRepair" 1 + WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Run" "$(^Name)" "$INSTDIR\$(^Name)" + ${EndIf} + + ;Create uninstaller + WriteUninstaller "$INSTDIR\Uninstall.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 + ;ADD YOUR OWN FILES HERE... + Delete "$INSTDIR\qtest.exe" + Delete "$INSTDIR\LICENSE.txt" + Delete "$INSTDIR\Uninstall.exe" +;!define PRODUCT_UNINST_ROOT_KEY "HKLM" + RMDir "$INSTDIR" + + ${If} $Install_Type == "user" + DeleteRegValue HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Run" "$(^Name)" + DeleteRegKey HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" + ${Else} + DeleteRegValue HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Run" "$(^Name)" + DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" + ${EndIf} + +SectionEnd diff --git a/install/version.nsi b/install/version.nsi new file mode 100644 index 0000000..6f5ac83 --- /dev/null +++ b/install/version.nsi @@ -0,0 +1,22 @@ +!define File "..\build\debug\qtest.exe" + +OutFile "GetVersion.exe" +SilentInstall silent +RequestExecutionLevel user ; don't write $EXEDIR\Version.txt with admin permissions and prevent invoking UAC + +Section + + ## Get file version + GetDllVersion "${File}" $R0 $R1 + IntOp $R2 $R0 / 0x00010000 + IntOp $R3 $R0 & 0x0000FFFF + IntOp $R4 $R1 / 0x00010000 + IntOp $R5 $R1 & 0x0000FFFF + StrCpy $R1 "$R2.$R3.$R4.$R5" + + ## Write it to a !define for use in main script + FileOpen $R0 "$EXEDIR\Version.txt" w + FileWrite $R0 '!define version "$R1"' + FileClose $R0 + +SectionEnd \ No newline at end of file