From c86a2148f6dd7bfcd6637b6e1c9e7b5a9b53a996 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Wed, 23 Mar 2022 10:25:49 -0700 Subject: Make "decompile" an MSI-only command instead of a backend requirement As much as I'd like decompiling to be global functionality provided by all backends there are only two output types that support decompiling: MSI and MSM. In the future, perhaps we can invest in a generic symbols to source code converter that would reduce the redundant work backends need to do today. Until then, make decompile an MSI specific command --- .../Data/IDecompileContext.cs | 59 ------------- .../Data/IDecompileResult.cs | 18 ---- .../Data/IWindowsInstallerDecompileContext.cs | 95 +++++++++++++++++++++ .../Data/IWindowsInstallerDecompileResult.cs | 18 ++++ src/api/wix/WixToolset.Extensibility/IBackend.cs | 3 - .../WixToolset.Extensibility/IBackendFactory.cs | 6 +- .../IDecompilerExtension.cs | 22 ----- .../IWindowsInstallerBackendDecompilerExtension.cs | 26 ------ .../IWindowsInstallerDecompilerExtension.cs | 26 ++++++ .../Services/ICommandLineParser.cs | 97 +++++++++++++++++++--- 10 files changed, 228 insertions(+), 142 deletions(-) delete mode 100644 src/api/wix/WixToolset.Extensibility/Data/IDecompileContext.cs delete mode 100644 src/api/wix/WixToolset.Extensibility/Data/IDecompileResult.cs create mode 100644 src/api/wix/WixToolset.Extensibility/Data/IWindowsInstallerDecompileContext.cs create mode 100644 src/api/wix/WixToolset.Extensibility/Data/IWindowsInstallerDecompileResult.cs delete mode 100644 src/api/wix/WixToolset.Extensibility/IDecompilerExtension.cs delete mode 100644 src/api/wix/WixToolset.Extensibility/IWindowsInstallerBackendDecompilerExtension.cs create mode 100644 src/api/wix/WixToolset.Extensibility/IWindowsInstallerDecompilerExtension.cs (limited to 'src/api') diff --git a/src/api/wix/WixToolset.Extensibility/Data/IDecompileContext.cs b/src/api/wix/WixToolset.Extensibility/Data/IDecompileContext.cs deleted file mode 100644 index fe7d0465..00000000 --- a/src/api/wix/WixToolset.Extensibility/Data/IDecompileContext.cs +++ /dev/null @@ -1,59 +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.Data -{ - using System; - using System.Collections.Generic; - using WixToolset.Data; - using WixToolset.Extensibility.Services; - -#pragma warning disable 1591 // TODO: add documentation - public interface IDecompileContext - { - IServiceProvider ServiceProvider { get; } - - string DecompilePath { get; set; } - - OutputType DecompileType { get; set; } - - IReadOnlyCollection Extensions { get; set; } - - string ExtractFolder { get; set; } - - string CabinetExtractFolder { get; set; } - - /// - /// Optional gets or sets the base path for the File/@Source. - /// - /// Default value is "SourceDir" to enable use of BindPaths. - string BaseSourcePath { get; set; } - - string IntermediateFolder { get; set; } - - bool IsAdminImage { get; set; } - - string OutputPath { get; set; } - - /// - /// Gets or sets the option to suppress custom tables. - /// - bool SuppressCustomTables { get; set; } - - /// - /// Gets or sets the option to suppress dropping empty tables. - /// - bool SuppressDroppingEmptyTables { get; set; } - - bool SuppressExtractCabinets { get; set; } - - /// - /// Gets or sets the option to suppress decompiling UI-related tables. - /// - bool SuppressUI { get; set; } - - /// - /// Gets or sets whether the decompiler should use module logic on a product output. - /// - bool TreatProductAsModule { get; set; } - } -} diff --git a/src/api/wix/WixToolset.Extensibility/Data/IDecompileResult.cs b/src/api/wix/WixToolset.Extensibility/Data/IDecompileResult.cs deleted file mode 100644 index cffd0976..00000000 --- a/src/api/wix/WixToolset.Extensibility/Data/IDecompileResult.cs +++ /dev/null @@ -1,18 +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.Data -{ - using System.Collections.Generic; - using System.Xml.Linq; - using WixToolset.Data; - -#pragma warning disable 1591 // TODO: add documentation - public interface IDecompileResult - { - XDocument Document { get; set; } - - IReadOnlyCollection ExtractedFilePaths { get; set; } - - Platform? Platform { get; set; } - } -} diff --git a/src/api/wix/WixToolset.Extensibility/Data/IWindowsInstallerDecompileContext.cs b/src/api/wix/WixToolset.Extensibility/Data/IWindowsInstallerDecompileContext.cs new file mode 100644 index 00000000..f744121a --- /dev/null +++ b/src/api/wix/WixToolset.Extensibility/Data/IWindowsInstallerDecompileContext.cs @@ -0,0 +1,95 @@ +// 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.Data +{ + using System; + using System.Collections.Generic; + using WixToolset.Data; + + /// + /// The context used to decompile Windows Installer packages. + /// + public interface IWindowsInstallerDecompileContext + { + /// + /// Gets or sets the service provider. + /// + IServiceProvider ServiceProvider { get; } + + /// + /// Gets or sets the path to the file to decompile. + /// + string DecompilePath { get; set; } + + /// + /// Gets or sets the type to decompile. + /// + OutputType DecompileType { get; set; } + + /// + /// Gets or sets the decompiler extensions. + /// + IReadOnlyCollection Extensions { get; set; } + + /// + /// Gets or sets the folder where content is extracted. + /// + string ExtractFolder { get; set; } + + /// + /// Gets or sets the folder where files are extracted. + /// + string CabinetExtractFolder { get; set; } + + /// + /// Optional gets or sets the base path for the File/@Source. + /// + /// Default value is "SourceDir" to enable use of BindPaths. + string BaseSourcePath { get; set; } + + /// + /// Gets or sets the intermediate folder. + /// + string IntermediateFolder { get; set; } + + /// + /// Gets or sets whether the decompiler admin image. + /// + bool IsAdminImage { get; set; } + + /// + /// Gets or sets where to output the result. + /// + string OutputPath { get; set; } + + /// + /// Gets or sets the option to suppress custom tables. + /// + bool SuppressCustomTables { get; set; } + + /// + /// Gets or sets the option to suppress dropping empty tables. + /// + bool SuppressDroppingEmptyTables { get; set; } + + /// + /// Gets or sets whether to prevent extract cabinets. + /// + bool SuppressExtractCabinets { get; set; } + + /// + /// Gets or sets whether to suppress relative action sequencing. + /// + bool SuppressRelativeActionSequencing { get; set; } + + /// + /// Gets or sets the option to suppress decompiling UI-related tables. + /// + bool SuppressUI { get; set; } + + /// + /// Gets or sets whether the decompiler should use module logic on a product output. + /// + bool TreatProductAsModule { get; set; } + } +} diff --git a/src/api/wix/WixToolset.Extensibility/Data/IWindowsInstallerDecompileResult.cs b/src/api/wix/WixToolset.Extensibility/Data/IWindowsInstallerDecompileResult.cs new file mode 100644 index 00000000..3b1dd815 --- /dev/null +++ b/src/api/wix/WixToolset.Extensibility/Data/IWindowsInstallerDecompileResult.cs @@ -0,0 +1,18 @@ +// 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.Data +{ + using System.Collections.Generic; + using System.Xml.Linq; + using WixToolset.Data; + +#pragma warning disable 1591 // TODO: add documentation + public interface IWindowsInstallerDecompileResult + { + XDocument Document { get; set; } + + IReadOnlyCollection ExtractedFilePaths { get; set; } + + Platform? Platform { get; set; } + } +} diff --git a/src/api/wix/WixToolset.Extensibility/IBackend.cs b/src/api/wix/WixToolset.Extensibility/IBackend.cs index cb151e05..720abe15 100644 --- a/src/api/wix/WixToolset.Extensibility/IBackend.cs +++ b/src/api/wix/WixToolset.Extensibility/IBackend.cs @@ -15,8 +15,5 @@ namespace WixToolset.Extensibility /// Bind context. /// Result of the bind operation. IBindResult Bind(IBindContext context); - -#pragma warning disable 1591 // TODO: add documentation - IDecompileResult Decompile(IDecompileContext context); } } diff --git a/src/api/wix/WixToolset.Extensibility/IBackendFactory.cs b/src/api/wix/WixToolset.Extensibility/IBackendFactory.cs index 7f9ef62d..8e84f5b6 100644 --- a/src/api/wix/WixToolset.Extensibility/IBackendFactory.cs +++ b/src/api/wix/WixToolset.Extensibility/IBackendFactory.cs @@ -3,7 +3,7 @@ namespace WixToolset.Extensibility { /// - /// Implemented by extensions to create backends. + /// Implemented by extensions that are backends. /// public interface IBackendFactory { @@ -12,8 +12,8 @@ namespace WixToolset.Extensibility /// /// Type of output being created. /// Path to the output to create. - /// The backend for the output. + /// The backend for the output. /// True if the backend was created, otherwise false. - bool TryCreateBackend(string outputType, string outputPath, out IBackend backend); + bool TryCreateBackend(string outputType, string outputPath, out IBackend binder); } } diff --git a/src/api/wix/WixToolset.Extensibility/IDecompilerExtension.cs b/src/api/wix/WixToolset.Extensibility/IDecompilerExtension.cs deleted file mode 100644 index 24ef3bff..00000000 --- a/src/api/wix/WixToolset.Extensibility/IDecompilerExtension.cs +++ /dev/null @@ -1,22 +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 WixToolset.Extensibility.Data; - - /// - /// Base class for creating a decompiler extension. - /// - public interface IDecompilerExtension - { - /// - /// Called before decompiling occurs. - /// - void PreDecompile(IDecompileContext context); - - /// - /// Called after all decompiling occurs. - /// - void PostDecompile(IDecompileResult result); - } -} diff --git a/src/api/wix/WixToolset.Extensibility/IWindowsInstallerBackendDecompilerExtension.cs b/src/api/wix/WixToolset.Extensibility/IWindowsInstallerBackendDecompilerExtension.cs deleted file mode 100644 index a56b63c3..00000000 --- a/src/api/wix/WixToolset.Extensibility/IWindowsInstallerBackendDecompilerExtension.cs +++ /dev/null @@ -1,26 +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 WixToolset.Data; - using WixToolset.Data.WindowsInstaller; - using WixToolset.Extensibility.Data; - - /// - /// Interface all binder extensions implement. - /// - public interface IWindowsInstallerBackendDecompilerExtension - { - /// - /// Called before decompiling occurs. - /// - void PreBackendDecompile(IDecompileContext context); - - // TODO: Redesign this interface to be useful. - - /// - /// Called after all output changes occur and right before the output is bound into its final format. - /// - void PostBackendDecompile(IDecompileResult result); - } -} diff --git a/src/api/wix/WixToolset.Extensibility/IWindowsInstallerDecompilerExtension.cs b/src/api/wix/WixToolset.Extensibility/IWindowsInstallerDecompilerExtension.cs new file mode 100644 index 00000000..add5f886 --- /dev/null +++ b/src/api/wix/WixToolset.Extensibility/IWindowsInstallerDecompilerExtension.cs @@ -0,0 +1,26 @@ +// 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 WixToolset.Data; + using WixToolset.Data.WindowsInstaller; + using WixToolset.Extensibility.Data; + + /// + /// Interface all binder extensions implement. + /// + public interface IWindowsInstallerDecompilerExtension + { + /// + /// Called before decompiling occurs. + /// + void PreDecompile(IWindowsInstallerDecompileContext context); + + // TODO: Redesign this interface to be useful. + + /// + /// Called after all output changes occur and right before the output is bound into its final format. + /// + void PostDecompile(IWindowsInstallerDecompileResult result); + } +} diff --git a/src/api/wix/WixToolset.Extensibility/Services/ICommandLineParser.cs b/src/api/wix/WixToolset.Extensibility/Services/ICommandLineParser.cs index cd17f100..efd6600d 100644 --- a/src/api/wix/WixToolset.Extensibility/Services/ICommandLineParser.cs +++ b/src/api/wix/WixToolset.Extensibility/Services/ICommandLineParser.cs @@ -5,36 +5,111 @@ namespace WixToolset.Extensibility.Services using System.Collections.Generic; using WixToolset.Data; -#pragma warning disable 1591 // TODO: add documentation + /// + /// Provides the command-line arguments. + /// public interface ICommandLineParser { + /// + /// Gets the argument that caused the error. + /// string ErrorArgument { get; } /// /// Validates that a valid switch (starts with "/" or "-"), and returns a bool indicating its validity /// - /// The string check. + /// The string check. /// True if a valid switch, otherwise false. - bool IsSwitch(string arg); + bool IsSwitch(string argument); + /// + /// Gets the current argument as a file or displays an error. + /// + /// Current argument used in the error message if necessary. + /// Type of file displayed in the error message if necessary. + /// The fully expanded path if the argument is a file path, otherwise null. string GetArgumentAsFilePathOrError(string argument, string fileType); - void GetArgumentAsFilePathOrError(string argument, string fileType, IList paths); + /// + /// Adds the current argument as a file to the list or displays an error. + /// + /// Current argument used in the error message if necessary. + /// Type of file displayed in the error message if necessary. + /// List to add the fully expanded path if the argument is a file path. + /// True if the argument is a file path, otherwise false. + bool GetArgumentAsFilePathOrError(string argument, string fileType, IList paths); - string GetNextArgumentOrError(string commandLineSwitch); + /// + /// Gets the next argument or displays error if no argument is available. + /// + /// Current argument used in the error message if necessary. + /// The next argument if present or null + string GetNextArgumentOrError(string argument); - bool GetNextArgumentOrError(string commandLineSwitch, IList argument); + /// + /// Adds the next argument to a list or displays error if no argument is available. + /// + /// Current argument used in the error message if necessary. + /// List to add the argument to. + /// True if an argument is available, otherwise false. + bool GetNextArgumentOrError(string argument, IList arguments); - string GetNextArgumentAsDirectoryOrError(string commandLineSwitch); + /// + /// Gets the next argument as a directory or displays an error. + /// + /// Current argument used in the error message if necessary. + /// The fully expanded path if the argument is a directory, otherwise null. + string GetNextArgumentAsDirectoryOrError(string argument); - bool GetNextArgumentAsDirectoryOrError(string commandLineSwitch, IList directories); + /// + /// Adds the next argument as a directory to the list or displays an error. + /// + /// Current argument used in the error message if necessary. + /// List to add the fully expanded directory if the argument is a file path. + /// True if the argument is a directory, otherwise false. + bool GetNextArgumentAsDirectoryOrError(string argument, IList directories); - string GetNextArgumentAsFilePathOrError(string commandLineSwitch); + /// + /// Gets the next argument as a file or displays an error. + /// + /// Current argument used in the error message if necessary. + /// The fully expanded path if the argument is a file path, otherwise null. + string GetNextArgumentAsFilePathOrError(string argument); - bool GetNextArgumentAsFilePathOrError(string commandLineSwitch, string fileType, IList paths); + /// + /// Adds the next argument as a file to the list or displays an error. + /// + /// Current argument used in the error message if necessary. + /// Type of file displayed in the error message if necessary. + /// List to add the fully expanded path if the argument is a file path. + /// True if the argument is a file path, otherwise false. + bool GetNextArgumentAsFilePathOrError(string argument, string fileType, IList paths); + /// + /// Reports a command line error for the provided argument. + /// + /// Argument that caused the error. + /// Message to report. void ReportErrorArgument(string argument, Message message = null); - bool TryGetNextSwitchOrArgument(out string arg); + /// + /// Tries to get the next argument. + /// + /// Next argument if available. + /// True if argument is available, otherwise false. + bool TryGetNextSwitchOrArgument(out string argument); + + /// + /// Looks ahead to the next argument without moving to the next argument. + /// + /// Next argument if available, otherwise null. + string PeekNextArgument(); + + /// + /// Tries to looks ahead to the next argument without moving to the next argument. + /// + /// Argument found if present. + /// True if argument is found, otherwise false. + bool TryPeekNextArgument(out string argument); } } -- cgit v1.2.3-55-g6feb