main
cs 90 lines 3.29 KB
Raw
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.Burn.CommandLine
4 {
5 using System;
6 using System.IO;
7 using System.Threading;
8 using System.Threading.Tasks;
9 using WixToolset.Core.Burn.Inscribe;
10 using WixToolset.Data;
11 using WixToolset.Extensibility.Data;
12 using WixToolset.Extensibility.Services;
13
14 internal class DetachSubcommand : BurnSubcommandBase
15 {
16 public DetachSubcommand(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 EngineOutputPath { get; set; }
31
32 public override CommandLineHelp GetCommandLineHelp()
33 {
34 return new CommandLineHelp("Detaches the Burn engine from a bundle so it can be signed.", "burn detach [options] original.exe -engine engine.exe", new[]
35 {
36 new CommandLineHelpSwitch("-intermediateFolder", "Optional working folder. If not specified %TMP% will be used."),
37 new CommandLineHelpSwitch("-engine", "Path for extracted bundle engine."),
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 bundle"));
46 }
47 else if (String.IsNullOrEmpty(this.EngineOutputPath))
48 {
49 this.Messaging.Write(ErrorMessages.FilePathRequired("output the bundle engine"));
50 }
51 else
52 {
53 if (String.IsNullOrEmpty(this.IntermediateFolder))
54 {
55 this.IntermediateFolder = Path.GetTempPath();
56 }
57
58 var command = new InscribeBundleEngineCommand(this.ServiceProvider, this.InputPath, this.EngineOutputPath, this.IntermediateFolder);
59 command.Execute();
60 }
61
62 return Task.FromResult(this.Messaging.LastErrorNumber);
63 }
64
65 public override bool TryParseArgument(ICommandLineParser parser, string argument)
66 {
67 if (parser.IsSwitch(argument))
68 {
69 var parameter = argument.Substring(1);
70 switch (parameter.ToLowerInvariant())
71 {
72 case "intermediatefolder":
73 this.IntermediateFolder = parser.GetNextArgumentAsDirectoryOrError(argument);
74 return true;
75
76 case "engine":
77 this.EngineOutputPath = parser.GetNextArgumentAsFilePathOrError(argument, "output the bundle engine");
78 return true;
79 }
80 }
81 else if (String.IsNullOrEmpty(this.InputPath))
82 {
83 this.InputPath = argument;
84 return true;
85 }
86
87 return false;
88 }
89 }
90 }