Skip to content
⌘ NSIS Forum Archive

Condition of !if

12 posts

Noude#

Condition of !if

Hello !

Please, I have a problem (again, yes...).
I don't understand why my !if doesn't work !

Look my code:

!define PLUG2 ""
!if ${PLUG2} != ""
IfFileExists     "C:\k3\studies\config\plugins\${PLUG2}" done2
Goto check2
check2:
FindFirst $R0 $R1 "C:\k3\studies\config\plugins\${NAMEPLUG2}*.k3plug"
FindClose $R0
StrCpy $R0 "$R1.BAK"
Rename "C:\k3\studies\config\plugins\$R1" "C:\k3\studies\config\plugins\$R0"
CopyFiles             "$TEMP\${PLUG}\${PLUG2}"     "C:\k3\studies\config\plugins\"
done2:
!endif 
I have this error:

Usage: !if [!] value [(==,!=,<=,<,>,>=,&&,||) value2] [...]
Error in script "C:\Program Files\Veracity local installer\Client installer\Setup.nsi" on line 193 -- aborting creation process 

Please help me ! I really don't know why !
Animaether#
Looks like you can't use defines in the !if check.
Edit: Wrong - read below %)

It's likely that you could use a regular !ifdef or !ifndef instead, defining or -not- defining PLUG2 as appropriate.
Noude#
I don't think because this code works:

!define BOOL_PLUGINS 1
!if ${BOOL_PLUGINS} == 1
SetOutPath    $TEMP
File    /r    "${DIRPLUGINS}\*.*" 
So I can use define in a !if (I think 0_o)
Netsurfer24#
Originally Posted by Animaether View Post
Looks like you can't use defines in the !if check.
I guess the problem is that the define has no value ("").
BTW: What's the sense of defining a constant which has no value?

It's likely that you could use a regular !ifdef or !ifndef instead, defining or -not- defining PLUG2 as appropriate.
AFAIK there are the following options:
If there is no value => do not define a constant and use !ifdef | !ifndef
Use a variable instead of a constant and use !if | !if !

Gunther
Animaether#
oh, silly me -_-

The `!define PLUG2 ""` literally defines PLUG2 as ... zilch, nothing, nada..

So when you use `!if ${PLUG2} != ""`, it's parsing that as `!if != ""`, rather than `!if "" != ""`. You'd have to define it as '""' or something silly like that.
Why not use !ifdef/!ifndef, though?
Noude#
My define is here for a good reason,

This define can be equal to "" or to a string following the procedure in my previous code.

"" -> is for me a null string
Noude#
ooooooooooooooh ! Okay ! =) it doesn't look like C ! =)

Ok I'll try with !ifdef/!ifndef, I don't know how to use these "things" but I will try ^^
Animaether#
If PLUG2 is programmatically defined, then you could use single quotes around the tests instead?

!define PLUG2 ""

!if '${PLUG2}' != ''
!endif
Noude#
You know why ?

I will cheat ! :0 yes !

!define PLUG2 "null"
!if ${PLUG2} != "null"
IfFileExists     "C:\k3\studies\config\plugins\${PLUG2}" done2
Goto check2
check2:
FindFirst $R0 $R1 "C:\k3\studies\config\plugins\${NAMEPLUG2}*.k3plug"
FindClose $R0
StrCpy $R0 "$R1.BAK"
Rename "C:\k3\studies\config\plugins\$R1" "C:\k3\studies\config\plugins\$R0"
CopyFiles             "$TEMP\${PLUG}\${PLUG2}"     "C:\k3\studies\config\plugins\"
done2:
!endif 
That will work for the moment...
Noude#
YEAAAAAAH ! =) =) =)

Thanks Animaether !

The code:

!define PLUG2 ""
!if '${PLUG2}' != '""'
IfFileExists     "C:\k3\studies\config\plugins\${PLUG2}" done2
Goto check2
check2:
FindFirst $R0 $R1 "C:\k3\studies\config\plugins\${NAMEPLUG2}*.k3plug"
FindClose $R0
StrCpy $R0 "$R1.BAK"
Rename "C:\k3\studies\config\plugins\$R1" "C:\k3\studies\config\plugins\$R0"
CopyFiles             "$TEMP\${PLUG}\${PLUG2}"     "C:\k3\studies\config\plugins\"
done2:
!endif 
Thanks !