- NSIS Discussion
- Condition of !if
Archive: Condition of !if
Noude
18th August 2010 13:50 UTC
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 ***91;!***93; value ***91;(==,!=,<=,<,>,>=,&&,||) value2***93; ***91;...***93;
>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
18th August 2010 13:59 UTC
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
18th August 2010 14:03 UTC
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
18th August 2010 14:07 UTC
Originally posted by Animaether
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
18th August 2010 14:09 UTC
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
18th August 2010 14:10 UTC
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
18th August 2010 14:13 UTC
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 ^^
Noude
18th August 2010 14:18 UTC
No... it doesn't work...
error is:
!ifdef expects 1+ parameters, got 0.
Animaether
18th August 2010 14:22 UTC
If PLUG2 is programmatically defined, then you could use single quotes around the tests instead?
!define PLUG2 ""
!if '${PLUG2}' != ''
!endif
Noude
18th August 2010 14:23 UTC
You know why ?
I will cheat ! :0 yes !
"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
18th August 2010 14:24 UTC
yes I will try ^^ wait a second :)
Noude
18th August 2010 14:27 UTC
YEAAAAAAH ! =) =) =)
Thanks Animaether !
The code:
""
>!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 !