NSIS multiple if conditions

14.9k Views Asked by At

Can I implement the following C code inside NSIS script?

C code

if ( (value1 == 1) && ((value2 == "text") || (value3 >= 100)) )
  //Do something

NSIS code

${If} $value2 == "text"
${OrIf} $value3 >= 100

But I don't think on the above condition I can add another ${AndIf} statement. Instead I need to do the following:

${If} $value1 == 1
    ${If} $value2 == "text"
    ${OrIf} $value3 >= 100
        //Condition success
    ${EndIf}
${Else}
    //Conditon failed
${EndIf}

Am I correct or is there any better way to do it?

4

There are 4 best solutions below

0
On BEST ANSWER

Combining ${OrIf} and ${AndIf} in one statement will give you undefined results, you need to nest the if statements. I don't know of a better way...

1
On
${If} $value1 == 1
    ${AndIf} $value2 == "text"    ;useAndif
    ${OrIf} $value3 >= 100
        //Condition success
    ${EndIf}
${Else}
    //Conditon failed
${EndIf}
0
On
strcmp $value1 1 0 Error
strcmp $value2 'Text' 0 Error
strcmp $value3 100 Do Do

Try This Code

0
On

;In case a working example helps anyone.

!include LogicLib.nsh

Section testSec
    Var /GLOBAL equalsFive

    StrCpy $equalsFive 5

    Var /GLOBAL equalsSix

    StrCpy $equalsSix 6

    Var /GLOBAL equalsSeven

    StrCpy $equalsSeven 7

    ${If} $equalsFive = 5
        ${AndIf} $equalsSix = 8
            ${OrIf} $equalsSeven = 7
                DetailPrint "OrIf Works"
    ${EndIf}
SectionEnd