Archive: Not understanding the results of IntOp Binary AND operation


Not understanding the results of IntOp Binary AND operation
Hello,

I've been using NSIS for a while but I am not much of a coder. I am trying to use one of Jan's code samples (thanks Jan) that simply states "If the section "section_index" is selected, show the custom page "Policytool". If the section "section_index" is not selected, abort the custom page." Jan's code uses IntOp to perform a binary AND operation, and I don't understand the numbers I am getting back. Since the section I am performing the operation on is a section group, the binary should look like this, assuming the section group is selected:

00000011 = 3

If section group is partially selected:

00100011 = 67

However, when I read the flag into a variable using SectionGetFlags, it always returns "2" before the IntOp AND operation and it returns "0" after the IntOp AND operation. This is regardless of what has been selected on the components page. So apparently, the lowest bit isn't being set when the section group is selected. I have attached my script. Could someone tell me what I am doing wrong? Thanks so much, and thanks to everyone that I have borrowed code from!

William


SectionGetFlags's first parameter must be an index, which is a number given by the "Section"'s 2nd parameter and "SectionGroup"'s 3rd parameter.


Thanks for the feedback deguix. I changed the following lines in the code:

"SectionGetFlags POL $R0" to "SectionGetFlags 25 $R0"

and

"SectionGroup "Best Practice and Regulatory Policies" POL" to "SectionGroup "Best Practice and Regulatory Policies" POL 25"

Now when I run it, it returns "5" before the AND operation, and it returns "1" after the AND operation, regardless of what is checked on the components page. There is still something I am doing wrong. Am I not understanding the SectionGroup parameters?

Thanks.


Oh, sorry. Put a string in the "Section"'s 2nd parameter or "SectionGroup"'s 3rd parameter to be used as a constant name for the index constant, and then use this constant's value in the SectionGetFlags instruction like you would with a normal NSIS define. Like this below:

Section "MySection" Test
SectionGetFlags ${Test} $0
The value of ${Test} is the index of the section "MySection".

EDIT: NOTE: Every section or section group has to have a different constant name for the index.

Ok so I changed the code to look like this:

SectionGetFlags ${POL} $R0

But when I compile, I get the warning:

"unknown variable/constant "{POL}" detected, ignoring"


My Section Group looks like this:

SectionGroup "Best Practice and Regulatory Policies" POL


Am I not getting it right? Am I missing a parameter?


So I found my problem. The issue appears in the following thread:

http://forums.winamp.com/showthread....roup+and+index

Apparently if you try to use the section_index before it is defined, it will choke when compiling. I just simply moved my function to the end of the script and it works fine now. Thanks!

William


Just as an additional note, when using Jan's code for section groups, it will not work unless all sections in the section group have been selected. You can modify the code so that it will continue even if only part of the section group has been selected:



SectionGetFlags ${secID} $R0
IntOp $R1 $R0 & ${SF_SELECTED}
IntOp $R2 $R0 & ${SF_PSELECTED}
StrCmp $R1 ${SF_SELECTED} +3
StrCmp $R2 ${SF_PSELECTED} +2
Abort



Thanks!