MSIVer.nsh

From NSIS Wiki
Jump to navigationJump to search
Author: jveazey (talk, contrib)



Description

The MSIVer.nsh provides versioning information for the Windows Installer using the same conventions as the WinVer.nsh.

The Script

; ---------------------
;      MSIVer.nsh
; ---------------------
;
; LogicLib extensions for handling Windows Installer versions.
;
; AtLeastMSI<version> checks if the Windows Installer (msi.dll) is at least the version specified.
; IsMSI<version> checks if the Windows Installer (msi.dll) is exactly as specified.
; AtMostMSI<version> checks if the Windows Installer (msi.dll) is at most as specified.
;
; <version> can be replaced with the following values:
;
;   10  ; for Windows Installer 1.0
;   11  ; for 1.1
;   12  ; for 1.2
;
;   20  ; for 2.0
;   30  ; for 3.0
;   40  ; for 4.0
;   45  ; for 4.5
;   50  ; for 5.0
;
; Usage examples:
;
;   ${AndIf} ${AtLeastMSI20}
;     DetailPrint "Running Windows Installer 2.0 or better.  Could be up to 5.0."
;   ${EndIf}
;
;   ${If} ${AtLeastMSI45}
;     DetailPrint "Running Windows Installer 4.5 or better."
;   ${EndIf}
;
;   ${If} ${IsMSI30}
;     DetailPrint "Running Windows Installer 3.0."
;   ${EndIf}
;
;   ${If} ${AtMostMSI40}
;     DetailPrint "Running Windows Installer 4.0 or older.  Surely not 5.0 or 4.5.  Maybe 3.0, 2.0, 1.2, 1.1 or even 1.0
;   ${EndIf}
;
 
!verbose push
!verbose 3
 
!ifndef ___MSIVER__NSH___
!define ___MSIVER__NSH___
 
!include LogicLib.nsh
!include Util.nsh
 
# possible variable values for different versions
 
!define MSIVER_10     0x00010000 ; 1.0
!define MSIVER_11     0x00010001 ; 1.1
!define MSIVER_12     0x00010010 ; 1.2
!define MSIVER_20     0x00020000 ; 2.0
!define MSIVER_30     0x00030000 ; 3.0
!define MSIVER_40     0x00040000 ; 4.0
!define MSIVER_45     0x00040005 ; 4.5
!define MSIVER_50     0x00050000 ; 5.0
 
# variable declaration
 
!macro __MSIVer_DeclareVars
 
  !ifndef __MSIVER_VARS_DECLARED
 
    !define __MSIVER_VARS_DECLARED
 
    Var /GLOBAL __MSIVERV
 
  !endif
 
!macroend
 
# lazy initialization macro
 
!macro __MSIVer_InitVars
    # variables
    !insertmacro __MSIVer_DeclareVars
 
    # only calculate version once
    StrCmp $__MSIVERV "" _msiver_noveryet
    Return
    _msiver_noveryet:
 
    Push $0
    GetDLLVersion "$SYSDIR\msi.dll" $__MSIVERV $0
    Pop $0
 
!macroend
 
# version comparison LogicLib macros
 
!macro _MSIVerAtLeast _a _b _t _f
  ${CallArtificialFunction} __MSIVer_InitVars
  !insertmacro _>= $__MSIVERV `${_b}` `${_t}` `${_f}`
!macroend
!macro _MSIVerIs _a _b _t _f
  ${CallArtificialFunction} __MSIVer_InitVars
  !insertmacro _= $__MSIVERV `${_b}` `${_t}` `${_f}`
!macroend
!macro _MSIVerAtMost _a _b _t _f
  ${CallArtificialFunction} __MSIVer_InitVars
  detailprint ${_b}
  !insertmacro _<= $__MSIVERV `${_b}` `${_t}` `${_f}`
!macroend
 
!macro __MSIVer_DefineTest Test Ver
  !define ${Test}MSI${Ver} `"" MSIVer${Test} ${MSIVER_${Ver}}`
!macroend
 
!macro __MSIVer_DefineTests Test
  !insertmacro __MSIVer_DefineTest ${Test} 10
  !insertmacro __MSIVer_DefineTest ${Test} 11
  !insertmacro __MSIVer_DefineTest ${Test} 12
  !insertmacro __MSIVer_DefineTest ${Test} 20
  !insertmacro __MSIVer_DefineTest ${Test} 30
  !insertmacro __MSIVer_DefineTest ${Test} 40
  !insertmacro __MSIVer_DefineTest ${Test} 45
  !insertmacro __MSIVer_DefineTest ${Test} 50
!macroend
 
!insertmacro __MSIVer_DefineTests AtLeast 
!insertmacro __MSIVer_DefineTests Is
!insertmacro __MSIVer_DefineTests AtMost
 
!endif # !___MSIVER__NSH___
 
!verbose pop