From 13eedbfcf97e402ade06f2be29f98723ef7ff286 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Thu, 18 Oct 2018 13:42:54 -0700 Subject: Extract interfaces for Preprocess/Compile/Link/Bind/etc --- src/WixToolset.Core/Decompiler.cs | 75 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/WixToolset.Core/Decompiler.cs (limited to 'src/WixToolset.Core/Decompiler.cs') diff --git a/src/WixToolset.Core/Decompiler.cs b/src/WixToolset.Core/Decompiler.cs new file mode 100644 index 00000000..5f14dfca --- /dev/null +++ b/src/WixToolset.Core/Decompiler.cs @@ -0,0 +1,75 @@ +// 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.Core +{ + using System; + using WixToolset.Data; + using WixToolset.Extensibility; + using WixToolset.Extensibility.Data; + using WixToolset.Extensibility.Services; + + /// + /// Decompiler of the WiX toolset. + /// + internal class Decompiler : IDecompiler + { + internal Decompiler(IServiceProvider serviceProvider) + { + this.ServiceProvider = serviceProvider; + } + + public OutputType DecompileType { get; set; } + + public string IntermediateFolder { get; set; } + + public string OutputPath { get; set; } + + public IServiceProvider ServiceProvider { get; } + + public BindResult Decompile(IDecompileContext context) + { + // Pre-decompile. + // + foreach (var extension in context.Extensions) + { + extension.PreDecompile(context); + } + + // Decompile. + // + var bindResult = this.BackendDecompile(context); + + if (bindResult != null) + { + // Post-decompile. + // + foreach (var extension in context.Extensions) + { + extension.PostDecompile(bindResult); + } + } + + return bindResult; + } + + private BindResult BackendDecompile(IDecompileContext context) + { + var extensionManager = context.ServiceProvider.GetService(); + + var backendFactories = extensionManager.Create(); + + foreach (var factory in backendFactories) + { + if (factory.TryCreateBackend(context.DecompileType.ToString(), context.OutputPath, out var backend)) + { + var result = backend.Decompile(context); + return result; + } + } + + // TODO: messaging that a backend could not be found to decompile the decompile type? + + return null; + } + } +} -- cgit v1.2.3-55-g6feb