Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup NSIS to support non-admin users #538

Merged
merged 3 commits into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions cmake/CPackConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,6 @@ if(WIN32 OR MSYS OR MINGW)
set(CPACK_COMPONENT_TOOL_MANUAL_DISPLAY_NAME "Server Manual Tool")
set(CPACK_COMPONENT_TRANSLATIONS_DISPLAY_NAME "Languages")

# Give the components a long description
set(CPACK_COMPONENT_FREECIV21_DESCRIPTION "All programs and supporting files to run Freeciv21. Includes Qt Client, Server and Qt Modpack Installer.")
set(CPACK_COMPONENT_TOOL_RULEDIT_DESCRIPTION "Freeciv21 Ruleset Editor")
set(CPACK_COMPONENT_TOOL_FCMP_CLI_DESCRIPTION "Modpack Installer Command Line Interpreter Edition")
set(CPACK_COMPONENT_TOOL_RULEUP_DESCRIPTION "Freeciv21 Ruleset Upgrade Tool")
set(CPACK_COMPONENT_TOOL_MANUAL_DESCRIPTION "Freeciv21 Server Manual Tool")
set(CPACK_COMPONENT_TRANSLATIONS_DESCRIPTION "Supported Languages")

## Generator-specific configuration ##

# NSIS (Windows .exe installer)
Expand All @@ -90,7 +82,6 @@ if(WIN32 OR MSYS OR MINGW)
set(CPACK_NSIS_COMPRESSOR "/SOLID lzma") # zlib|bzip2|lzma
set(CPACK_NSIS_COMPRESSOR "${CPACK_NSIS_COMPRESSOR}\n SetCompressorDictSize 64") # hack (improve compression)
set(CPACK_NSIS_COMPRESSOR "${CPACK_NSIS_COMPRESSOR}\n BrandingText '${CPACK_PACKAGE_DESCRIPTION_SUMMARY}'") # hack (overwrite BrandingText)
set(CPACK_NSIS_COMPRESSOR "${CPACK_NSIS_COMPRESSOR}\n !define MUI_COMPONENTSPAGE_SMALLDESC") # hack (better components page layout)

endif()

Expand Down
93 changes: 49 additions & 44 deletions cmake/NSIS.template.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,11 @@
Unicode true
SetCompressor @CPACK_NSIS_COMPRESSOR@

;#########################################################
; Includes
;#########################################################

!include "MUI2.nsh"
!include "LogicLib.nsh"
!include "Integration.nsh"
!include "Sections.nsh"
!include "Library.nsh"
!include "x64.nsh"

;#########################################################
; Defines
;#########################################################

;Generic Variables
!define APPNAME "@CPACK_PACKAGE_NAME@"
!define VERSION "@CPACK_PACKAGE_VERSION@"
!define PATCH "@CPACK_PACKAGE_VERSION_PATCH@"
Expand All @@ -38,6 +28,28 @@
!define REGPATH_UNINSTSUBKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPID}"
!define MUI_ICON "@CPACK_NSIS_MUI_ICON@"
!define MUI_UNICON "@CPACK_NSIS_MUI_UNIICON@"
!define MUI_UI_COMPONENTSPAGE_SMALLDESC
!define MUI_LICENSEPAGE_CHECKBOX
!define MUI_LICENSEPAGE_CHECKBOX_TEXT "I agree to the license terms."

;Multi-User Variables
!define MULTIUSER_EXECUTIONLEVEL Highest
!define MULTIUSER_MUI
!define MULTIUSER_INSTALLMODE_COMMANDLINE
!define MULTIUSER_INSTALLMODEPAGE_TEXT_TOP "Select the type of installation you want to perform:"
!define MULTIUSER_INSTALLMODE_INSTDIR "${APPNAME}-${VERSION}"

;#########################################################
; Includes
;#########################################################

!include "MUI2.nsh"
!include "MultiUser.nsh"
!include "LogicLib.nsh"
!include "Integration.nsh"
!include "Sections.nsh"
!include "Library.nsh"
!include "x64.nsh"

;#########################################################
; General
Expand All @@ -48,10 +60,6 @@
ShowInstDetails show
ShowUninstDetails show
SetOverwrite on
RequestExecutionLevel Admin ; Request admin rights on WinVista+ (when UAC is turned on)

;Default installation folder
InstallDir "@CPACK_NSIS_INSTALL_ROOT@\${APPNAME}-${VERSION}"

;#########################################################
; Interface Settings
Expand Down Expand Up @@ -79,34 +87,34 @@

Section "Freeciv21" freeciv21
SectionIn RO 1 2
SetOutPath "$INSTDIR"
SetOutPath $INSTDIR
lmoureaux marked this conversation as resolved.
Show resolved Hide resolved
File /r "${INST_DIR}\freeciv21\*.*"
SectionEnd
SectionGroup "Tools" Tools
Section "Ruleset Editor" tool_ruledit
SectionIn 2
SetOutPath "$INSTDIR"
SetOutPath $INSTDIR
File /r "${INST_DIR}\tool_ruledit\*.*"
SectionEnd
Section "Modpack Installer CLI Edition" tool_fcmp_cli
SectionIn 2
SetOutPath "$INSTDIR"
SetOutPath $INSTDIR
File /r "${INST_DIR}\tool_fcmp_cli\*.*"
SectionEnd
Section "Ruleset Upgrade Tool" tool_ruleup
SectionIn 2
SetOutPath "$INSTDIR"
SetOutPath $INSTDIR
File /r "${INST_DIR}\tool_ruleup\*.*"
SectionEnd
Section "Server Manual Tool" tool_manual
SectionIn 2
SetOutPath "$INSTDIR"
SetOutPath $INSTDIR
File /r "${INST_DIR}\tool_manual\*.*"
SectionEnd
SectionGroupEnd
Section "Languages" translations
SectionIn 1 2
SetOutPath "$INSTDIR"
SetOutPath $INSTDIR
File /r "${INST_DIR}\translations\*.*"
SectionEnd

Expand All @@ -127,8 +135,9 @@
; Installer Pages
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "@CPACK_RESOURCE_FILE_LICENSE@"
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MULTIUSER_PAGE_INSTALLMODE
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
; TODO: add a run feature
!insertmacro MUI_PAGE_FINISH
Expand All @@ -149,35 +158,34 @@
; Macros
;#########################################################

!macro EnsureAdminRights
!macro CheckAdminRights
UserInfo::GetAccountType
Pop $0
${If} $0 != "admin" ; Require admin rights on WinNT4+
MessageBox MB_IconStop "Administrator rights required!"
SetErrorLevel 740 ; ERROR_ELEVATION_REQUIRED
Quit
${If} $0 != "admin" ; Check for admin rights on WinNT4+
MessageBox MB_IconInformation "Administrator rights not detected, installing in User's Home Directory by default."
${EndIf}
!macroend

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace 💮

;#########################################################
; Funtions
;#########################################################

Function .onInit
SetShellVarContext All
!insertmacro EnsureAdminRights
!insertmacro MULTIUSER_INIT
;!insertmacro CheckAdminRights
FunctionEnd

Function un.onInit
SetShellVarContext All
!insertmacro EnsureAdminRights
!insertmacro MULTIUSER_UNINIT
FunctionEnd

Function ConditionalAddToRegisty
Pop $0
Pop $1
StrCmp "$0" "" ConditionalAddToRegisty_EmptyString
WriteRegStr HKLM "${REGPATH_UNINSTSUBKEY}" "$1" "$0"
WriteRegStr "SHCTX" "${REGPATH_UNINSTSUBKEY}" "$1" "$0"
ConditionalAddToRegisty_EmptyString:
FunctionEnd

Expand All @@ -190,21 +198,20 @@
SetOutPath "$INSTDIR"

; Store installation folder.
WriteRegStr HKLM "Software\${APPID}" "Install Directory" $INSTDIR
WriteRegStr "SHCTX" "SOFTWARE\${APPNAME}\${VERSION}\${CPU_ARCH}" "" "$INSTDIR"

; Create uninstaller.
WriteUninstaller "$INSTDIR\Uninstall.exe"


; Create Desktop Icon
CreateShortCut "$DESKTOP\${APPNAME} Client.lnk" "$INSTDIR\freeciv21-client.exe" '"${Arg}"' "$INSTDIR\client.ico" 0
CreateShortCut "$DESKTOP\${APPNAME} Client.lnk" "$INSTDIR\freeciv21-client.exe" "" "$INSTDIR\client.ico" 0

; Create Start Menu Entries
CreateDirectory "$SMPROGRAMS\${APPNAME} v${VERSION}"
CreateShortCut "$SMPROGRAMS\${APPNAME} v${VERSION}\${APPNAME} Client.lnk" "$INSTDIR\freeciv21-client.exe" '"${Arg}"' "$INSTDIR\client.ico" 0
CreateShortCut "$SMPROGRAMS\${APPNAME} v${VERSION}\${APPNAME} Modpack Installer.lnk" "$INSTDIR\freeciv21-modpack-qt.exe" '"${Arg}"' "$INSTDIR\mp.ico" 0
CreateShortCut "$SMPROGRAMS\${APPNAME} v${VERSION}\Uninstall ${APPNAME}.lnk" "$INSTDIR\Uninstall.exe"


CreateShortCut "$SMPROGRAMS\${APPNAME} v${VERSION}\${APPNAME} Client.lnk" "$INSTDIR\freeciv21-client.exe" "" "$INSTDIR\client.ico" 0
CreateShortCut "$SMPROGRAMS\${APPNAME} v${VERSION}\${APPNAME} Modpack Installer.lnk" "$INSTDIR\freeciv21-modpack-qt.exe" "" "$INSTDIR\mp.ico" 0

; Create entry in Windows "Add/Remove programs" panel.
Push "DisplayName"
Push "${APPNAME} v${VERSION}"
Expand Down Expand Up @@ -254,18 +261,16 @@

; Remove shortcuts
Delete "$DESKTOP\${APPNAME} Client.lnk"
Delete "$SMPROGRAMS\${APPNAME} v${VERSION}\${APPNAME} Client.lnk"
Delete "$SMPROGRAMS\${APPNAME} v${VERSION}\${APPNAME} Modpack Installer.lnk"
Delete "$SMPROGRAMS\${APPNAME} v${VERSION}\Uninstall ${APPNAME}.lnk"
RMDir "$SMPROGRAMS\${APPNAME} v${VERSION]"
Delete "$SMPROGRAMS\${APPNAME} v${VERSION}\*.*"
RMDir "$SMPROGRAMS\${APPNAME} v${VERSION}"

; Remove rest of installed files.
; Custom files are left intact.
RMDir "$INSTDIR"

; Remove entry from Windows "Add/Remove programs" panel.
DeleteRegKey HKLM "${REGPATH_UNINSTSUBKEY}"
DeleteRegKey HKLM "Software\${APPID}"
DeleteRegKey "SHCTX" "${REGPATH_UNINSTSUBKEY}"
DeleteRegKey "SHCTX" "Software\${APPID}"

SectionEnd

Expand Down