Merge pull request #844 from McGiverGim/bf-windows_rights

Win installer with/without admin rights
10.3.x-maintenance
Michael Keller 2018-01-13 16:30:11 +13:00 committed by GitHub
commit 8c9ca07b3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 61 additions and 16 deletions

View File

@ -26,16 +26,12 @@ BrandingText "${COMPANY_NAME}"
!define MUI_ICON ".\bf_installer_icon.ico"
!define MUI_UNICON ".\bf_uninstaller_icon.ico"
# Request rights user level
RequestExecutionLevel highest
# define the resulting installer's name:
OutFile "..\..\${DEST_FOLDER}\${FILE_NAME_INSTALLER}"
# set the default installation directory
!if ${PLATFORM} == 'win64'
InstallDir "$PROGRAMFILES64\${GROUP_NAME}\${FOLDER_NAME}\"
!else
InstallDir "$PROGRAMFILES\${GROUP_NAME}\${FOLDER_NAME}\"
!endif
# app dialogs
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE ${LICENSE}
@ -52,19 +48,62 @@ OutFile "..\..\${DEST_FOLDER}\${FILE_NAME_INSTALLER}"
!insertmacro MUI_LANGUAGE "Korean"
!insertmacro MUI_LANGUAGE "Spanish"
# default install dir, readed from registry from latest installation
InstallDirRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" "InstallLocation"
Function .onInit
# default section start
Section
# remove the older version
# Check if older version
ReadRegStr $R0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" \
"InstallLocation"
${If} $R0 != ""
StrCpy $INSTDIR $R0
${Else}
# Check if older version without administrative rights
ReadRegStr $R1 HKCU "Software\${GROUP_NAME}\${APP_NAME}" \
"InstallLocation"
${If} $R1 != ""
StrCpy $INSTDIR $R1
${Else}
# New version, select default folder
UserInfo::GetAccountType
Pop $R2
${If} $R2 == "Admin"
# set the default installation directory
!if ${PLATFORM} == 'win64'
StrCpy $INSTDIR "$PROGRAMFILES64\${GROUP_NAME}\${FOLDER_NAME}\"
!else
StrCpy $INSTDIR "$PROGRAMFILES\${GROUP_NAME}\${FOLDER_NAME}\"
!endif
${Else}
StrCpy $INSTDIR "$DOCUMENTS\${GROUP_NAME}\${FOLDER_NAME}\"
${Endif}
${Endif}
${Endif}
FunctionEnd
# default section start
Section
# remove the older version, users with admin rights
ReadRegStr $R3 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" \
"InstallLocation"
${If} $R3 != ""
# delete the installed files of the older version
RMDir /r $R0
RMDir /r $R3
${Else}
# remove the older version, users without admin rights
ReadRegStr $R4 HKCU "Software\${GROUP_NAME}\${APP_NAME}" \
"InstallLocation"
${If} $R4 != ""
# delete the installed files of the older version
RMDir /r $R4
${EndIf}
${EndIf}
# define the path to which the installer should install
@ -97,6 +136,10 @@ Section
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" \
"DisplayVersion" "${VERSION}"
# include for users without admin rights
WriteRegStr HKCU "Software\${GROUP_NAME}\${APP_NAME}" \
"InstallLocation" "$INSTDIR"
# estimate the size
${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
IntFmt $0 "0x%08X" $0
@ -122,5 +165,7 @@ Section "Uninstall"
# remove from add/remove programs
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}"
DeleteRegKey HKCU "Software\${GROUP_NAME}\${APP_NAME}"
DeleteRegKey /ifempty HKCU "Software\${GROUP_NAME}"
SectionEnd