Archive: Conditional License Agreement Page based on Component Selection?


Conditional License Agreement Page based on Component Selection?
Just as the topic title asks,

I'm sure it's possible, but I'm not sure how I would go about inserting a License Agreement Page (MUI) depending on whether or not a specific Component had been selected for installation.

If you need further details, I'd be happy to provide. I've searched but all the answers and/or relevant examples a slightly off of what I'm looking for. I'm sorry if I missed anything that directly relates to this question. Please excuse my ignorance.

Thanks in advance for any and all help.


Do you show your license page after your components page?


Yes, that is what I want to do.

If Component X is selected, show License page for Component X.
If Component X is not selected, do now show License page for Component X.


I just tried it, this is possible:

  !include "MUI.nsh"
!include "LogicLib.nsh"
Name "Example"
OutFile "example.exe"

!insertmacro MUI_PAGE_COMPONENTS
!define MUI_PAGE_CUSTOMFUNCTION_PRE SkipLicense
!insertmacro MUI_PAGE_LICENSE "license.txt"
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"

Section "test1"
SectionEnd

Section "test2"
SectionEnd

Function SkipLicense
${IfNot} ${SectionIsSelected} test1
abort ;skip license if test1 was not enabled
${EndIf}
FunctionEnd

I think you will need 2 license pages. This is what I would try, but I'm not sure declaring two license pages is supported.

So if you have two different license pages and you want to show one or the other, then declare both pages, each with it's own pre function, and use the pre function to decide whether to show that license page or not. If the logic is structured correctly then it will only show one of the two pages for any given scenario.

Edit: I think I misunderstood. for some reason I thought you had two different licenses. My bad. The example above with the pre function is probably what you want.


That works for that example, but it doesn't seem to work when I try incorporating that into my current script. I have no idea why since it seems identical. I will post back here with updates as soon as I figure something out or reach a road block.

Thanks for the reply.


Originally posted by AaronLS
I think you will need 2 license pages. This is what I would try, but I'm not sure declaring two license pages is supported.

So if you have two different license pages and you want to show one or the other, then declare both pages, each with it's own pre function, and use the pre function to decide whether to show that license page or not. If the logic is structured correctly then it will only show one of the two pages for any given scenario.

Edit: I think I misunderstood. for some reason I thought you had two different licenses. My bad. The example above with the pre function is probably what you want.
I actually do have multiple license pages (3 to be exact). 2 are shown at the beginning (before component selection since their respective components are required for installation) and 1 post-component selection because it's respective component is not required for installation.

This example code with multiple license pages works fine (adapted from MSG):


!include "MUI.nsh"
!include "LogicLib.nsh"
Name "Example"
OutFile "example.exe"

!insertmacro MUI_PAGE_LICENSE "pre-license.txt"
!insertmacro MUI_PAGE_COMPONENTS
!define MUI_PAGE_CUSTOMFUNCTION_PRE SkipLicense
!insertmacro MUI_PAGE_LICENSE "license.txt"
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"

Section /o "test one section" SEC001
MessageBox MB_OK "Test 1 Section"
SectionEnd

Section "test2"
SectionEnd

Function SkipLicense
${IfNot} ${SectionIsSelected} "test one section"
MessageBox MB_OK "Test 1 Section SKIP"
abort ;skip license if test1 was not enabled
${EndIf}
FunctionEnd


I put in some message boxes just to make sure I understood the flow.

So, the example there works perfectly fine, however, when I implement that same logic in my script it does not seem to work at all. The 'conditional' license page still shows every time no matter the selection.

Thanks for your help so far guys, hopefully I can get to the bottom of this soon...

I'm really stumped here. The PRE function (SkipLicense) is being called correctly, but the If statement does not get evaluated.


Function SkipLicense
MessageBox MB_OK "Skip?"
${IfNot} ${SectionIsSelected} "Section to Skip"
MessageBox MB_OK "Skipping!"
Abort ;skip license if component not selected
${EndIf}
FunctionEnd


The first message box shows up, but the second doesn't. It's having trouble evaluating if the SectionIsSelected for "Section to Skip" I guess. I'm not sure what else to do.

Aha!! Got it. You need to reference the section by the section ID inside variable braces like so:


Function SkipLicense
MessageBox MB_OK "SkipLicense Function Called"
${IfNot} ${SectionIsSelected} ${SEC001}
MessageBox MB_OK "Skipping!"
Abort ;skip license if component not selected
${EndIf}
FunctionEnd


I guess that is necessary for when you have a large number of sections ? (I have about 15 or so)...

Anyway, works well now, thanks!