- NSIS Discussion
- Section with options, howto?
Archive: Section with options, howto?
gurzixo
17th January 2008 14:53 UTC
Section with options, howto?
Dear All,
While this is not my first nsis script, I think I have not grabbed the full NSIS spirit yet..., and I am ckoking on this seemingly very simple problem:
My install script needs an user-selectable section, with an user-selectable option. By default, this option is checked or not depending on the value of a registry key. Obviously, if the section is not selected, the option should be grayed out. The action of this section (if selected) is something like:
"execwait myprog.exe -myoption" or "execwait myprog" depending if the option is checked or not.
I tried using sections inside sections (does not work), then SectionGroups. But I have not been able to to get a consistent checking logic.
Any help would be *really* welcome!
Michel
Red Wine
17th January 2008 15:29 UTC
Something like this I guess,
!include "Sections.nsh"
!include "logiclib.nsh"
Section "MyProg" sec1
#
SectionEnd
Section /o "MyOption" sec2
#
SectionEnd
Function .onSelChange
SectionGetFlags ${sec1} $R0
IntOp $R0 $R0 & ${SF_SELECTED}
${If} $R0 == ${SF_SELECTED}
!insertmacro ClearSectionFlag ${sec2} ${SF_RO}
${ElseIf} $R0 != ${SF_SELECTED}
!insertmacro UnSelectSection ${sec2}
!insertmacro SetSectionFlag ${sec2} ${SF_RO}
${EndIf}
FunctionEnd
gurzixo
17th January 2008 15:44 UTC
Thanks a lot, Red Wine for your fast++ answer! At least I have now a working solution.
But could it be possible to have "MyOption" indented, like when using SectionGroup? This makes sense, as MyOption is a MyProg option, not an install option.
Again thanks,
Michel
Red Wine
17th January 2008 16:04 UTC
SectionGroup /e "MyProg"
Section "" sec1
#
SectionEnd
Section /o "MyOption" sec2
#
SectionEnd
SectionGroupEnd
gurzixo
17th January 2008 17:57 UTC
Red Wine, You rock!
As this could be of great use for the next newbie, I have created a new wiki page here: http://nsis.sourceforge.net/Simple_s...on_with_option
Again thanks,
Michel
Red Wine
17th January 2008 19:01 UTC
You're welcome :)
Url submitted by the user gurzixo
vlad-mal
5th March 2008 12:59 UTC
Originally posted by Red Wine
Something like this I guess,
!include "Sections.nsh"
!include "logiclib.nsh"
Section "MyProg" sec1
#
SectionEnd
Section /o "MyOption" sec2
#
SectionEnd
Function .onSelChange
SectionGetFlags ${sec1} $R0
IntOp $R0 $R0 & ${SF_SELECTED}
${If} $R0 == ${SF_SELECTED}
!insertmacro ClearSectionFlag ${sec2} ${SF_RO}
${ElseIf} $R0 != ${SF_SELECTED}
!insertmacro UnSelectSection ${sec2}
!insertmacro SetSectionFlag ${sec2} ${SF_RO}
${EndIf}
FunctionEnd
That is interesting solution.
If there is a lot similar "slaved" sections, then code will be like this:
!Include "MUI.nsh"
!include "Sections.nsh"
!include "logiclib.nsh"
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_LANGUAGE "English"
Name "Section with options"
OutFile "test.exe"
SectionGroup /e "MyProg"
Section "Common" common
SectionEnd
Section /o "Option1" opt1
SectionEnd
Section /o "Option2" opt2
SectionEnd
Section /o "Option3" opt3
SectionEnd
;...
;...etc.
;...
Section /o "OptionN" optN
SectionEnd
SectionGroupEnd
Function .onSelChange
SectionGetFlags ${common} $R0
IntOp $R0 $R0 & ${SF_SELECTED}
${If} $R0 == ${SF_SELECTED}
!insertmacro ClearSectionFlag ${opt1} ${SF_RO}
!insertmacro ClearSectionFlag ${opt2} ${SF_RO}
!insertmacro ClearSectionFlag ${opt3} ${SF_RO}
;...
;...etc
;...
!insertmacro ClearSectionFlag ${optN} ${SF_RO}
${ElseIf} $R0 != ${SF_SELECTED}
!insertmacro UnSelectSection ${opt1}
!insertmacro SetSectionFlag ${opt1} ${SF_RO}
!insertmacro UnSelectSection ${opt1}
!insertmacro SetSectionFlag ${opt2} ${SF_RO}
!insertmacro UnSelectSection ${opt3}
!insertmacro SetSectionFlag ${opt3} ${SF_RO}
;...
;...etc
;...
!insertmacro UnSelectSection ${optN}
!insertmacro SetSectionFlag ${optN} ${SF_RO}
${EndIf}
FunctionEnd
A question: how to iterate across all sections from "opt1" to "optN" to avoid "Copy/Paste" in code?
Thanks.
/* Sorry for my poor English. */
vlad-mal
5th March 2008 15:00 UTC
Solution:
As sinse section indexes is sequential, it possible simple iterate them from first section ("Common") till <Section Group End> flag is occured:
Function ReCheckSection
Var /Global fNextSection
Var /Global IsSelected
Pop $fNextSection
SectionGetFlags $fNextSection $IsSelected
IntOp $IsSelected $IsSelected & ${SF_SELECTED}
IntOp $fNextSection $fNextSection + 1
${DoUntil} ${SectionIsSectionGroupEnd} $fNextSection
${If} $IsSelected == ${SF_SELECTED}
!insertmacro ClearSectionFlag $fNextSection ${SF_RO}
${ElseIf} $R0 != ${SF_SELECTED}
!insertmacro UnSelectSection $fNextSection
!insertmacro SetSectionFlag $fNextSection ${SF_RO}
${EndIf}
IntOp $fNextSection $fNextSection + 1
${LoopUntil} ${SectionIsSectionGroupEnd} $fNextSection
FunctionEnd
Function .onSelChange
; First section:
Push ${common}
Call ReCheckSection
FunctionEnd
Thanks a lot.
vlad-mal
5th March 2008 15:06 UTC
Just in case, full source code:
!Include "MUI.nsh"
!include "Sections.nsh"
!include "logiclib.nsh"
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_LANGUAGE "English"
Name "Section with options"
OutFile "test.exe"
SectionGroup /e "MyProg"
Section "Common" common
SectionEnd
Section /o "Option1" opt1
SectionEnd
Section /o "Option2" opt2
SectionEnd
Section /o "Option3" opt3
SectionEnd
;...
;...etc.
;...
Section /o "OptionN" optN
SectionEnd
SectionGroupEnd
Function ReCheckSection
Var /Global fNextSection
Var /Global IsSelected
Pop $fNextSection
SectionGetFlags $fNextSection $IsSelected
IntOp $IsSelected $IsSelected & ${SF_SELECTED}
IntOp $fNextSection $fNextSection + 1
${DoUntil} ${SectionIsSectionGroupEnd} $fNextSection
${If} $IsSelected == ${SF_SELECTED}
!insertmacro ClearSectionFlag $fNextSection ${SF_RO}
${ElseIf} $R0 != ${SF_SELECTED}
!insertmacro UnSelectSection $fNextSection
!insertmacro SetSectionFlag $fNextSection ${SF_RO}
${EndIf}
IntOp $fNextSection $fNextSection + 1
${LoopUntil} ${SectionIsSectionGroupEnd} $fNextSection
FunctionEnd
Function .onSelChange
Push ${common}
Call ReCheckSection
FunctionEnd