Paul van Dison
Paul van Dison

Reputation: 3

Behavior of StrCmp in NSIS. Can we compare "" with other strings?

Can we compare zero string ("") and non-zero string (for example, "foo") with StrCmp in NSIS?

When I update application with my NSIS installer, I wanna remove links of previously installed release version. Also, I wanna remove links when I uninstall application. To avoid code duplication, I wrote next macro:

!macro Delete_Links un
        MessageBox MB_OK "Previous version is: $PVN and p1 is: ${un}"
        StrCmp ${un} "un." 0 +2 
            StrCpy $PVN ${VERSION_INFO}
        Delete "$SMPROGRAMS\${APP_NAME}\${APP_NAME} $PVN.lnk"
        ; ...
!macroend

Here $PVN is variable which contains number of previous installed release version number (as string) and ${VERSION_INFO} is a current release version number (as string too).

Code works correctly, if I call it with non-zero parameter un, for example, i can invoke macro in uninstaller section as:

!insertmacro Delete_Links ".un"

And in installer section as:

!insertmacro Delete_Links ".in"

But if I pass to macro zero string

!insertmacro Delete_Links ""

StrCmp in macro doesn't make relative jump +2 to

Delete "$SMPROGRAMS\${APP_NAME}\${APP_NAME} $PVN.lnk"

and execute next instruction

StrCmp ${un} "un." 0 +2

which isn't expected behavior.

But i've checked, (${un} == "") and ("" != ".un"). What's wrong with this code?

Upvotes: 0

Views: 1340

Answers (1)

Anders
Anders

Reputation: 101666

!insertmacro will eat the quotes so when the parameter is "" you actually end up executing StrCmp "un." 0 +2 in the macro and "un." is never equal to "0"!

You need to quote the macro parameter when using it: StrCmp "${un}" "un." 0 +2

Upvotes: 1

Related Questions