Skip to content
⌘ NSIS Forum Archive

NSIS Logic Library

43 posts

Animaether#
besides what Afrow said - yes, that'd be correct 🙂
'd still go with what Afrow said, though 😁
phunkydizco#
Originally posted by Afrow UK
You can just use the ${If} ${SectionIsSelected} ... ${OrIf} ${SectionIsSelected} ...

Stu
That is not a good idea. Because with your code I have to copy my "Do Something" code twice.

${Unless} $R0 <> $R1
${OrUnless} $R2 <> $R3
Do Something
${EndUnless}

This seems to work and is very short.
Afrow UK#
Why?

${If} ${SectionIsSelected} ${SEC02}
${OrIf} ${SectionIsSelected} ${SEC03}
...
${EndIf}

Stu
Afrow UK#
It may work but the proper logic is to check if ${SF_SELECTED} (1) is set:

SectionGetFlags ${SEC02} $R0
IntOp $R0 $R0 & ${SF_SELECTED}
${If} $R0 != 0
...

This is what ${If} ${SectionIsSelected} ${SEC02} would be doing internally.

Stu
o___O#
There's a replacement macro for ${FileExists} in the Wiki, but it doesn't work with ${IfNot} or ${Unless}.



FileExists

The ${FileExists} condition included in LogicLib will evaluate to true if what exists is actually a directory. I suggest you add the following macros to your script (right after including LogicLib.nsh):
!macro _FileExists2 _a _b _t _f
StrCmp `${_b}` `` `${_f}` 0
IfFileExists `${_b}` `0` `${_f}` ;returns true if this is a directory
IfFileExists `${_b}\*.*` `${_f}` `${_t}` ;so if it is a directory, jump to false
!macroend
!undef FileExists
!define FileExists `"" FileExists2`
!macro _DirExists _a _b _t _f
StrCmp `${_b}` `` `${_f}` 0
IfFileExists `${_b}\*.*` `${_t}` `${_f}`
!macroend
!define DirExists `"" DirExists`

Then you can use ${If} ${FileExists} and ${If} ${DirExists}.
In my script if I use:

${If} ${FileExists} <path> and it exists, it will perform.

However, if I use:

${IfNot} ${FileExists} <path> and the file doesn't exist, it won't perform.

I deleted the FileExists2 macro code from my script and returned to the one included in LogicLib.nsh and it works correctly again.
MSG#
There's no need for a new macro. You can simply use ${If} ${FileExists} $YourFile ${AndIfNot} ${FileExists} "$YourFile\*.*" .
o___O#
I know that but the code in the LogicLib Wiki (which is the official entry for LogicLib and makes the recommendation, actually - and links to this thread) doesn't work. It's weird that it doesn't work actually, FileExists2 is nearly identical to the old one, it looks like it should work the same except for returning false on directories.

Original:
!macro _FileExists _a _b _t _f
        IfFileExists `${_b}` `${_t}` `${_f}`
!macroend
!define FileExists `"" FileExists` 
FileExists2 (slightly edited version)
!macro _FileExists2 _a _b _t _f
    IfFileExists `${_b}` `0` `${_f}` ;continues if something exists, returns false if not
    IfFileExists `${_b}\*.*` `${_f}` `${_t}` ;so if it is a directory, jump to false - else return true
!macroend
!define FileExists2 `"" FileExists2` 

Wonder why it doesn't work?
MSG#
Ah, my bad for not reading your post completely. I've reverted the wiki entry.


Edit: As for why it doesn't work, not sure, I'm not that pro with preprocessor magic. But his/her 'suggested' code, even if it were working, changes LogicLib in a way that breaks backwards compatibility. It is therefore a big no-no. Also, if he/she wants to change logiclib, he/she should submit a patch for logiclib.nsh, not start messing around with the wiki page and advising people to do bad things.
o___O#
I guess that's true, but they didn't advise modifying LogicLib.nsh - the code goes inside your .nsi right after LogicLib.nsh is included and merely replaces the functionality of LogicLib. It goes after LogicLib so it doesn't override the new macro. The information about FileExists returning true for directories is a useful addition to the Wiki but the provided solution just doesn't work with IfNot or Unless...
jiake#
I thought a problem must be correct: Switch... Case... EndSwitch is used to detect the numeric value of the variable. But once I use it, I found in fact it can't be used to compare numbers. Such as I have defined a hexadecimal notification code 0x0300, if it is used to compile with a decimal number returned by NSIS, of course, they undoubtedly are not equal. Actually, I found that Switch and Case are only used in mathematical expression but not a string. So I modify the header, use the macro "_=" to replace with the original "_==". But I still advice official developtors to modify this.