Search code examples
installationnsis

Stop Advance to Next Page if conditions are not met


How do I stop a NSIS Custom Page from advancing to the next page?

I have a custom page where the user can decide which version of an application they can install our plugins for - thus theres 3 checkboxes to select.

The user must pick atleast 1 version to install our plugins to/for, otherwise the installer will have nothing to install.

So when the user clicks next I need to check whether 1 or more checkboxes are checked, if not then I disable going next and display a MessageBox.

If I cant stop the advance to the next page, can I disable the next button?

Page Custom CustomPageInitialise CustomPageFinalise
Function CustomPageFinalise
    Var /GLOBAL versToInstall
    ${NSD_GetState} $hasVersion8ChkBx  $0
    ${NSD_GetState} $hasVersion9ChkBx  $1
    ${NSD_GetState} $hasVersion10ChkBx $2
    IntOp $versToInstall $0 + $1
    IntOp $versToInstall $versToInstall + $2

    # TODO: stop advance to NEXT page if no versions selected to install
    # If no versions selected to install
    ${If} $versToInstall <= 0
        MessageBox MB_ICONEXCLAMATION|MB_OK "You must select at least one version of the Application to install our plugins to."
        # how do I stop the advance to the next page?
    ${EndIf}
FunctionEnd

Solution

  • Use the Abort command.

    NSIS Manual, Chapter 4, Scripting Reference, section 5, Pages, subsection 3, Callbacks:

    The leave-function allows you to force the user to stay on the current page using Abort.