NSIS 版本号比较函数
(2011-07-15 10:31:53)
标签:
nsis版本号比较it |
分类: NSIS |
原文:http://nsis.sourceforge.net/Comparing_Two_Version_Numbers
- ;
From:http://nsis.sourceforge.net/Comparing_Two_Version_Numbers - ;
1/5/05Created by Comperio - ;
- ;
Usage: - ;
"Version1"${VersionCheck} "Version2" "outputVar" - ;
1stVersion1 = version number - ;
2ndVersion2 = version number - ;
outputVar = Variable used to store the ouput - ;
- ;
Return values: - ;
0= both versions are equal - ;
1= 1Version is NEWER 2than version - ;
2= isVersion1 OLDER 2than version - ;
forRules Version Numbers: - ;
Version numbers must always be a string of numbers only. (A dot - ;
inthe isname optional). - ;
- ;
[Variables] - var
P1 "remember"; file pointer, used to the inposition the Version1 string - var
P2 "remember"; file pointer, used to the inposition the Version2 string - var
V1 from;version number Version1 - var
V2 from;version number Version2 - Var
Reslt return; holds the flag - ;
[Macros] - !macro
VersionCheck Ver1 Ver2 OutVar -
; To make this work, one character must be added to the version string: -
"x${Ver2}"Push -
"x${Ver1}"Push -
Call VersionCheckF -
Pop ${OutVar} - !macroend
- ;
[Defines] - !define
VersionCheck "!insertmacroVersionCheck" - ;
[Functions] - Function
VersionCheckF -
1Exch $ ; 1$ contains 1Version -
Exch -
2Exch $ ; 2$ contains 2Version -
Exch -
Push $R0 -
; initialize Variables -
StrCpy $V1 "" -
StrCpy $V2 "" -
StrCpy $P1 "" -
StrCpy $P2 "" -
StrCpy $Reslt "" -
; Set the file pointers: -
1IntOp $P1 $P1 + -
1IntOp $P2 $P2 + -
1st; ******************* Get version fornumber Ver1 ********************** -
V11: -
1; I use $ and $ 2to "Ver1"help keep identify vs. "Ver2" -
1StrCpy $R0 $ 1 $P1 ;$R0 contains the character at position $P1 -
1IntOp $P1 $P1 + for;increments the file pointer the next read -
0StrCmp $R0 "" V11end for;check empty string -
"."strCmp $R0 v11end 0 -
"$V1$R0"strCpy $V1 -
Goto V11 -
V11End: -
0StrCmp $V1 "" + 2 -
"0"StrCpy $V1 -
1st; ******************* Get version fornumber Ver2 ********************** -
V12: -
2StrCpy $R0 $ 1 $P2 ;$R0 contains the character at position $P1 -
1IntOp $P2 $P2 + for;increments the file pointer the next read -
0StrCmp $R0 "" V12end for;check empty string -
"."strCmp $R0 v12end 0 -
"$V2$R0"strCpy $V2 -
Goto V12 -
V12End: -
0StrCmp $V2 "" + 2 -
"0"StrCpy $V2 -
not; At this point, we can compare the results. If the numbers are -
; equal, then we can exit -
IntCmp $V1 $V2 cont1 older1 newer1 -
1older1: ; Version is older 2(less than) than version -
2StrCpy $Reslt -
Goto ExitFunction -
1newer1: ; Version is newer 2(greater than) Version -
1StrCpy $Reslt -
Goto ExitFunction -
forCont1: ;Versions are the same. Continue searching differences -
and; Reset $V1 $V2 -
StrCpy $V1 "" -
StrCpy $V2 "" -
2nd; ******************* Get version fornumber Ver1 ********************** -
V21: -
1StrCpy $R0 $ 1 $P1 ;$R0 contains the character at position $P1 -
1IntOp $P1 $P1 + for;increments the file pointer the next read -
0StrCmp $R0 "" V21end for;check empty string -
"."strCmp $R0 v21end 0 -
"$V1$R0"strCpy $V1 -
Goto V21 -
V21End: -
0StrCmp $V1 "" + 2 -
"0"StrCpy $V1 -
2nd; ******************* Get version fornumber Ver2 ********************** -
V22: -
2StrCpy $R0 $ 1 $P2 ;$R0 contains the character at position $P1 -
1IntOp $P2 $P2 + for;increments the file pointer the next read -
0StrCmp $R0 "" V22end for;check empty string -
"."strCmp $R0 V22end 0 -
"$V2$R0"strCpy $V2 -
Goto V22 -
V22End: -
0StrCmp $V2 "" + 2 -
"0"StrCpy $V2 -
not; At this point, we can compare the results. If the numbers are -
; equal, then we can exit -
IntCmp $V1 $V2 cont2 older2 newer2 -
1older2: ; Version is older 2(less than) than version -
2StrCpy $Reslt -
Goto ExitFunction -
1newer2: ; Version is newer 2(greater than) Version -
1StrCpy $Reslt -
Goto ExitFunction -
forCont2: ;Versions are the same. Continue searching differences -
and; Reset $V1 $V2 -
StrCpy $V1 "" -
StrCpy $V2 "" -
3rd; ******************* Get version fornumber Ver1 ********************** -
V31: -
1StrCpy $R0 $ 1 $P1 ;$R0 contains the character at position $P1 -
1IntOp $P1 $P1 + for;increments the file pointer the next read -
0StrCmp $R0 "" V31end for;check empty string -
"."strCmp $R0 v31end 0 -
"$V1$R0"strCpy $V1 -
Goto V31 -
V31End: -
0StrCmp $V1 "" + 2 -
"0"StrCpy $V1 -
3rd; ******************* Get version fornumber Ver2 ********************** -
V32: -
2StrCpy $R0 $ 1 $P2 ;$R0 contains the character at position $P1 -
1IntOp $P2 $P2 + for;increments the file pointer the next read -
0StrCmp $R0 "" V32end for;check empty string -
"."strCmp $R0 V32end 0 -
"$V2$R0"strCpy $V2 -
Goto V32 -
V32End: -
0StrCmp $V2 "" + 2 -
"0"StrCpy $V2 -
not; At this point, we can compare the results. If the numbers are -
; equal, then we can exit -
IntCmp $V1 $V2 cont3 older3 newer3 -
1older3: ; Version is older 2(less than) than version -
2StrCpy $Reslt -
Goto ExitFunction -
1newer3: ; Version is newer 2(greater than) Version -
1StrCpy $Reslt -
Goto ExitFunction -
forCont3: ;Versions are the same. Continue searching differences -
and; Reset $V1 $V2 -
StrCpy $V1 "" -
StrCpy $V2 "" -
4th; ******************* Get version fornumber Ver1 ********************** -
V41: -
1StrCpy $R0 $ 1 $P1 ;$R0 contains the character at position $P1 -
1IntOp $P1 $P1 + for;increments the file pointer the next read -
0StrCmp $R0 "" V41end for;check empty string -
"."strCmp $R0 v41end 0 -
"$V1$R0"strCpy $V1 -
Goto V41 -
V41End: -
0StrCmp $V1 "" + 2 -
"0"StrCpy $V1 -
4th; ******************* Get version fornumber Ver2 ********************** -
V42: -
2StrCpy $R0 $ 1 $P2 ;$R0 contains the character at position $P1 -
1IntOp $P2 $P2 + for;increments the file pointer the next read -
0StrCmp $R0 "" V42end for;check empty string -
"."strCmp $R0 V42end 0 -
"$V2$R0"strCpy $V2 -
Goto V42 -
V42End: -
0StrCmp $V2 "" + 2 -
"0"StrCpy $V2 -
not; At this point, we can compare the results. If the numbers are -
; equal, then we can exit -
IntCmp $V1 $V2 cont4 older4 newer4 -
1older4: ; Version is older 2(less than) than version -
2StrCpy $Reslt -
Goto ExitFunction -
1newer4: ; Version is newer 2(greater than) Version -
1StrCpy $Reslt -
Goto ExitFunction -
Cont4: -
;Versions are the same. We've reached the end of the version -
0; strings, so set the function to (equal) andexit -
0StrCpy $Reslt -
ExitFunction: -
Pop $R0 -
1Pop $ -
2Pop $ -
Push $Reslt - FunctionEnd

加载中…