Archive: how to disable custompage, when section selected


how to disable custompage, when section selected
  Hey all,
I can't find a solution for my problem:
I want to show custompage conditionally (only when section is selected). At the moment my custompage appears always, no mather if section is selected or not. here is my simplified script:
(original script contains more than 1000 lines, several sections and a lot of functions)

!include "MUI.nsh"
Name "Test"
OutFile "text.exe"
InstallDir "$PROGRAMFILES\Test"

!insertmacro MUI_PAGE_COMPONENTS
Page custom CustomPage
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES

ReserveFile "CustomPFile.ini"
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS

Section "Section" SecIndex
SetOutPath "$INSTDIR"
WriteRegStr HKCU "Software\Modern UI Test" "" $INSTDIR
WriteUninstaller "$INSTDIR\Uninstall.exe"
SectionEnd

Function .onInit
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "CustomPFile.ini"
FunctionEnd

Function CustomPage
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "CustomPFile.ini"
FunctionEnd

I would be very greatful, if someone could tell me how to make custompage disappear when section is not selected


i used this :

Function YourName

SectionGetFlags${YourSection} $0
StrCmp$0 ${SF_SELECTED} 0 skipPage
!insertmacro MUI_HEADER_TEXT "bla" "bla bla"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "YourINIfile.ini"
>skipPage:
>FunctionEnd
>
this function dispays the custom page if the section IS SELECTED. just replace

StrCmp $0 ${SF_SELECTED} 0 skipPage

with

StrCmp $0 ${SF_SELECTED} 1 skipPage

that should work.

OJi.

big tnx to o_owd,
I got it now working by, editing the code a little.
The replacement(wich o_owd advised didn't work (0 -> 1), It could be +1 or label(i like it more):
StrCmp $0 ${SF_SELECTED} showpage skipPage

And then i had to !include Sections.nsh to get whole thing working.
I attach my script..Hopefully it helps someone. To get this script working you have to rename some custompage ini file(for example from nsis examples dir) to CustomPFile.ini


here it is


it doesn't work, as i thought frist place! :eek:
now that i have tested it with more than one section it seems that it considers only the section, that is the first on the list, not the one, that i have selected with SectionGetFlags. i really need some help. can someone please look and correct my script(this one has 3 sections) :confused:


sorry for that! my mistake. :down:

replace


SectionGetFlags Sec2Index $0

StrCmp$0 ${SF_SELECTED} showpage skipPage
showpage:
!
insertmacro MUI_HEADER_TEXT "bla" "bla bla"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "CustomPFile.ini"
>skipPage:
with this
SectionGetFlags${Sec2Index} $0

StrCmp$0 "0" 0 skipPage
!insertmacro MUI_HEADER_TEXT "bla" "bla bla"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "CustomPFile.ini"
>skipPage:
i'm really sorry for the mistake. stupid me! the reply was written in a hurry...

sorry again.

OJi.

no problem..tnx


ok, now i got it working, almost as i wanted. It works great with usual sections, but still don't know how to make it working with subsections. by the way there was still one little mistake in last post:

change this:
SectionGetFlags ${Sec2Index} $0
StrCmp $0 "0" 0 skipPage #shows if not selected
!insertmacro MUI_HEADER_TEXT "bla" "bla bla"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "CustomPFile.ini"
skipPage:

with:

SectionGetFlags ${Sec2Index} $0
StrCmp $0 "0" 1 skipPage # shows if selected
!insertmacro MUI_HEADER_TEXT "bla" "bla bla"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "CustomPFile.ini"
skipPage:


Originally posted by k2rnkonn

change this:
StrCmp $0 "0" 0 skipPage #shows if not selected

with:
StrCmp $0 "0" 1 skipPage # shows if selected

you must change the number beetween quotes.

StrCmp $0 "0" 0 skipPage #shows if not selected

StrCmp $0 "1" 0 skipPage # shows if selected

i don't know how to make it work with subsections. maybe somebody else can help!

OJi.

my dear.
u didn't read the docs about section-flags.
the command SectionGetFlags return ALL flags as 32bit integer. means, that if the section has more than one flag set (like subsections have, or bold sections, see the docs), the number is different.
this code will extract the needed flag:

!macro  GetSectionSelection  SECTION
Push $1
SectionGetFlags "${SECTION}" $1
IntOp $1 $1 & 1
Exch $1
!macroend

use it like this:
!insertmacro GetSectionSelection ${mysection}
Pop $0
StrCmp $0 1 selected not_selected
selected:
not_selected:

Quote:


why didn't u read my post?
it's much easier, than ur "work-around" ...


ok, after posting my reply i read Comm@nder21's reply. but it didn't work, as i thought(maybe i did something wrong).
$0 is 0 when subsection is not selected, or is partly selected (only some sections inside subsection is selected)
and 1 when whole subsection tree is selected.

maybe did i something wrong..anyway my script is attached. tnx Comm@nder21, i'm waiting for youre reply



Originally posted by o_owd
you must change the number beetween quotes.

StrCmp $0 "0" 0 skipPage #shows if not selected

StrCmp $0 "1" 0 skipPage # shows if selected

i don't know how to make it work with subsections. maybe somebody else can help!

OJi.
it doesn't matter :p , both will work the same way, only solution will change
now i figured out the way how to show page when at least one section from subsection is selected(only don't know, if it is the best solution):

CustomPage

SectionGetFlags${s1} $1
SectionGetFlags${s2} $2
SectionGetFlags${s3} $3
SectionGetFlags${s4} $4
IntOp$0 0 + $1
IntOp$0 $0 + $2
IntOp$0 $0 + $3
IntOp$0 $0 + $4
messagebox mb_ok "Selected $0 sections from subsection"
>IntCmp $0 0 skipPage skipPage
#if $0(sum of selected sections)=0 skipPage, if less(can't be possibel) also skipPage,
# if more, go on with next line
!insertmacro MUI_HEADER_TEXT "bla" "bla bla"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "CustomPFile.ini"
>skipPage:
>FunctionEnd
>
s1-s4 are sections in subsection, so if one or more of sections form subsections are selected, then it adds the number of selected sections to $0(original value is 0).
then it will compere $0 with 0, and if result is equal or less, then it goes to skipPage, otherwise goes on with next line:blah:

whole script attached file