From fb54576f1d05e82ba47cd718c4c4f8b3bad624c9 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Fri, 18 Mar 2022 20:15:33 -0500 Subject: Give BA process id and option to wait for cancelled process to exit. --- .../inc/BootstrapperApplication.h | 27 ++++++++++++++++ .../WixToolset.Mba.Core/BootstrapperApplication.cs | 25 +++++++++++++++ src/api/burn/WixToolset.Mba.Core/EventArgs.cs | 36 ++++++++++++++++++++++ .../IBootstrapperApplication.cs | 32 +++++++++++++++++++ .../IDefaultBootstrapperApplication.cs | 5 +++ src/api/burn/balutil/inc/BAFunctions.h | 1 + src/api/burn/balutil/inc/BalBaseBAFunctions.h | 10 ++++++ src/api/burn/balutil/inc/BalBaseBAFunctionsProc.h | 1 + .../balutil/inc/BalBaseBootstrapperApplication.h | 10 ++++++ .../inc/BalBaseBootstrapperApplicationProc.h | 12 ++++++++ .../burn/balutil/inc/IBootstrapperApplication.h | 9 ++++++ 11 files changed, 168 insertions(+) (limited to 'src/api') diff --git a/src/api/burn/WixToolset.BootstrapperCore.Native/inc/BootstrapperApplication.h b/src/api/burn/WixToolset.BootstrapperCore.Native/inc/BootstrapperApplication.h index 0b81b35a..df8cac76 100644 --- a/src/api/burn/WixToolset.BootstrapperCore.Native/inc/BootstrapperApplication.h +++ b/src/api/burn/WixToolset.BootstrapperCore.Native/inc/BootstrapperApplication.h @@ -224,6 +224,7 @@ enum BOOTSTRAPPER_APPLICATION_MESSAGE BOOTSTRAPPER_APPLICATION_MESSAGE_ONPLANRESTORERELATEDBUNDLE, BOOTSTRAPPER_APPLICATION_MESSAGE_ONPLANRELATEDBUNDLETYPE, BOOTSTRAPPER_APPLICATION_MESSAGE_ONAPPLYDOWNGRADE, + BOOTSTRAPPER_APPLICATION_MESSAGE_ONEXECUTEPROCESSCANCEL, }; enum BOOTSTRAPPER_APPLYCOMPLETE_ACTION @@ -282,6 +283,18 @@ enum BOOTSTRAPPER_EXECUTEPACKAGECOMPLETE_ACTION BOOTSTRAPPER_EXECUTEPACKAGECOMPLETE_ACTION_SUSPEND, }; +enum BOOTSTRAPPER_EXECUTEPROCESSCANCEL_ACTION +{ + // Instructs the engine to stop waiting for the process to exit. + // The package is immediately considered to have failed with ERROR_INSTALL_USEREXIT. + // The engine will never rollback the package. + BOOTSTRAPPER_EXECUTEPROCESSCANCEL_ACTION_ABANDON, + // Instructs the engine to wait for the process to exit. + // Once the process has exited, the package is considered to have failed with ERROR_INSTALL_USEREXIT. + // This allows the engine to rollback the package if necessary. + BOOTSTRAPPER_EXECUTEPROCESSCANCEL_ACTION_WAIT, +}; + enum BOOTSTRAPPER_SHUTDOWN_ACTION { BOOTSTRAPPER_SHUTDOWN_ACTION_NONE, @@ -997,6 +1010,20 @@ struct BA_ONEXECUTEPATCHTARGET_RESULTS BOOL fCancel; }; +struct BA_ONEXECUTEPROCESSCANCEL_ARGS +{ + DWORD cbSize; + LPCWSTR wzPackageId; + DWORD dwProcessId; + BOOTSTRAPPER_EXECUTEPROCESSCANCEL_ACTION recommendation; +}; + +struct BA_ONEXECUTEPROCESSCANCEL_RESULTS +{ + DWORD cbSize; + BOOTSTRAPPER_EXECUTEPROCESSCANCEL_ACTION action; +}; + struct BA_ONEXECUTEPROGRESS_ARGS { DWORD cbSize; diff --git a/src/api/burn/WixToolset.Mba.Core/BootstrapperApplication.cs b/src/api/burn/WixToolset.Mba.Core/BootstrapperApplication.cs index 8a2e0e93..5ed064fa 100644 --- a/src/api/burn/WixToolset.Mba.Core/BootstrapperApplication.cs +++ b/src/api/burn/WixToolset.Mba.Core/BootstrapperApplication.cs @@ -280,6 +280,9 @@ namespace WixToolset.Mba.Core /// public event EventHandler PlanRestoreRelatedBundle; + /// + public event EventHandler ExecuteProcessCancel; + /// /// Entry point that is called when the bootstrapper application is ready to run. /// @@ -1369,6 +1372,19 @@ namespace WixToolset.Mba.Core } } + /// + /// Called by the engine, raises the event. + /// + /// Additional arguments for this event. + protected virtual void OnExecuteProcessCancel(ExecuteProcessCancelEventArgs args) + { + EventHandler handler = this.ExecuteProcessCancel; + if (null != handler) + { + handler(this, args); + } + } + #region IBootstrapperApplication Members int IBootstrapperApplication.BAProc(int message, IntPtr pvArgs, IntPtr pvResults, IntPtr pvContext) @@ -2119,6 +2135,15 @@ namespace WixToolset.Mba.Core return args.HResult; } + int IBootstrapperApplication.OnExecuteProcessCancel(string wzPackageId, int processId, BOOTSTRAPPER_EXECUTEPROCESSCANCEL_ACTION recommendation, ref BOOTSTRAPPER_EXECUTEPROCESSCANCEL_ACTION pAction) + { + ExecuteProcessCancelEventArgs args = new ExecuteProcessCancelEventArgs(wzPackageId, processId, recommendation, pAction); + this.OnExecuteProcessCancel(args); + + pAction = args.Action; + return args.HResult; + } + #endregion } } diff --git a/src/api/burn/WixToolset.Mba.Core/EventArgs.cs b/src/api/burn/WixToolset.Mba.Core/EventArgs.cs index c93c2885..c2c73067 100644 --- a/src/api/burn/WixToolset.Mba.Core/EventArgs.cs +++ b/src/api/burn/WixToolset.Mba.Core/EventArgs.cs @@ -2488,4 +2488,40 @@ namespace WixToolset.Mba.Core /// public RequestState State { get; set; } } + + /// + /// Event arguments for + /// + [Serializable] + public class ExecuteProcessCancelEventArgs : HResultEventArgs + { + /// + public ExecuteProcessCancelEventArgs(string packageId, int processId, BOOTSTRAPPER_EXECUTEPROCESSCANCEL_ACTION recommendation, BOOTSTRAPPER_EXECUTEPROCESSCANCEL_ACTION action) + { + this.PackageId = packageId; + this.ProcessId = processId; + this.Recommendation = recommendation; + this.Action = action; + } + + /// + /// Gets the identity of the package. + /// + public string PackageId { get; private set; } + + /// + /// Gets the process id. + /// + public int ProcessId { get; private set; } + + /// + /// Gets the recommended action from the engine. + /// + public BOOTSTRAPPER_EXECUTEPROCESSCANCEL_ACTION Recommendation { get; private set; } + + /// + /// Gets or sets the action to be performed. This is passed back to the engine. + /// + public BOOTSTRAPPER_EXECUTEPROCESSCANCEL_ACTION Action { get; set; } + } } diff --git a/src/api/burn/WixToolset.Mba.Core/IBootstrapperApplication.cs b/src/api/burn/WixToolset.Mba.Core/IBootstrapperApplication.cs index d4fe8320..1786eecd 100644 --- a/src/api/burn/WixToolset.Mba.Core/IBootstrapperApplication.cs +++ b/src/api/burn/WixToolset.Mba.Core/IBootstrapperApplication.cs @@ -1170,6 +1170,18 @@ namespace WixToolset.Mba.Core [MarshalAs(UnmanagedType.I4)] int hrRecommended, [MarshalAs(UnmanagedType.I4)] ref int hrStatus ); + + /// + /// See . + /// + [PreserveSig] + [return: MarshalAs(UnmanagedType.I4)] + int OnExecuteProcessCancel( + [MarshalAs(UnmanagedType.LPWStr)] string wzPackageId, + int processId, + [MarshalAs(UnmanagedType.I4)] BOOTSTRAPPER_EXECUTEPROCESSCANCEL_ACTION recommendation, + [MarshalAs(UnmanagedType.I4)] ref BOOTSTRAPPER_EXECUTEPROCESSCANCEL_ACTION pAction + ); } /// @@ -1906,6 +1918,26 @@ namespace WixToolset.Mba.Core Suspend, } + /// + /// The available actions for . + /// + public enum BOOTSTRAPPER_EXECUTEPROCESSCANCEL_ACTION + { + /// + /// Instructs the engine to stop waiting for the process to exit. + /// The package is immediately considered to have failed with ERROR_INSTALL_USEREXIT. + /// The engine will never rollback the package. + /// + Abandon, + + /// + /// Instructs the engine to wait for the process to exit. + /// Once the process has exited, the package is considered to have failed with ERROR_INSTALL_USEREXIT. + /// This allows the engine to rollback the package if necessary. + /// + Wait, + } + /// /// The result of evaluating a condition from a package. /// diff --git a/src/api/burn/WixToolset.Mba.Core/IDefaultBootstrapperApplication.cs b/src/api/burn/WixToolset.Mba.Core/IDefaultBootstrapperApplication.cs index c9284b69..21d99b32 100644 --- a/src/api/burn/WixToolset.Mba.Core/IDefaultBootstrapperApplication.cs +++ b/src/api/burn/WixToolset.Mba.Core/IDefaultBootstrapperApplication.cs @@ -243,6 +243,11 @@ namespace WixToolset.Mba.Core /// event EventHandler ExecutePackageComplete; + /// + /// Fired when a package that spawned a process is cancelled. + /// + event EventHandler ExecuteProcessCancel; + /// /// Fired when the engine executes one or more patches targeting a product. /// diff --git a/src/api/burn/balutil/inc/BAFunctions.h b/src/api/burn/balutil/inc/BAFunctions.h index 58c26166..158e65b5 100644 --- a/src/api/burn/balutil/inc/BAFunctions.h +++ b/src/api/burn/balutil/inc/BAFunctions.h @@ -91,6 +91,7 @@ enum BA_FUNCTIONS_MESSAGE BA_FUNCTIONS_MESSAGE_ONPLANRESTORERELATEDBUNDLE = BOOTSTRAPPER_APPLICATION_MESSAGE_ONPLANRESTORERELATEDBUNDLE, BA_FUNCTIONS_MESSAGE_ONPLANRELATEDBUNDLETYPE = BOOTSTRAPPER_APPLICATION_MESSAGE_ONPLANRELATEDBUNDLETYPE, BA_FUNCTIONS_MESSAGE_ONAPPLYDOWNGRADE = BOOTSTRAPPER_APPLICATION_MESSAGE_ONAPPLYDOWNGRADE, + BA_FUNCTIONS_MESSAGE_ONEXECUTEPROCESSCANCEL = BOOTSTRAPPER_APPLICATION_MESSAGE_ONEXECUTEPROCESSCANCEL, BA_FUNCTIONS_MESSAGE_ONTHEMELOADED = 1024, BA_FUNCTIONS_MESSAGE_WNDPROC, diff --git a/src/api/burn/balutil/inc/BalBaseBAFunctions.h b/src/api/burn/balutil/inc/BalBaseBAFunctions.h index fe5c99ba..614d4bcf 100644 --- a/src/api/burn/balutil/inc/BalBaseBAFunctions.h +++ b/src/api/burn/balutil/inc/BalBaseBAFunctions.h @@ -877,6 +877,16 @@ public: // IBootstrapperApplication return S_OK; } + virtual STDMETHODIMP OnExecuteProcessCancel( + __in_z LPCWSTR /*wzPackageId*/, + __in DWORD /*dwProcessId*/, + __in BOOTSTRAPPER_EXECUTEPROCESSCANCEL_ACTION /*recommendation*/, + __inout BOOTSTRAPPER_EXECUTEPROCESSCANCEL_ACTION* /*pAction*/ + ) + { + return S_OK; + } + public: // IBAFunctions virtual STDMETHODIMP OnPlan( ) diff --git a/src/api/burn/balutil/inc/BalBaseBAFunctionsProc.h b/src/api/burn/balutil/inc/BalBaseBAFunctionsProc.h index 100e5c30..b96a180c 100644 --- a/src/api/burn/balutil/inc/BalBaseBAFunctionsProc.h +++ b/src/api/burn/balutil/inc/BalBaseBAFunctionsProc.h @@ -162,6 +162,7 @@ static HRESULT WINAPI BalBaseBAFunctionsProc( case BA_FUNCTIONS_MESSAGE_ONPLANRESTORERELATEDBUNDLE: case BA_FUNCTIONS_MESSAGE_ONPLANRELATEDBUNDLETYPE: case BA_FUNCTIONS_MESSAGE_ONAPPLYDOWNGRADE: + case BA_FUNCTIONS_MESSAGE_ONEXECUTEPROCESSCANCEL: hr = BalBaseBootstrapperApplicationProc((BOOTSTRAPPER_APPLICATION_MESSAGE)message, pvArgs, pvResults, pvContext); break; case BA_FUNCTIONS_MESSAGE_ONTHEMELOADED: diff --git a/src/api/burn/balutil/inc/BalBaseBootstrapperApplication.h b/src/api/burn/balutil/inc/BalBaseBootstrapperApplication.h index fd06a83f..25570ffd 100644 --- a/src/api/burn/balutil/inc/BalBaseBootstrapperApplication.h +++ b/src/api/burn/balutil/inc/BalBaseBootstrapperApplication.h @@ -1077,6 +1077,16 @@ public: // IBootstrapperApplication return S_OK; } + virtual STDMETHODIMP OnExecuteProcessCancel( + __in_z LPCWSTR /*wzPackageId*/, + __in DWORD /*dwProcessId*/, + __in BOOTSTRAPPER_EXECUTEPROCESSCANCEL_ACTION /*recommendation*/, + __inout BOOTSTRAPPER_EXECUTEPROCESSCANCEL_ACTION* /*pAction*/ + ) + { + return S_OK; + } + public: //CBalBaseBootstrapperApplication virtual STDMETHODIMP Initialize( __in const BOOTSTRAPPER_CREATE_ARGS* pCreateArgs diff --git a/src/api/burn/balutil/inc/BalBaseBootstrapperApplicationProc.h b/src/api/burn/balutil/inc/BalBaseBootstrapperApplicationProc.h index 4e413e4e..b196d183 100644 --- a/src/api/burn/balutil/inc/BalBaseBootstrapperApplicationProc.h +++ b/src/api/burn/balutil/inc/BalBaseBootstrapperApplicationProc.h @@ -486,6 +486,15 @@ static HRESULT BalBaseBAProcOnExecutePackageComplete( return pBA->OnExecutePackageComplete(pArgs->wzPackageId, pArgs->hrStatus, pArgs->restart, pArgs->recommendation, &pResults->action); } +static HRESULT BalBaseBAProcOnExecuteProcessCancel( + __in IBootstrapperApplication* pBA, + __in BA_ONEXECUTEPROCESSCANCEL_ARGS* pArgs, + __inout BA_ONEXECUTEPROCESSCANCEL_RESULTS* pResults + ) +{ + return pBA->OnExecuteProcessCancel(pArgs->wzPackageId, pArgs->dwProcessId, pArgs->recommendation, &pResults->action); +} + static HRESULT BalBaseBAProcOnExecuteComplete( __in IBootstrapperApplication* pBA, __in BA_ONEXECUTECOMPLETE_ARGS* pArgs, @@ -1012,6 +1021,9 @@ static HRESULT WINAPI BalBaseBootstrapperApplicationProc( case BOOTSTRAPPER_APPLICATION_MESSAGE_ONAPPLYDOWNGRADE: hr = BalBaseBAProcOnApplyDowngrade(pBA, reinterpret_cast(pvArgs), reinterpret_cast(pvResults)); break; + case BOOTSTRAPPER_APPLICATION_MESSAGE_ONEXECUTEPROCESSCANCEL: + hr = BalBaseBAProcOnExecuteProcessCancel(pBA, reinterpret_cast(pvArgs), reinterpret_cast(pvResults)); + break; } } diff --git a/src/api/burn/balutil/inc/IBootstrapperApplication.h b/src/api/burn/balutil/inc/IBootstrapperApplication.h index c9cf3126..6174c290 100644 --- a/src/api/burn/balutil/inc/IBootstrapperApplication.h +++ b/src/api/burn/balutil/inc/IBootstrapperApplication.h @@ -714,4 +714,13 @@ DECLARE_INTERFACE_IID_(IBootstrapperApplication, IUnknown, "53C31D56-49C0-426B-A __in HRESULT hrRecommended, __inout HRESULT* phrStatus ) = 0; + + // OnExecuteProcessCancel - called when a package that spawned a process is cancelled. + // + STDMETHOD(OnExecuteProcessCancel)( + __in_z LPCWSTR wzPackageId, + __in DWORD dwProcessId, + __in BOOTSTRAPPER_EXECUTEPROCESSCANCEL_ACTION recommendation, + __inout BOOTSTRAPPER_EXECUTEPROCESSCANCEL_ACTION* pAction + ) = 0; }; -- cgit v1.2.3-55-g6feb