Old 12th July 2010, 13:27   #1
dbach
Member
 
Join Date: Apr 2006
Location: Somewhere in Germany
Posts: 81
VersionCompare fails

Hi Community.

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

Example call of Macro:
PHP Code:
${GetMostRecentFile"$PLUGINSDIR\${DLL}" "${_platformpath}\${_applicationpath}\${DLL}" $

The "GetVersion" Macro:
PHP Code:
; --- 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:
PHP Code:
; --- 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:
PHP Code:
IfFileExistsfile "C:\DOCUME~1\VIRTUA~1\LOCALS~1\Temp\nssF.tmp\NAMEOF.dll" existsjumping 0
IfFileExists
file "C:\Program Files\product\NAMEOF.dll" existsjumping 0
C
:\DOCUME~1\VIRTUA~1\LOCALS~1\Temp\nssF.tmp\NAMEOF.dllGetting version
C
:\DOCUME~1\VIRTUA~1\LOCALS~1\Temp\nssF.tmp\NAMEOF.dllVersion 4.2.0.33
C
:\Program Files\product\NAMEOF.dllGetting version
C
:\Program Files\product\NAMEOF.dllVersion 4.4.0.22
Comparing
'C:\DOCUME~1\VIRTUA~1\LOCALS~1\Temp\nssF.tmp\NAMEOF.dll' vs'C:\Program Files\product\NAMEOF.dll'
Call859
Jump
915
Jump
926
Result
1
Result mean
C:\DOCUME~1\VIRTUA~1\LOCALS~1\Temp\nssF.tmp\NAMEOF.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 Files\product\' 
The older version is detected as newer version? Am I doing something wrong which I don't see here? :|

thnx
dbach is offline   Reply With Quote
Old 12th July 2010, 14:35   #2
dbach
Member
 
Join Date: Apr 2006
Location: Somewhere in Germany
Posts: 81
Changed: ${VersionCompare} "${_file1}" "${_file2}" $_VersionCompareResult
To: ${VersionCompare} "$_VersionCompareFile1" "$_VersionCompareFile2" $_VersionCompareResult

Now its working.
dbach 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