Archive: Comparing version numbers of OCX's?


Comparing version numbers of OCX's?
Hi,

I'm using a 98 host to check whether the user already has a given OCX. If not, I'll just download and register it; If the file is already present, I'll compare its version number with the one given in an INI located on the server : If the OCX on the server is more recent, we download and register; If the one on the host is more recent, we leave it as is, and go to end.

Thing is... it doesn't work. Incidently, the version number of an OCX isn't formatted exactly the same on 98 and W2K, but I suspect the reason why this script doesn't work is that IntCmpU is unable to compare numbers like "1.2.3.4".

Here's the INI that my NSIS scripts downloads and reads to get the version number of the OCX on the server, before comparing it with the one already on the host:


;VERSION.INI
[mscomctl]
;BAD? mscomctl.ocx=6.01.9545
mscomctl.ocx=6.1.95.45

========================

;SETUP.NSI

# Input: $1 = name of file, $2 = full destination path on host, $9 = version or size on www, $3 = URL to path on www
Function CheckFile
IfFileExists $2 checkversion
Call Download
Goto register

checkversion:
GetDllVersion "$2" $R0 $R1
IntOp $R2 $R0 / 0x00010000
IntOp $R3 $R0 & 0x0000FFFF
IntOp $R4 $R1 / 0x00010000
IntOp $R5 $R1 & 0x0000FFFF
StrCpy $R8 "$R2.$R3.$R4.$R5"

;If version on host the same or more recent than one on www, go to end; else, download
DetailPrint "www=$9 local=$R8"
IntCmpU $9 $R8 end end 0
Call Download
Goto register

register:
RegDLL "$2"

end:
DetailPrint "File $1 OK"
FunctionEnd


Most likely, I'm not the first one who wants to update the OCX's on a host by first comparing their version numbers against what's on the web server. Anybody has some working code?

Thank you :-)
JD.

You should compare these number directly (see UpgradeDLL).


Thank you, makes sense :-)

Since I'm (obviously) a NSIS newbie, before I spend more time trying to figure out how to do this, has someone already done the reverse of the code in Include\UpgradeDLL.nsh, namely going from a version number in the form "1.2.3.4" to HIWORD and LOWORD, ready for comparison?

Or, alternatively, extracting tokens between two such strings, and comparing them token by token.

The ultimate goal obviously being to determine whether I need to download and upgrade that OCX/DLL or leave it alone if it turns out that the only currently installed is newer.

BTW, for those interested, MS gives history information on OCX's on this page:

DLL Help Database
http://support.microsoft.com/default...nfo.asp&SD=msd

Thank you
JD.


OK, after more searching in the archives, I located BigMac's excellent StrTok(). Here's some working code to compare two version numbers formatted as "1.2.3.4". Experienced NSISers, please feel free to simplify, eg. turning it into a loop :-)


GetDllVersion "$2" $R0 $R1
;Extracting version # of $2 and turning into tokens, ie. "1.2.3.4"
IntOp $R2 $R0 / 0x00010000
IntOp $R3 $R0 & 0x0000FFFF
IntOp $R4 $R1 / 0x00010000
IntOp $R5 $R1 & 0x0000FFFF
StrCpy $R8 "$R2.$R3.$R4.$R5"

;Same, this time from version info in $9 returned by www server
Push "$9"
Push "."
Call StrTok
Pop $R6

Push "."
Call StrTok
Pop $R7

Push "."
Call StrTok
Pop $R8

;4th and last token
Pop $R9

IntCmpU $R2 $R6 0 download end
IntCmpU $R3 $R7 0 download end
IntCmpU $R4 $R8 0 download end
IntCmpU $R5 $R9 end download end

download:
DetailPrint "File $2 exists on host but in an older version. Downloading..."
Call Download
Goto register

register:
RegDLL "$2"

end:
DetailPrint "File $1 OK"


Thank you
JD.

StrFunc.nsh inside NSIS\Include folder has a better StrTok made by me which is not in the Archive.

To use it, read StrFunc.txt inside the same NSIS\Include folder for instructions to use the command ${StrTok}.

This file has a selection of the best string functions (in my opinion) inside Archive plus the improvement of some. StrTok fortunately is one of the improved ones.


>StrFunc.nsh inside NSIS\Include folder has a better StrTok made by me which is not in the Archive.

Thx for the tip. For those interested, here's how to use Deguix's version:


!include "StrFunc.nsh"

outfile "test.exe"

${StrTok}

Section
;If looping, don't use $R1, because seems to be used internally by this macro
${StrTok} $R2 "1.2.3.4" "." "1" "1"
${StrTok} $R3 "1.2.3.4" "." "2" "1"
${StrTok} $R4 "1.2.3.4" "." "3" "1"
${StrTok} $R5 "1.2.3.4" "." "4" "1"
MessageBox MB_OK "$R2.$R3.$R4.$R5"
SectionEnd


Thank you
JD.