Archive: Problem with sections.


Problem with sections.
Hello.

...
I have this little program of mine that consists of two parts: the server side and the client side. I wrote this script to let the user choose between the server and the client to install:

SectionGroup "MyApp"
Section "MyApp client" cli
/*
Client files
*/
SectionEnd
Section "MyApp server" ser
/*
Server files
*/
SectionEnd
SectionGroupEnd

Now, what I want to do is this: when the user selects either client or server, the other section becomes read-only (i.e. you have to install either client or server, or both of them), so I wrote this .onSelChange function:
Function .onSelChange
SectionGetFlags cli $1
SectionGetFlags ser $2
IntOp $R1 $1 & 0x1
IntOp $R2 $2 & 0x1
IntCmp $R1 0x0 client_unselected
IntCmp $R2 0x0 server_unselected
Abort
client_unselected:
IntOp $2 $2 | 0x11
SectionSetFlags ser $2
Abort
server_unselected:
IntOp $1 $1 | 0x11
SectionSetFlags cli $1
Abort
FunctionEnd

The problem is when the user deselects either server or client option, the whole section group becomes read-only and the user can not change his decision now. It seems that SectionSetFlags command somehow affects both sections at the same time. How can I make it work properly?

Thanks.

I think you're after the effect of radio buttons.
If so, this code will work:

!include Sections.nsh

SectionGroup "MyApp" main
Section "MyApp client" cli
/*
Client files
*/
SectionEnd
Section "MyApp server" ser
/*
Server files
*/
SectionEnd
SectionGroupEnd

Function .onInit
StrCpy $1 ${main}
FunctionEnd

Function .onSelChange

!insertmacro StartRadioButtons $1
!insertmacro RadioButton ${cli}
!insertmacro RadioButton ${ser}
!insertmacro EndRadioButtons

FunctionEnd
-Stu

Hello.

No, actually, it's not what I mean. I want to allow user to select OR client option OR server option OR both of them BUT NOT neither of them. Radiobuttons only allow you to select one option out of many.

Anyway, your code is not working. I have both options selected and when I try to deselect one of them, nothing happens :(


That's because it's radio buttons - all must start unselected except for one otherwise it will not work properly.

However, for what you need is different.
This code works:

!include Sections.nsh
Function .onSelChange

SectionGetFlags ${cli} $R0
IntOp $R0 $R0 & ${SF_SELECTED}
SectionGetFlags ${ser} $R1
IntOp $R1 $R1 & ${SF_SELECTED}

StrCmp $R0 ${SF_SELECTED} noSelA2
StrCmp $R1 ${SF_SELECTED} noSelA1

!insertmacro SelectSection ${cli}
!insertmacro UnselectSection ${ser}

Goto noSelA2
noSelA1:

!insertmacro SelectSection ${ser}
!insertmacro UnselectSection ${cli}

noSelA2:
StrCmp $R1 ${SF_SELECTED} noSelB2
StrCmp $R0 ${SF_SELECTED} noSelB1

!insertmacro SelectSection ${ser}
!insertmacro UnselectSection ${cli}

Goto noSelB2
noSelB1:

!insertmacro SelectSection ${cli}
!insertmacro UnselectSection ${ser}

noSelB2:

FunctionEnd

-Stu

Why do you use SectionGroup at all?


Originally posted by Mæster
Why do you use SectionGroup at all?
Because I like when things look organized :)
I also have some other stuff there that has no direct connection to the main application, so I decided to put it to another group...

Originally posted by Afrow UK
However, for what you need is different.
This code works:
It works indeed! :cool:
Thank you for your help

BTW, what's the difference between ${variable} and $variable ?

Also you can use LogicLib:


!define LOGICLIB_SECTIONCMP
!include "LogicLib.nsh"

var SingleSecID

Function .onSelChange
${If} ${SectionIsSelected} ${cli}
${AndUnless} ${SectionIsSelected} ${ser}
StrCpy $SingleSecID ${cli}
${ElseIf} ${SectionIsSelected} ${ser}
${AndUnless} ${SectionIsSelected} ${cli}
StrCpy $SingleSecID ${ser}
${ElseUnless} ${SectionIsSelected} ${cli}
${AndUnless} ${SectionIsSelected} ${ser}
!insertmacro SelectSection $SingleSecID
${EndIf}
FunctionEnd

${variable} wouldn't be a variable, but instead a constant (cannot be changed).

E.g.
!define Constant "hello world"
The constant ${Constant} could then be placed in strings afterwards. !defines can also contain variables.

When using:
Section "A section" SEC01
SectionEnd
...the ${SEC01} constant becomes available, which simply contains the section index (in which case would be 0 if it's the first section).
Basically, it's the same as doing:
!define SEC01 0

-Stu