Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does VIProductVersion argument override value of ProductVersion key?

Tags:

nsis

Code snippet from the nsi script:

VIProductVersion 1.2.0.0   
VIAddVersionKey /LANG=${LANG_ENGLISH} FileVersion 1.1.0.0

I want to set FileVersion to 1.1.0.0 but in file properties it is set to 1.2.0.0. I also noticed that VIProductVersion executed on its own adds FileVersion key and sets its value.

Documentation says that VIProductVersion adds the Product Version but what I see is that FileVersion is actually added. Is this the bug in NSIS? What is the purpose of VIAddVersionKey FileVersion if value it sets is overriden with one set by VIProductVersion?

VIAddVersionKey requires VIProductVersion call, script does not compile otherwise.

Versions I am using: EclipseNSIS 0.9.8; MakeNSIS 2.46. OS: Windows 7.

like image 848
Bojan Komazec Avatar asked Jul 28 '11 12:07

Bojan Komazec


1 Answers

The version info resource is stored in two parts:

  • VS_FIXEDFILEINFO is a fixed block with product and file versions, VIProductVersion sets this
  • Zero, one or more (multiple languages) string blocks with one or more name=value strings, VIAddVersionKey sets those.

Some applications use the FileVersion string and fall back to VS_FIXEDFILEINFO::dwFileVersion if the string is not present, other apps only use VS_FIXEDFILEINFO::dwFileVersion etc.

VIProductVersion "1.2.3.4" will generate a version header that looks like

1 VERSIONINFO
FILEVERSION 1,2,3,4
PRODUCTVERSION 1,2,3,4
FILEOS 0x4
FILETYPE 0x1

this is often enough but it will not let you set PRODUCTVERSION != FILEVERSION.

I would consider this a bug in NSIS, they should add a VIFileVersion command or extend VIProductVersion to VIProductVersion <productver> [filever].

You can add a feature request on the tracker.

In the mean time you might be able to work around this by calling resource hacker during the build with !packhdr


Edit:

It can be done with 2.46 at compile time with !packhdr, external 3rd party tools (I was unable to get reshacker to import a .rc version resource so I had to convert to .res first) and horrible hacks:

!macro HackyVIFileVersion reshack gorcjorg fixedfilever
;http://www.angusj.com/resourcehacker/
;http://web.archive.org/web/20090918063311/http://www.jorgon.freeserve.co.uk/Gorcjorg.zip
!searchreplace HackyVIFileVersion_id "${__TIME__}" ":" ""
!define HackyVIFileVersion_cmd "$%TEMP%\nsisVIFV${HackyVIFileVersion_id}.cmd"
!appendfile "${HackyVIFileVersion_cmd}" `@echo off&setlocal ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION$\n`
!appendfile "${HackyVIFileVersion_cmd}" `set eh=%TEMP%\exehead%~1.tmp$\n`
!appendfile "${HackyVIFileVersion_cmd}" `set rh=%~2$\n`
!appendfile "${HackyVIFileVersion_cmd}" `call "%rh%" -extract "%eh%", "%eh%1.rc", VersionInfo,1,$\n`
!appendfile "${HackyVIFileVersion_cmd}" `> "%eh%2.rc" echo.LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US $\n` ;must force lang for Gorcjorg
!appendfile "${HackyVIFileVersion_cmd}" `FOR /F "usebackq tokens=* delims=" %%A IN ("%eh%1.rc") DO ($\n`
!appendfile "${HackyVIFileVersion_cmd}" `   FOR /F "usebackq" %%B IN ('%%A') DO ($\n`
!appendfile "${HackyVIFileVersion_cmd}" `       if "%%~B"=="FILEVERSION" (>> "%eh%2.rc" echo.FILEVERSION %~4) else (>> "%eh%2.rc" echo.%%A)$\n`
!appendfile "${HackyVIFileVersion_cmd}" `   )$\n`
!appendfile "${HackyVIFileVersion_cmd}" `)$\n`
!appendfile "${HackyVIFileVersion_cmd}" `call "%~3" /fo "%eh%.res" /r "%eh%2.rc"$\n`
!appendfile "${HackyVIFileVersion_cmd}" `call "%rh%" -addoverwrite "%eh%", "%eh%", "%eh%.res", versioninfo,1,$\n`
!appendfile "${HackyVIFileVersion_cmd}" `del "%eh%2.rc"&del "%eh%1.rc"&del "%eh%.res"&del "%~0"`
!packhdr "$%TEMP%\exehead${HackyVIFileVersion_id}.tmp" '"${HackyVIFileVersion_cmd}" "${HackyVIFileVersion_id}" "${reshack}" "${gorcjorg}" "${fixedfilever}"'
!undef HackyVIFileVersion_cmd
!undef HackyVIFileVersion_id 
!macroend


VIProductVersion "1.2.3.4"
VIAddVersionKey /LANG=1033 FileVersion 5.6.7.8
VIAddVersionKey /LANG=1033 ProductVersion "1.2.3.4"
VIAddVersionKey /LANG=1033 Comments "A test comment"
!insertmacro HackyVIFileVersion "C:\tools\ResHacker.exe" "C:\tools\GoRC.exe" "5,6,7,8"

...and you end up with this version resource:

1 VERSIONINFO
FILEVERSION 5,6,7,8
PRODUCTVERSION 1,2,3,4
FILEOS 0x4
FILETYPE 0x1
{
BLOCK "StringFileInfo"
{
    BLOCK "040904e4"
    {
        VALUE "Comments", "A test comment"
        VALUE "FileVersion", "5.6.7.8"
        VALUE "ProductVersion", "1.2.3.4"
    }
}

BLOCK "VarFileInfo"
{
    VALUE "Translation", 0x0409 0x04E4
}
}
like image 199
Anders Avatar answered Oct 20 '22 18:10

Anders