| 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.IO; |
| 7 | using System.Threading; |
| 8 | using System.Threading.Tasks; |
| 9 | using WixToolset.Core.WindowsInstaller.Inscribe; |
| 10 | using WixToolset.Data; |
| 11 | using WixToolset.Extensibility.Data; |
| 12 | using WixToolset.Extensibility.Services; |
| 13 | |
| 14 | internal class InscribeSubcommand : WindowsInstallerSubcommandBase |
| 15 | { |
| 16 | public InscribeSubcommand(IServiceProvider serviceProvider) |
| 17 | { |
| 18 | this.ServiceProvider = serviceProvider; |
| 19 | this.Messaging = serviceProvider.GetService<IMessaging>(); |
| 20 | } |
| 21 | |
| 22 | private IServiceProvider ServiceProvider { get; } |
| 23 | |
| 24 | private IMessaging Messaging { get; } |
| 25 | |
| 26 | private string InputPath { get; set; } |
| 27 | |
| 28 | private string IntermediateFolder { get; set; } |
| 29 | |
| 30 | private string OutputPath { get; set; } |
| 31 | |
| 32 | public override CommandLineHelp GetCommandLineHelp() |
| 33 | { |
| 34 | return new CommandLineHelp("Updates MSI database with cabinet signature information.", "msi inscribe [options] input.msi [-out inscribed.msi]", new[] |
| 35 | { |
| 36 | new CommandLineHelpSwitch("-intermediateFolder", "Optional working folder. If not specified %TMP% will be used."), |
| 37 | new CommandLineHelpSwitch("-out", "-o", "Path to output the inscribed MSI. If not provided, the input MSI is updated in place."), |
| 38 | }); |
| 39 | } |
| 40 | |
| 41 | public override Task<int> ExecuteAsync(CancellationToken cancellationToken) |
| 42 | { |
| 43 | if (String.IsNullOrEmpty(this.InputPath)) |
| 44 | { |
| 45 | this.Messaging.Write(ErrorMessages.FilePathRequired("input MSI database")); |
| 46 | } |
| 47 | else |
| 48 | { |
| 49 | if (String.IsNullOrEmpty(this.IntermediateFolder)) |
| 50 | { |
| 51 | this.IntermediateFolder = Path.GetTempPath(); |
| 52 | } |
| 53 | |
| 54 | if (String.IsNullOrEmpty(this.OutputPath)) |
| 55 | { |
| 56 | this.OutputPath = this.InputPath; |
| 57 | } |
| 58 | |
| 59 | var command = new InscribeMsiPackageCommand(this.ServiceProvider, this.InputPath, this.IntermediateFolder, this.OutputPath); |
| 60 | command.Execute(); |
| 61 | } |
| 62 | |
| 63 | return Task.FromResult(this.Messaging.LastErrorNumber); |
| 64 | } |
| 65 | |
| 66 | public override bool TryParseArgument(ICommandLineParser parser, string argument) |
| 67 | { |
| 68 | if (parser.IsSwitch(argument)) |
| 69 | { |
| 70 | var parameter = argument.Substring(1); |
| 71 | switch (parameter.ToLowerInvariant()) |
| 72 | { |
| 73 | case "intermediatefolder": |
| 74 | this.IntermediateFolder = parser.GetNextArgumentAsDirectoryOrError(argument); |
| 75 | return true; |
| 76 | |
| 77 | case "o": |
| 78 | case "out": |
| 79 | this.OutputPath = parser.GetNextArgumentAsFilePathOrError(argument, "output file"); |
| 80 | return true; |
| 81 | } |
| 82 | } |
| 83 | else if (String.IsNullOrEmpty(this.InputPath)) |
| 84 | { |
| 85 | this.InputPath = argument; |
| 86 | return true; |
| 87 | } |
| 88 | |
| 89 | return false; |
| 90 | } |
| 91 | } |
| 92 | } |