Maxim30
5th June 2006 23:56 UTC
Code to handle file version
Hello,
I would install some files only if them have version above those existing; so I have written the following code to recognize the file version, but it does not work:
StrCpy $R0 "Filename"
StrCpy $0 VersionMajor
StrCpy $1 VersionMinor
StrCpy $2 BuildMajor
StrCpy $3 BuildMinor
Call IfVersionAbove
StrCmp $R1 "DontCopy" +2
File Filename
...
Function IfVersionAbove
StrCpy $R1 "DontCopy"
GetDllVersion "$WINDIR\System\$R0" $8 $9
IntOp $R2 $8 / 0x00010000
IntOp $R3 $8 & 0x0000FFFF
IntOp $R4 $9 / 0x00010000
IntOp $R5 $9 & 0x0000FFFF
${If} $R2 < $0
StrCpy $R1 "Copy"
${ElseIf} $R2 == $0
${AndIf} $R3 < $1
StrCpy $R1 "Copy"
${ElseIf} $R3 == $1
${AndIf} $R4 < $2
StrCpy $R1 "Copy"
${ElseIf} $R4 == $2
${AndIf} $R5 <= $3
StrCpy $R1 "Copy"
${EndIf}
FunctionEnd
Can you give me the working code ?
Comperio
6th June 2006 05:47 UTC
There are some version handling functions included with NSIS. (Look in your help files under Appendix E, "Word Functions Header")
You might find other examples in thedeveloper's section of the WIKI
Maxim30
7th June 2006 22:39 UTC
Hello,
I have the following code now but it does not work:
!include "WordFunc.nsh"
!insertmacro VersionCompare
...
GetDllVersion "$WINDIR\System\$Filename" $R8 $R9
SetOverwrite on
IfErrors +9
IntOp $R1 $R8 / 0x00010000 ; Version major
IntOp $R2 $R8 & 0x0000FFFF ; Version minor
IntOp $R3 $R9 / 0x00010000 ; Build major
IntOp $R4 $R9 & 0x0000FFFF ; Build minor
StrCpy $R5 "$R1.$R2.$R3.$R4" ; Version
${VersionCompare} "$R5" "$R7" $R6
StrCmp $R6 2 +3
StrCmp $R6 1 +3 ; $R6=0, equal; $R6=1, Version is newer; $R6=2, Version is older
SetOverwrite ifnewer
File "${SourceSetup}\$Filename"
I would install files only if existing have version below ($R6=2) or if existing have the same version and are older ($R6=0); but in the case $R6=2 (and it is checked) the +3 jump does not work not considering the 'File' instruction: Why ?
Afrow UK
7th June 2006 23:22 UTC
Surely this will work:
StrCmp $R6 1 +2
File "${SourceSetup}\$Filename"
-Stu
Maxim30
9th June 2006 22:48 UTC
Hello,
I have found that the SetOverwrite instruction is not considered by the StrCmp jumps so it needs to decrease the goto by +1. But even so, one of the jumps does not work.
I have had to use the LogicLib instructions to make the code works.