Archive: Skip Sections programatically


Skip Sections programatically
Is it possible to skip sections if a certain condition exists? If so, could someone point me in the right direction on how to do this? Thanks much!


yes...use SectionSetFlags


Is SetSectionFlags a built-in function or is that a function/macro that I need to put in my script?


Need put in...a Section, Macro or Function.


You need to do this:
## add at top of script file
!define SF_SELECTED 1
!define SECTION_OFF 0xFFFFFFFE

Section "Section Name" Sec1
## have stuff here in your section
SectionEnd

Section "Section Name" Sec2
## have stuff here in your section
SectionEnd

Then in your functions use:
## Turn sections off
Push $R0 ;save variable
SectionGetFlags ${Sec1} $R0
IntOp $R0 $R0 & ${SECTION_OFF}
SectionSetFlags ${Sec1} $R0
Pop $R0 ;return variable


## Turn sections on
Push $R0 ;save variable
SectionGetFlags ${Sec2} $R0
IntOp $R0 $R0 & ${SF_SELECTED}
SectionSetFlags ${Sec2} $R0
Pop $R0 ;return variable

The Sec1 and Sec2 bits are the important parts. Just change those bits for the different sections.

-Stu


Ok, this is what I have...Could I get someone's verification that I am doing this correctly(I think I supplied all the related code)? Also, are sections initialized to "ON" when a script runs?

!include Sections.nsh

!define MUI_CUSTOMFUNCTION_DIRECTORY_PRE DirectoryPre

Section "Section Name" Sec1
## have stuff here in your section
SectionEnd
Section "Section Name" Sec2
## have stuff here in your section
SectionEnd
Section "Section Name" Sec3
## have stuff here in your section
SectionEnd

Function DirectoryPre
push $R1
ReadRegStr $R1 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" "UninstallString"
StrCmp $R1 "" OK
SetSectionFlag ${sec1} ${SECTION_OFF}
SetSectionFlag ${sec2} ${SECTION_OFF}
SetSectionFlag ${sec3} ${SECTION_OFF}
Abort
OK:
FunctionEnd

I REALLY appreciate everyone's help on this!!!!


It's SectionSetFlags not SetSectionFlag.
Also, your code is wrong and it will not work.
Use the code that I showed you.

Yes, sections are on by default.

-Stu


In Sections.nsh (in NSIS/include), there is the macro:
!macro SetSectionFlag SECTION BITS
Push $R0
SectionGetFlags "${SECTION}" $R0
IntOp $R0 $R0 | "${BITS}"
SectionSetFlags "${SECTION}" $R0
Pop $R0
!macroend
Can't I use that?? The only difference I see between this macro and your code, Afrow, is you have a "&" instead of "|"...which is correct?

Maybe my code should be modified to:
!insertmacro SetSectionFlag ${sec1} ${SECTION_OFF}
!insertmacro SetSectionFlag ${sec2} ${SECTION_OFF}
!insertmacro SetSectionFlag ${sec3} ${SECTION_OFF}


That is correct.
If it doesn't work, then try replacing | with & in the macro.

-Stu


Re: Skip Sections programatically

Originally posted by jcagle
Is it possible to skip sections if a certain condition exists?
When I want to skip a section depending on some conditions I write a StrCmp at the beginning and place one jump label at the end of the section.

This seems eaiser to me.

Yes, thats another way, but you could say it's cheaper and less tidy, but it still works :)

-Stu