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

feat: add custom macro for checking uninstallation results #5712

Merged
merged 1 commit into from
Apr 5, 2021

Conversation

dlon
Copy link
Contributor

@dlon dlon commented Mar 15, 2021

Due to #5292, installers created using the default NSIS script ignore any errors returned by uninstallers, for example if files cannot be replaced, or if the uninstaller has been deleted. This behavior is often unwanted.

The changes here allow users to define customUnInstallCheck to handle such cases. In customUnInstallCheck, the error flag is set if the uninstaller cannot be executed at all (probably because it is missing). If the error flag is not set, $R0 contains the return status/error level, which should be set to 0 if the uninstaller exits successfully.

@mmaietta
Copy link
Collaborator

Thanks for the PR @dlon! The changes seeem good to me. What's the best way for me to test this locally?

@dlon
Copy link
Contributor Author

dlon commented Mar 16, 2021

Create an installer using something like this config:

nsis: {
    oneClick: false,
    perMachine: true,
    allowToChangeInstallationDirectory: false,
    include: 'install.nsh',
}

In install.nsh, add:

!macro customUnInstallCheck

  IfErrors 0 customUnInstallCheck_CheckCode

  MessageBox MB_OK "Uninstaller failed to run"
  SetErrorLevel 5
  Abort

  customUnInstallCheck_CheckCode:

  ${If} $R0 != 0
    MessageBox MB_OK "Uninstaller returned an error"
    SetErrorLevel 4
    Abort
  ${EndIf}

!macroend

To test the non-failing case, just run the installer twice (so that it will uninstall before re-installing). To test the case where the uninstaller fails to run, you can run the installer and delete the uninstaller executable before running the installer again. To test the return code check, add the following to install.nsh before running the installer twice:

!macro customRemoveFiles

  SetErrorLevel 5
  Abort

!macroend

@mmaietta
Copy link
Collaborator

@develar the changes LGTM atm and I'll run an example test later once I can get my Win env set up. Any thoughts/concerns from your side?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants