VersionCompare: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (Updated author links.) |
Instructor (talk | contribs) No edit summary |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{ | {{PageAuthor|Instructor}} | ||
== | {{User:Instructor/Headers/Template}} | ||
<highlight-nsis> | |||
== Function Description == | |||
<highlight-nsis> | |||
____________________________________________________________________________ | ____________________________________________________________________________ | ||
Line 14: | Line 11: | ||
____________________________________________________________________________ | ____________________________________________________________________________ | ||
Thanks Afrow UK (Based on his Function "VersionCheckNew2") | |||
Thanks Afrow UK (Based on his Function "VersionCheckNew2" | |||
Line 23: | Line 18: | ||
Syntax: | Syntax: | ||
${VersionCompare} "[Version1]" "[Version2]" $var | |||
"[Version1]" ; First version | |||
"[Version2]" ; Second version | |||
$var ; Result: | |||
; $var=0 Versions are equal | |||
; $var=1 Version1 is newer | |||
; $var=2 Version2 is newer | |||
</highlight-nsis> | |||
Example: | <b>Example:</b> | ||
Section | <highlight-nsis>Section | ||
${VersionCompare} "1.1.1.9" "1.1.1.01" $R0 | |||
; $R0="1" | |||
SectionEnd | |||
</highlight-nsis> | |||
SectionEnd | |||
== Function Code == | |||
<highlight-nsis> | |||
Function VersionCompare | Function VersionCompare | ||
!define VersionCompare `!insertmacro VersionCompareCall` | |||
!macro VersionCompareCall _VER1 _VER2 _RESULT | |||
Push `${_VER1}` | |||
Push `${_VER2}` | |||
Call VersionCompare | |||
Pop ${_RESULT} | |||
!macroend | |||
Exch $1 | Exch $1 | ||
Exch | Exch | ||
Line 123: | Line 124: | ||
FunctionEnd | FunctionEnd | ||
</highlight-nsis> | </highlight-nsis> | ||
[[Category:Version Manipulation Functions]] |
Latest revision as of 11:27, 30 November 2005
Author: Instructor (talk, contrib) |
Page for NSIS 2.07 and below users
You can use the latest version of headers (recommended) or the following function code (put the function code in your script before calling it)
Function Description
____________________________________________________________________________ VersionCompare v1.0 ____________________________________________________________________________ Thanks Afrow UK (Based on his Function "VersionCheckNew2") Compare version numbers. Syntax: ${VersionCompare} "[Version1]" "[Version2]" $var "[Version1]" ; First version "[Version2]" ; Second version $var ; Result: ; $var=0 Versions are equal ; $var=1 Version1 is newer ; $var=2 Version2 is newer
Example:
Section ${VersionCompare} "1.1.1.9" "1.1.1.01" $R0 ; $R0="1" SectionEnd
Function Code
Function VersionCompare !define VersionCompare `!insertmacro VersionCompareCall` !macro VersionCompareCall _VER1 _VER2 _RESULT Push `${_VER1}` Push `${_VER2}` Call VersionCompare Pop ${_RESULT} !macroend Exch $1 Exch Exch $0 Exch Push $2 Push $3 Push $4 Push $5 Push $6 Push $7 begin: StrCpy $2 -1 IntOp $2 $2 + 1 StrCpy $3 $0 1 $2 StrCmp $3 '' +2 StrCmp $3 '.' 0 -3 StrCpy $4 $0 $2 IntOp $2 $2 + 1 StrCpy $0 $0 '' $2 StrCpy $2 -1 IntOp $2 $2 + 1 StrCpy $3 $1 1 $2 StrCmp $3 '' +2 StrCmp $3 '.' 0 -3 StrCpy $5 $1 $2 IntOp $2 $2 + 1 StrCpy $1 $1 '' $2 StrCmp $4$5 '' equal StrCpy $6 -1 IntOp $6 $6 + 1 StrCpy $3 $4 1 $6 StrCmp $3 '0' -2 StrCmp $3 '' 0 +2 StrCpy $4 0 StrCpy $7 -1 IntOp $7 $7 + 1 StrCpy $3 $5 1 $7 StrCmp $3 '0' -2 StrCmp $3 '' 0 +2 StrCpy $5 0 StrCmp $4 0 0 +2 StrCmp $5 0 begin newer2 StrCmp $5 0 newer1 IntCmp $6 $7 0 newer1 newer2 StrCpy $4 '1$4' StrCpy $5 '1$5' IntCmp $4 $5 begin newer2 newer1 equal: StrCpy $0 0 goto end newer1: StrCpy $0 1 goto end newer2: StrCpy $0 2 end: Pop $7 Pop $6 Pop $5 Pop $4 Pop $3 Pop $2 Pop $1 Exch $0 FunctionEnd