6

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?

hypheni
  • 756
  • 3
  • 17
  • 37

4 Answers4

6

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...

Anders
  • 97,548
  • 12
  • 110
  • 164
3

;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
vbp13
  • 1,040
  • 1
  • 10
  • 20
1
${If} $value1 == 1
    ${AndIf} $value2 == "text"    ;useAndif
    ${OrIf} $value3 >= 100
        //Condition success
    ${EndIf}
${Else}
    //Conditon failed
${EndIf}
buluw
  • 19
  • 1
  • 3
    Welcome to StackOverflow, please add some context/information to your answer and prevent posting code only answers. – Chris Oct 05 '20 at 15:00
0
strcmp $value1 1 0 Error
strcmp $value2 'Text' 0 Error
strcmp $value3 100 Do Do

Try This Code