- NSIS Discussion
- Comparing Version numbers
Archive: Comparing Version numbers
RobGrant
3rd November 2004 16:14 UTC
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
RobGrant
3rd November 2004 16:16 UTC
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
RobGrant
3rd November 2004 16:23 UTC
Lifesaver thanks. Sorry I didn't look hard enough I'm bloomin knackered today!
RobGrant
8th November 2004 10:52 UTC
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-
Afrow UK
8th November 2004 17:40 UTC
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
Afrow UK
8th November 2004 18:34 UTC
Ok, here it is. I've tested it a lot and it works perfectly.
http://nsis.sourceforge.net/archive/...b.php?page=643
-Stu
RobGrant
9th November 2004 09:37 UTC
Fantastic, thanks! I'll try it out now.
-rob-
P.S. wow I'm mentioned in the archive I'm famous! :D
RobGrant
23rd November 2004 10:37 UTC
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...:)
RobGrant
23rd November 2004 10:49 UTC
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.
RobGrant
23rd November 2004 11:12 UTC
Equally, http://nsis.sourceforge.net/archive/...nstances=0,110 seems to be incorrect.
kichik
23rd November 2004 19:08 UTC
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.
RobGrant
24th November 2004 12:33 UTC
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.
RobGrant
24th November 2004 12:38 UTC
Updated JDK detection attached.
RobGrant
24th November 2004 12:41 UTC
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.
kichik
25th November 2004 17:24 UTC
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.
RobGrant
26th November 2004 08:38 UTC
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.
kichik
26th November 2004 09:53 UTC
The script you've attached reads the minor version from the JRE and the rest from the JDK.
RobGrant
26th November 2004 10:12 UTC
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...