Archive: Relative jumps


Relative jumps
Suppose you have a macro that consists of 5 lines.

You do a

IfFileExists "$ApplicationDir\${MY_DIR}\${MY_EXE}" 0 +1
!insertmacro UnselectSection ${MySec}


I don't think will work because the macro is expanded into 5 lines. The +1 will jump into the middle of the macro code.

Other than using a label for the jump, is there a way around this?

I have about 7-8 lines od code that need this logic and didn't want to use a lot of labels.

u could do:

function UnselectSectionFunc
!insertmacro UnselectSection ${MySec}
functionend

IfFileExists "$ApplicationDir\${MY_DIR}\${MY_EXE}" 0 +1
call UnselectSectionFunc


First of all it should be +2 instead of +1 to jump over the next line.

Second, you should use a label when jumping over macros. A function won't help if you have to insert a macro multiple times with different parameters.


I'm thinking of going with something like this for now.


!macro SetSection SectionName FileToCheck
!insertmacro SelectSection ${SectionName}
IfFileExists ${FileToCheck} 0 Skip${SectionName}
!insertmacro UnselectSection ${SectionName}
Skip${SectionName}:
!macroend

Another option is LogicLib, which hopefully makes scripts more readable:

!include LogicLib.nsh

...

${If} ${FileExists} "$ApplicationDir\${MY_DIR}\${MY_EXE}"
!insertmacro UnselectSection ${MySec}
${EndIf}