@joebigelow / wix / commits / 54cacc56

Enable MSI backends to add custom tables from tuples

Rob Mensching committed Dec 7, 2017 at 14:17 UTC 54cacc5653a0c8a053d6641badf4470d1b54e865
6 files changed +73 -80
src/WixToolset.Extensibility/BasePreprocessorExtension.cs
+1 -1
@@ -16,7 +16,7 @@ namespace WixToolset.Extensibility
16 protected IPreprocessContext Context { get; private set; }
17
18 /// <summary>
19 - /// ParserHelper for use by the extension.
19 + /// PreprocessHelper for use by the extension.
20 /// </summary>
21 protected IPreprocessHelper PreprocessHelper { get; private set; }
22
src/WixToolset.Extensibility/BaseWindowsInstallerBackendExtension.cs new
+53
@@ -0,0 +1,53 @@
1 +// 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.
2 +
3 +namespace WixToolset.Extensibility
4 +{
5 + using System.Collections.Generic;
6 + using WixToolset.Data;
7 + using WixToolset.Data.Bind;
8 + using WixToolset.Data.Tuples;
9 + using WixToolset.Data.WindowsInstaller;
10 + using WixToolset.Extensibility.Services;
11 +
12 + /// <summary>
13 + /// Base class for creating a preprocessor extension.
14 + /// </summary>
15 + public abstract class BaseWindowsInstallerBackendExtension : IWindowsInstallerBackendExtension
16 + {
17 + /// <summary>
18 + /// Context for use by the extension.
19 + /// </summary>
20 + protected IBindContext Context { get; private set; }
21 +
22 + /// <summary>
23 + /// Backend helper for use by the extension.
24 + /// </summary>
25 + protected IWindowsInstallerBackendHelper BackendHelper { get; private set; }
26 +
27 + public virtual void PreBackendBind(IBindContext context)
28 + {
29 + this.Context = context;
30 +
31 + this.BackendHelper = context.ServiceProvider.GetService<IWindowsInstallerBackendHelper>();
32 + }
33 +
34 + public virtual ResolvedCabinet ResolveCabinet(string cabinetPath, IEnumerable<BindFileWithPath> files)
35 + {
36 + return null;
37 + }
38 +
39 + public virtual string ResolveMedia(MediaTuple mediaRow, string mediaLayoutDirectory, string layoutDirectory)
40 + {
41 + return null;
42 + }
43 +
44 + public virtual bool TryAddTupleToOutput(IntermediateTuple tuple, Output output)
45 + {
46 + return false;
47 + }
48 +
49 + public virtual void PostBackendBind(BindResult result)
50 + {
51 + }
52 + }
53 +}
src/WixToolset.Extensibility/ExtensionData.cs deleted
-77
@@ -1,77 +0,0 @@
1 -// 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.
2 -
3 -namespace WixToolset.Extensibility
4 -{
5 - using System;
6 - using System.IO;
7 - using System.Reflection;
8 - using System.Xml;
9 - using WixToolset.Data;
10 -
11 -#if BRING_BACK_LATER
12 - public abstract class ExtensionData : IExtensionData
13 - {
14 - /// <summary>
15 - /// Gets the optional table definitions for this extension.
16 - /// </summary>
17 - /// <value>Table definisions for this extension or null if there are no table definitions.</value>
18 - public virtual TableDefinitionCollection TableDefinitions
19 - {
20 - get { return null; }
21 - }
22 -
23 - /// <summary>
24 - /// Gets the optional default culture.
25 - /// </summary>
26 - /// <value>The optional default culture.</value>
27 - public virtual string DefaultCulture
28 - {
29 - get { return null; }
30 - }
31 -
32 - /// <summary>
33 - /// Gets the optional library associated with this extension.
34 - /// </summary>
35 - /// <param name="tableDefinitions">The table definitions to use while loading the library.</param>
36 - /// <returns>The library for this extension or null if there is no library.</returns>
37 - public virtual Library GetLibrary(TableDefinitionCollection tableDefinitions)
38 - {
39 - return null;
40 - }
41 -
42 - /// <summary>
43 - /// Help for loading a library from an embedded resource.
44 - /// </summary>
45 - /// <param name="assembly">The assembly containing the embedded resource.</param>
46 - /// <param name="resourceName">The name of the embedded resource being requested.</param>
47 - /// <param name="tableDefinitions">The table definitions to use while loading the library.</param>
48 - /// <returns>The loaded library.</returns>
49 - protected static Library LoadLibraryHelper(Assembly assembly, string resourceName, TableDefinitionCollection tableDefinitions)
50 - {
51 - using (Stream resourceStream = assembly.GetManifestResourceStream(resourceName))
52 - {
53 - UriBuilder uriBuilder = new UriBuilder(assembly.CodeBase);
54 - uriBuilder.Scheme = "embeddedresource";
55 - uriBuilder.Fragment = resourceName;
56 -
57 - return Library.Load(resourceStream, uriBuilder.Uri, tableDefinitions, false);
58 - }
59 - }
60 -
61 - /// <summary>
62 - /// Helper for loading table definitions from an embedded resource.
63 - /// </summary>
64 - /// <param name="assembly">The assembly containing the embedded resource.</param>
65 - /// <param name="resourceName">The name of the embedded resource being requested.</param>
66 - /// <returns>The loaded table definitions.</returns>
67 - protected static TableDefinitionCollection LoadTableDefinitionHelper(Assembly assembly, string resourceName)
68 - {
69 - using (Stream resourceStream = assembly.GetManifestResourceStream(resourceName))
70 - using (XmlReader reader = XmlReader.Create(resourceStream))
71 - {
72 - return TableDefinitionCollection.Load(reader);
73 - }
74 - }
75 - }
76 -#endif
77 -}
src/WixToolset.Extensibility/IPreprocessorExtension.cs
-2
@@ -2,9 +2,7 @@
2
3 namespace WixToolset.Extensibility
4 {
5 - using System;
5 using System.Xml.Linq;
7 - using WixToolset.Data;
6
7 /// <summary>
8 /// Interface for extending the WiX toolset preprocessor.
src/WixToolset.Extensibility/IWindowsInstallerBackendExtension.cs
+4
@@ -3,8 +3,10 @@
3 namespace WixToolset.Extensibility
4 {
5 using System.Collections.Generic;
6 + using WixToolset.Data;
7 using WixToolset.Data.Bind;
8 using WixToolset.Data.Tuples;
9 + using WixToolset.Data.WindowsInstaller;
10 using WixToolset.Extensibility.Services;
11
12 /// <summary>
@@ -21,6 +23,8 @@ namespace WixToolset.Extensibility
23
24 string ResolveMedia(MediaTuple mediaRow, string mediaLayoutDirectory, string layoutDirectory);
25
26 + bool TryAddTupleToOutput(IntermediateTuple tuple, Output output);
27 +
28 /// <summary>
29 /// Called after all output changes occur and right before the output is bound into its final format.
30 /// </summary>
src/WixToolset.Extensibility/Services/IWindowsInstallerBackendHelper.cs new
+15
@@ -0,0 +1,15 @@
1 +// 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.
2 +
3 +namespace WixToolset.Extensibility.Services
4 +{
5 + using WixToolset.Data;
6 + using WixToolset.Data.WindowsInstaller;
7 +
8 + /// <summary>
9 + /// Interface provided to help Windows Installer backend extensions.
10 + /// </summary>
11 + public interface IWindowsInstallerBackendHelper
12 + {
13 + bool TryAddTupleToOutputMatchingTableDefinitions(IntermediateTuple tuple, Output output, TableDefinition[] tableDefinitions);
14 + }
15 +}