.:: CODE SNIPPET ::.

"Your time is limited, so don't waste it living someone else's life"

Section flag in NSIS script


1. Flag
The flag is just a 32 bit integer. The below table assembles every bit in it

The first bit (lowest) represents whether the section is currently selected
The second bit represents whether the section is a section group (don’t modify this unless you really know what you are doing)
The third bit represents whether the section is a section group end (again, don’t modify)
The fourth bit represents whether the section is shown in bold or not
The fifth bit represents whether the section is read-only
The sixth bit represents whether the section group is to be automatically expanded
The seventh bit is set for section groups which are partially selected
The eighth bit is internally used for partially selected section group toggling and the ninth bit is used for reflecting section name changes
The error flag will be set if an out of range section is specified.
Each flag has a name, prefixed with `SF_`:

!define SF_SELECTED 1
!define SF_SECGRP 2
!define SF_SECGRPEND 4
!define SF_BOLD 8
!define SF_RO 16
!define SF_EXPAND 32
!define SF_PSELECTED 64
2. The Section Flag
The section flag is a combination of the flags in a section. The section flag is still a 32 bit integer. To create the section flag, we use the OR (|) operation on all the flags in binary format.
0000…00001 | 0000…00010…
For example: we have a section with 2 flags like this:

Section test test_section_id
     SectionIn RO
SectionEnd

Here we have the flag SF_SECLECTED (which value is 1) and the flag SF_RO (which value is 16). So, we have the section flag will be:
0000…0001 | 0000…1 0000 = 0000…1 0001 (that is 17 in decimal format.
Since, when we get the section flag via the SectionGetFlags instruction we will have the value 17 (actually, it’s in binary format)

SectionGetFlags test_section_id

3. Check for a flag in section flag
Now, simple instance below will show how to test a flag in section flag. We have a simple section

Section testSection testSectionId
    SectionIn RO
SectionEnd

The problem is how to indicate that the above section is selected or not. We have 3 steps have to be done:
– Get the section flag an store in a variable
– Process that flag with the operation binary AND (&) and store in any variable (clear any other flag out of the section flag)
– Compare the variable in second step with the flag you want to know (the SF_SELECTED in this case)

SectionGetFlags testSectionId $0
IntOp $0 $0 & SF_SELECTED
IntCmp $0 SF_SELECTED IS_SELECTED NOT_SELECTED
IS_SELECTED;
; do some stuff when selected
NOT_SELECTED:
; do some otherwise stuff

Why don’t we use just a comparation?
Because in the section flag there are still other flags, so if we compare it when not clear the other ones, the comparation operation will be able to be wrong since we need the accurate binary number.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: