I have to compare the versions of current file and already the installed in NSIS installer. I understand the version numbers are in string but I read at couple of places that the NSIS automaticaly converts the strings to intergers if needed in logic operations.
Just for the test purpose, I wrote the following script:
Var Test1
Var Test2
section
StrCpy $Test1 "4.3.1.50245"
StrCpy $Test2 "4.2.1.50245"
${If} $Test1 > $Test2
MessageBox MB_ICONSTOP "$Test1 is bigger than $Test2"
${Else}
MessageBox MB_ICONSTOP "$Test2 is bigger than $Test1"
${EndIf}
Quit
sectionEnd
PROBLEM: It gives me the result 4.2.1.50245
is greated than 4.3.1.50245
. However, it gives me correct results if I try to compare 4.2.1.50245
with 3.2.1.50245
(or if I compare 50245
and 40256
etc.)
Check out the following function, Version Compare http://nsis.sourceforge.net/VersionCompare
Section
${VersionCompare} "1.1.1.9" "1.1.1.01" $R0
; $R0="1"
SectionEnd
; Result:
; $var=0 Versions are equal
; $var=1 Version1 is newer
; $var=2 Version2 is newer
If not, another method would be to implement an Explode of the string and then compare the Major, Minor, Revision, ... portions. But that may be overkill: http://nsis.sourceforge.net/Explode
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With