From 54cacc5653a0c8a053d6641badf4470d1b54e865 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Thu, 7 Dec 2017 14:17:45 -0800 Subject: Enable MSI backends to add custom tables from tuples --- .../BasePreprocessorExtension.cs | 2 +- .../BaseWindowsInstallerBackendExtension.cs | 53 +++++++++++++++ src/WixToolset.Extensibility/ExtensionData.cs | 77 ---------------------- .../IPreprocessorExtension.cs | 2 - .../IWindowsInstallerBackendExtension.cs | 4 ++ .../Services/IWindowsInstallerBackendHelper.cs | 15 +++++ 6 files changed, 73 insertions(+), 80 deletions(-) create mode 100644 src/WixToolset.Extensibility/BaseWindowsInstallerBackendExtension.cs delete mode 100644 src/WixToolset.Extensibility/ExtensionData.cs create mode 100644 src/WixToolset.Extensibility/Services/IWindowsInstallerBackendHelper.cs (limited to 'src') diff --git a/src/WixToolset.Extensibility/BasePreprocessorExtension.cs b/src/WixToolset.Extensibility/BasePreprocessorExtension.cs index acfcd5b9..f5d89103 100644 --- a/src/WixToolset.Extensibility/BasePreprocessorExtension.cs +++ b/src/WixToolset.Extensibility/BasePreprocessorExtension.cs @@ -16,7 +16,7 @@ namespace WixToolset.Extensibility protected IPreprocessContext Context { get; private set; } /// - /// ParserHelper for use by the extension. + /// PreprocessHelper for use by the extension. /// protected IPreprocessHelper PreprocessHelper { get; private set; } diff --git a/src/WixToolset.Extensibility/BaseWindowsInstallerBackendExtension.cs b/src/WixToolset.Extensibility/BaseWindowsInstallerBackendExtension.cs new file mode 100644 index 00000000..0bcfce01 --- /dev/null +++ b/src/WixToolset.Extensibility/BaseWindowsInstallerBackendExtension.cs @@ -0,0 +1,53 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +namespace WixToolset.Extensibility +{ + using System.Collections.Generic; + using WixToolset.Data; + using WixToolset.Data.Bind; + using WixToolset.Data.Tuples; + using WixToolset.Data.WindowsInstaller; + using WixToolset.Extensibility.Services; + + /// + /// Base class for creating a preprocessor extension. + /// + public abstract class BaseWindowsInstallerBackendExtension : IWindowsInstallerBackendExtension + { + /// + /// Context for use by the extension. + /// + protected IBindContext Context { get; private set; } + + /// + /// Backend helper for use by the extension. + /// + protected IWindowsInstallerBackendHelper BackendHelper { get; private set; } + + public virtual void PreBackendBind(IBindContext context) + { + this.Context = context; + + this.BackendHelper = context.ServiceProvider.GetService(); + } + + public virtual ResolvedCabinet ResolveCabinet(string cabinetPath, IEnumerable files) + { + return null; + } + + public virtual string ResolveMedia(MediaTuple mediaRow, string mediaLayoutDirectory, string layoutDirectory) + { + return null; + } + + public virtual bool TryAddTupleToOutput(IntermediateTuple tuple, Output output) + { + return false; + } + + public virtual void PostBackendBind(BindResult result) + { + } + } +} diff --git a/src/WixToolset.Extensibility/ExtensionData.cs b/src/WixToolset.Extensibility/ExtensionData.cs deleted file mode 100644 index 0cd0c420..00000000 --- a/src/WixToolset.Extensibility/ExtensionData.cs +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. - -namespace WixToolset.Extensibility -{ - using System; - using System.IO; - using System.Reflection; - using System.Xml; - using WixToolset.Data; - -#if BRING_BACK_LATER - public abstract class ExtensionData : IExtensionData - { - /// - /// Gets the optional table definitions for this extension. - /// - /// Table definisions for this extension or null if there are no table definitions. - public virtual TableDefinitionCollection TableDefinitions - { - get { return null; } - } - - /// - /// Gets the optional default culture. - /// - /// The optional default culture. - public virtual string DefaultCulture - { - get { return null; } - } - - /// - /// Gets the optional library associated with this extension. - /// - /// The table definitions to use while loading the library. - /// The library for this extension or null if there is no library. - public virtual Library GetLibrary(TableDefinitionCollection tableDefinitions) - { - return null; - } - - /// - /// Help for loading a library from an embedded resource. - /// - /// The assembly containing the embedded resource. - /// The name of the embedded resource being requested. - /// The table definitions to use while loading the library. - /// The loaded library. - protected static Library LoadLibraryHelper(Assembly assembly, string resourceName, TableDefinitionCollection tableDefinitions) - { - using (Stream resourceStream = assembly.GetManifestResourceStream(resourceName)) - { - UriBuilder uriBuilder = new UriBuilder(assembly.CodeBase); - uriBuilder.Scheme = "embeddedresource"; - uriBuilder.Fragment = resourceName; - - return Library.Load(resourceStream, uriBuilder.Uri, tableDefinitions, false); - } - } - - /// - /// Helper for loading table definitions from an embedded resource. - /// - /// The assembly containing the embedded resource. - /// The name of the embedded resource being requested. - /// The loaded table definitions. - protected static TableDefinitionCollection LoadTableDefinitionHelper(Assembly assembly, string resourceName) - { - using (Stream resourceStream = assembly.GetManifestResourceStream(resourceName)) - using (XmlReader reader = XmlReader.Create(resourceStream)) - { - return TableDefinitionCollection.Load(reader); - } - } - } -#endif -} diff --git a/src/WixToolset.Extensibility/IPreprocessorExtension.cs b/src/WixToolset.Extensibility/IPreprocessorExtension.cs index 8511abbc..68f82693 100644 --- a/src/WixToolset.Extensibility/IPreprocessorExtension.cs +++ b/src/WixToolset.Extensibility/IPreprocessorExtension.cs @@ -2,9 +2,7 @@ namespace WixToolset.Extensibility { - using System; using System.Xml.Linq; - using WixToolset.Data; /// /// Interface for extending the WiX toolset preprocessor. diff --git a/src/WixToolset.Extensibility/IWindowsInstallerBackendExtension.cs b/src/WixToolset.Extensibility/IWindowsInstallerBackendExtension.cs index f6ffc69c..ed10a077 100644 --- a/src/WixToolset.Extensibility/IWindowsInstallerBackendExtension.cs +++ b/src/WixToolset.Extensibility/IWindowsInstallerBackendExtension.cs @@ -3,8 +3,10 @@ namespace WixToolset.Extensibility { using System.Collections.Generic; + using WixToolset.Data; using WixToolset.Data.Bind; using WixToolset.Data.Tuples; + using WixToolset.Data.WindowsInstaller; using WixToolset.Extensibility.Services; /// @@ -21,6 +23,8 @@ namespace WixToolset.Extensibility string ResolveMedia(MediaTuple mediaRow, string mediaLayoutDirectory, string layoutDirectory); + bool TryAddTupleToOutput(IntermediateTuple tuple, Output output); + /// /// Called after all output changes occur and right before the output is bound into its final format. /// diff --git a/src/WixToolset.Extensibility/Services/IWindowsInstallerBackendHelper.cs b/src/WixToolset.Extensibility/Services/IWindowsInstallerBackendHelper.cs new file mode 100644 index 00000000..2de455fd --- /dev/null +++ b/src/WixToolset.Extensibility/Services/IWindowsInstallerBackendHelper.cs @@ -0,0 +1,15 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +namespace WixToolset.Extensibility.Services +{ + using WixToolset.Data; + using WixToolset.Data.WindowsInstaller; + + /// + /// Interface provided to help Windows Installer backend extensions. + /// + public interface IWindowsInstallerBackendHelper + { + bool TryAddTupleToOutputMatchingTableDefinitions(IntermediateTuple tuple, Output output, TableDefinition[] tableDefinitions); + } +} -- cgit v1.2.3-55-g6feb