Section Dependency: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
No edit summary
Line 3: Line 3:
== Description ==
== 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.
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 ==
<highlight-nsis>!insertmacro SectionDependencyVars $Var1 $Var2</highlight-nsis>
Specifies which temporary variables to use within the macros.
<highlight-nsis>!insertmacro SectionDependency SectionID</highlight-nsis>
<b>(Required)</b> Specifies that the Section <i>SectionID</i> should have a dependency on another Section.
<highlight-nsis>!insertmacro SectionDependentUpon_Begin</highlight-nsis>
<b>(Required)</b> Begins the list of Sections for other Sections to be dependent upon.
<highlight-nsis>!insertmacro SectionDependentUpon SectionID</highlight-nsis>
<b>(Required)</b> Adds the Section <i>SectionID</i> to the list of Sections for other Sections to be dependent on.
<highlight-nsis>!insertmacro SectionDependentUpon_End</highlight-nsis>
<b>(Required)</b> Ends the list.


== Example ==
== 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).
This is a complete working example script which can be compiled.
<highlight-nsis>
This script defines Sec2 ("Section 2") as the component which must be selected to install the other two components Sec3 ("Section 3") and Sec4 ("Section 4").
Name SectionDependency
<highlight-nsis>Name SectionDependency
OutFile SectionDependency.exe
OutFile SectionDependency.exe


!include SectionDependency.nsh
Var IndependentSectionState


Page Components
Page Components
!include Sections.nsh


Section "Section 1" Sec1
Section "Section 1" Sec1
Line 43: Line 29:
SectionEnd
SectionEnd


Function .onSelChange
Function .onInit
Push $R0
Push $R1
 
  !insertmacro SectionDependencyVars $R0 $R1


   !insertmacro SectionDependency Sec3
   SectionGetFlags ${Sec2} $R0
   !insertmacro SectionDependency Sec4
   IntOp $R0 $R0 & ${SF_SELECTED}
  StrCpy $IndependentSectionState $R0


  !insertmacro SectionDependentUpon_Begin
  !insertmacro SectionDependentUpon Sec2
  !insertmacro SectionDependentUpon_End
Pop $R1
Pop $R0
FunctionEnd
FunctionEnd
</highlight-nsis>


== The Code ==
Function .onSelChange
Copy and paste the following code into a plain text file and save it as <b>NSIS\Include\SectionDependency.nsh</b>.
Push $R0
Push $R1


<highlight-nsis>
  SectionGetFlags ${Sec2} $R0
!ifndef SectionDependency
  IntOp $R0 $R0 & ${SF_SELECTED}
  StrCmp $R0 $IndependentSectionState +3
    StrCpy $IndependentSectionState $R0
  Goto UnselectDependentSections
    StrCpy $IndependentSectionState $R0


!define SectionDependency
  Goto CheckDependentSections


!include Sections.nsh
  SelectIndependentSection:


!macro SectionDependencyVars Var1 Var2
    SectionGetFlags ${Sec2} $R0
    IntOp $R1 $R0 & ${SF_SELECTED}
    StrCmp $R1 ${SF_SELECTED} +3


  !define SectionVar1 ${Var1}
    IntOp $R0 $R0 | ${SF_SELECTED}
  !define SectionVar2 ${Var2}
    SectionSetFlags ${Sec2} $R0


!macroend
    StrCpy $IndependentSectionState ${SF_SELECTED}


!macro SectionDependency Section
  Goto End


   !ifndef SectionVar1
   CheckDependentSections:
    !define SectionVar1 $R0
  !endif
  !ifndef SectionVar2
    !define SectionVar2 $R1
  !endif


   SectionGetFlags ${${Section}} ${SectionVar1}
   SectionGetFlags ${Sec3} $R0
   IntOp ${SectionVar1} ${SectionVar1} & ${SF_SELECTED}
   IntOp $R0 $R0 & ${SF_SELECTED}
   StrCmp ${SectionVar1} ${SF_SELECTED} SelectDependentSection
   StrCmp $R0 ${SF_SELECTED} SelectIndependentSection


!macroend
  SectionGetFlags ${Sec4} $R0
 
  IntOp $R0 $R0 & ${SF_SELECTED}
!macro SectionDependentUpon_Begin
  StrCmp $R0 ${SF_SELECTED} SelectIndependentSection


   Goto End
   Goto End


   SelectDependentSection:
   UnselectDependentSections:


!macroend
    SectionGetFlags ${Sec3} $R0
    IntOp $R1 $R0 & ${SF_SELECTED}
    StrCmp $R1 ${SF_SELECTED} 0 +3


!macro SectionDependentUpon Section
    IntOp $R0 $R0 ^ ${SF_SELECTED}
    SectionSetFlags ${Sec3} $R0


     SectionGetFlags ${${Section}} ${SectionVar1}
     SectionGetFlags ${Sec4} $R0
     IntOp ${SectionVar2} ${SectionVar1} & ${SF_SELECTED}
     IntOp $R1 $R0 & ${SF_SELECTED}
     StrCmp ${SectionVar2} ${SF_SELECTED} +3
     StrCmp $R1 ${SF_SELECTED} 0 +3


     IntOp ${SectionVar1} ${SectionVar1} | ${SF_SELECTED}
     IntOp $R0 $R0 ^ ${SF_SELECTED}
     SectionSetFlags ${${Section}} ${SectionVar1}
     SectionSetFlags ${Sec4} $R0
 
!macroend
 
!macro SectionDependentUpon_End


   End:
   End:


  !undef SectionVar2
Pop $R1
  !undef SectionVar1
Pop $R0
 
FunctionEnd</highlight-nsis>
!macroend
 
!endif
</highlight-nsis>


-Stu
-Stu


[[Category:Section Management Functions]]
[[Category:Section Management Functions]]

Revision as of 18:29, 10 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.

Example

This is a complete working example script which can be compiled. This script defines Sec2 ("Section 2") as the component which must be selected to install the other two components Sec3 ("Section 3") and Sec4 ("Section 4").

Name SectionDependency
OutFile SectionDependency.exe
 
Var IndependentSectionState
 
Page Components
 
!include Sections.nsh
 
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 .onInit
 
  SectionGetFlags ${Sec2} $R0
  IntOp $R0 $R0 & ${SF_SELECTED}
  StrCpy $IndependentSectionState $R0
 
FunctionEnd
 
Function .onSelChange
Push $R0
Push $R1
 
  SectionGetFlags ${Sec2} $R0
  IntOp $R0 $R0 & ${SF_SELECTED}
  StrCmp $R0 $IndependentSectionState +3
    StrCpy $IndependentSectionState $R0
  Goto UnselectDependentSections
    StrCpy $IndependentSectionState $R0
 
  Goto CheckDependentSections
 
  SelectIndependentSection:
 
    SectionGetFlags ${Sec2} $R0
    IntOp $R1 $R0 & ${SF_SELECTED}
    StrCmp $R1 ${SF_SELECTED} +3
 
    IntOp $R0 $R0 | ${SF_SELECTED}
    SectionSetFlags ${Sec2} $R0
 
    StrCpy $IndependentSectionState ${SF_SELECTED}
 
  Goto End
 
  CheckDependentSections:
 
  SectionGetFlags ${Sec3} $R0
  IntOp $R0 $R0 & ${SF_SELECTED}
  StrCmp $R0 ${SF_SELECTED} SelectIndependentSection
 
  SectionGetFlags ${Sec4} $R0
  IntOp $R0 $R0 & ${SF_SELECTED}
  StrCmp $R0 ${SF_SELECTED} SelectIndependentSection
 
  Goto End
 
  UnselectDependentSections:
 
    SectionGetFlags ${Sec3} $R0
    IntOp $R1 $R0 & ${SF_SELECTED}
    StrCmp $R1 ${SF_SELECTED} 0 +3
 
    IntOp $R0 $R0 ^ ${SF_SELECTED}
    SectionSetFlags ${Sec3} $R0
 
    SectionGetFlags ${Sec4} $R0
    IntOp $R1 $R0 & ${SF_SELECTED}
    StrCmp $R1 ${SF_SELECTED} 0 +3
 
    IntOp $R0 $R0 ^ ${SF_SELECTED}
    SectionSetFlags ${Sec4} $R0
 
  End:
 
Pop $R1
Pop $R0
FunctionEnd

-Stu