Archive: VersionCompare fails


VersionCompare fails
  Hi Community.

I wrote a macro named GetMostRecentFile. It compares two files and delivers the winner back.

Example call of Macro:


0 

>

The "GetVersion" Macro:

Requirements

>!ifndef LOGICLIB
!include "LogicLib.nsh"
>!endif

; -- GetVersion
>!define MACRO_GETVERSION_INCLUDED
>!define GetVersion "!insertmacro GetVersion"
>!macro GetVersion _GetVersionFile _GetVersionVar
ClearErrors

StrCpy $R0 ""
StrCpy $R1 ""
StrCpy $R2 ""
StrCpy $R3 ""
StrCpy $R4 ""
StrCpy $R5 ""

GetDLLVersion "${_GetVersionFile}" $R0 $R1
${If} ${Errors}
DetailPrint "Could not get version info from '${_GetVersionFile}'"
${EndIf}

IntOp $R2 $R0 / 0x00010000 ; $R2 now contains major version
IntOp $R3 $R0& 0x0000FFFF ; $R3 now contains minor version
IntOp $R4 $R1/ 0x00010000 ; $R4 now contains release
IntOp $R5 $R1& 0x0000FFFF ; $R5 now contains build

StrCpy${_GetVersionVar} "$R2.$R3.$R4.$R5"
>!macroend
>

The GetMostRecentFile macro:

Requirements

>!ifndef LOGICLIB
!include "LogicLib.nsh"
>!endif

!ifndef WORDFUNC_INCLUDED
!include "WordFunc.nsh"
>!endif

!ifndef MACRO_GETVERSION_INCLUDED
!include "macro.getversion.nsh"
>!endif

!insertmacro VersionCompare
>Var _VersionCompareFile1
>Var _VersionCompareFile2
>Var _VersionCompareResult


>; --- GetMostRecentFile
>!define GetMostRecentFile '!insertmacro GetMostRecentFile'
>!define MACRO_GETMOSTRECENTFILE_INCLUDED

>!macro GetMostRecentFile _file1 _file2 _var
ClearErrors
>${If} ${FileExists} "${_file1}"
>${AndIf} ${FileExists} "${_file2}"

LogText "${_file1}: Getting version"
${GetVersion} "${_file1}" $_VersionCompareFile1
LogText "${_file1}: Version - $_VersionCompareFile1"

${IfNot} ${Errors}

LogText "${_file2}: Getting version"
${GetVersion} "${_file2}" $_VersionCompareFile2
LogText "${_file2}: Version - $_VersionCompareFile2"

${IfNot} ${Errors}

LogText "Comparing: '${_file1}' vs. '${_file2}'"
${VersionCompare} "${_file1}" "${_file2}" $_VersionCompareResult
LogText "Result: $_VersionCompareResult"

${If} $_VersionCompareResult == "0" ; equal
LogText "Result mean: Equal"
StrCpy ${_var} "${_file1}" ; copy back the first value

${ElseIf} $_VersionCompareResult == "1" ; file 1 newer
LogText "Result mean: ${_file1} is newer"
StrCpy ${_var} "${_file1}" ; copy back the first value

${ElseIf} $_VersionCompareResult == "2" ; file 2 newer
LogText "Result mean: ${_file2} is newer"
StrCpy ${_var} "${_file2}" ; copy back the second value

${EndIf}

${Else}
DetailPrint "GetMostRecentFile failed on '${_file2}'. Returning ${_file1} as result."
StrCpy ${_var} "${_file2}"

${EndIf}

${Else}
DetailPrint "GetMostRecentFile failed on '${_file1}'. Returning ${_file1} as result."
StrCpy ${_var} "${_file1}"

${EndIf}


${Else}
${
IfNot} ${FileExists} "${_file1}"
DetailPrint "GetMostRecentFile Error: '${_file1}' does not exists."
StrCpy ${_var} "${_file2}"

${EndIf}

${IfNot} ${FileExists} "${_file2}"
DetailPrint "GetMostRecentFile Error: '${_file2}' does not exists."
StrCpy ${_var} "${_file1}"

${EndIf}
${EndIf}
!macroend
>
And the (frustrating) result:

IfFileExists: file "C:\DOCUME~1\VIRTUA~1\LOCALS~1\Temp\nssF.tmp\NAMEOF.dll" exists, jumping 0

IfFileExists
: file "C:\Program Files\product\NAMEOF.dll" exists, jumping 0
C:DOCUME~1VIRTUA~1LOCALS~1TempnssF.tmpNAMEOF.dll: Getting version
C:DOCUME~1VIRTUA~1LOCALS~1TempnssF.tmpNAMEOF.dll: Version - 4.2.0.33
C:Program FilesproductNAMEOF.dll: Getting version
C:Program FilesproductNAMEOF.dll: Version - 4.4.0.22
Comparing: 'C:\DOCUME~1\VIRTUA~1\LOCALS~1\Temp\nssF.tmp\NAMEOF.dll' vs. 'C:\Program Files\product\NAMEOF.dll'
>Call: 859
Jump: 915
Jump: 926
Result: 1
Result mean: C:DOCUME~1VIRTUA~1LOCALS~1TempnssF.tmpNAMEOF.dll is newer
Jump: 939
Jump: 942
Jump: 945
Jump: 952
Most recent version'C:\DOCUME~1\VIRTUA~1\LOCALS~1\Temp\nssF.tmp\NAMEOF.dll' is copied to C:Program Filesproduct
>
The older version is detected as newer version? Am I doing something wrong which I don't see here? :|

thnx

Changed: ${VersionCompare} "${_file1}" "${_file2}" $_VersionCompareResult
To: ${VersionCompare} "$_VersionCompareFile1" "$_VersionCompareFile2" $_VersionCompareResult

Now its working. ;)