Archive: Comparing Version numbers


Comparing Version numbers
I want to compare two version numbers (e.g. 1.5 compared to 1.5.1). Easiest way to do that would seem to be to simply strip out the .s (giving 15 vs 151) then compare the two as integers.

How do I strip out the .s?

Thanks!

Rob


Bearing in mind the two numbers have to be the same length before I can do that, of course...:) 16 vs 151 (1.6 vs 1.5.1) is not a planned alternative :)

In fact if any other solutions spring to mind they'd be helpfully received, thanks!

Rob


http://nsis.sourceforge.net/archive/nsisweb.php?page=34

-Stu


Lifesaver thanks. Sorry I didn't look hard enough I'm bloomin knackered today!


Also, I've just found that it thinks that version 6 is a lower version than version 6.0. That's not the most helpful behaviour in the world, and unfortunately I don't have the scripting skill to change it myself...can anyone help?

Cheers

-rob-


The code looks bad, and I know of a better way to do version comparisons which would definately always work.

Let me write you a function, will take maybe an hour at most.

-Stu


Ok, here it is. I've tested it a lot and it works perfectly.

http://nsis.sourceforge.net/archive/...b.php?page=643

-Stu


Fantastic, thanks! I'll try it out now.

-rob-

P.S. wow I'm mentioned in the archive I'm famous! :D


P.S. guys just so's you know, if you want to detect the Java version number you have to:
a) Look under HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment\CurrentVersion
b) Take that previous value, look under the subkey of the same name and append to said value the value of "MicroVersion" under that subkey.

E.g. HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment\CurrentVersion is "1.4"

So look for HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment\CurrentVersion\1.4\MicroVersion, say that is 1.

So the actual version of the current Java install is 1.4.1, NOT 1.4!

Just thought that might help someone at some point...:)


And that behaviour is documented here: http://java.sun.com/j2se/1.3/runtime_win32.html.

This info also applies to the JDK, so someone might wanna update the "Detecting the JDK version" archive docs (http://nsis.sourceforge.net/archive/...nstances=0,110.


Equally, http://nsis.sourceforge.net/archive/...nstances=0,110 seems to be incorrect.


JDK is not the same as JRE. The first Archive page does what it says it does. I haven't looked at the second one.


I agree that JDK isn't the same as JRE, hence my mentioning them separately. The archive page says that it will set $1 to the current version, which it does not currently do properly.

Sorry for any inconvenience caused by me pointing this stuff out, thought it might help.


Updated JDK detection attached.


I can update the Runtime one as well (which currently kinda does it right but in a slightly roundabout way) using the proper version number comparison (so 1.4 = 1.4.0 etc), if you like.


I don't think it's a good idea to append the minor version of the JRE to the JDK. As for the second example, you can create your own Archive page that uses the registry to get the version. Everyone can create an Archive page.


OK, that sounds cool, I'll make an archive page if/when I get some time.

Also I am of course talking about the JDK Microversion Registry entry, not the JRE Microversion.

E.g. on this machine HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\CurrentVersion is 1.4, and HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\1.4\Microversion is 2.

So the JDK version is 1.4.2. Incidentally the JRE version on here is 1.5.0.


The script you've attached reads the minor version from the JRE and the rest from the JDK.


Fair play, didn't notice that cos I adapted it from another script. The overall point I was making was not that specifically my script should be used but that the archive page should be changed...