Search code examples
functionnsis

NSIS call function once time if at least one section is selected


I have a function

Function installDll

...
EndFunction

I have some sections :

  • a
  • b
  • c
  • d
  • e
  • f

I would like call the function installDll once time if at least one of sections { a, b, c, d} is selected.


Solution

  • You could call your function from each concerned section and use a variable as a flag to know if the function has already been called:

    !include "LogicLib.nsh"    ;used for ${if} constructs
    
    Section "A"
        Call installDll
    SectionEnd
    
    Section "B"
        Call installDll
    SectionEnd
    
    Section "C"
        Call installDll
    SectionEnd
    
    Section "D"
        Call installDll
    SectionEnd
    
    Section "Other"
        ;... do not call the function
    SectionEnd
    
    Var instFlag
    Function installDll
    
        ${ifThen} $instFlag = 1 ${|} goto skip ${|}
        StrCpy $instFlag 1
    
        ;... the rest of your function
    
        ;the following label is the last statement of the function
        skip:
    EndFunction