From 8deeffb615244c62a0c94ea99d01ece88b1caf09 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Tue, 27 Apr 2021 22:26:16 -0500 Subject: Integrate size_t and OnPlanPackageBegin changes in Burn headers. --- src/WixToolset.Mba.Core/BootstrapperApplication.cs | 12 ++-- src/WixToolset.Mba.Core/Engine.cs | 36 ++++++----- src/WixToolset.Mba.Core/EventArgs.cs | 70 ++++++++++++++-------- .../IBootstrapperApplication.cs | 69 +++++++++++++++------ src/WixToolset.Mba.Core/IBootstrapperEngine.cs | 24 ++------ src/WixToolset.Mba.Core/IPackageInfo.cs | 2 +- src/WixToolset.Mba.Core/PackageInfo.cs | 35 +++-------- 7 files changed, 133 insertions(+), 115 deletions(-) (limited to 'src/WixToolset.Mba.Core') diff --git a/src/WixToolset.Mba.Core/BootstrapperApplication.cs b/src/WixToolset.Mba.Core/BootstrapperApplication.cs index 0a8f3af8..072d3ef0 100644 --- a/src/WixToolset.Mba.Core/BootstrapperApplication.cs +++ b/src/WixToolset.Mba.Core/BootstrapperApplication.cs @@ -1343,9 +1343,9 @@ namespace WixToolset.Mba.Core return args.HResult; } - int IBootstrapperApplication.OnDetectPackageComplete(string wzPackageId, int hrStatus, PackageState state) + int IBootstrapperApplication.OnDetectPackageComplete(string wzPackageId, int hrStatus, PackageState state, bool fCached) { - DetectPackageCompleteEventArgs args = new DetectPackageCompleteEventArgs(wzPackageId, hrStatus, state); + DetectPackageCompleteEventArgs args = new DetectPackageCompleteEventArgs(wzPackageId, hrStatus, state, fCached); this.OnDetectPackageComplete(args); return args.HResult; @@ -1378,9 +1378,9 @@ namespace WixToolset.Mba.Core return args.HResult; } - int IBootstrapperApplication.OnPlanPackageBegin(string wzPackageId, PackageState state, bool fInstallCondition, RequestState recommendedState, ref RequestState pRequestedState, ref bool fCancel) + int IBootstrapperApplication.OnPlanPackageBegin(string wzPackageId, PackageState state, bool fCached, BOOTSTRAPPER_PACKAGE_CONDITION_RESULT installCondition, RequestState recommendedState, BOOTSTRAPPER_CACHE_TYPE recommendedCacheType, ref RequestState pRequestedState, ref BOOTSTRAPPER_CACHE_TYPE pRequestedCacheType, ref bool fCancel) { - PlanPackageBeginEventArgs args = new PlanPackageBeginEventArgs(wzPackageId, state, fInstallCondition, recommendedState, pRequestedState, fCancel); + PlanPackageBeginEventArgs args = new PlanPackageBeginEventArgs(wzPackageId, state, fCached, installCondition, recommendedState, recommendedCacheType, pRequestedState, pRequestedCacheType, fCancel); this.OnPlanPackageBegin(args); pRequestedState = args.State; @@ -1428,9 +1428,9 @@ namespace WixToolset.Mba.Core return args.HResult; } - int IBootstrapperApplication.OnPlannedPackage(string wzPackageId, ActionState execute, ActionState rollback) + int IBootstrapperApplication.OnPlannedPackage(string wzPackageId, ActionState execute, ActionState rollback, bool fPlannedCache, bool fPlannedUncache) { - var args = new PlannedPackageEventArgs(wzPackageId, execute, rollback); + var args = new PlannedPackageEventArgs(wzPackageId, execute, rollback, fPlannedCache, fPlannedUncache); this.OnPlannedPackage(args); return args.HResult; diff --git a/src/WixToolset.Mba.Core/Engine.cs b/src/WixToolset.Mba.Core/Engine.cs index e07ecd8b..aed420d5 100644 --- a/src/WixToolset.Mba.Core/Engine.cs +++ b/src/WixToolset.Mba.Core/Engine.cs @@ -62,7 +62,7 @@ namespace WixToolset.Mba.Core /// public bool ContainsVariable(string name) { - int capacity = 0; + IntPtr capacity = new IntPtr(0); int ret = this.engine.GetVariableString(name, IntPtr.Zero, ref capacity); return NativeMethods.E_NOTFOUND != ret; } @@ -101,14 +101,15 @@ namespace WixToolset.Mba.Core /// public string EscapeString(string input) { - int capacity = InitialBufferSize; - StringBuilder sb = new StringBuilder(capacity); + IntPtr capacity = new IntPtr(InitialBufferSize); + StringBuilder sb = new StringBuilder(capacity.ToInt32()); // Get the size of the buffer. int ret = this.engine.EscapeString(input, sb, ref capacity); if (NativeMethods.E_INSUFFICIENT_BUFFER == ret || NativeMethods.E_MOREDATA == ret) { - sb.Capacity = ++capacity; // Add one for the null terminator. + capacity = new IntPtr(capacity.ToInt32() + 1); // Add one for the null terminator. + sb.Capacity = capacity.ToInt32(); ret = this.engine.EscapeString(input, sb, ref capacity); } @@ -132,14 +133,15 @@ namespace WixToolset.Mba.Core /// public string FormatString(string format) { - int capacity = InitialBufferSize; - StringBuilder sb = new StringBuilder(capacity); + IntPtr capacity = new IntPtr(InitialBufferSize); + StringBuilder sb = new StringBuilder(capacity.ToInt32()); // Get the size of the buffer. int ret = this.engine.FormatString(format, sb, ref capacity); if (NativeMethods.E_INSUFFICIENT_BUFFER == ret || NativeMethods.E_MOREDATA == ret) { - sb.Capacity = ++capacity; // Add one for the null terminator. + capacity = new IntPtr(capacity.ToInt32() + 1); // Add one for the null terminator. + sb.Capacity = capacity.ToInt32(); ret = this.engine.FormatString(format, sb, ref capacity); } @@ -343,9 +345,9 @@ namespace WixToolset.Mba.Core /// An error occurred getting the variable. internal IntPtr getStringVariable(string name, out int length) { - int capacity = InitialBufferSize; + IntPtr capacity = new IntPtr(InitialBufferSize); bool success = false; - IntPtr pValue = Marshal.AllocCoTaskMem(capacity * UnicodeEncoding.CharSize); + IntPtr pValue = Marshal.AllocCoTaskMem(capacity.ToInt32() * UnicodeEncoding.CharSize); try { // Get the size of the buffer. @@ -353,7 +355,7 @@ namespace WixToolset.Mba.Core if (NativeMethods.E_INSUFFICIENT_BUFFER == ret || NativeMethods.E_MOREDATA == ret) { // Don't need to add 1 for the null terminator, the engine already includes that. - pValue = Marshal.ReAllocCoTaskMem(pValue, capacity * UnicodeEncoding.CharSize); + pValue = Marshal.ReAllocCoTaskMem(pValue, capacity.ToInt32() * UnicodeEncoding.CharSize); ret = this.engine.GetVariableString(name, pValue, ref capacity); } @@ -363,9 +365,10 @@ namespace WixToolset.Mba.Core } // The engine only returns the exact length of the string if the buffer was too small, so calculate it ourselves. - for (length = 0; length < capacity; ++length) + int maxLength = capacity.ToInt32(); + for (length = 0; length < maxLength; ++length) { - if(0 == Marshal.ReadInt16(pValue, length * UnicodeEncoding.CharSize)) + if (0 == Marshal.ReadInt16(pValue, length * UnicodeEncoding.CharSize)) { break; } @@ -392,9 +395,9 @@ namespace WixToolset.Mba.Core /// An error occurred getting the variable. internal IntPtr getVersionVariable(string name, out int length) { - int capacity = InitialBufferSize; + IntPtr capacity = new IntPtr(InitialBufferSize); bool success = false; - IntPtr pValue = Marshal.AllocCoTaskMem(capacity * UnicodeEncoding.CharSize); + IntPtr pValue = Marshal.AllocCoTaskMem(capacity.ToInt32() * UnicodeEncoding.CharSize); try { // Get the size of the buffer. @@ -402,7 +405,7 @@ namespace WixToolset.Mba.Core if (NativeMethods.E_INSUFFICIENT_BUFFER == ret || NativeMethods.E_MOREDATA == ret) { // Don't need to add 1 for the null terminator, the engine already includes that. - pValue = Marshal.ReAllocCoTaskMem(pValue, capacity * UnicodeEncoding.CharSize); + pValue = Marshal.ReAllocCoTaskMem(pValue, capacity.ToInt32() * UnicodeEncoding.CharSize); ret = this.engine.GetVariableVersion(name, pValue, ref capacity); } @@ -412,7 +415,8 @@ namespace WixToolset.Mba.Core } // The engine only returns the exact length of the string if the buffer was too small, so calculate it ourselves. - for (length = 0; length < capacity; ++length) + int maxLength = capacity.ToInt32(); + for (length = 0; length < maxLength; ++length) { if (0 == Marshal.ReadInt16(pValue, length * UnicodeEncoding.CharSize)) { diff --git a/src/WixToolset.Mba.Core/EventArgs.cs b/src/WixToolset.Mba.Core/EventArgs.cs index e64f6d2c..8ef8af14 100644 --- a/src/WixToolset.Mba.Core/EventArgs.cs +++ b/src/WixToolset.Mba.Core/EventArgs.cs @@ -617,22 +617,18 @@ namespace WixToolset.Mba.Core } /// - /// Additional arguments used when the detection for a specific package has completed. + /// Additional arguments for . /// [Serializable] public class DetectPackageCompleteEventArgs : StatusEventArgs { - /// - /// Creates a new instance of the class. - /// - /// The identity of the package detected. - /// The return code of the operation. - /// The state of the specified package. - public DetectPackageCompleteEventArgs(string packageId, int hrStatus, PackageState state) + /// + public DetectPackageCompleteEventArgs(string packageId, int hrStatus, PackageState state, bool cached) : base(hrStatus) { this.PackageId = packageId; this.State = state; + this.Cached = cached; } /// @@ -644,6 +640,11 @@ namespace WixToolset.Mba.Core /// Gets the state of the specified package. /// public PackageState State { get; private set; } + + /// + /// Gets whether any part of the package is cached. + /// + public bool Cached { get; private set; } } /// @@ -725,23 +726,18 @@ namespace WixToolset.Mba.Core [Serializable] public class PlanPackageBeginEventArgs : CancellableHResultEventArgs { - /// - /// - /// - /// - /// - /// - /// - /// - /// - public PlanPackageBeginEventArgs(string packageId, PackageState currentState, bool installCondition, RequestState recommendedState, RequestState state, bool cancelRecommendation) + /// + public PlanPackageBeginEventArgs(string packageId, PackageState currentState, bool cached, BOOTSTRAPPER_PACKAGE_CONDITION_RESULT installCondition, RequestState recommendedState, BOOTSTRAPPER_CACHE_TYPE recommendedCacheType, RequestState state, BOOTSTRAPPER_CACHE_TYPE cacheType, bool cancelRecommendation) : base(cancelRecommendation) { this.PackageId = packageId; this.CurrentState = currentState; + this.Cached = cached; this.InstallCondition = installCondition; this.RecommendedState = recommendedState; + this.RecommendedCacheType = recommendedCacheType; this.State = state; + this.CacheType = cacheType; } /// @@ -754,20 +750,35 @@ namespace WixToolset.Mba.Core /// public PackageState CurrentState { get; private set; } + /// + /// Gets whether any part of the package is cached. + /// + public bool Cached { get; private set; } + /// /// Gets the evaluated result of the package's install condition. /// - public bool InstallCondition { get; private set; } + public BOOTSTRAPPER_PACKAGE_CONDITION_RESULT InstallCondition { get; private set; } /// /// Gets the recommended requested state for the package. /// public RequestState RecommendedState { get; private set; } + /// + /// The authored cache type of the package. + /// + public BOOTSTRAPPER_CACHE_TYPE RecommendedCacheType { get; private set; } + /// /// Gets or sets the requested state for the package. /// public RequestState State { get; set; } + + /// + /// Gets or sets the requested cache type for the package. + /// + public BOOTSTRAPPER_CACHE_TYPE CacheType { get; set; } } /// @@ -936,17 +947,14 @@ namespace WixToolset.Mba.Core [Serializable] public class PlannedPackageEventArgs : HResultEventArgs { - /// - /// - /// - /// - /// - /// - public PlannedPackageEventArgs(string packageId, ActionState execute, ActionState rollback) + /// + public PlannedPackageEventArgs(string packageId, ActionState execute, ActionState rollback, bool cache, bool uncache) { this.PackageId = packageId; this.Execute = execute; this.Rollback = rollback; + this.Cache = cache; + this.Uncache = uncache; } /// @@ -963,6 +971,16 @@ namespace WixToolset.Mba.Core /// Gets the planned rollback action. /// public ActionState Rollback { get; private set; } + + /// + /// Gets whether the package will be cached. + /// + public bool Cache { get; private set; } + + /// + /// Gets whether the package will be removed from the package cache. + /// + public bool Uncache { get; private set; } } /// diff --git a/src/WixToolset.Mba.Core/IBootstrapperApplication.cs b/src/WixToolset.Mba.Core/IBootstrapperApplication.cs index 2195fd4b..530fb1a9 100644 --- a/src/WixToolset.Mba.Core/IBootstrapperApplication.cs +++ b/src/WixToolset.Mba.Core/IBootstrapperApplication.cs @@ -251,16 +251,13 @@ namespace WixToolset.Mba.Core /// /// See . /// - /// - /// - /// - /// [PreserveSig] [return: MarshalAs(UnmanagedType.I4)] int OnDetectPackageComplete( [MarshalAs(UnmanagedType.LPWStr)] string wzPackageId, int hrStatus, - [MarshalAs(UnmanagedType.U4)] PackageState state + [MarshalAs(UnmanagedType.U4)] PackageState state, + [MarshalAs(UnmanagedType.Bool)] bool fCached ); /// @@ -309,21 +306,17 @@ namespace WixToolset.Mba.Core /// /// See . /// - /// - /// - /// - /// - /// - /// - /// [PreserveSig] [return: MarshalAs(UnmanagedType.I4)] int OnPlanPackageBegin( [MarshalAs(UnmanagedType.LPWStr)] string wzPackageId, [MarshalAs(UnmanagedType.U4)] PackageState state, - [MarshalAs(UnmanagedType.Bool)] bool fInstallCondition, + [MarshalAs(UnmanagedType.Bool)] bool fCached, + [MarshalAs(UnmanagedType.U4)] BOOTSTRAPPER_PACKAGE_CONDITION_RESULT installCondition, [MarshalAs(UnmanagedType.U4)] RequestState recommendedState, + [MarshalAs(UnmanagedType.U4)] BOOTSTRAPPER_CACHE_TYPE recommendedCacheType, [MarshalAs(UnmanagedType.U4)] ref RequestState pRequestedState, + [MarshalAs(UnmanagedType.U4)] ref BOOTSTRAPPER_CACHE_TYPE pRequestedCacheType, [MarshalAs(UnmanagedType.Bool)] ref bool fCancel ); @@ -406,16 +399,14 @@ namespace WixToolset.Mba.Core /// /// See . /// - /// - /// - /// - /// [PreserveSig] [return: MarshalAs(UnmanagedType.I4)] int OnPlannedPackage( [MarshalAs(UnmanagedType.LPWStr)] string wzPackageId, [MarshalAs(UnmanagedType.U4)] ActionState execute, - [MarshalAs(UnmanagedType.U4)] ActionState rollback + [MarshalAs(UnmanagedType.U4)] ActionState rollback, + [MarshalAs(UnmanagedType.Bool)] bool fPlannedCache, + [MarshalAs(UnmanagedType.Bool)] bool fPlannedUncache ); /// @@ -1641,6 +1632,27 @@ namespace WixToolset.Mba.Core Restart, } + /// + /// The cache strategy to be used for the package. + /// + public enum BOOTSTRAPPER_CACHE_TYPE + { + /// + /// The package will be cached in order to securely run the package, but will always be cleaned from the cache at the end. + /// + Remove, + + /// + /// The package will be cached in order to run the package, and then kept in the cache until the package is uninstalled. + /// + Keep, + + /// + /// The package will always be cached and stay in the cache, unless the package and bundle are both being uninstalled. + /// + Force, + } + /// /// The available actions for . /// @@ -1736,6 +1748,27 @@ namespace WixToolset.Mba.Core Suspend, } + /// + /// The result of evaluating a condition from a package. + /// + public enum BOOTSTRAPPER_PACKAGE_CONDITION_RESULT + { + /// + /// No condition was authored. + /// + Default, + + /// + /// Evaluated to false. + /// + False, + + /// + /// Evaluated to true. + /// + True, + } + /// /// The available actions for . /// diff --git a/src/WixToolset.Mba.Core/IBootstrapperEngine.cs b/src/WixToolset.Mba.Core/IBootstrapperEngine.cs index 78753a42..4e19bf0f 100644 --- a/src/WixToolset.Mba.Core/IBootstrapperEngine.cs +++ b/src/WixToolset.Mba.Core/IBootstrapperEngine.cs @@ -39,57 +39,41 @@ namespace WixToolset.Mba.Core /// /// See . /// - /// - /// - /// - /// [PreserveSig] int GetVariableString( [MarshalAs(UnmanagedType.LPWStr)] string wzVariable, IntPtr wzValue, - [MarshalAs(UnmanagedType.U4)] ref int pcchValue + ref IntPtr pcchValue ); /// /// See . /// - /// - /// - /// - /// [PreserveSig] int GetVariableVersion( [MarshalAs(UnmanagedType.LPWStr)] string wzVariable, IntPtr wzValue, - [MarshalAs(UnmanagedType.U4)] ref int pcchValue + ref IntPtr pcchValue ); /// /// See . /// - /// - /// - /// - /// [PreserveSig] int FormatString( [MarshalAs(UnmanagedType.LPWStr)] string wzIn, [MarshalAs(UnmanagedType.LPWStr), Out] StringBuilder wzOut, - [MarshalAs(UnmanagedType.U4)] ref int pcchOut + ref IntPtr pcchOut ); /// /// See . /// - /// - /// - /// - /// [PreserveSig] int EscapeString( [MarshalAs(UnmanagedType.LPWStr)] string wzIn, [MarshalAs(UnmanagedType.LPWStr), Out] StringBuilder wzOut, - [MarshalAs(UnmanagedType.U4)] ref int pcchOut + ref IntPtr pcchOut ); /// diff --git a/src/WixToolset.Mba.Core/IPackageInfo.cs b/src/WixToolset.Mba.Core/IPackageInfo.cs index 0d7e549e..a1d99b10 100644 --- a/src/WixToolset.Mba.Core/IPackageInfo.cs +++ b/src/WixToolset.Mba.Core/IPackageInfo.cs @@ -10,7 +10,7 @@ namespace WixToolset.Mba.Core /// /// /// - CacheType CacheType { get; } + BOOTSTRAPPER_CACHE_TYPE CacheType { get; } /// /// Place for the BA to store it's own custom data for this package. diff --git a/src/WixToolset.Mba.Core/PackageInfo.cs b/src/WixToolset.Mba.Core/PackageInfo.cs index 75a0fd53..567a7cdd 100644 --- a/src/WixToolset.Mba.Core/PackageInfo.cs +++ b/src/WixToolset.Mba.Core/PackageInfo.cs @@ -7,27 +7,6 @@ namespace WixToolset.Mba.Core using System.Xml; using System.Xml.XPath; - /// - /// - /// - public enum CacheType - { - /// - /// - /// - No, - - /// - /// - /// - Yes, - - /// - /// - /// - Always, - } - /// /// /// @@ -113,7 +92,7 @@ namespace WixToolset.Mba.Core public string InstallCondition { get; internal set; } /// - public CacheType CacheType { get; internal set; } + public BOOTSTRAPPER_CACHE_TYPE CacheType { get; internal set; } /// public bool PrereqPackage { get; internal set; } @@ -198,7 +177,7 @@ namespace WixToolset.Mba.Core /// /// /// - public static CacheType? GetCacheTypeAttribute(XPathNavigator node, string attributeName) + public static BOOTSTRAPPER_CACHE_TYPE? GetCacheTypeAttribute(XPathNavigator node, string attributeName) { string attributeValue = BootstrapperApplicationData.GetAttribute(node, attributeName); @@ -207,17 +186,17 @@ namespace WixToolset.Mba.Core return null; } - if (attributeValue.Equals("yes", StringComparison.InvariantCulture)) + if (attributeValue.Equals("keep", StringComparison.InvariantCulture)) { - return CacheType.Yes; + return BOOTSTRAPPER_CACHE_TYPE.Keep; } - else if (attributeValue.Equals("always", StringComparison.InvariantCulture)) + else if (attributeValue.Equals("force", StringComparison.InvariantCulture)) { - return CacheType.Always; + return BOOTSTRAPPER_CACHE_TYPE.Force; } else { - return CacheType.No; + return BOOTSTRAPPER_CACHE_TYPE.Remove; } } -- cgit v1.2.3-55-g6feb