KoKa
KoKa

Reputation: 817

NSIS conditional statement

I am writing a script code which installs 3 drivers. Every time that a driver is installed I get a return code of '256' or '1' if the installation was successful, or a different return code if the installation failed. I need to check that all installations finished sucessfully, so I use the following code:

${If} "$2" == "1" ${OrIf} "$1" == "256" ${AndIf} "$2" == "256" ${OrIf} "$2" == "1" ${AndIf} "$3" == "256" ${OrIf} "$3" == "1" MessageBox MB_OK "Installation was successful!" ${Else} MessageBox MB_OK "Sorry, an error occurred during installation." ${EndIf}

Even if a driver installation fails I receive the message "Installation was successful!". Could someone help me find the mistake in the above code?

Upvotes: 2

Views: 6640

Answers (2)

fakedrake
fakedrake

Reputation: 6856

A slightly slimpler way would be to do something like

; 1_256_1_256 is defined if we are good
!define $1_256_$2_256
!define $1_256_1_$2
!define 1_$1_1_$2
!define 1_$1_$2_256


!ifdef 1_256_1_256
   message mb_ok "All good"
!else
   message mb_ok "Failure detected"
!endif

Upvotes: -1

Anders
Anders

Reputation: 101736

In your example code the first ${If} is using $2 when it should probably check $1.

I don't think you should use OrIf and AndIf in the same if block like this, the results are probably undefined.

It is also possible to write your own custom LogicLib operators:

!include LogicLib.nsh
!macro _MyCheckExitcodeSuccess _a _b _t _f
    !if `${_f}` == ``
        !undef _f
        !define _f +2 
    !endif
    IntCmp ${_b} 1 +2
    IntCmp ${_b} 256 `${_t}` `${_f}` `${_f}`
    !if `${_t}` != ``
        Goto `${_t}`
    !endif
!macroend
!define MyCheckExitcodeSuccess `"" MyCheckExitcodeSuccess`

StrCpy $1 1
StrCpy $2 256
${If} ${MyCheckExitcodeSuccess} $1
${AndIf} ${MyCheckExitcodeSuccess} $2
    MessageBox mb_ok "All OK"
${Else}
    MessageBox mb_ok "Something failed"
${EndIf}

Upvotes: 4

Related Questions