installationcustom-controlsnsisnsis-mui

using nsis installer, adding custom radiobuttons, calling sections according to radiobutton chosen


enter image description here

I want that if none of the RadioButtons are selected , then ,when the Next button is pressed, then it should give an alert that PLEASE CHOSE ATLEAST ONE ITEM, and it should not go to the next Dialog.

Also, I want that if the user selects the option : UPDATE EXISTING SOFTWARE, then only some files are copied, and if the other radiobutton is selected , then all files are copied,

Is this possible using sections or functions have to be used? can i call a Section, like if RadioButton 1 is chosen, then SECTION CREATEALLFILES is called, else SECTION CREATEONLYTWOFILES is called?

According to me, i think i want the code to HOW TO HOLD THE ids of these two RadioButtons and use them accordingly , to call different sections or functions. What would be the code? Please help?

Also, after pressing NEXT on this page, the next dialog will come as in image below: i want to show a LABEL , whether DEMO is done, or UPDATE is running, for this i will add a Label using Resource Hacker, but how to display that Label and hide it according to user choice of RadioButton enter image description here


Solution

  • You can select/unselect sections or just put the logic in a single section, this example does both:

    !include nsDialogs.nsh
    !include Sections.nsh
    
    var InstallType
    
    Section 
    #Install common files...
    ${If} $InstallType == DEMO
        #Do demo specific stuff
    ${Else}
        #Do update specific stuff
    ${EndIf}
    SectionEnd
    
    Section "" SEC_DEMO
    #Install demo..
    SectionEnd
    
    Section "" SEC_UPDATE
    #Do update..
    SectionEnd
    
    Page custom InstTypePageCreate InstTypePageLeave
    
    Function InstTypePageCreate
    nsDialogs::Create 1018
    pop $0
    ${NSD_CreateRadioButton} 0 50u 100% 10u "Demo"
    pop $1
    ${IfThen} $InstallType == DEMO ${|} ${NSD_Check} $1 ${|}
    ${NSD_CreateRadioButton} 0 70u 100% 10u "Update"
    pop $2
    ${IfThen} $InstallType == UPDATE ${|} ${NSD_Check} $2 ${|}
    nsDialogs::Show
    FunctionEnd
    
    Function InstTypePageLeave
    ${NSD_GetState} $1 $0
    ${If} $0 = ${BST_CHECKED}
        StrCpy $InstallType DEMO
        !insertmacro UnselectSection ${SEC_UPDATE}
        !insertmacro SelectSection ${SEC_DEMO}
    ${Else}
        ${NSD_GetState} $2 $0
        ${If} $0 = ${BST_CHECKED}
            StrCpy $InstallType UPDATE
            !insertmacro UnselectSection ${SEC_DEMO}
            !insertmacro SelectSection ${SEC_UPDATE}
        ${Else}
            MessageBox MB_ICONSTOP "You must select something!"
            Abort
        ${EndIf}
    ${EndIf}
    FunctionEnd
    

    To set the text on the next page, just use ${NSD_SetText} $hwndYourLabel "Text" and ShowWindow inside a if block that tests $InstallType (This code needs to be in the show function callback (MUI_PAGE_CUSTOMFUNCTION_SHOW) for that page)