Implement non elevated installer (#2497)

* changed install location and elevation

* change registry keys to HKCU
change context to current user

* filetype associations non elevated

* added an "upgrade" from elevated to non elevated

* added comment to clarify bug

* removed commented out registry entries

* Update CONTRIBUTORS

add mgrottenthaler to contributors

* change upgrade routine to manual uninstall

* added suggestion
This commit is contained in:
Martin Grottenthaler 2023-05-18 09:06:38 +02:00 committed by GitHub
parent 2fa63af9c2
commit f4f5844ca3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 18 deletions

View file

@ -120,6 +120,7 @@ Ben Kerman <ben@kermanic.org>
Euan Kemp <euank@euank.com> Euan Kemp <euank@euank.com>
Kieran Black <kieranlblack@gmail.com> Kieran Black <kieranlblack@gmail.com>
XeR <github.com/XeR> XeR <github.com/XeR>
mgrottenthaler <github.com/mgrottenthaler>
Austin Siew <github.com/Aquafina-water-bottle> Austin Siew <github.com/Aquafina-water-bottle>
******************** ********************

View file

@ -20,11 +20,14 @@ Unicode true
; The file to write (make relative to repo root instead of out/bundle) ; The file to write (make relative to repo root instead of out/bundle)
OutFile "..\..\@@INSTALLER@@" OutFile "..\..\@@INSTALLER@@"
; Non elevated
RequestExecutionLevel user
; The default installation directory ; The default installation directory
InstallDir "$PROGRAMFILES64\Anki" InstallDir "$LOCALAPPDATA\Programs\Anki"
; Remember the install location ; Remember the install location
InstallDirRegKey HKLM "Software\Anki" "Install_Dir64" InstallDirRegKey HKCU "Software\Anki" "Install_Dir64"
AllowSkipFiles off AllowSkipFiles off
@ -127,10 +130,43 @@ FunctionEnd
;-------------------------------- ;--------------------------------
; Macro from fileassoc changed to work non elevated
!macro APP_ASSOCIATE_HKCU EXT FILECLASS DESCRIPTION ICON COMMANDTEXT COMMAND
; Backup the previously associated file class
ReadRegStr $R0 HKCU "Software\Classes\.${EXT}" ""
WriteRegStr HKCU "Software\Classes\.${EXT}" "${FILECLASS}_backup" "$R0"
WriteRegStr HKCU "Software\Classes\.${EXT}" "" "${FILECLASS}"
WriteRegStr HKCU "Software\Classes\${FILECLASS}" "" `${DESCRIPTION}`
WriteRegStr HKCU "Software\Classes\${FILECLASS}\DefaultIcon" "" `${ICON}`
WriteRegStr HKCU "Software\Classes\${FILECLASS}\shell" "" "open"
WriteRegStr HKCU "Software\Classes\${FILECLASS}\shell\open" "" `${COMMANDTEXT}`
WriteRegStr HKCU "Software\Classes\${FILECLASS}\shell\open\command" "" `${COMMAND}`
!macroend
; Macro from fileassoc changed to work non elevated
!macro APP_UNASSOCIATE_HKCU EXT FILECLASS
; Backup the previously associated file class
ReadRegStr $R0 HKCU "Software\Classes\.${EXT}" `${FILECLASS}_backup`
WriteRegStr HKCU "Software\Classes\.${EXT}" "" "$R0"
DeleteRegKey HKCU `Software\Classes\${FILECLASS}`
!macroend
; The stuff to install ; The stuff to install
Section "" Section ""
SetShellVarContext all SetShellVarContext current
; "Upgrade" from elevated anki
ReadRegStr $0 HKLM "Software\WOW6432Node\Anki" "Install_Dir64"
${IF} $0 != ""
; old value exists, we want to inform the user that a manual uninstall is required first and then start the uninstall.exe
MessageBox MB_ICONEXCLAMATION|MB_OK "A previous Anki version needs to be uninstalled first. After uninstallation completes, please run this installer again."
ExecShell "open" "$0\uninstall.exe"
Quit
${ENDIF}
Call removeManifestFiles Call removeManifestFiles
@ -144,29 +180,30 @@ Section ""
File /r ..\..\@@SRC@@\*.* File /r ..\..\@@SRC@@\*.*
!endif !endif
!insertmacro APP_ASSOCIATE "apkg" "anki.apkg" \ !insertmacro APP_ASSOCIATE_HKCU "apkg" "anki.apkg" \
"Anki deck package" "$INSTDIR\anki.exe,0" \ "Anki deck package" "$INSTDIR\anki.exe,0" \
"Open with Anki" "$INSTDIR\anki.exe $\"%L$\"" "Open with Anki" "$INSTDIR\anki.exe $\"%L$\""
!insertmacro APP_ASSOCIATE "colpkg" "anki.colpkg" \ !insertmacro APP_ASSOCIATE_HKCU "colpkg" "anki.colpkg" \
"Anki collection package" "$INSTDIR\anki.exe,0" \ "Anki collection package" "$INSTDIR\anki.exe,0" \
"Open with Anki" "$INSTDIR\anki.exe $\"%L$\"" "Open with Anki" "$INSTDIR\anki.exe $\"%L$\""
!insertmacro APP_ASSOCIATE "ankiaddon" "anki.ankiaddon" \ !insertmacro APP_ASSOCIATE_HKCU "ankiaddon" "anki.ankiaddon" \
"Anki add-on" "$INSTDIR\anki.exe,0" \ "Anki add-on" "$INSTDIR\anki.exe,0" \
"Open with Anki" "$INSTDIR\anki.exe $\"%L$\"" "Open with Anki" "$INSTDIR\anki.exe $\"%L$\""
!insertmacro UPDATEFILEASSOC !insertmacro UPDATEFILEASSOC
; Write the installation path into the registry ; Write the installation path into the registry
WriteRegStr HKLM Software\Anki "Install_Dir64" "$INSTDIR" ; WriteRegStr HKLM Software\Anki "Install_Dir64" "$INSTDIR"
WriteRegStr HKCU Software\Anki "Install_Dir64" "$INSTDIR"
; Write the uninstall keys for Windows ; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Anki" "DisplayName" "Anki" WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Anki" "DisplayName" "Anki"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Anki" "DisplayVersion" "@@VERSION@@" WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Anki" "DisplayVersion" "@@VERSION@@"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Anki" "UninstallString" '"$INSTDIR\uninstall.exe"' WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Anki" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Anki" "NoModify" 1 WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Anki" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Anki" "NoRepair" 1 WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Anki" "NoRepair" 1
!ifdef WRITE_UNINSTALLER !ifdef WRITE_UNINSTALLER
WriteUninstaller "uninstall.exe" WriteUninstaller "uninstall.exe"
@ -186,7 +223,7 @@ functionEnd
Section "Uninstall" Section "Uninstall"
SetShellVarContext all SetShellVarContext current
Call un.removeManifestFiles Call un.removeManifestFiles
@ -195,16 +232,16 @@ Section "Uninstall"
Delete "$SMPROGRAMS\Anki.lnk" Delete "$SMPROGRAMS\Anki.lnk"
; associations ; associations
!insertmacro APP_UNASSOCIATE "apkg" "anki.apkg" !insertmacro APP_UNASSOCIATE_HKCU "apkg" "anki.apkg"
!insertmacro APP_UNASSOCIATE "colpkg" "anki.colpkg" !insertmacro APP_UNASSOCIATE_HKCU "colpkg" "anki.colpkg"
!insertmacro APP_UNASSOCIATE "ankiaddon" "anki.ankiaddon" !insertmacro APP_UNASSOCIATE_HKCU "ankiaddon" "anki.ankiaddon"
!insertmacro UPDATEFILEASSOC !insertmacro UPDATEFILEASSOC
; try to remove top level folder if empty ; try to remove top level folder if empty
RMDir "$INSTDIR" RMDir "$INSTDIR"
; Remove registry keys ; Remove registry keys
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Anki" DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Anki"
DeleteRegKey HKLM Software\Anki DeleteRegKey HKCU Software\Anki
SectionEnd SectionEnd