Search code examples
nsis

when a box is checked I want to another one to be chek


I have the next two section

Section /o "Communications Toolbox"
    ;SectionIn RO
FileWrite $9 "product=Communications Toolbox$\r$\n"
    AddSize 0
SectionEnd


Section  /o "Control System Toolbox"
    ;SectionIn RO
FileWrite $9 "product=Control System Toolbox$\r$\n"
    AddSize 0
SectionEnd

and in process of installation, when a user check the second one"Control System Toolbox", automatically the first one "Communications Toolbox" I want to be check, and in that moment to be displayed a message " To install Control System Toolbox you need also to install "Communications Toolbox". How I can do this thing?

I tried to put a textbox in "Control System Toolbox" :

Section  /o "Control System Toolbox"
     MessageBox MB_OK "Do you want to stay in the license page?" IDOK 
     Abort  
FileWrite $9 "product=Control System Toolbox$\r$\n"
    AddSize 0
SectionEnd

I don't understand why after I push the button OK, didn't turned in previous page ??


Solution

  • There are two ways to handle this:

    A) Enforce the requirements on the component page:

    Page Components
    Page InstFiles
    
    Section /o "Main Component" SID_MAIN
    DetailPrint "Installing Main Component..."
    SectionEnd
    
    Section /o "Bonus feature" SID_BONUS
    DetailPrint "Installing bonus Component..."
    SectionEnd
    
    !include Sections.nsh
    !include LogicLib.nsh
    Function .OnSelChange
    ${If} ${SectionIsSelected} ${SID_BONUS}
        !insertmacro SelectSection ${SID_MAIN} ; The main component is required when installing the bonus component
        !insertmacro SetSectionFlag ${SID_MAIN} ${SF_RO}
    ${Else}
        !insertmacro ClearSectionFlag ${SID_MAIN} ${SF_RO}
    ${EndIf}
    FunctionEnd
    

    You can also use section groups like I suggested in your other question.

    B) Use a MessageBox during the install phase (code in sections are executed on the InstFiles page) and force a component to be installed if required:

    Page Components
    Page InstFiles
    
    Section "" ; Hidden section
    Call EnsureRequiredSections ; We have to call a function because SID_MAIN has not been defined yet
    SectionEnd
    
    Section "Main Component" SID_MAIN
    DetailPrint "Installing Main Component..."
    SectionEnd
    
    Section /o "Bonus feature" SID_BONUS
    DetailPrint "Installing bonus Component..."
    SectionEnd
    
    !include Sections.nsh
    !include LogicLib.nsh
    Function EnsureRequiredSections
    ${If} ${SectionIsSelected} ${SID_BONUS}
    ${AndIfNot} ${SectionIsSelected} ${SID_MAIN}
        MessageBox MB_YESNO|MB_ICONQUESTION "Main Component is required when installing the Bonus feature, do you want to install both?" IDNO no
        !insertmacro SelectSection ${SID_MAIN}
        Goto done
        no:
        !insertmacro UnSelectSection ${SID_BONUS}
        done:
    ${EndIf}
    FunctionEnd