| 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.Core.WindowsInstaller.CommandLine |
| 4 | { |
| 5 | using System; |
| 6 | using System.Threading; |
| 7 | using System.Threading.Tasks; |
| 8 | using WixToolset.Data; |
| 9 | using WixToolset.Extensibility; |
| 10 | using WixToolset.Extensibility.Data; |
| 11 | using WixToolset.Extensibility.Services; |
| 12 | |
| 13 | /// <summary> |
| 14 | /// Windows Installer specialized command. |
| 15 | /// </summary> |
| 16 | internal class WindowsInstallerCommand : BaseCommandLineCommand |
| 17 | { |
| 18 | public WindowsInstallerCommand(IServiceProvider serviceProvider) |
| 19 | { |
| 20 | this.ServiceProvider = serviceProvider; |
| 21 | this.Messaging = this.ServiceProvider.GetService<IMessaging>(); |
| 22 | } |
| 23 | |
| 24 | private IServiceProvider ServiceProvider { get; } |
| 25 | |
| 26 | private IMessaging Messaging { get; } |
| 27 | |
| 28 | private WindowsInstallerSubcommandBase Subcommand { get; set; } |
| 29 | |
| 30 | public override CommandLineHelp GetCommandLineHelp() |
| 31 | { |
| 32 | return this.Subcommand?.GetCommandLineHelp() ?? new CommandLineHelp("Specialized operations for manipulating Windows Installer databases.", "msi decompile|inscribe|transform|validate") |
| 33 | { |
| 34 | Commands = new[] |
| 35 | { |
| 36 | new CommandLineHelpCommand("decompile", "Converts a Windows Installer database back into source code."), |
| 37 | new CommandLineHelpCommand("inscribe", "Updates MSI database with cabinet signature information."), |
| 38 | new CommandLineHelpCommand("transform", "Creates an MST transform file."), |
| 39 | new CommandLineHelpCommand("validate", "Validates MSI database using standard or custom ICEs."), |
| 40 | } |
| 41 | }; |
| 42 | } |
| 43 | |
| 44 | public override Task<int> ExecuteAsync(CancellationToken cancellationToken) |
| 45 | { |
| 46 | if (this.Subcommand is null) |
| 47 | { |
| 48 | this.Messaging.Write(ErrorMessages.CommandLineCommandRequired("msi")); |
| 49 | return Task.FromResult(this.Messaging.LastErrorNumber); |
| 50 | } |
| 51 | |
| 52 | return this.Subcommand.ExecuteAsync(cancellationToken); |
| 53 | } |
| 54 | |
| 55 | public override bool TryParseArgument(ICommandLineParser parser, string argument) |
| 56 | { |
| 57 | if (this.Subcommand is null) |
| 58 | { |
| 59 | switch (argument.ToLowerInvariant()) |
| 60 | { |
| 61 | case "decompile": |
| 62 | this.Subcommand = new DecompilerSubcommand(this.ServiceProvider); |
| 63 | return true; |
| 64 | |
| 65 | case "inscribe": |
| 66 | this.Subcommand = new InscribeSubcommand(this.ServiceProvider); |
| 67 | return true; |
| 68 | |
| 69 | case "transform": |
| 70 | this.Subcommand = new TransformSubcommand(this.ServiceProvider); |
| 71 | return true; |
| 72 | |
| 73 | case "validate": |
| 74 | this.Subcommand = new ValidateSubcommand(this.ServiceProvider); |
| 75 | return true; |
| 76 | } |
| 77 | |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | return this.Subcommand.TryParseArgument(parser, argument); |
| 82 | } |
| 83 | } |
| 84 | } |