Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plan MSI transactions #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/WixToolset.Mba.Core/BootstrapperApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ protected BootstrapperApplication(IEngine engine)
/// <inheritdoc/>
public event EventHandler<PlanPackageBeginEventArgs> PlanPackageBegin;

/// <inheritdoc/>
public event EventHandler<PlanMsiTransactionEventArgs> PlanMsiTransaction;

/// <inheritdoc/>
public event EventHandler<PlanPatchTargetEventArgs> PlanPatchTarget;

Expand Down Expand Up @@ -522,6 +525,19 @@ protected virtual void OnPlanPatchTarget(PlanPatchTargetEventArgs args)
}
}

/// <summary>
/// Called by the engine, raises the <see cref="PlanMsiTransaction"/> event.
/// </summary>
/// <param name="args">Additional arguments for this event.</param>
protected virtual void OnPlanMsiTransaction(PlanMsiTransactionEventArgs args)
{
EventHandler<PlanMsiTransactionEventArgs> handler = this.PlanMsiTransaction;
if (null != handler)
{
handler(this, args);
}
}

/// <summary>
/// Called by the engine, raises the <see cref="PlanMsiFeature"/> event.
/// </summary>
Expand Down Expand Up @@ -1398,6 +1414,15 @@ int IBootstrapperApplication.OnPlanPatchTarget(string wzPackageId, string wzProd
return args.HResult;
}

int IBootstrapperApplication.OnPlanMsiTransaction(string wzPackageId, bool fTransaction, ref bool pfTransaction)
{
PlanMsiTransactionEventArgs args = new PlanMsiTransactionEventArgs(wzPackageId, fTransaction);
this.OnPlanMsiTransaction(args);

pfTransaction = args.Transaction;
return 0;
}

int IBootstrapperApplication.OnPlanMsiFeature(string wzPackageId, string wzFeatureId, FeatureState recommendedState, ref FeatureState pRequestedState, ref bool fCancel)
{
PlanMsiFeatureEventArgs args = new PlanMsiFeatureEventArgs(wzPackageId, wzFeatureId, recommendedState, pRequestedState, fCancel);
Expand Down
30 changes: 30 additions & 0 deletions src/WixToolset.Mba.Core/EventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,36 @@ public PlanPackageBeginEventArgs(string packageId, PackageState currentState, bo
public RequestState State { get; set; }
}

/// <summary>
/// Additional arguments used when the engine has plans an MSI transaction.
/// </summary>
[Serializable]
public class PlanMsiTransactionEventArgs : EventArgs
{
/// <summary>
/// Creates a new instance of the <see cref="PlanMsiTransactionEventArgs"/> class.
/// </summary>
/// <param name="transactionId">The identity of the transaction to plan for.</param>
/// <param name="fTransaction">Whether or not an MSI transaction can be used in the rollback boundary.</param>
public PlanMsiTransactionEventArgs(string transactionId, bool fTransaction)
{
this.TransactionId = transactionId;
this.Transaction = fTransaction;
}

/// <summary>
/// Gets the identity of the transaction to plan for.
/// </summary>
public string TransactionId { get; private set; }

/// <summary>
/// Whether or not an MSI transaction will be used in the rollback boundary.
/// When false on entry, then an MSI tranaction is either not authored or not supported on the target machine. In this case, setting the value to true has no effect.
/// When true on entry, setting to false will disable the transaction and packages will be installed without a wrapping MSI transaction.
Comment on lines +797 to +798
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the engine should send OnPlanMsiTransaction at all unless it was authored as an MSI transaction. This probably made more sense in your v3 fork where it could have been running on a machine that didn't support MSI transactions, but it doesn't make sense here. Following from that, the signature should just be wzTransactionId as input parameter and fTransaction as in/out. There's no reason for fTransaction and pfTransaction.

/// </summary>
public bool Transaction { get; set; }
}

/// <summary>
/// Event arguments for <see cref="IDefaultBootstrapperApplication.PlanPatchTarget"/>
/// </summary>
Expand Down
15 changes: 15 additions & 0 deletions src/WixToolset.Mba.Core/IBootstrapperApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,21 @@ int OnPlanPatchTarget(
[MarshalAs(UnmanagedType.Bool)] ref bool fCancel
);

/// <summary>
/// See <see cref="IDefaultBootstrapperApplication.PlanMsiTransaction"/>.
/// </summary>
/// <param name="wzTransactionId"></param>
/// <param name="fTransaction"></param>
/// <param name="pfTransaction"></param>
/// <returns></returns>
[PreserveSig]
[return: MarshalAs(UnmanagedType.I4)]
int OnPlanMsiTransaction(
[MarshalAs(UnmanagedType.LPWStr)] string wzTransactionId,
[MarshalAs(UnmanagedType.Bool)] bool fTransaction,
[MarshalAs(UnmanagedType.Bool)] ref bool pfTransaction
);

/// <summary>
/// See <see cref="IDefaultBootstrapperApplication.PlanMsiFeature"/>.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions src/WixToolset.Mba.Core/IDefaultBootstrapperApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,11 @@ public interface IDefaultBootstrapperApplication : IBootstrapperApplication
/// </summary>
event EventHandler<PlanPackageCompleteEventArgs> PlanPackageComplete;

/// <summary>
/// Fired when the engine has plans an MSI transaction.
/// </summary>
event EventHandler<PlanMsiTransactionEventArgs> PlanMsiTransaction;

/// <summary>
/// Fired when the engine is about to plan a target of an MSP package.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/balutil/inc/BAFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ enum BA_FUNCTIONS_MESSAGE
BA_FUNCTIONS_MESSAGE_ONPLANRELATEDBUNDLE = BOOTSTRAPPER_APPLICATION_MESSAGE_ONPLANRELATEDBUNDLE,
BA_FUNCTIONS_MESSAGE_ONPLANPACKAGEBEGIN = BOOTSTRAPPER_APPLICATION_MESSAGE_ONPLANPACKAGEBEGIN,
BA_FUNCTIONS_MESSAGE_ONPLANPATCHTARGET = BOOTSTRAPPER_APPLICATION_MESSAGE_ONPLANPATCHTARGET,
BA_FUNCTIONS_MESSAGE_ONPLANMSITRANSACTION = BOOTSTRAPPER_APPLICATION_MESSAGE_ONPLANMSITRANSACTION,
BA_FUNCTIONS_MESSAGE_ONPLANMSIFEATURE = BOOTSTRAPPER_APPLICATION_MESSAGE_ONPLANMSIFEATURE,
BA_FUNCTIONS_MESSAGE_ONPLANPACKAGECOMPLETE = BOOTSTRAPPER_APPLICATION_MESSAGE_ONPLANPACKAGECOMPLETE,
BA_FUNCTIONS_MESSAGE_ONAPPLYBEGIN = BOOTSTRAPPER_APPLICATION_MESSAGE_ONAPPLYBEGIN,
Expand Down
9 changes: 9 additions & 0 deletions src/balutil/inc/BalBaseBAFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,15 @@ class CBalBaseBAFunctions : public IBAFunctions
return S_OK;
}

virtual STDMETHODIMP OnPlanMsiTransaction(
__in_z LPCWSTR /*wzTransactionId*/,
__in BOOL /*fTransaction*/,
__out BOOL* /*pfTransaction*/
)
{
return S_OK;
}

virtual STDMETHODIMP OnPlanMsiFeature(
__in_z LPCWSTR /*wzPackageId*/,
__in_z LPCWSTR /*wzFeatureId*/,
Expand Down
1 change: 1 addition & 0 deletions src/balutil/inc/BalBaseBAFunctionsProc.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ static HRESULT WINAPI BalBaseBAFunctionsProc(
case BA_FUNCTIONS_MESSAGE_ONPLANRELATEDBUNDLE:
case BA_FUNCTIONS_MESSAGE_ONPLANPACKAGEBEGIN:
case BA_FUNCTIONS_MESSAGE_ONPLANPATCHTARGET:
case BA_FUNCTIONS_MESSAGE_ONPLANMSITRANSACTION:
case BA_FUNCTIONS_MESSAGE_ONPLANMSIFEATURE:
case BA_FUNCTIONS_MESSAGE_ONPLANPACKAGECOMPLETE:
case BA_FUNCTIONS_MESSAGE_ONAPPLYBEGIN:
Expand Down
9 changes: 9 additions & 0 deletions src/balutil/inc/BalBaseBootstrapperApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,15 @@ class CBalBaseBootstrapperApplication : public IBootstrapperApplication
return S_OK;
}

virtual STDMETHODIMP OnPlanMsiTransaction(
__in_z LPCWSTR /*wzTransactionId*/,
__in BOOL /*fTransaction*/,
__out BOOL* /*pfTransaction*/
)
{
return S_OK;
}

virtual STDMETHODIMP OnPlanMsiFeature(
__in_z LPCWSTR /*wzPackageId*/,
__in_z LPCWSTR /*wzFeatureId*/,
Expand Down
9 changes: 9 additions & 0 deletions src/balutil/inc/BalBaseBootstrapperApplicationProc.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@ static HRESULT BalBaseBAProcOnPlanPatchTarget(
return pBA->OnPlanPatchTarget(pArgs->wzPackageId, pArgs->wzProductCode, pArgs->recommendedState, &pResults->requestedState, &pResults->fCancel);
}

static HRESULT BalBaseBAProcOnPlanMsiTransaction(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will need to call this from a new case statement below.

__in IBootstrapperApplication* pBA,
__in BA_ONPLANMSITRANSACTION_ARGS* pArgs,
__inout BA_ONPLANMSITRANSACTION_RESULTS* pResults
)
{
return pBA->OnPlanMsiTransaction(pArgs->wzTransactionId, pArgs->fTransaction, &pResults->fTransaction);
}

static HRESULT BalBaseBAProcOnPlanMsiFeature(
__in IBootstrapperApplication* pBA,
__in BA_ONPLANMSIFEATURE_ARGS* pArgs,
Expand Down
7 changes: 7 additions & 0 deletions src/balutil/inc/IBootstrapperApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ DECLARE_INTERFACE_IID_(IBootstrapperApplication, IUnknown, "53C31D56-49C0-426B-A
__inout BOOL* pfCancel
) = 0;

// OnPlanMsiTransaction - called when the engine plans an MSI transaction.
STDMETHOD(OnPlanMsiTransaction)(
__in_z LPCWSTR wzTransactionId,
__in BOOL fTransaction,
__out BOOL* pfTransaction
) = 0;

// OnPlanMsiFeature - called when the engine plans a feature in an
// MSI package.
STDMETHOD(OnPlanMsiFeature)(
Expand Down