Archive: Enable/Disable Sections based on prerequisites?


Enable/Disable Sections based on prerequisites?
Hello!

I'm just learning NSIS, and so far I am enjoying the ride. It seems pretty straightforward so far, but I've hit a problem that I can't find an answer to with searches in the forums and Google.

Problem Background:
I am writing a plugin for web browsers on Windows. Usually Internet Explorer will be installed, but other browsers like Firefox, Chrome, Safari, and Opera will be installed as well. The plugin has different installation locations based on which browser it's for, so I've set up different Sections for each browser type (all contained within a SectionGroup). I also have the details of installation already completed for each browser type.

Problem:
I'm trying to add functionality to the installer that will enable/disable the proper section(s) if the user has the particular browser installed (basically just trying to make it an 'intelligent' installer). For example, if the user has IE and Firefox installed, those plugin sections will be selected automatically, and ideally the others (Chrome, Safari, and Opera) would all be disabled/grayed out.

I already have the actual tests for each browser completed, so I know if each browser is installed. The problem is that when I try to add this code to the .onInit callback that it's not working. In fact, for some reason it modifies the selection tree by moving the web browser sections to the same level as the SectionGroup.

I've tried adding the testing code to the .onSelChange function too, but that makes things really messy as well.

Here is some of the example code (just Firefox for easier reading). IsFirefoxInstalled is initialized as part of the .onInit callback.


!include Sections.nsh
...
# If the non-IE web browsers are installed, automatically select them.
# If not, disable the selection of that item.
${If} $IsFirefoxInstalled == "1"
!insertmacro SelectSection MozillaFirefox
${Else}
!insertmacro UnselectSection MozillaFirefox
${EndIf}


Is NSIS capable of doing something like this? If so, do I have the right idea, or am I going the wrong direction? Why won't this work?

Any help someone could provide would be greatly appreciated.

Thanks!

-Bill

you must specify the section id (Section NAME ID), also the .onInit function must come after your sections in the script.

So it would look something like:

!include Sections.nsh

Section "Firefox" secfirefox
...
SectionEnd

Function .OnInit
${If} $IsFirefoxInstalled == "1"
!insertmacro SelectSection ${secfirefox}
${Else}
!insertmacro UnselectSection ${secfirefox}
${EndIf}

FunctionEnd


With all of the information I was trying to give, I forgot to mention that I did have the Section Name in there:

Section "Mozilla Firefox" MozillaFirefox 


But, I noticed that you put the ${} around the section name. I tried that and it worked exactly like I wanted it to.

The confusing thing is that I don't understand why the compiler built the installer if I didn't treat the section name as a variable. Shouldn't this have thrown an error during compilation? If not, is there a rule of thumb as to when to use the ${} and when not to?

I'm still a little confused, but I thank you very much for your help - you made my installer work exactly the way I wanted it to!

-Bill