Old 5th June 2006, 23:56   #1
Maxim30
Member
 
Maxim30's Avatar
 
Join Date: Sep 2005
Location: Martinsicuro -Teramo- Italy
Posts: 76
Question 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 ?

Massimo
Maxim30 is offline   Reply With Quote
Old 6th June 2006, 05:47   #2
Comperio
Major Dude
 
Comperio's Avatar
 
Join Date: Jan 2005
Location: Oregon Coast
Posts: 737
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
Comperio is offline   Reply With Quote
Old 6th June 2006, 11:16   #3
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
http://nsis.sourceforge.net/VersionCompare

-Stu
Afrow UK is offline   Reply With Quote
Old 7th June 2006, 22:39   #4
Maxim30
Member
 
Maxim30's Avatar
 
Join Date: Sep 2005
Location: Martinsicuro -Teramo- Italy
Posts: 76
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 ?

Massimo
Maxim30 is offline   Reply With Quote
Old 7th June 2006, 23:22   #5
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Surely this will work:

StrCmp $R6 1 +2
File "${SourceSetup}\$Filename"

-Stu
Afrow UK is offline   Reply With Quote
Old 9th June 2006, 22:48   #6
Maxim30
Member
 
Maxim30's Avatar
 
Join Date: Sep 2005
Location: Martinsicuro -Teramo- Italy
Posts: 76
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.

Massimo
Maxim30 is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump