Search code examples
nsis

NSIS - Use offset with combination of !insertmacro


I was forced to use labels in my installer like this:

  IfFileExists "$INSTDIR\XX\*.*" XX_Found 0
      !insertmacro UnselectSection ${Section_XX}
  XX_Found:

  IfFileExists "$INSTDIR\YY\*.*" YY_Found 0
      !insertmacro UnselectSection ${Section_YY}
  YY_Found:

because these does not work:

  IfFileExists "$INSTDIR\XX\*.*" +2 0
      !insertmacro UnselectSection ${Section_XX}

  IfFileExists "$INSTDIR\YY\*.*" +2 0
      !insertmacro UnselectSection ${Section_YY}

Any proposal why? I think its because of !insertmacro statement but i could not find any information or workaround on the internet.


Solution

  • You cannot use relative jumps on macros because a macro can contain more than one instruction. !insertmacro basically pastes the content of the !macro into your code during the first compiler phase.

    I prefer using the LogicLib:

    !include LogicLib.nsh
    Section
    ${If} ${FileExists} "$InstDir\file.ext"
      !insertmacro ...
    ${EndIf}
    SectionEnd
    

    You can also use labels to jump over !insertmacro.