Archive: Require user to choose one component


Require user to choose one component
Hi,
I'm writing an installer with four components, all optional. Now I'd like people to be stopped and prompted to select at least one of them upon leaving the component page.

I already know that this can be done by associationg the respective function like this

Page Components "" "" MyFunction

but I just can't come up with a function that does the job properly.

I have put together an example barebones script that works. it uses pageex for the components page because it needs the callback function of leaving the page. Here's the example script and it's exe.

EDIT: Forget about the pageex and use the function described above. I didn't realize a page command could use function calls as well as custom pages.


Simpler:

!include Sections.nsh

Page Components "" "" ComponentsLeaveFunc

Section "A section" SEC1
SectionEnd

Section "A section" SEC2
SectionEnd

Function ComponentsLeaveFunc

!insertmacro SectionFlagIsSet ${SEC1} ${SF_SELECTED} End ""
!insertmacro SectionFlagIsSet ${SEC2} ${SF_SELECTED} End ""
MessageBox MB_OK|MB_ICONSTOP "Select atleast one component."
Abort
End:

FunctionEnd


-Stu

Simpler:

!include LogicLib.nsh

Page Components "" "" ComponentsLeaveFunc

Section "A section" SEC1
SectionEnd

Section "A section" SEC2
SectionEnd

Function ComponentsLeaveFunc

${Unless} ${SectionIsSelected} ${SEC1}
${AndUnless} ${SectionIsSelected} ${SEC2}
MessageBox MB_OK|MB_ICONSTOP "Select atleast one component."
Abort
${EndUnless}

FunctionEnd

:)

So far I tried Jason's solution and it worked like a charm. But I might play around with the other two later on to thin out the code.

Anyway, thx to all of you. :)


The extra stuff in the .oninit function sets the components page checkboxes to not checked so the end user HAS to choose one option before continuing.


You should use Section /o for that.
Similarely, Section flags (with SectionGetFlags) are not always going to be "1" (the flags specify more than the selected state).

-Stu


Yes, I know that. But I just don't know what the return value should look like if several settings are set and you call SectionGetFlags.