From 576914555d15983beda09bc09591c8b4969af8ab Mon Sep 17 00:00:00 2001 From: Nir Bar Date: Thu, 9 May 2024 10:59:29 +0300 Subject: [PATCH] Let the child bundle know whether the parent can receive custom messages --- src/burn/engine/EngineForApplication.cpp | 9 +++++++-- src/burn/engine/core.cpp | 11 +++++++++++ src/burn/engine/core.h | 1 + src/burn/engine/embedded.cpp | 2 +- src/burn/engine/pipe.h | 11 +++++++++++ src/ext/BalExtension/mba/core/Engine.cs | 3 +++ 6 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/burn/engine/EngineForApplication.cpp b/src/burn/engine/EngineForApplication.cpp index 32db03b80..283347bcd 100644 --- a/src/burn/engine/EngineForApplication.cpp +++ b/src/burn/engine/EngineForApplication.cpp @@ -384,7 +384,12 @@ class CEngineForApplication : public IBootstrapperEngine, public IMarshal if (BURN_MODE_EMBEDDED != m_pEngineState->mode) { hr = HRESULT_FROM_WIN32(ERROR_INVALID_STATE); - ExitOnRootFailure(hr, "Application requested to send embedded progress message when not in embedded mode."); + ExitOnRootFailure(hr, "Application requested to send embedded custom message when not in embedded mode."); + } + if ((m_pEngineState->embeddedConnection.dwCapabilities & BURN_PIPE_CAPABILITIES_CUSTOM_MESSAGE) != BURN_PIPE_CAPABILITIES_CUSTOM_MESSAGE) + { + hr = HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); + ExitOnRootFailure(hr, "Parent engine does not support receiving embedded custom messages."); } hr = BuffWriteNumber(&pbData, &cbData, dwCode); @@ -394,7 +399,7 @@ class CEngineForApplication : public IBootstrapperEngine, public IMarshal ExitOnFailure(hr, "Failed to write text to message buffer."); hr = PipeSendMessage(m_pEngineState->embeddedConnection.hPipe, BURN_EMBEDDED_MESSAGE_TYPE_CUSTOM, pbData, cbData, NULL, NULL, &dwResult); - ExitOnFailure(hr, "Failed to send embedded progress message over pipe."); + ExitOnFailure(hr, "Failed to send embedded custom message over pipe."); *pnResult = static_cast(dwResult); diff --git a/src/burn/engine/core.cpp b/src/burn/engine/core.cpp index c1a878834..0c601955c 100644 --- a/src/burn/engine/core.cpp +++ b/src/burn/engine/core.cpp @@ -1430,6 +1430,17 @@ static HRESULT ParseCommandLine( i += 2; } + else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, &argv[i][1], -1, BURN_COMMANDLINE_SWITCH_EMBEDDED_CAPABILITIES, -1)) + { + if (i + 1 >= argc) + { + ExitOnRootFailure(hr = E_INVALIDARG, "Must specify the embedded capabilities."); + } + ++i; + + hr = StrStringToUInt32(argv[i], 0, reinterpret_cast(&pEmbeddedConnection->dwCapabilities)); + ExitOnFailure(hr, "Failed to parse parent pipe capabilities."); + } else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, &argv[i][1], -1, BURN_COMMANDLINE_SWITCH_RELATED_DETECT, -1)) { pCommand->relationType = BOOTSTRAPPER_RELATION_DETECT; diff --git a/src/burn/engine/core.h b/src/burn/engine/core.h index 5f68ccac7..5fc0f66bf 100644 --- a/src/burn/engine/core.h +++ b/src/burn/engine/core.h @@ -16,6 +16,7 @@ const LPCWSTR BURN_COMMANDLINE_SWITCH_PARENT_NONE = L"parent:none"; const LPCWSTR BURN_COMMANDLINE_SWITCH_CLEAN_ROOM = L"burn.clean.room"; const LPCWSTR BURN_COMMANDLINE_SWITCH_ELEVATED = L"burn.elevated"; const LPCWSTR BURN_COMMANDLINE_SWITCH_EMBEDDED = L"burn.embedded"; +const LPCWSTR BURN_COMMANDLINE_SWITCH_EMBEDDED_CAPABILITIES = L"burn.embedded.capabilities"; const LPCWSTR BURN_COMMANDLINE_SWITCH_RUNONCE = L"burn.runonce"; const LPCWSTR BURN_COMMANDLINE_SWITCH_LOG_APPEND = L"burn.log.append"; const LPCWSTR BURN_COMMANDLINE_SWITCH_RELATED_DETECT = L"burn.related.detect"; diff --git a/src/burn/engine/embedded.cpp b/src/burn/engine/embedded.cpp index e8d36b7ad..b6ee63a96 100644 --- a/src/burn/engine/embedded.cpp +++ b/src/burn/engine/embedded.cpp @@ -75,7 +75,7 @@ extern "C" HRESULT EmbeddedRunBundle( hr = PipeCreatePipes(&connection, FALSE, &hCreatedPipesEvent); ExitOnFailure(hr, "Failed to create embedded pipe."); - hr = StrAllocFormattedSecure(&sczCommand, L"%ls -%ls %ls %ls %u", wzArguments, BURN_COMMANDLINE_SWITCH_EMBEDDED, connection.sczName, connection.sczSecret, dwCurrentProcessId); + hr = StrAllocFormattedSecure(&sczCommand, L"%ls -%ls %ls %ls %u -%ls %u", wzArguments, BURN_COMMANDLINE_SWITCH_EMBEDDED, connection.sczName, connection.sczSecret, dwCurrentProcessId, BURN_COMMANDLINE_SWITCH_EMBEDDED_CAPABILITIES, BURN_PIPE_CAPABILITIES_ALL); ExitOnFailure(hr, "Failed to allocate embedded command."); if (!::CreateProcessW(wzExecutablePath, sczCommand, NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi)) diff --git a/src/burn/engine/pipe.h b/src/burn/engine/pipe.h index b6a7742ab..b03c11e82 100644 --- a/src/burn/engine/pipe.h +++ b/src/burn/engine/pipe.h @@ -6,11 +6,22 @@ extern "C" { #endif + +enum BURN_PIPE_CAPABILITIES +{ + BURN_PIPE_CAPABILITIES_NONE = 0, + BURN_PIPE_CAPABILITIES_CUSTOM_MESSAGE = 1, + + // All the capabilities that this engine supports, used when creating capabilities command line for the embedded bundle + BURN_PIPE_CAPABILITIES_ALL = BURN_PIPE_CAPABILITIES_CUSTOM_MESSAGE, +}; + typedef struct _BURN_PIPE_CONNECTION { LPWSTR sczName; LPWSTR sczSecret; DWORD dwProcessId; + DWORD dwCapabilities; // Capabilities of the engine that created the pipe HANDLE hProcess; HANDLE hPipe; diff --git a/src/ext/BalExtension/mba/core/Engine.cs b/src/ext/BalExtension/mba/core/Engine.cs index 4462d53f7..caa7d8d08 100644 --- a/src/ext/BalExtension/mba/core/Engine.cs +++ b/src/ext/BalExtension/mba/core/Engine.cs @@ -445,6 +445,9 @@ public int SendEmbeddedProgress(int progressPercentage, int overallPercentage) /// /// Custom message code. /// Optional text. + /// + /// Thrown when the parent burn engine does not support receiving custom messages + /// public int SendEmbeddedCustomMessage(int code, string message) { int result = 0;