Old 17th January 2008, 13:53   #1
gurzixo
Junior Member
 
Join Date: Jan 2008
Posts: 3
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
gurzixo is offline   Reply With Quote
Old 17th January 2008, 14:29   #2
Red Wine
Forum King
 
Red Wine's Avatar
 
Join Date: Mar 2006
Location: Ath. GR
Posts: 2,078
Something like this I guess,
code:
!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


Quick AVI Creator - Quick and easy convert from DVD/MPEG/AVI/MKV to AVI/MP4/MKV
Quick AVI Creator entirely edited with NSIS and entirely upgraded to Unicode NSIS
Red Wine is offline   Reply With Quote
Old 17th January 2008, 14:44   #3
gurzixo
Junior Member
 
Join Date: Jan 2008
Posts: 3
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
gurzixo is offline   Reply With Quote
Old 17th January 2008, 15:04   #4
Red Wine
Forum King
 
Red Wine's Avatar
 
Join Date: Mar 2006
Location: Ath. GR
Posts: 2,078
code:
SectionGroup /e "MyProg"
Section "" sec1
#
SectionEnd

Section /o "MyOption" sec2
#
SectionEnd
SectionGroupEnd


Quick AVI Creator - Quick and easy convert from DVD/MPEG/AVI/MKV to AVI/MP4/MKV
Quick AVI Creator entirely edited with NSIS and entirely upgraded to Unicode NSIS
Red Wine is offline   Reply With Quote
Old 17th January 2008, 16:57   #5
gurzixo
Junior Member
 
Join Date: Jan 2008
Posts: 3
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
gurzixo is offline   Reply With Quote
Old 17th January 2008, 18:01   #6
Red Wine
Forum King
 
Red Wine's Avatar
 
Join Date: Mar 2006
Location: Ath. GR
Posts: 2,078
You're welcome

Url submitted by the user gurzixo

Quick AVI Creator - Quick and easy convert from DVD/MPEG/AVI/MKV to AVI/MP4/MKV
Quick AVI Creator entirely edited with NSIS and entirely upgraded to Unicode NSIS
Red Wine is offline   Reply With Quote
Old 5th March 2008, 11:59   #7
vlad-mal
Junior Member
 
Join Date: Mar 2008
Posts: 5
Quote:
Originally posted by Red Wine
Something like this I guess,
code:
!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:

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 .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 is offline   Reply With Quote
Old 5th March 2008, 14:00   #8
vlad-mal
Junior Member
 
Join Date: Mar 2008
Posts: 5
Solution:
As sinse section indexes is sequential, it possible simple iterate them from first section ("Common") till <Section Group End> flag is occured:

code:

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 is offline   Reply With Quote
Old 5th March 2008, 14:06   #9
vlad-mal
Junior Member
 
Join Date: Mar 2008
Posts: 5
Just in case, full source code:

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


vlad-mal is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump