Dictating an install order frustrates anyone that has to deploy your software. Machines are made to follow the same instructions identically over and over again, but people are not. I am presenting the below Nullsoft script to prevent anyone from caring about install order(the code must be forwards compatible).

The macro only replaces the file if it is a greater version than the one already present. If they are equal or the existing file is later, then no action is taken.

!macro CopyIfGreaterVersion existingFile installFile
	Var /GLOBAL existingVersion
	Var /GLOBAL newVersion

	${GetFileVersion} ${existingFile} $existingVersion
	${GetFileVersion} ${installFile} $newVersion

 	${VersionCompare} $existingVersion $newVersion $R0

	${If} $R0 == 2
	  File ${installFile}
	${Else}
	  ;DetailPrint "The existing file below is up to date."
	  ;DetailPrint ${existingFile}
	${EndIf}
!macroend

# create a default section.
Section
	setOutPath "C:\test\"

	!insertmacro CopyIfGreaterVersion "C:\test\A.exe" "A.exe"

SectionEnd

The following definitions and references must be used at the top of the file to prevent compilation errors.

  1. !include LogicLib.nsh
  2. VersionCompare
  3. GetFileVersion
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s