|
|
#1 |
|
Senior Member
Join Date: Sep 2004
Location: Nottingham
Posts: 263
|
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 |
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Sep 2004
Location: Nottingham
Posts: 263
|
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 |
|
|
|
|
|
#3 |
|
Moderator
Join Date: Nov 2002
Location: Shropshire, England
Posts: 6,887
|
|
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Sep 2004
Location: Nottingham
Posts: 263
|
Lifesaver thanks. Sorry I didn't look hard enough I'm bloomin knackered today!
|
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Sep 2004
Location: Nottingham
Posts: 263
|
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- |
|
|
|
|
|
#6 |
|
Moderator
Join Date: Nov 2002
Location: Shropshire, England
Posts: 6,887
|
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 |
|
|
|
|
|
#7 |
|
Moderator
Join Date: Nov 2002
Location: Shropshire, England
Posts: 6,887
|
Ok, here it is. I've tested it a lot and it works perfectly.
http://nsis.sourceforge.net/archive/...b.php?page=643 -Stu |
|
|
|
|
|
#8 |
|
Senior Member
Join Date: Sep 2004
Location: Nottingham
Posts: 263
|
Fantastic, thanks! I'll try it out now.
-rob- P.S. wow I'm mentioned in the archive I'm famous!
|
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Sep 2004
Location: Nottingham
Posts: 263
|
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...
|
|
|
|
|
|
#10 |
|
Senior Member
Join Date: Sep 2004
Location: Nottingham
Posts: 263
|
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. Last edited by RobGrant; 23rd November 2004 at 10:14. |
|
|
|
|
|
#11 |
|
Senior Member
Join Date: Sep 2004
Location: Nottingham
Posts: 263
|
Equally, http://nsis.sourceforge.net/archive/...nstances=0,110 seems to be incorrect.
|
|
|
|
|
|
#12 |
|
M.I.A.
[NSIS Dev, Mod] Join Date: Oct 2001
Location: Israel
Posts: 11,310
|
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.
NSIS FAQ | NSIS Home Page | Donate $ "I hear and I forget. I see and I remember. I do and I understand." -- Confucius |
|
|
|
|
|
#13 |
|
Senior Member
Join Date: Sep 2004
Location: Nottingham
Posts: 263
|
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. |
|
|
|
|
|
#14 |
|
Senior Member
Join Date: Sep 2004
Location: Nottingham
Posts: 263
|
Updated JDK detection attached.
|
|
|
|
|
|
#15 |
|
Senior Member
Join Date: Sep 2004
Location: Nottingham
Posts: 263
|
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.
|
|
|
|
|
|
#16 |
|
M.I.A.
[NSIS Dev, Mod] Join Date: Oct 2001
Location: Israel
Posts: 11,310
|
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.
NSIS FAQ | NSIS Home Page | Donate $ "I hear and I forget. I see and I remember. I do and I understand." -- Confucius |
|
|
|
|
|
#17 |
|
Senior Member
Join Date: Sep 2004
Location: Nottingham
Posts: 263
|
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. |
|
|
|
|
|
#18 |
|
M.I.A.
[NSIS Dev, Mod] Join Date: Oct 2001
Location: Israel
Posts: 11,310
|
The script you've attached reads the minor version from the JRE and the rest from the JDK.
NSIS FAQ | NSIS Home Page | Donate $ "I hear and I forget. I see and I remember. I do and I understand." -- Confucius |
|
|
|
|
|
#19 |
|
Senior Member
Join Date: Sep 2004
Location: Nottingham
Posts: 263
|
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...
|
|
|
|
![]() |
|
|||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|