Inject MSI Property at Compile-Time: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
(Initial Release) |
m (→Macro: Changed Macro name from !MSIProperty to MSIPropertyGet) |
||
Line 5: | Line 5: | ||
== Macro == | == Macro == | ||
<highlight-nsis>/******************** | <highlight-nsis>/******************** | ||
! | !MSIPropertyGet | ||
This macro provides a compile-time ability to inject Microsoft Installer Database file properties at compile time. | This macro provides a compile-time ability to inject Microsoft Installer Database file properties at compile time. | ||
Example: | Example: | ||
${! | ${!MSIPropertyGet} "SomePackage.ProductName" "SomePackage.msi" "ProductName" | ||
${! | ${!MSIPropertyGet} "SomePackage.ProductVersion" "SomePackage.msi" "ProductVersion" | ||
!define DisplayName `${SomePackage.ProductName} v${SomePackage.ProductVersion}` | !define DisplayName `${SomePackage.ProductName} v${SomePackage.ProductVersion}` | ||
Line 17: | Line 17: | ||
!verbose push | !verbose push | ||
!verbose 0 | !verbose 0 | ||
!define ! | !define !MSIPropertyGet `!insertmacro _!MSIPropertyGet` | ||
!macro _! | !macro _!MSIPropertyGet _DefineToCreate _MSIFilePath _PropertyToRead | ||
!verbose Push | !verbose Push | ||
!verbose 0 | !verbose 0 | ||
Line 28: | Line 28: | ||
!ifdef `${__DefineToCreate}` | !ifdef `${__DefineToCreate}` | ||
!verbose 1 | !verbose 1 | ||
!error "! | !error "!MSIPropertyGet: Value previously defined! [${__DefineToCreate}=${${__DefineToCreate}}]" | ||
!else | !else | ||
!tempfile | !tempfile MSIPropertyGet_VBScript | ||
!appendfile `${ | !appendfile `${MSIPropertyGet_VBScript}` `Set A=WScript.Arguments:Set B=CreateObject("WindowsInstaller.Installer").OpenDatabase(A(2),0)` | ||
!appendfile `${ | !appendfile `${MSIPropertyGet_VBScript}` `.OpenView("SELECT Value FROM Property WHERE Property='"&A(3)&"'"):B.Execute:Set C=CreateObjec` | ||
!appendfile `${ | !appendfile `${MSIPropertyGet_VBScript}` `t("Scripting.Filesystemobject"):Set D=C.OpenTextFile(A(0),2,1):D.WriteLine "!define $\`"&A(1)` | ||
!appendfile `${ | !appendfile `${MSIPropertyGet_VBScript}` `&"$\` $\`"&B.Fetch.StringData(1)&"$\`":D.Close` | ||
!tempfile | !tempfile MSIPropertyGet_Result | ||
!system `WScript.exe "${ | !system `WScript.exe "${MSIPropertyGet_VBScript}" //B //E:VBSCRIPT //T:30 "${MSIPropertyGet_Result}" "${__DefineToCreate}" "${_MSIFilePath}" "${_PropertyToRead}"` = 0 | ||
!include "${ | !include "${MSIPropertyGet_Result}" | ||
!system `Notepad "${ | !system `Notepad "${MSIPropertyGet_Result}"` | ||
!delfile `${ | !delfile `${MSIPropertyGet_VBScript}` | ||
!delfile `${ | !delfile `${MSIPropertyGet_Result}` | ||
!undef | !undef MSIPropertyGet_VBScript | ||
!undef | !undef MSIPropertyGet_Result | ||
!ifndef `${__DefineToCreate}` | !ifndef `${__DefineToCreate}` | ||
!error "! | !error "!MSIPropertyGet: Value was not defined! [${__DefineToCreate}] Ensure the MSI file exists and is not locked from reading" | ||
!else if `${${__DefineToCreate}}` == `` | !else if `${${__DefineToCreate}}` == `` | ||
!warning "! | !warning "!MSIPropertyGet: Value is a zero length string! [${__DefineToCreate}=${${__DefineToCreate}}]" | ||
!endif | !endif | ||
!endif | !endif |
Revision as of 20:52, 23 February 2011
Author: Zinthose (talk, contrib) |
About
This macro provides a compile-time ability to inject Microsoft Installer Database file properties at compile time. It uses a dynamically created VBScript to open the MSI file and read the property then creates the requested property value.
Macro
/******************** !MSIPropertyGet This macro provides a compile-time ability to inject Microsoft Installer Database file properties at compile time. Example: ${!MSIPropertyGet} "SomePackage.ProductName" "SomePackage.msi" "ProductName" ${!MSIPropertyGet} "SomePackage.ProductVersion" "SomePackage.msi" "ProductVersion" !define DisplayName `${SomePackage.ProductName} v${SomePackage.ProductVersion}` Name `${DisplayName} Special Build` ********************/ !verbose push !verbose 0 !define !MSIPropertyGet `!insertmacro _!MSIPropertyGet` !macro _!MSIPropertyGet _DefineToCreate _MSIFilePath _PropertyToRead !verbose Push !verbose 0 !if `${_DefineToCreate}` == `` !define __DefineToCreate `${_PropertyToRead}` !else !define __DefineToCreate `${_DefineToCreate}` !endif !ifdef `${__DefineToCreate}` !verbose 1 !error "!MSIPropertyGet: Value previously defined! [${__DefineToCreate}=${${__DefineToCreate}}]" !else !tempfile MSIPropertyGet_VBScript !appendfile `${MSIPropertyGet_VBScript}` `Set A=WScript.Arguments:Set B=CreateObject("WindowsInstaller.Installer").OpenDatabase(A(2),0)` !appendfile `${MSIPropertyGet_VBScript}` `.OpenView("SELECT Value FROM Property WHERE Property='"&A(3)&"'"):B.Execute:Set C=CreateObjec` !appendfile `${MSIPropertyGet_VBScript}` `t("Scripting.Filesystemobject"):Set D=C.OpenTextFile(A(0),2,1):D.WriteLine "!define $\`"&A(1)` !appendfile `${MSIPropertyGet_VBScript}` `&"$\` $\`"&B.Fetch.StringData(1)&"$\`":D.Close` !tempfile MSIPropertyGet_Result !system `WScript.exe "${MSIPropertyGet_VBScript}" //B //E:VBSCRIPT //T:30 "${MSIPropertyGet_Result}" "${__DefineToCreate}" "${_MSIFilePath}" "${_PropertyToRead}"` = 0 !include "${MSIPropertyGet_Result}" !system `Notepad "${MSIPropertyGet_Result}"` !delfile `${MSIPropertyGet_VBScript}` !delfile `${MSIPropertyGet_Result}` !undef MSIPropertyGet_VBScript !undef MSIPropertyGet_Result !ifndef `${__DefineToCreate}` !error "!MSIPropertyGet: Value was not defined! [${__DefineToCreate}] Ensure the MSI file exists and is not locked from reading" !else if `${${__DefineToCreate}}` == `` !warning "!MSIPropertyGet: Value is a zero length string! [${__DefineToCreate}=${${__DefineToCreate}}]" !endif !endif !undef __DefineToCreate !verbose pop !macroend !verbose pop