SetSectionInInstType, ClearSectionInInstType

From NSIS Wiki
Jump to navigationJump to search
Author: Datenbert (talk, contrib)


Description

These are two macros you can use to set a Section in an InstType or clear it from an InstType. The macros and defines are included in Sections.nsh

Usage

  !insertmacro SetSectionInInstType   "${section_name}" "${INSTTYPE_X}"
  !insertmacro ClearSectionInInstType "${section_name}" "${INSTTYPE_X}"

The Script

Please find an example below the following code.

; The defines for more than 8 installation types are included in
; Sections.nsh
 
!define INSTTYPE_1 1
!define INSTTYPE_2 2
!define INSTTYPE_3 4
!define INSTTYPE_4 8
!define INSTTYPE_5 16
!define INSTTYPE_6 32
!define INSTTYPE_7 64
!define INSTTYPE_8 128
 
!macro SetSectionInInstType SECTION_NAME WANTED_INSTTYPE
	Push $0
	SectionGetInstTypes "${SECTION_NAME}" $0
	IntOp $0 $0 | ${WANTED_INSTTYPE}
	SectionSetInstTypes "${SECTION_NAME}" $0
	Pop $0
!macroend
 
!macro ClearSectionInInstType SECTION_NAME WANTED_INSTTYPE
	Push $0
	Push $1
	SectionGetInstTypes "${SECTION_NAME}" $0
	StrCpy $1 ${WANTED_INSTTYPE}
	IntOp $1 $1 ~
	IntOp $0 $0 & $1
	SectionSetInstTypes "${SECTION_NAME}" $0
	Pop $1
	Pop $0
!macroend

Example

Assume we have created four InstTypes:

  !ifndef NOINSTTYPES # allow user to switch the usage of InstTypes
    InstType "Full"                   # This is INSTTYPE_1
    InstType "Typical"                # INSTTYPE_2
    InstType "Needed on this system"  # INSTTYPE_3
    InstType "None"                   # guess what? INSTTYPE_4!
  !endif

Furtheron we have three Sections "webserver", "database" and "source" - see a sample Definition for the first one:

  Section "Super Webserver" webserver
    [...codecodecode...]
  SectionEnd

The other sections are defined similar. This way, each section can be adressed by using ${section_name}.

To set section "webserver" in InstType "Needed on this system", you'd only have to insert this line anywhere you need it in your code:

  !insertmacro SetSectionInInstType   "${webserver}" "${INSTTYPE_3}"

To clear for example section "source" from InstType "Typical", you'd use this:

  !insertmacro ClearSectionInInstType   "${source}" "${INSTTYPE_2}"

Contact

You may contact me via my homepage http://robertkehl.de/ if you feel you should.

Have fun using your NSIS,

Robert Kehl