Version Info manipulations on compile-time: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m ("occurence" -> "occurrence")
(Added note about this page being outdated)
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{|align=right
{{PageAuthor|Lion}}
|<small>Author: [[{{ns:2}}:Lion|Lion]] ([[{{ns:3}}:Lion|talk]], [[{{ns:-1}}:Contributions/Lion|contrib]])</small>
 
|}
<div style="background-color:#FFB3B3;border:1px solid #FF1111;color:#A20000;padding:0.4em"><b>The technique described on this page can now be accomplished in NSIS 3 without using 3rd-party tools by using !getdllversion and VIProductVersion/VIAddVersionKey</b></div>
<br style="clear:both;">
 
 
== Description ==
== Description ==


Line 30: Line 31:
<highlight-nsis>
<highlight-nsis>
!define _RESHACKER "C:\WinApps\NSIS2\ResHacker\ResHacker.exe"
!define _RESHACKER "C:\WinApps\NSIS2\ResHacker\ResHacker.exe"
Var _VERSION


Function InitVersion
Function InitVersion
Line 38: Line 41:
   Push 'C:\WinApps\NSIS2\_Production\FileVersionInfo.rc'
   Push 'C:\WinApps\NSIS2\_Production\FileVersionInfo.rc'
   Call GetBetween
   Call GetBetween
   Pop "$R0"
   Pop "$_VERSION"
 
  !define _VERSION "$R0"
FunctionEnd
FunctionEnd


Line 67: Line 68:
== About the Author ==
== About the Author ==


I'm a newbie to NSIS's depths so please do not blame me out of hand if you found an error or smthg else not-good here.
I'm a newbie to NSIS's depths so please do not blame me out of hand if you found an error or smth else not-good here.


Let the NSIS be with you!
Let the NSIS be with you!
Line 73: Line 74:
Lion
Lion


[[{{ns:14}}:Code Examples]]
[[Category:Code Examples]]

Latest revision as of 15:18, 8 October 2016

Author: Lion (talk, contrib)


The technique described on this page can now be accomplished in NSIS 3 without using 3rd-party tools by using !getdllversion and VIProductVersion/VIAddVersionKey


Description

Recently, I was faced with the problem of automating my scripts on compile-time. I first started with the VersionInfo automation.

Examples

Before the change

This is how it WAS before (I had to change version variables manually before each compile):

;...
!define _VERSION "1.2.3.4"
;...
;from {NSISDIR}\Examples\VersionInfo.nsi
VIProductVersion "${_VERSION}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" "${_PRODUCT}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "CompanyName" "..."
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "${_VERSION}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "InternalName" "FileSetup.exe"
;...

After the change

And this is how it is NOW:

!define _RESHACKER "C:\WinApps\NSIS2\ResHacker\ResHacker.exe"
 
Var _VERSION
 
Function InitVersion
  !execute '"${_RESHACKER}" -extract ${_SRCDIR}\File.exe, FileVersionInfo.rc, versioninfo,1,'
 
  Push 'VALUE "FileVersion", "'
  Push '"'
  Push 'C:\WinApps\NSIS2\_Production\FileVersionInfo.rc'
  Call GetBetween
  Pop "$_VERSION"
FunctionEnd
 
Function .onInit
  ;...
  call InitVersion
  ;...
FunctionEnd
 
;...
  !execute '"${_RESHACKER}" -extract ${_SRCDIR}\File.exe, FileVersionInfo.res, versioninfo,1,'
  !packhdr tmp.dat '"${_RESHACKER}" -addoverwrite tmp.dat, tmp.dat, FileVersionInfo.res, versioninfo,1,'
  !echo "VersionInfo added"
;...

In the first case, ResHacker is used to extract decompiled VersionInfo resource from .exe to a text .rc file, the I have to parse it to get version in a string "x.x.x.x" form. Personaly, I'm using it e.g. in the installer's window caption (Caption "${_PRODUCT} v${_VERSION} Setup").

And the second case where I need ResHacker again is just duplicating the VersionInfo resource from my File.exe to FileSetup.exe.

This was inspired by these articles (listed in order of occurrence on my display :))

About the Author

I'm a newbie to NSIS's depths so please do not blame me out of hand if you found an error or smth else not-good here.

Let the NSIS be with you!

Lion