Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Version comparison in NSIS installer

Tags:

nsis

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.50245with 3.2.1.50245 (or if I compare 50245and 40256 etc.)

like image 421
skm Avatar asked Jan 10 '17 16:01

skm


1 Answers

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

like image 110
Damian Avatar answered Oct 22 '22 01:10

Damian