From 62b32cd6f21292c73dae8d5cfcd3a1cb13a1fd7d Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Mon, 19 Apr 2021 17:32:32 -0500 Subject: Replace OnResolveSource with OnCacheAcquireResolving. Update balretry to have a separate type for container vs payload. #3640 --- src/WixToolset.Mba.Core/BootstrapperApplication.cs | 24 ++-- src/WixToolset.Mba.Core/EventArgs.cs | 143 +++++++++++++-------- .../IBootstrapperApplication.cs | 100 +++++++------- .../IDefaultBootstrapperApplication.cs | 19 +-- 4 files changed, 168 insertions(+), 118 deletions(-) (limited to 'src/WixToolset.Mba.Core') diff --git a/src/WixToolset.Mba.Core/BootstrapperApplication.cs b/src/WixToolset.Mba.Core/BootstrapperApplication.cs index b6c0dd0d..79cbfa86 100644 --- a/src/WixToolset.Mba.Core/BootstrapperApplication.cs +++ b/src/WixToolset.Mba.Core/BootstrapperApplication.cs @@ -146,7 +146,7 @@ namespace WixToolset.Mba.Core public event EventHandler CacheAcquireProgress; /// - public event EventHandler ResolveSource; + public event EventHandler CacheAcquireResolving; /// public event EventHandler CacheAcquireComplete; @@ -736,12 +736,12 @@ namespace WixToolset.Mba.Core } /// - /// Called by the engine, raises the event. + /// Called by the engine, raises the event. /// /// Additional arguments for this event. - protected virtual void OnResolveSource(ResolveSourceEventArgs args) + protected virtual void OnCacheAcquireResolving(CacheAcquireResolvingEventArgs args) { - EventHandler handler = this.ResolveSource; + EventHandler handler = this.CacheAcquireResolving; if (null != handler) { handler(this, args); @@ -1126,9 +1126,9 @@ namespace WixToolset.Mba.Core return args.HResult; } - int IBootstrapperApplication.OnDetectBegin(bool fInstalled, int cPackages, ref bool fCancel) + int IBootstrapperApplication.OnDetectBegin(bool fCached, bool fInstalled, int cPackages, ref bool fCancel) { - DetectBeginEventArgs args = new DetectBeginEventArgs(fInstalled, cPackages, fCancel); + DetectBeginEventArgs args = new DetectBeginEventArgs(fCached, fInstalled, cPackages, fCancel); this.OnDetectBegin(args); fCancel = args.Cancel; @@ -1400,11 +1400,12 @@ namespace WixToolset.Mba.Core return args.HResult; } - int IBootstrapperApplication.OnCacheAcquireBegin(string wzPackageOrContainerId, string wzPayloadId, CacheOperation operation, string wzSource, ref bool fCancel) + int IBootstrapperApplication.OnCacheAcquireBegin(string wzPackageOrContainerId, string wzPayloadId, string wzSource, string wzDownloadUrl, string wzPayloadContainerId, CacheOperation recommendation, ref CacheOperation action, ref bool fCancel) { - CacheAcquireBeginEventArgs args = new CacheAcquireBeginEventArgs(wzPackageOrContainerId, wzPayloadId, operation, wzSource, fCancel); + CacheAcquireBeginEventArgs args = new CacheAcquireBeginEventArgs(wzPackageOrContainerId, wzPayloadId, wzSource, wzDownloadUrl, wzPayloadContainerId, recommendation, action, fCancel); this.OnCacheAcquireBegin(args); + action = args.Action; fCancel = args.Cancel; return args.HResult; } @@ -1418,11 +1419,12 @@ namespace WixToolset.Mba.Core return args.HResult; } - int IBootstrapperApplication.OnResolveSource(string wzPackageOrContainerId, string wzPayloadId, string wzLocalSource, string wzDownloadSource, BOOTSTRAPPER_RESOLVESOURCE_ACTION recommendation, ref BOOTSTRAPPER_RESOLVESOURCE_ACTION action, ref bool fCancel) + int IBootstrapperApplication.OnCacheAcquireResolving(string wzPackageOrContainerId, string wzPayloadId, string[] searchPaths, int cSearchPaths, bool fFoundLocal, int dwRecommendedSearchPath, string wzDownloadUrl, string wzPayloadContainerId, CacheResolveOperation recommendation, ref int dwChosenSearchPath, ref CacheResolveOperation action, ref bool fCancel) { - ResolveSourceEventArgs args = new ResolveSourceEventArgs(wzPackageOrContainerId, wzPayloadId, wzLocalSource, wzDownloadSource, action, recommendation, fCancel); - this.OnResolveSource(args); + CacheAcquireResolvingEventArgs args = new CacheAcquireResolvingEventArgs(wzPackageOrContainerId, wzPayloadId, searchPaths, fFoundLocal, dwRecommendedSearchPath, wzDownloadUrl, wzPayloadContainerId, recommendation, dwChosenSearchPath, action, fCancel); + this.OnCacheAcquireResolving(args); + dwChosenSearchPath = args.ChosenSearchPath; action = args.Action; fCancel = args.Cancel; return args.HResult; diff --git a/src/WixToolset.Mba.Core/EventArgs.cs b/src/WixToolset.Mba.Core/EventArgs.cs index 7e7cbd11..ee89b583 100644 --- a/src/WixToolset.Mba.Core/EventArgs.cs +++ b/src/WixToolset.Mba.Core/EventArgs.cs @@ -122,6 +122,31 @@ namespace WixToolset.Mba.Core public T Action { get; set; } } + /// + /// Base class for cancellable action BA classes. + /// + [Serializable] + public abstract class CancellableActionEventArgs : CancellableHResultEventArgs + { + /// + public CancellableActionEventArgs(bool cancelRecommendation, T recommendation, T action) + : base(cancelRecommendation) + { + this.Recommendation = recommendation; + this.Action = action; + } + + /// + /// Gets the recommended action from the engine. + /// + public T Recommendation { get; private set; } + + /// + /// Gets or sets the action to be performed. This is passed back to the engine. + /// + public T Action { get; set; } + } + /// /// Additional arguments used when startup has begun. /// @@ -196,24 +221,25 @@ namespace WixToolset.Mba.Core } /// - /// Additional arguments used when the overall detection phase has begun. + /// Event arguments for /// [Serializable] public class DetectBeginEventArgs : CancellableHResultEventArgs { - /// - /// Creates a new instance of the class. - /// - /// Specifies whether the bundle is installed. - /// The number of packages to detect. - /// The recommendation from the engine. - public DetectBeginEventArgs(bool installed, int packageCount, bool cancelRecommendation) + /// + public DetectBeginEventArgs(bool cached, bool installed, int packageCount, bool cancelRecommendation) : base(cancelRecommendation) { + this.Cached = cached; this.Installed = installed; this.PackageCount = packageCount; } + /// + /// Gets whether the bundle is cached. + /// + public bool Cached { get; private set; } + /// /// Gets whether the bundle is installed. /// @@ -290,6 +316,7 @@ namespace WixToolset.Mba.Core : base(cancelRecommendation) { this.UpdateLocation = updateLocation; + this.Skip = skipRecommendation; } /// @@ -1242,6 +1269,8 @@ namespace WixToolset.Mba.Core /// public UnregisterBeginEventArgs(bool keepRegistration, bool forceKeepRegistration) { + this.KeepRegistration = keepRegistration; + this.ForceKeepRegistration = forceKeepRegistration; } /// @@ -1288,21 +1317,20 @@ namespace WixToolset.Mba.Core } /// - /// Additional arguments used when the engine begins to acquire containers or payloads. + /// EventArgs for . /// [Serializable] - public class CacheAcquireBeginEventArgs : CancellableHResultEventArgs + public class CacheAcquireBeginEventArgs : CancellableActionEventArgs { - /// - /// Creates a new instance of the class. - /// - public CacheAcquireBeginEventArgs(string packageOrContainerId, string payloadId, CacheOperation operation, string source, bool cancelRecommendation) - : base(cancelRecommendation) + /// + public CacheAcquireBeginEventArgs(string packageOrContainerId, string payloadId, string source, string downloadUrl, string payloadContainerId, CacheOperation recommendation, CacheOperation action, bool cancelRecommendation) + : base(cancelRecommendation, recommendation, action) { this.PackageOrContainerId = packageOrContainerId; this.PayloadId = payloadId; - this.Operation = operation; this.Source = source; + this.DownloadUrl = downloadUrl; + this.PayloadContainerId = payloadContainerId; } /// @@ -1316,25 +1344,28 @@ namespace WixToolset.Mba.Core public string PayloadId { get; private set; } /// - /// Gets the cache acquire operation. + /// Gets the source of the container or payload. /// - public CacheOperation Operation { get; private set; } + public string Source { get; private set; } /// - /// Gets the source of the container or payload. + /// Gets the optional URL to download container or payload. /// - public string Source { get; private set; } + public string DownloadUrl { get; private set; } + + /// + /// Gets the optional identity of the container that contains the payload being acquired. + /// + public string PayloadContainerId { get; private set; } } /// - /// Additional arguments used when the engine acquires some part of a container or payload. + /// EventArgs for . /// [Serializable] public class CacheAcquireProgressEventArgs : CancellableHResultEventArgs { - /// - /// Creates a new instance of the class. - /// + /// public CacheAcquireProgressEventArgs(string packageOrContainerId, string payloadId, long progress, long total, int overallPercentage, bool cancelRecommendation) : base(cancelRecommendation) { @@ -1372,14 +1403,12 @@ namespace WixToolset.Mba.Core } /// - /// Additional arguments used when the engine completes the acquisition of a container or payload. + /// EventArgs for . /// [Serializable] public class CacheAcquireCompleteEventArgs : ActionEventArgs { - /// - /// Creates a new instance of the class. - /// + /// public CacheAcquireCompleteEventArgs(string packageOrContainerId, string payloadId, int hrStatus, BOOTSTRAPPER_CACHEACQUIRECOMPLETE_ACTION recommendation, BOOTSTRAPPER_CACHEACQUIRECOMPLETE_ACTION action) : base(hrStatus, recommendation, action) { @@ -1729,62 +1758,64 @@ namespace WixToolset.Mba.Core } /// - /// Additional arguments used by the engine to allow the BA to change the source - /// using or . + /// EventArgs for . /// [Serializable] - public class ResolveSourceEventArgs : CancellableHResultEventArgs + public class CacheAcquireResolvingEventArgs : CancellableActionEventArgs { - /// - /// Creates a new instance of the class. - /// - /// The identity of the package or container that requires source. - /// The identity of the payload that requires source. - /// The current path used for source resolution. - /// Optional URL to download container or payload. - /// The recommended action from the engine. - /// The action to perform. - /// The recommendation from the engine. - public ResolveSourceEventArgs(string packageOrContainerId, string payloadId, string localSource, string downloadSource, BOOTSTRAPPER_RESOLVESOURCE_ACTION recommendation, BOOTSTRAPPER_RESOLVESOURCE_ACTION action, bool cancelRecommendation) - : base(cancelRecommendation) + /// + public CacheAcquireResolvingEventArgs(string packageOrContainerId, string payloadId, string[] searchPaths, bool foundLocal, int recommendedSearchPath, string downloadUrl, string payloadContainerId, CacheResolveOperation recommendation, int chosenSearchPath, CacheResolveOperation action, bool cancel) + : base(cancel, recommendation, action) { this.PackageOrContainerId = packageOrContainerId; this.PayloadId = payloadId; - this.LocalSource = localSource; - this.DownloadSource = downloadSource; - this.Recommendation = recommendation; - this.Action = action; + this.SearchPaths = searchPaths; + this.FoundLocal = foundLocal; + this.RecommendedSearchPath = recommendedSearchPath; + this.DownloadUrl = downloadUrl; + this.PayloadContainerId = payloadContainerId; + this.ChosenSearchPath = chosenSearchPath; } /// - /// Gets the identity of the package or container that requires source. + /// Gets the identity of the package or container that is being acquired. /// public string PackageOrContainerId { get; private set; } /// - /// Gets the identity of the payload that requires source. + /// Gets the identity of the payload that is being acquired. /// public string PayloadId { get; private set; } /// - /// Gets the current path used for source resolution. + /// Gets the search paths used for source resolution. /// - public string LocalSource { get; private set; } + public string[] SearchPaths { get; private set; } + + /// + /// Gets whether indicates that a file was found at that search path. + /// + public bool FoundLocal { get; private set; } + + /// + /// When is true, the index to for the recommended local file. + /// + public int RecommendedSearchPath { get; private set; } /// /// Gets the optional URL to download container or payload. /// - public string DownloadSource { get; private set; } + public string DownloadUrl { get; private set; } /// - /// Gets the recommended action from the engine. + /// Gets the optional identity of the container that contains the payload being acquired. /// - public BOOTSTRAPPER_RESOLVESOURCE_ACTION Recommendation { get; private set; } + public string PayloadContainerId { get; private set; } /// - /// Gets or sets the action to perform. + /// Gets or sets the index to to use when is set to . /// - public BOOTSTRAPPER_RESOLVESOURCE_ACTION Action { get; set; } + public int ChosenSearchPath { get; set; } } /// diff --git a/src/WixToolset.Mba.Core/IBootstrapperApplication.cs b/src/WixToolset.Mba.Core/IBootstrapperApplication.cs index 14cb8fd5..88c65674 100644 --- a/src/WixToolset.Mba.Core/IBootstrapperApplication.cs +++ b/src/WixToolset.Mba.Core/IBootstrapperApplication.cs @@ -44,13 +44,10 @@ namespace WixToolset.Mba.Core /// /// See . /// - /// - /// - /// - /// [PreserveSig] [return: MarshalAs(UnmanagedType.I4)] int OnDetectBegin( + [MarshalAs(UnmanagedType.Bool)] bool fCached, [MarshalAs(UnmanagedType.Bool)] bool fInstalled, [MarshalAs(UnmanagedType.U4)] int cPackages, [MarshalAs(UnmanagedType.Bool)] ref bool fCancel @@ -540,32 +537,22 @@ namespace WixToolset.Mba.Core /// /// See . /// - /// - /// - /// - /// - /// - /// [PreserveSig] [return: MarshalAs(UnmanagedType.I4)] int OnCacheAcquireBegin( [MarshalAs(UnmanagedType.LPWStr)] string wzPackageOrContainerId, [MarshalAs(UnmanagedType.LPWStr)] string wzPayloadId, - [MarshalAs(UnmanagedType.U4)] CacheOperation operation, [MarshalAs(UnmanagedType.LPWStr)] string wzSource, + [MarshalAs(UnmanagedType.LPWStr)] string wzDownloadUrl, + [MarshalAs(UnmanagedType.LPWStr)] string wzPayloadContainerId, + [MarshalAs(UnmanagedType.U4)] CacheOperation recommendation, + [MarshalAs(UnmanagedType.I4)] ref CacheOperation action, [MarshalAs(UnmanagedType.Bool)] ref bool fCancel ); /// /// See . /// - /// - /// - /// - /// - /// - /// - /// [PreserveSig] [return: MarshalAs(UnmanagedType.I4)] int OnCacheAcquireProgress( @@ -578,37 +565,28 @@ namespace WixToolset.Mba.Core ); /// - /// See . + /// See . /// - /// - /// - /// - /// - /// - /// - /// - /// [PreserveSig] [return: MarshalAs(UnmanagedType.I4)] - int OnResolveSource( + int OnCacheAcquireResolving( [MarshalAs(UnmanagedType.LPWStr)] string wzPackageOrContainerId, [MarshalAs(UnmanagedType.LPWStr)] string wzPayloadId, - [MarshalAs(UnmanagedType.LPWStr)] string wzLocalSource, - [MarshalAs(UnmanagedType.LPWStr)] string wzDownloadSource, - BOOTSTRAPPER_RESOLVESOURCE_ACTION recommendation, - ref BOOTSTRAPPER_RESOLVESOURCE_ACTION action, + [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3, ArraySubType = UnmanagedType.LPWStr), In] string[] searchPaths, + [MarshalAs(UnmanagedType.U4)] int cSearchPaths, + [MarshalAs(UnmanagedType.Bool)] bool fFoundLocal, + [MarshalAs(UnmanagedType.U4)] int dwRecommendedSearchPath, + [MarshalAs(UnmanagedType.LPWStr)] string wzDownloadUrl, + [MarshalAs(UnmanagedType.LPWStr)] string wzPayloadContainerId, + [MarshalAs(UnmanagedType.I4)] CacheResolveOperation recommendation, + [MarshalAs(UnmanagedType.U4)] ref int dwChosenSearchPath, + [MarshalAs(UnmanagedType.I4)] ref CacheResolveOperation action, [MarshalAs(UnmanagedType.Bool)] ref bool fCancel ); /// /// See . /// - /// - /// - /// - /// - /// - /// [PreserveSig] [return: MarshalAs(UnmanagedType.I4)] int OnCacheAcquireComplete( @@ -1419,19 +1397,55 @@ namespace WixToolset.Mba.Core public enum CacheOperation { /// - /// Container or payload is being copied. + /// There is no source available. + /// + None, + + /// + /// Copy the payload or container from the chosen local source. /// Copy, /// - /// Container or payload is being downloaded. + /// Download the payload or container using the download URL. /// Download, /// - /// Container or payload is being extracted. + /// Extract the payload from the container. + /// + Extract, + } + + /// + /// The source to be used to acquire a container or payload. + /// + public enum CacheResolveOperation + { + /// + /// There is no source available. + /// + None, + + /// + /// Copy the payload or container from the chosen local source. /// - Extract + Local, + + /// + /// Download the payload or container from the download URL. + /// + Download, + + /// + /// Extract the payload from the container. + /// + Container, + + /// + /// Look again for the payload or container locally. + /// + Retry, } /// @@ -1637,7 +1651,7 @@ namespace WixToolset.Mba.Core } /// - /// The available actions for . + /// The available actions for . /// public enum BOOTSTRAPPER_RESOLVESOURCE_ACTION { diff --git a/src/WixToolset.Mba.Core/IDefaultBootstrapperApplication.cs b/src/WixToolset.Mba.Core/IDefaultBootstrapperApplication.cs index 269d4955..03f94d37 100644 --- a/src/WixToolset.Mba.Core/IDefaultBootstrapperApplication.cs +++ b/src/WixToolset.Mba.Core/IDefaultBootstrapperApplication.cs @@ -30,12 +30,16 @@ namespace WixToolset.Mba.Core event EventHandler BeginMsiTransactionComplete; /// - /// Fired when the engine has begun acquiring the installation sources. + /// Fired when the engine has begun acquiring the payload or container. + /// The BA can change the source using + /// or . /// event EventHandler CacheAcquireBegin; /// - /// Fired when the engine has completed the acquisition of the installation sources. + /// Fired when the engine has completed the acquisition of the payload or container. + /// The BA can change the source using + /// or . /// event EventHandler CacheAcquireComplete; @@ -44,6 +48,11 @@ namespace WixToolset.Mba.Core /// event EventHandler CacheAcquireProgress; + /// + /// Fired by the engine to allow the BA to override the acquisition action. + /// + event EventHandler CacheAcquireResolving; + /// /// Fired when the engine has begun caching the installation sources. /// @@ -284,12 +293,6 @@ namespace WixToolset.Mba.Core /// event EventHandler RegisterComplete; - /// - /// Fired by the engine to allow the BA to change the source - /// using or . - /// - event EventHandler ResolveSource; - /// /// Fired when the engine is about to rollback an MSI transaction. /// -- cgit v1.2.3-55-g6feb