From a37013d41f0702cbdf2aee6dce95d26dafc069b4 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Sat, 1 Aug 2020 10:20:31 -0600 Subject: WIXFEAT:4763 Change "string" variable type to literal and add "formatted". --- src/WixToolset.Mba.Core/Engine.cs | 4 +-- src/WixToolset.Mba.Core/IBootstrapperEngine.cs | 3 +- src/balutil/BalBootstrapperEngine.cpp | 4 ++- src/balutil/balutil.cpp | 5 +-- src/balutil/balutil.vcxproj | 8 ++--- src/balutil/inc/IBootstrapperEngine.h | 3 +- src/balutil/inc/balutil.h | 3 +- src/balutil/packages.config | 4 +-- src/bextutil/BextBundleExtensionEngine.cpp | 21 ++--------- src/bextutil/bextutil.cpp | 50 +++++++++++++++++++++++--- src/bextutil/bextutil.vcxproj | 8 ++--- src/bextutil/inc/IBundleExtensionEngine.h | 8 ++--- src/bextutil/inc/bextutil.h | 20 +++++++++++ src/bextutil/packages.config | 4 +-- src/mbanative/mbanative.vcxproj | 8 ++--- src/mbanative/packages.config | 4 +-- 16 files changed, 103 insertions(+), 54 deletions(-) diff --git a/src/WixToolset.Mba.Core/Engine.cs b/src/WixToolset.Mba.Core/Engine.cs index 408278ed..2c544f29 100644 --- a/src/WixToolset.Mba.Core/Engine.cs +++ b/src/WixToolset.Mba.Core/Engine.cs @@ -79,7 +79,7 @@ namespace WixToolset.Mba.Core IntPtr pValue = Marshal.SecureStringToCoTaskMemUnicode(value); try { - this.engine.SetVariableString(name, pValue); + this.engine.SetVariableString(name, pValue, true); } finally { @@ -115,7 +115,7 @@ namespace WixToolset.Mba.Core IntPtr pValue = Marshal.StringToCoTaskMemUni(value); try { - this.engine.SetVariableString(name, pValue); + this.engine.SetVariableString(name, pValue, true); } finally { diff --git a/src/WixToolset.Mba.Core/IBootstrapperEngine.cs b/src/WixToolset.Mba.Core/IBootstrapperEngine.cs index d070998e..85ca8693 100644 --- a/src/WixToolset.Mba.Core/IBootstrapperEngine.cs +++ b/src/WixToolset.Mba.Core/IBootstrapperEngine.cs @@ -106,7 +106,8 @@ namespace WixToolset.Mba.Core void SetVariableString( [MarshalAs(UnmanagedType.LPWStr)] string wzVariable, - IntPtr wzValue + IntPtr wzValue, + [MarshalAs(UnmanagedType.Bool)] bool fFormatted ); void SetVariableVersion( diff --git a/src/balutil/BalBootstrapperEngine.cpp b/src/balutil/BalBootstrapperEngine.cpp index 945940c5..6a0c66d6 100644 --- a/src/balutil/BalBootstrapperEngine.cpp +++ b/src/balutil/BalBootstrapperEngine.cpp @@ -391,7 +391,8 @@ public: // IBootstrapperEngine virtual STDMETHODIMP SetVariableString( __in_z LPCWSTR wzVariable, - __in_z_opt LPCWSTR wzValue + __in_z_opt LPCWSTR wzValue, + __in BOOL fFormatted ) { BAENGINE_SETVARIABLESTRING_ARGS args = { }; @@ -400,6 +401,7 @@ public: // IBootstrapperEngine args.cbSize = sizeof(args); args.wzVariable = wzVariable; args.wzValue = wzValue; + args.fFormatted = fFormatted; results.cbSize = sizeof(results); diff --git a/src/balutil/balutil.cpp b/src/balutil/balutil.cpp index 7567752c..ebfaede4 100644 --- a/src/balutil/balutil.cpp +++ b/src/balutil/balutil.cpp @@ -225,7 +225,8 @@ LExit: DAPI_(HRESULT) BalSetStringVariable( __in_z LPCWSTR wzVariable, - __in_z_opt LPCWSTR wzValue + __in_z_opt LPCWSTR wzValue, + __in BOOL fFormatted ) { HRESULT hr = S_OK; @@ -236,7 +237,7 @@ DAPI_(HRESULT) BalSetStringVariable( ExitOnRootFailure(hr, "BalInitialize() must be called first."); } - hr = vpEngine->SetVariableString(wzVariable, wzValue); + hr = vpEngine->SetVariableString(wzVariable, wzValue, fFormatted); LExit: return hr; diff --git a/src/balutil/balutil.vcxproj b/src/balutil/balutil.vcxproj index 72c23991..39be0bed 100644 --- a/src/balutil/balutil.vcxproj +++ b/src/balutil/balutil.vcxproj @@ -2,8 +2,8 @@ - - + + @@ -106,8 +106,8 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - + + diff --git a/src/balutil/inc/IBootstrapperEngine.h b/src/balutil/inc/IBootstrapperEngine.h index 3fe3d401..3b648df1 100644 --- a/src/balutil/inc/IBootstrapperEngine.h +++ b/src/balutil/inc/IBootstrapperEngine.h @@ -89,7 +89,8 @@ DECLARE_INTERFACE_IID_(IBootstrapperEngine, IUnknown, "6480D616-27A0-44D7-905B-8 STDMETHOD(SetVariableString)( __in_z LPCWSTR wzVariable, - __in_z_opt LPCWSTR wzValue + __in_z_opt LPCWSTR wzValue, + __in BOOL fFormatted ) = 0; STDMETHOD(SetVariableVersion)( diff --git a/src/balutil/inc/balutil.h b/src/balutil/inc/balutil.h index e0f5874c..b718e48b 100644 --- a/src/balutil/inc/balutil.h +++ b/src/balutil/inc/balutil.h @@ -131,7 +131,8 @@ BalSetStringVariable - sets a string variable in the engine. ********************************************************************/ DAPI_(HRESULT) BalSetStringVariable( __in_z LPCWSTR wzVariable, - __in_z_opt LPCWSTR wzValue + __in_z_opt LPCWSTR wzValue, + __in BOOL fFormatted ); /******************************************************************* diff --git a/src/balutil/packages.config b/src/balutil/packages.config index 56f0cea3..e8417860 100644 --- a/src/balutil/packages.config +++ b/src/balutil/packages.config @@ -1,6 +1,6 @@  - - + + \ No newline at end of file diff --git a/src/bextutil/BextBundleExtensionEngine.cpp b/src/bextutil/BextBundleExtensionEngine.cpp index 02070a6f..a78b3130 100644 --- a/src/bextutil/BextBundleExtensionEngine.cpp +++ b/src/bextutil/BextBundleExtensionEngine.cpp @@ -225,23 +225,6 @@ public: // IBundleExtensionEngine return m_pfnBundleExtensionEngineProc(BUNDLE_EXTENSION_ENGINE_MESSAGE_LOG, &args, &results, m_pvBundleExtensionEngineProcContext); } - virtual STDMETHODIMP SetVariableLiteralString( - __in_z LPCWSTR wzVariable, - __in_z_opt LPCWSTR wzValue - ) - { - BUNDLE_EXTENSION_ENGINE_SETVARIABLELITERALSTRING_ARGS args = { }; - BUNDLE_EXTENSION_ENGINE_SETVARIABLELITERALSTRING_RESULTS results = { }; - - args.cbSize = sizeof(args); - args.wzVariable = wzVariable; - args.wzValue = wzValue; - - results.cbSize = sizeof(results); - - return m_pfnBundleExtensionEngineProc(BUNDLE_EXTENSION_ENGINE_MESSAGE_SETVARIABLELITERALSTRING, &args, &results, m_pvBundleExtensionEngineProcContext); - } - virtual STDMETHODIMP SetVariableNumeric( __in_z LPCWSTR wzVariable, __in LONGLONG llValue @@ -261,7 +244,8 @@ public: // IBundleExtensionEngine virtual STDMETHODIMP SetVariableString( __in_z LPCWSTR wzVariable, - __in_z_opt LPCWSTR wzValue + __in_z_opt LPCWSTR wzValue, + __in BOOL fFormatted ) { BUNDLE_EXTENSION_ENGINE_SETVARIABLESTRING_ARGS args = { }; @@ -270,6 +254,7 @@ public: // IBundleExtensionEngine args.cbSize = sizeof(args); args.wzVariable = wzVariable; args.wzValue = wzValue; + args.fFormatted = fFormatted; results.cbSize = sizeof(results); diff --git a/src/bextutil/bextutil.cpp b/src/bextutil/bextutil.cpp index baf35591..4b22d502 100644 --- a/src/bextutil/bextutil.cpp +++ b/src/bextutil/bextutil.cpp @@ -119,6 +119,29 @@ DAPIV_(HRESULT) BextLog( { HRESULT hr = S_OK; va_list args; + + if (!vpEngine) + { + hr = E_POINTER; + ExitOnRootFailure(hr, "BextInitialize() must be called first."); + } + + va_start(args, szFormat); + hr = BextLogArgs(level, szFormat, args); + va_end(args); + +LExit: + return hr; +} + + +DAPI_(HRESULT) BextLogArgs( + __in BUNDLE_EXTENSION_LOG_LEVEL level, + __in_z __format_string LPCSTR szFormat, + __in va_list args + ) +{ + HRESULT hr = S_OK; LPSTR sczFormattedAnsi = NULL; LPWSTR sczMessage = NULL; @@ -128,9 +151,7 @@ DAPIV_(HRESULT) BextLog( ExitOnRootFailure(hr, "BextInitialize() must be called first."); } - va_start(args, szFormat); hr = StrAnsiAllocFormattedArgs(&sczFormattedAnsi, szFormat, args); - va_end(args); ExitOnFailure(hr, "Failed to format log string."); hr = StrAllocStringAnsi(&sczMessage, sczFormattedAnsi, 0, CP_UTF8); @@ -153,6 +174,29 @@ DAPIV_(HRESULT) BextLogError( { HRESULT hr = S_OK; va_list args; + + if (!vpEngine) + { + hr = E_POINTER; + ExitOnRootFailure(hr, "BextInitialize() must be called first."); + } + + va_start(args, szFormat); + hr = BextLogErrorArgs(hrError, szFormat, args); + va_end(args); + +LExit: + return hr; +} + + +DAPI_(HRESULT) BextLogErrorArgs( + __in HRESULT hrError, + __in_z __format_string LPCSTR szFormat, + __in va_list args + ) +{ + HRESULT hr = S_OK; LPSTR sczFormattedAnsi = NULL; LPWSTR sczMessage = NULL; @@ -162,9 +206,7 @@ DAPIV_(HRESULT) BextLogError( ExitOnRootFailure(hr, "BextInitialize() must be called first."); } - va_start(args, szFormat); hr = StrAnsiAllocFormattedArgs(&sczFormattedAnsi, szFormat, args); - va_end(args); ExitOnFailure(hr, "Failed to format error log string."); hr = StrAllocFormatted(&sczMessage, L"Error 0x%08x: %S", hrError, sczFormattedAnsi); diff --git a/src/bextutil/bextutil.vcxproj b/src/bextutil/bextutil.vcxproj index 78ff290d..32518202 100644 --- a/src/bextutil/bextutil.vcxproj +++ b/src/bextutil/bextutil.vcxproj @@ -2,8 +2,8 @@ - - + + @@ -95,8 +95,8 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - + + diff --git a/src/bextutil/inc/IBundleExtensionEngine.h b/src/bextutil/inc/IBundleExtensionEngine.h index 869c6695..7772b016 100644 --- a/src/bextutil/inc/IBundleExtensionEngine.h +++ b/src/bextutil/inc/IBundleExtensionEngine.h @@ -42,11 +42,6 @@ DECLARE_INTERFACE_IID_(IBundleExtensionEngine, IUnknown, "9D027A39-F6B6-42CC-973 __in_z LPCWSTR wzMessage ) = 0; - STDMETHOD(SetVariableLiteralString)( - __in_z LPCWSTR wzVariable, - __in_z_opt LPCWSTR wzValue - ) = 0; - STDMETHOD(SetVariableNumeric)( __in_z LPCWSTR wzVariable, __in LONGLONG llValue @@ -54,7 +49,8 @@ DECLARE_INTERFACE_IID_(IBundleExtensionEngine, IUnknown, "9D027A39-F6B6-42CC-973 STDMETHOD(SetVariableString)( __in_z LPCWSTR wzVariable, - __in_z_opt LPCWSTR wzValue + __in_z_opt LPCWSTR wzValue, + __in BOOL fFormatted ) = 0; STDMETHOD(SetVariableVersion)( diff --git a/src/bextutil/inc/bextutil.h b/src/bextutil/inc/bextutil.h index e80d3944..ac9c0062 100644 --- a/src/bextutil/inc/bextutil.h +++ b/src/bextutil/inc/bextutil.h @@ -71,6 +71,16 @@ DAPIV_(HRESULT) BextLog( ... ); +/******************************************************************* + BextLogArgs - logs a message with the engine. + +********************************************************************/ +DAPI_(HRESULT) BextLogArgs( + __in BUNDLE_EXTENSION_LOG_LEVEL level, + __in_z __format_string LPCSTR szFormat, + __in va_list args + ); + /******************************************************************* BextLogError - logs an error message with the engine. @@ -81,6 +91,16 @@ DAPIV_(HRESULT) BextLogError( ... ); +/******************************************************************* + BextLogErrorArgs - logs an error message with the engine. + +********************************************************************/ +DAPI_(HRESULT) BextLogErrorArgs( + __in HRESULT hr, + __in_z __format_string LPCSTR szFormat, + __in va_list args + ); + #ifdef __cplusplus } #endif diff --git a/src/bextutil/packages.config b/src/bextutil/packages.config index 56f0cea3..e8417860 100644 --- a/src/bextutil/packages.config +++ b/src/bextutil/packages.config @@ -1,6 +1,6 @@  - - + + \ No newline at end of file diff --git a/src/mbanative/mbanative.vcxproj b/src/mbanative/mbanative.vcxproj index 23e38e49..c2d0bded 100644 --- a/src/mbanative/mbanative.vcxproj +++ b/src/mbanative/mbanative.vcxproj @@ -5,8 +5,8 @@ - - + + @@ -102,7 +102,7 @@ - - + + \ No newline at end of file diff --git a/src/mbanative/packages.config b/src/mbanative/packages.config index 9515379a..c3c26daa 100644 --- a/src/mbanative/packages.config +++ b/src/mbanative/packages.config @@ -4,6 +4,6 @@ - - + + \ No newline at end of file -- cgit v1.2.3-55-g6feb