How do I check if a component is selected in NSIS?
Asked Answered
H

1

6

I would like to prompt the user for extra information if a certain component is selected, but I'm not really sure how to check that a given component is selected. It seems like http://nsis.sourceforge.net/Docs/Chapter4.html#4.9.13.2 might be somehow related, but I was under the impression that a section is a group of components...

Given help from Anders I have this that works:

!include MUI.nsh
!include nsDialogs.nsh
!include LogicLib.nsh
!include sections.nsh

Name A
InstProgressFlags smooth colored
LicenseBkColor /windows
OutFile A.exe
InstallDir $PROGRAMFILES\A

Var Dialog

Section "A" SEC_A
SectionEnd
Section "B" SEC_B
SectionEnd

!insertmacro MUI_PAGE_COMPONENTS
Page custom getA setA # {{{
!insertmacro MUI_PAGE_DIRECTORY # {{{ install
Function getA

   ${Unless} ${SectionIsSelected} ${SEC_A}
      Abort
   ${EndUnless}

   nsDialogs::Create 1018
   Pop $Dialog

   ${If} $Dialog == error
      Abort
   ${EndIf}

   ${NSD_CreateLabel} 0 0 100% 12u "Test"

   nsDialogs::Show
FunctionEnd
Function setA
   MessageBox MB_OK "clicked?"
FunctionEnd
# }}}
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
Hanukkah answered 21/2, 2013 at 19:8 Comment(0)
F
9

Every section (with a name) is displayed as a checkbox on the components page. (Section groups can be used to form a tree layout but only the actual sections contain executable code)

sections.nsh contains handy helper macros to manipulate setions and if you use logiclib.nsh you can do ${If} ${SectionIsSelected} ${MYSECTION} ...

Flaxman answered 21/2, 2013 at 20:18 Comment(4)
I tried this and it mostly works. See my edit for what is still giving me issues...Hanukkah
AHA! I got it, it MUST be in a group for SectionIsSelected to work.Hanukkah
Ugh, I was wrong. It still uses the first section, even if that's a SelectionGroup.Hanukkah
Any code that uses ${SEC_A} must appear after that section in the .nsi file...Flaxman

© 2022 - 2024 — McMap. All rights reserved.