Jump to content
Sign in to follow this  
ModemJunki

Checking software version numbers

Recommended Posts

ModemJunki

Never mind - changing the keywords I used to search means the answer was already existing - I will try this after I have some lunch.

'?do=embed' frameborder='0' data-embedContent>>

 

Hi all,

A very noobish question, this is not working for me and I'm <easily> confused.

I am remotely checking systems for a software version so that I can update the system (or prompt the user to update) if it is needed. The version to check against is in an INI file.

I thought the right way was to use _WinAPI_FloatToInt() for each value then compare them to assure the checked value is either equal to or greater than the expected value.

But the below does not work - it will return that 10.5 is greater than 10.5.2295 - so it's clear my inexperience is the problem (it even returns that 10.5.0000 is greater than 10.5.2295). What do I need to do to make the tool recognize the full decimal number? Note that sometimes the versions are actually seen as "xx.x" and others they are seen as "xx.xx.x" or "xx.xx.xxxx".

Do I somehow need to "pad" each part of the string out if it's too short in order for the compare to work (and not use _WinAPI_FloatToInt())?

If you know the answer please don't fix the code - instead tell me what I need to learn about to do this, if I get really stuck I will come back and ask for more help.

#include <winapi.au3>

$remtver = "10.5" ; lets say this is the remote system registry value
$s_MinVer = "10.5.2295" ;  The expected minimum

$Check1 = _WinAPI_FloatToInt($remtver)
$Check2 = _WinAPI_FloatToInt($s_MinVer)

Select
    Case $Check1 >= $Check2
        MsgBox(4096, "Pass", $remtver & " is greater than " & $s_MinVer)
    Case Else
        MsgBox(4096, "Fail", $remtver & " is less than " & $s_MinVer)
EndSelect
Edited by ModemJunki

Always carry a towel.

Share this post


Link to post
Share on other sites
ModemJunki

Thanks, Jos! I'm such a noob. If I had searched the help for "version" it would have been visible to me as well. :idiot:


Always carry a towel.

Share this post


Link to post
Share on other sites
ModemJunki

Hmm.. still not working right.

If I am comparing 10.5.23 against 10.5.2295, both _VersionCompare and the UDF found tell me that 10.5.23 is < 10.5.2295.


Always carry a towel.

Share this post


Link to post
Share on other sites
Melba23

ModemJunki,

it looks as if the function is being fooled by the lack of padding 0's in the .23 string. The Help file does say that the function tries a numerical comparison first - and "23" is definitely less than "2295" so it assumes the latter is the more recent version. If you add the padding then the result is what you would expect. :)

I will look at the function and see if it could be improved to prevent this happening - possibly by forcing the comparison type. ;)

M23

Edit:

Looks like a fairly simple fix: :)

$sVersion1 = "10.5.23"
$sVersion2 = "10.5.2295"

ConsoleWrite(_VersionCompare($sVersion1, $sVersion2) & " - " & @extended & @CRLF)

$sVersion1 = "10.5.2300"
$sVersion2 = "10.5.2295"

ConsoleWrite(_VersionCompare($sVersion1, $sVersion2) & " - " & @extended & @CRLF)

Func _VersionCompare($sVersion1, $sVersion2)
    If $sVersion1 = $sVersion2 Then Return 0
    Local $aVersion1 = StringSplit($sVersion1, ".,"), _
          $aVersion2 = StringSplit($sVersion2, ".,")
    If UBound($aVersion1) <> UBound($aVersion2) Or UBound($aVersion1) = 0 Then
        ; Compare as Strings
        If $sVersion1 > $sVersion2 Then
            Return SetExtended(1, 1) ; @extended set to 1 for string comparison.
        ElseIf $sVersion1 < $sVersion2 Then
            Return SetExtended(1, -1) ; @extended set to 1 for string comparison.
        EndIf
    Else
        For $i = 1 To UBound($aVersion1) - 1
            ; Compare this segment as numbers
            If StringIsDigit($aVersion1[$i]) And StringIsDigit($aVersion2[$i]) And _
               StringLen($aVersion1[$i]) = StringLen($aVersion2[$i]) Then ; <<<<<<<<<<<<<<<<<<<<<<
                If Number($aVersion1[$i]) > Number($aVersion2[$i]) Then
                    Return SetExtended(2, 1) ; @extended set to 2 for number comparison.
                ElseIf Number($aVersion1[$i]) < Number($aVersion2[$i]) Then
                    Return SetExtended(2, -1) ; @extended set to 2 for number comparison.
                EndIf
            Else ; Compare the segment as strings
                If $aVersion1[$i] > $aVersion2[$i] Then
                    Return SetExtended(1, 1) ; @extended set to 1 for string comparison.
                ElseIf $aVersion1[$i] < $aVersion2[$i] Then
                    Return SetExtended(1, -1) ; @extended set to 1 for string comparison.
                EndIf
            EndIf
        Next
    EndIf
    ; This point should never be reached
    Return SetError(2, 0, 0)
EndFunc   ;==>_VersionCompare
I will test some more and see how it fares with other version numbering systems. :) Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
ModemJunki

For version-checking, the results from the current UDF don't work out. The below example will report that 10.5.23 is lower version than 10.5.2295.

As a numeric expression it's correct to say that, but as a software version it's not because version "23" is really meaning version "2300", but most softwares don't express the versions with trailing zeros (certainly not the one I'm checking, which is a Trend Micro product). This is I think a widespread practice, even if it's a "bad habit". :mellow:

If I use the modified function from Melba it works fine.

#include <Misc.au3>

$remtver = '10.5.23' ; lets say this is the remote system registry value
$s_MinVer = '10.5.2295' ;  The expected minimum

$VerComp = _VersionCompare($s_MinVer, $remtver)

Select
    Case $VerComp = 0 Or $VerComp = -1
        MsgBox(4096, "Pass", $remtver & " is equal to or greater than " & $s_MinVer)
    Case Else
        MsgBox(4096, "Fail", $remtver & " is less than " & $s_MinVer)
EndSelect

Always carry a towel.

Share this post


Link to post
Share on other sites
BrewManNH

Change $sVersion 1 to another value and you'll see that the results are wrong.

$sVersion1 = "10.5.9"
$sVersion2 = "10.5.10"

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Melba23

ModemJunki,

The fix I initially proposed is not valid in all cases, as shown by BrewManNH above. I am already looking at other possible solutions, but given the huge range of possible mismatches I am not very optimistic - it may be that returning "unresolvable" when there is a possibility of confusion might be the least bad option. :(

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
ModemJunki

I do see that this possibly not solvable due to version numbering having no accepted standard.

E.g., in theory any of the below could mean the same thing.

10.5.9

10.05.09

10.005.009

So for each case a different method would be needed to interpret the numbering.


Always carry a towel.

Share this post


Link to post
Share on other sites
jchd

For version 10.5.2295 to be < 10.5.23 it needs to be 10.5.22.95 else nothing makes sense.

Moral: version "strings" need to strictly adhere to a fixed set of rules.

  • Like 1

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
Melba23

ModemJunki and anyone reading,

I have been playing around with the function for most of the afternoon and I cannot come up with any sensible logic to get a valid return in all 3 of the cases discussed above - let alone any others. As I suggested earlier, I feel the best that can be done is to get the function to return "unresolved" if there is a length mismatch between the version numbers or segments thereof - look for the <<<<<<<< lines:

#include <Misc.au3>

$sVersion1 = "10.5.2300"
$sVersion2 = "10.5.2295"
ConsoleWrite($sVersion1 & " - " & $sVersion2 & @CRLF)
ConsoleWrite("Return: " & _VersionCompare($sVersion1, $sVersion2) & " - " & @extended & @CRLF)
ConsoleWrite("Return: " & _VersionCompare_Mod($sVersion1, $sVersion2) & " - " & @extended & @CRLF & @CRLF)

$sVersion1 = "10.5.23"
$sVersion2 = "10.5.2295"
ConsoleWrite($sVersion1 & " - " & $sVersion2 & @CRLF)
ConsoleWrite("Return: " & _VersionCompare($sVersion1, $sVersion2) & " - " & @extended & @CRLF)
ConsoleWrite("Return: " & _VersionCompare_Mod($sVersion1, $sVersion2) & " - " & @extended & @CRLF & @CRLF)

$sVersion1 = "10.5.9"
$sVersion2 = "10.5.10"
ConsoleWrite($sVersion1 & " - " & $sVersion2 & @CRLF)
ConsoleWrite("Return: " & _VersionCompare($sVersion1, $sVersion2) & " - " & @extended & @CRLF)
ConsoleWrite("Return: " & _VersionCompare_Mod($sVersion1, $sVersion2) & " - " & @extended & @CRLF & @CRLF)

Func _VersionCompare_Mod($sVersion1, $sVersion2)
    ; Identical strings
    If $sVersion1 = $sVersion2 Then Return 0
    ; Split on standard delimiters
    Local $aVersion1 = StringSplit($sVersion1, ".,"), $aVersion2 = StringSplit($sVersion2, ".,")
    ; If dissimilar number of segments - return error (unresolvable)
    If $aVersion1[0] <> $aVersion2[0] Then Return SetError(1, 0, 99) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    ; If no delimiters found in one of the strings
    If $aVersion1[0] = 1 Or $aVersion2[0] = 1 Then
        ; If strings not same length then return error (unresolvable)
        If StringLen($sVersion1) <> StringLen($sVersion2) Then Return SetError(1, 0, 99) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        ; Compare as complete strings
        If $sVersion1 > $sVersion2 Then
            Return SetExtended(1, 1) ; @extended set to 1 for string comparison.
        ElseIf $sVersion1 < $sVersion2 Then
            Return SetExtended(1, -1) ; @extended set to 1 for string comparison.
        EndIf
    Else
        For $i = 1 To $aVersion1[0]
            ; If segments not same length then return error (unresolvable)
            If StringLen($aVersion1[$i]) <> StringLen($aVersion2[$i]) Then Return SetError(1, 0, 99) ; <<<<<<<<<<<<<<<<<<<<<<<<
            ; If both segments are digits
            If StringIsDigit($aVersion1[$i]) And StringIsDigit($aVersion2[$i]) Then
                ; Compare as numeric
                If Number($aVersion1[$i]) > Number($aVersion2[$i]) Then
                    Return SetExtended(2, 1) ; @extended set to 2 for number comparison.
                ElseIf Number($aVersion1[$i]) < Number($aVersion2[$i]) Then
                    Return SetExtended(2, -1) ; @extended set to 2 for number comparison.
                EndIf
            Else
                ; Compare as strings
                If $aVersion1[$i] > $aVersion2[$i] Then
                    Return SetExtended(1, 1) ; @extended set to 1 for string comparison.
                ElseIf $aVersion1[$i] < $aVersion2[$i] Then
                    Return SetExtended(1, -1) ; @extended set to 1 for string comparison.
                EndIf
            EndIf
        Next
    EndIf
    ; This point should never be reached
    Return SetError(2, 0, 99)
EndFunc   ;==>_VersionCompare_Mod
I gave some thought to checking if the smaller number segment ended in 9 as an exception which would allow the 9:10 comparison to return correctly, but thought it would overly complicate the function.

Comments? :huh:

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
BrewManNH

Personally, unless the current function isn't working correctly, I say leave it as-is. The comparison ModemJunki posted is not a valid comparison, and just because the software company doesn't know how to count is no indication that the function isn't working as expected. 23, as has been stated several times, IS less than 2295 and no amount of pretending it isn't, isn't going to make any difference.

You can't return unresolvable for unmatched lengths of version/subversion numbers, because 9 is clearly less than 10, and is clearly not the same length as 10.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
jchd

Was composing essentially what BrewManNH said.

Also a large number of software products have had versions with "spurious" appended increments to version strings, often to denote important bug fixes releases which don't fit the planned normal release schedule.

An easy example of this use of extra level is SQLite recent release history:

3.8.4.1

3.8.4

3.8.3.1

3.8.3

3.8.2

3.8.1

3.8.0.2

3.8.0.1

3.8.0

...

What I've never seen is version 10.5.22.95 being coded 10.5.2295: that defeats automatic comparison.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
ModemJunki

What I've never seen is version 10.5.22.95 being coded 10.5.2295: that defeats automatic comparison.

 

What I'm trying to check for is compounded by the concept that some of their version numbers could be expressed as "xx.x" or "xxxx" as well as the "xx.xx.xx" and "xx.xx.xxxx" schemas.

Behold!

post-46720-0-67277600-1395769556_thumb.p

On the other hand I'm kind of glad it isn't just me being a noob.... :blink:


Always carry a towel.

Share this post


Link to post
Share on other sites
Jos

I would think the current results returned by the UDF are correct. as 23 is clearly less than 2297.

Jos

Still agree with myself on this one. Each of the 4 sections in the version number need to be compared numerically as far as I understand.   ;)


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
BrewManNH

The problem is compounded by the fact that it appears that Trend has no clue whatsoever as to how to version software. I was doing some research on their site and the documentation is all over the place as to how to read the version number as they don't use a consistent numbering scheme for anything. Each one has it's own it looks like.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Melba23

OK,

I am convinced! Let us leave the function as it is. :D

M23

  • Like 1

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×