Archive: Modify sections at runtime via external config file


Modify sections at runtime via external config file
Hi, I've been looking for a simple solution for such situation:
there is a formed components structure filled with SectionGroups and Sections which is set in stone after compilation, but I need an option to remove some sections (at runtime) based on some external list, placed somewhere near setup executable.
The only solution I can think of is reading an .ini file with such a list and marking those sections with unselected+hidden attributes... Probably there is a better solution, what do you think?
(the basic idea is to remove or unrestrict some components from installation based on an external "license" file - instead of creating various setup packages there will be just one, but with this feature...)


Another solution I have in mind is NSIS sources modification. Customized TreeView on the MUI_PAGE_COMPONENTS should do the trick...


Originally posted by BreezeUADN
Probably there is a better solution, what do you think?
Why do you think there is a better solution? Your solution is exactly the way to do it. What's wrong with it?

Awww I just have a feeling that I'm "doing it wrong"... Well atm. it looks like this:

license.lic (no true/false analysis yet - maybe will add more options instead of bool)
[allowed]
Gate = true
Gate Client = true
Gate Server = true
...


!include "installerSections.nsh"
;--- фильтрация секций по файлу лицензии ---
Function FilterSections
${For} $R1 0 ${SECTIONCOUNT}
SectionGetText $R1 $R2
ReadINIStr $R0 ${LicensePath} "allowed" "$R2"
StrCmp $R0 "" +3 0 ;если секция не найдена, переход на следующую, иначе:
SectionSetFlags $R1 16 ;0+16 = снять выделение + ридонли
SectionSetText $R1 "" ;скрыть
${Next}
FunctionEnd
;------

${LicensePath} is defined as a result of OpenFileDialog which I call on my custom page, where I call this FilterSections inside of Validate part.
(installerSections.nsh and SECTIONCOUNT is formed by my helper program that allows to visually compose section tree from xml templates)

The problem is that I had limited time to get acquainted with NSIS so probably many many things can be done in a much more optimal way, thus the doubts...

Well, that looks pretty good to me. Looks like you've got a better grasp of NSIS than you think. However, you should probably use the macros in NSIS\Include\Sections.nsh, instead of calling SectionSetFlags directly. Right now, you're throwing away all the other section flags just to set flag 0 and 16.