From 822d917960cbd35f506598af4baa6a20ad4b447e Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Wed, 24 Oct 2018 21:06:51 -0700 Subject: Re-introduce "decompile" to backend --- .../CommandLine/DecompileCommand.cs | 212 +++++++++++++++++++++ src/WixToolset.Core/DecompileContext.cs | 20 +- src/WixToolset.Core/Decompiler.cs | 12 +- src/WixToolset.Core/IDecompiler.cs | 4 +- src/WixToolset.Core/OptimizeCA.cs | 4 +- 5 files changed, 241 insertions(+), 11 deletions(-) create mode 100644 src/WixToolset.Core/CommandLine/DecompileCommand.cs (limited to 'src/WixToolset.Core') diff --git a/src/WixToolset.Core/CommandLine/DecompileCommand.cs b/src/WixToolset.Core/CommandLine/DecompileCommand.cs new file mode 100644 index 00000000..87cead80 --- /dev/null +++ b/src/WixToolset.Core/CommandLine/DecompileCommand.cs @@ -0,0 +1,212 @@ +// 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.CommandLine +{ + using System; + using System.Collections.Generic; + using System.IO; + using WixToolset.Data; + using WixToolset.Extensibility; + using WixToolset.Extensibility.Data; + using WixToolset.Extensibility.Services; + + internal class DecompileCommand : ICommandLineCommand + { + private readonly CommandLine commandLine; + + public DecompileCommand(IServiceProvider serviceProvider) + { + this.ServiceProvider = serviceProvider; + this.Messaging = serviceProvider.GetService(); + this.commandLine = new CommandLine(this.Messaging); + } + + public bool ShowLogo => this.commandLine.ShowLogo; + + public bool StopParsing => this.commandLine.ShowHelp; + + private IServiceProvider ServiceProvider { get; } + + public IMessaging Messaging { get; } + + private IEnumerable SourceFiles { get; } + + private string OutputPath { get; } + + public int Execute() + { + if (this.commandLine.ShowHelp) + { + Console.WriteLine("TODO: Show decompile command help"); + return -1; + } + + var context = this.ServiceProvider.GetService(); + context.Extensions = this.ServiceProvider.GetService().Create(); + context.DecompilePath = this.commandLine.DecompileFilePath; + context.DecompileType = this.commandLine.CalculateDecompileType(); + context.IntermediateFolder = this.commandLine.CalculateIntermedateFolder(); + context.OutputPath = this.commandLine.CalculateOutputPath(); + + try + { + var decompiler = this.ServiceProvider.GetService(); + var result = decompiler.Decompile(context); + } + catch (WixException e) + { + this.Messaging.Write(e.Error); + } + + if (this.Messaging.EncounteredError) + { + return 1; + } + + return 0; + } + + public bool TryParseArgument(ICommandLineParser parser, string argument) + { + return this.commandLine.TryParseArgument(argument, parser); + } + + private class CommandLine + { + public CommandLine(IMessaging messaging) + { + this.Messaging = messaging; + } + + private IMessaging Messaging { get; } + + public string DecompileFilePath { get; private set; } + + public string DecompileType { get; private set; } + + public Platform Platform { get; private set; } + + public bool ShowLogo { get; private set; } + + public bool ShowHelp { get; private set; } + + public string IntermediateFolder { get; private set; } + + public string OutputFile { get; private set; } + + public bool TryParseArgument(string arg, ICommandLineParser parser) + { + if (parser.IsSwitch(arg)) + { + var parameter = arg.Substring(1); + switch (parameter.ToLowerInvariant()) + { + case "?": + case "h": + case "help": + this.ShowHelp = true; + return true; + + case "intermediatefolder": + this.IntermediateFolder = parser.GetNextArgumentAsDirectoryOrError(arg); + return true; + + case "o": + case "out": + this.OutputFile = parser.GetNextArgumentAsFilePathOrError(arg); + return true; + + case "nologo": + this.ShowLogo = false; + return true; + + case "v": + case "verbose": + this.Messaging.ShowVerboseMessages = true; + return true; + + case "sw": + case "suppresswarning": + var warning = parser.GetNextArgumentOrError(arg); + if (!String.IsNullOrEmpty(warning)) + { + var warningNumber = Convert.ToInt32(warning); + this.Messaging.SuppressWarningMessage(warningNumber); + } + return true; + } + } + else + { + if (String.IsNullOrEmpty(this.DecompileFilePath)) + { + this.DecompileFilePath = parser.GetArgumentAsFilePathOrError(arg, "decompile file"); + return true; + } + else if (String.IsNullOrEmpty(this.OutputFile)) + { + this.OutputFile = parser.GetArgumentAsFilePathOrError(arg, "output file"); + return true; + } + } + + return false; + } + + public OutputType CalculateDecompileType() + { + if (String.IsNullOrEmpty(this.DecompileType)) + { + this.DecompileType = Path.GetExtension(this.DecompileFilePath); + } + + switch (this.DecompileType.ToLowerInvariant()) + { + case "bundle": + case ".exe": + return OutputType.Bundle; + + case "library": + case ".wixlib": + return OutputType.Library; + + case "module": + case ".msm": + return OutputType.Module; + + case "patch": + case ".msp": + return OutputType.Patch; + + case ".pcp": + return OutputType.PatchCreation; + + case "product": + case "package": + case ".msi": + return OutputType.Product; + + case "transform": + case ".mst": + return OutputType.Transform; + + case "intermediatepostlink": + case ".wixipl": + return OutputType.IntermediatePostLink; + } + + return OutputType.Unknown; + } + + public string CalculateIntermedateFolder() + { + return String.IsNullOrEmpty(this.IntermediateFolder) ? Path.GetTempPath() : this.IntermediateFolder; + } + + public string CalculateOutputPath() + { + return String.IsNullOrEmpty(this.OutputFile) ? Path.ChangeExtension(this.DecompileFilePath, ".wxs") : this.OutputFile; + } + } + } +} diff --git a/src/WixToolset.Core/DecompileContext.cs b/src/WixToolset.Core/DecompileContext.cs index a9f0640a..b697c3cf 100644 --- a/src/WixToolset.Core/DecompileContext.cs +++ b/src/WixToolset.Core/DecompileContext.cs @@ -1,4 +1,4 @@ -// 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. +// 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 { @@ -17,12 +17,30 @@ namespace WixToolset.Core public IServiceProvider ServiceProvider { get; } + public string DecompilePath { get; set; } + public OutputType DecompileType { get; set; } public IEnumerable Extensions { get; set; } + public string ExtractFolder { get; set; } + + public string BaseSourcePath { get; set; } + public string IntermediateFolder { get; set; } + public bool IsAdminImage { get; set; } + public string OutputPath { get; set; } + + public bool SuppressCustomTables { get; set; } + + public bool SuppressDroppingEmptyTables { get; set; } + + public bool SuppressExtractCabinets { get; set; } + + public bool SuppressUI { get; set; } + + public bool TreatProductAsModule { get; set; } } } diff --git a/src/WixToolset.Core/Decompiler.cs b/src/WixToolset.Core/Decompiler.cs index 45cfbea0..685722a8 100644 --- a/src/WixToolset.Core/Decompiler.cs +++ b/src/WixToolset.Core/Decompiler.cs @@ -19,7 +19,7 @@ namespace WixToolset.Core public IServiceProvider ServiceProvider { get; } - public BindResult Decompile(IDecompileContext context) + public DecompileResult Decompile(IDecompileContext context) { // Pre-decompile. // @@ -30,22 +30,22 @@ namespace WixToolset.Core // Decompile. // - var bindResult = this.BackendDecompile(context); + var result = this.BackendDecompile(context); - if (bindResult != null) + if (result != null) { // Post-decompile. // foreach (var extension in context.Extensions) { - extension.PostDecompile(bindResult); + extension.PostDecompile(result); } } - return bindResult; + return result; } - private BindResult BackendDecompile(IDecompileContext context) + private DecompileResult BackendDecompile(IDecompileContext context) { var extensionManager = context.ServiceProvider.GetService(); diff --git a/src/WixToolset.Core/IDecompiler.cs b/src/WixToolset.Core/IDecompiler.cs index b9bb7ed8..82b02943 100644 --- a/src/WixToolset.Core/IDecompiler.cs +++ b/src/WixToolset.Core/IDecompiler.cs @@ -1,4 +1,4 @@ -// 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. +// 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 { @@ -6,6 +6,6 @@ namespace WixToolset.Core public interface IDecompiler { - BindResult Decompile(IDecompileContext context); + DecompileResult Decompile(IDecompileContext context); } } diff --git a/src/WixToolset.Core/OptimizeCA.cs b/src/WixToolset.Core/OptimizeCA.cs index ba17604d..0d7b5e1a 100644 --- a/src/WixToolset.Core/OptimizeCA.cs +++ b/src/WixToolset.Core/OptimizeCA.cs @@ -1,4 +1,4 @@ -// 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. +// 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 { @@ -8,7 +8,7 @@ namespace WixToolset.Core /// Values for the OptimizeCA MsiPatchMetdata property, which indicates whether custom actions can be skipped when applying the patch. /// [Flags] - internal enum OptimizeCA + public enum OptimizeCA // TODO: review where to place this data so it can not be exposed by WixToolset.Core { /// /// No custom actions are skipped. -- cgit v1.2.3-55-g6feb