Skip to content

Commit

Permalink
feat: add custom macro for checking uninstallation results (#5712)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlon authored Apr 5, 2021
1 parent 0dbc956 commit e425020
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
44 changes: 36 additions & 8 deletions packages/app-builder-lib/templates/nsis/include/installUtil.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,36 @@ Var /GLOBAL isTryToKeepShortcuts
${endif}
!macroend

Function handleUninstallResult
Var /GLOBAL rootKey_uninstallResult
Exch $rootKey_uninstallResult

${if} "$rootKey_uninstallResult" == "SHELL_CONTEXT"
!ifmacrodef customUnInstallCheck
!insertmacro customUnInstallCheck
Return
!endif
${elseif} "$rootKey_uninstallResult" == "HKEY_CURRENT_USER"
!ifmacrodef customUnInstallCheckCurrentUser
!insertmacro customUnInstallCheckCurrentUser
Return
!endif
${endif}

IfErrors 0 +3
DetailPrint `Uninstall was not successful. Not able to launch uninstaller!`
Return

${if} $R0 != 0
DetailPrint `Uninstall was not successful. Uninstaller error code: $R0.`
${endif}
FunctionEnd

!macro handleUninstallResult ROOT_KEY
Push "${ROOT_KEY}"
Call handleUninstallResult
!macroend

# http://stackoverflow.com/questions/24595887/waiting-for-nsis-uninstaller-to-finish-in-nsis-installer-either-fails-or-the-uni
Function uninstallOldVersion
Var /GLOBAL uninstallerFileName
Expand All @@ -116,12 +146,16 @@ Function uninstallOldVersion
ClearErrors
Exch $rootKey

Push 0
Pop $R0

!insertmacro readReg $uninstallString "$rootKey" "${UNINSTALL_REGISTRY_KEY}" UninstallString
${if} $uninstallString == ""
!ifdef UNINSTALL_REGISTRY_KEY_2
!insertmacro readReg $uninstallString "$rootKey" "${UNINSTALL_REGISTRY_KEY_2}" UninstallString
!endif
${if} $uninstallString == ""
ClearErrors
Goto Done
${endif}
${endif}
Expand All @@ -140,6 +174,7 @@ Function uninstallOldVersion

${if} $installationDir == ""
${andIf} $uninstallerFileName == ""
ClearErrors
Goto Done
${endif}

Expand Down Expand Up @@ -172,17 +207,10 @@ Function uninstallOldVersion
!insertmacro copyFile "$uninstallerFileName" "$uninstallerFileNameTemp"

ExecWait '"$uninstallerFileNameTemp" /S /KEEP_APP_DATA $0 _?=$installationDir' $R0
ifErrors 0 ExecErrorHandler
ifErrors 0 Done
# the execution failed - might have been caused by some group policy restrictions
# we try to execute the uninstaller in place
ExecWait '"$uninstallerFileName" /S /KEEP_APP_DATA $0 _?=$installationDir' $R0
ifErrors 0 ExecErrorHandler
# this also failed...
DetailPrint `Aborting, uninstall was not successful. Not able to launch uninstaller!`
ExecErrorHandler:
${if} $R0 != 0
DetailPrint `Aborting, uninstall was not successful. Uninstaller error code: $R0.`
${endif}
Done:
FunctionEnd

Expand Down
3 changes: 3 additions & 0 deletions packages/app-builder-lib/templates/nsis/installSection.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ ${if} $isTryToKeepShortcuts == "true"
${endif}

!insertmacro uninstallOldVersion SHELL_CONTEXT
!insertmacro handleUninstallResult SHELL_CONTEXT

${if} $installMode == "all"
!insertmacro uninstallOldVersion HKEY_CURRENT_USER
!insertmacro handleUninstallResult HKEY_CURRENT_USER
${endIf}

SetOutPath $INSTDIR
Expand Down

0 comments on commit e425020

Please sign in to comment.