Section Dependency: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
 
No edit summary
Line 29: Line 29:


Page Components
Page Components
!include Sections.nsh


Section "Section 1" Sec1
Section "Section 1" Sec1
Line 70: Line 68:


!define SectionDependency
!define SectionDependency
!include Sections.nsh


!macro SectionDependencyVars Var1 Var2
!macro SectionDependencyVars Var1 Var2

Revision as of 19:08, 9 January 2006

Author: Afrow UK (talk, contrib)


Description

Macro's that are inserted in a block by block basis to build a list of Sections that are dependent on another Section. By this we mean that 1 or more Sections must have 1 or more other Sections checked first.

Usage

!insertmacro SectionDependencyVars $Var1 $Var2

Specifies which temporary variables to use within the macros.

!insertmacro SectionDependency SectionID

(Required) Specifies that the Section SectionID should have a dependency on another Section.

!insertmacro SectionDependentUpon_Begin

(Required) Begins the list of Sections for other Sections to be dependent upon.

!insertmacro SectionDependentUpon SectionID

(Required) Adds the Section SectionID to the list of Sections for other Sections to be dependent on.

!insertmacro SectionDependentUpon_End

(Required) Ends the list.

Example

This is a complete working example script which can be compiled once you have saved the actual NSH source code (further down this page).

Name SectionDependency
OutFile SectionDependency.exe
 
!include SectionDependency.nsh
 
Page Components
 
Section "Section 1" Sec1
  SectionIn RO
SectionEnd
 
Section "Section 2" Sec2
SectionEnd
 
Section /o "Section 3" Sec3
SectionEnd
 
Section /o "Section 4" Sec4
SectionEnd
 
Function .onSelChange
Push $R0
Push $R1
 
  !insertmacro SectionDependencyVars $R0 $R1
 
  !insertmacro SectionDependency Sec3
  !insertmacro SectionDependency Sec4
 
  !insertmacro SectionDependentUpon_Begin
  !insertmacro SectionDependentUpon Sec2
  !insertmacro SectionDependentUpon_End
 
Pop $R1
Pop $R0
FunctionEnd

The Code

Copy and paste the following code into a plain text file and save it as NSIS\Include\SectionDependency.nsh.

!ifndef SectionDependency
 
!define SectionDependency
 
!include Sections.nsh
 
!macro SectionDependencyVars Var1 Var2
 
  !define SectionVar1 ${Var1}
  !define SectionVar2 ${Var2}
 
!macroend
 
!macro SectionDependency Section
 
  !ifndef SectionVar1
    !define SectionVar1 $R0
  !endif
  !ifndef SectionVar2
    !define SectionVar2 $R1
  !endif
 
  SectionGetFlags ${${Section}} ${SectionVar1}
  IntOp ${SectionVar1} ${SectionVar1} & ${SF_SELECTED}
  StrCmp ${SectionVar1} ${SF_SELECTED} SelectDependentSection
 
!macroend
 
!macro SectionDependentUpon_Begin
 
  Goto End
 
  SelectDependentSection:
 
!macroend
 
!macro SectionDependentUpon Section
 
    SectionGetFlags ${${Section}} ${SectionVar1}
    IntOp ${SectionVar2} ${SectionVar1} & ${SF_SELECTED}
    StrCmp ${SectionVar2} ${SF_SELECTED} End
 
    IntOp ${SectionVar1} ${SectionVar1} | ${SF_SELECTED}
    SectionSetFlags ${${Section}} ${SectionVar1}
 
!macroend
 
!macro SectionDependentUpon_End
 
  End:
 
  !undef SectionVar2
  !undef SectionVar1
 
!macroend
 
!endif

-Stu