Search code examples
nsis

How to include two custom pages in NSIS?


I have created EXE file using NSIS script.I have created custom page using following code,

page custom check

Function check
    ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\My app" "UninstallString"
    IfFileExists $R0 +1 NotInstalled
        call nsDialogpage

    NotInstalled:
FunctionEnd

Function nsDialogpage
     nsDialogs::Create 1018
     Pop $Dialog12
     ${If} $Dialog12 == error
         Abort
     ${EndIf}
     ${NSD_CreateRadioButton} 0 5u 100% 10u "Repair"
     Pop $Repair
     ${NSD_CreateRadioButton} 0 25u 100% 56u "Remove"
     Pop $Remove
     ${NSD_SetState} $Repair ${BST_CHECKED}
     ${NSD_GetState} $Repair $test
     --Do repair operation--
     ${NSD_OnClick} $Remove "Remove"
     nsDialogs::Show
     ${NSD_GetState} $Remove $RadioButton_State
     ${If} $RadioButton_State == ${BST_CHECKED}
         call Removed
     ${Else}
         Goto Done
     ${EndIf}
     Done:
FunctionEnd    

Function Remove
     nsDialogs::Create 1018
     Pop $Dialog12
     ${If} $Dialog12 == error
           Abort
     ${EndIf}
        --Do remove function--
      /* nsDialogs::Show*/
 FunctionEnd

If I run the above code it's not working.No code executed after show function.If i give show function before functionEnd it throws me Run time exception.Because inside Remove function also have one more show().

My Requirement is,

If the user clicks the remove radio button,moves to next page and do the un install process and page comes to end.I have tried this scenario using above code.but its working fine.

How to include two custom pages in nsis installer?

Can anyone help me?

Thanks.


Solution

  • You can add two custom pages in just the same way you are adding a custom page:

    Page custom check 
    Page custom Remove
    

    As Anders said, everything you put after nsDialogs::Show doesn't get executed. You need to move this code to a new "leave" function:

    Var RemoveRequested
    Function RemoveCheck
        ${NSD_GetState} $Remove $RadioButton_State
        ${If} $RadioButton_State == ${BST_CHECKED}
            StrCpy $RemoveRequested "1"
        ${Else}
            StrCpy $RemoveRequested "0"
        ${EndIf}
    FunctioEnd
    

    You are saving the user selection in a global variable $RemoveRequested. Then, in the next custom page you can check this variable, and do anything you need, or just Abort and the second page will not be displayed.

    And then, you need to modify your custom pages declaration:

    Page custom check RemoveCheck
    Page custom Remove
    

    Now, check will be used to show the custom page, and when the user leaves the page (== clicks on "Next"), the function RemoveCheck will be executed.

    Your Remove function should check the flag we just created:

    Function Remove
        ${If} $RemoveRequested == "1"
            nsDialogs::Create 1018
            Pop $Dialog12
            ${If} $Dialog12 == error
                Abort
            ${EndIf}
            --Do remove function--
            /* nsDialogs::Show*/
        ${EndIf}
    FunctionEnd