diff options
Diffstat (limited to 'src/wix/WixToolset.Core.Burn/CommandLine/ExtractSubcommand.cs')
| -rw-r--r-- | src/wix/WixToolset.Core.Burn/CommandLine/ExtractSubcommand.cs | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/wix/WixToolset.Core.Burn/CommandLine/ExtractSubcommand.cs b/src/wix/WixToolset.Core.Burn/CommandLine/ExtractSubcommand.cs new file mode 100644 index 00000000..859f5e34 --- /dev/null +++ b/src/wix/WixToolset.Core.Burn/CommandLine/ExtractSubcommand.cs | |||
| @@ -0,0 +1,86 @@ | |||
| 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.Bundles; | ||
| 10 | using WixToolset.Core.Burn.Inscribe; | ||
| 11 | using WixToolset.Extensibility.Services; | ||
| 12 | |||
| 13 | internal class ExtractSubcommand : BurnSubcommandBase | ||
| 14 | { | ||
| 15 | public ExtractSubcommand(IServiceProvider serviceProvider) | ||
| 16 | { | ||
| 17 | this.ServiceProvider = serviceProvider; | ||
| 18 | this.Messaging = serviceProvider.GetService<IMessaging>(); | ||
| 19 | } | ||
| 20 | |||
| 21 | private IServiceProvider ServiceProvider { get; } | ||
| 22 | |||
| 23 | private IMessaging Messaging { get; } | ||
| 24 | |||
| 25 | private string InputPath { get; set; } | ||
| 26 | |||
| 27 | private string IntermediateFolder { get; set; } | ||
| 28 | |||
| 29 | private string ExtractPath { get; set; } | ||
| 30 | |||
| 31 | public override Task<int> ExecuteAsync(CancellationToken cancellationToken) | ||
| 32 | { | ||
| 33 | if (String.IsNullOrEmpty(this.InputPath)) | ||
| 34 | { | ||
| 35 | Console.Error.WriteLine("Path to input bundle is required"); | ||
| 36 | return Task.FromResult(-1); | ||
| 37 | } | ||
| 38 | |||
| 39 | if (String.IsNullOrEmpty(this.ExtractPath)) | ||
| 40 | { | ||
| 41 | Console.Error.WriteLine("Path to output the extracted bundle is required"); | ||
| 42 | return Task.FromResult(-1); | ||
| 43 | } | ||
| 44 | |||
| 45 | if (String.IsNullOrEmpty(this.IntermediateFolder)) | ||
| 46 | { | ||
| 47 | this.IntermediateFolder = Path.GetTempPath(); | ||
| 48 | } | ||
| 49 | |||
| 50 | var uxExtractPath = Path.Combine(this.ExtractPath, "BA"); | ||
| 51 | |||
| 52 | using (var reader = BurnReader.Open(this.Messaging, this.InputPath)) | ||
| 53 | { | ||
| 54 | reader.ExtractUXContainer(uxExtractPath, this.IntermediateFolder); | ||
| 55 | reader.ExtractAttachedContainers(this.ExtractPath, this.IntermediateFolder); | ||
| 56 | } | ||
| 57 | |||
| 58 | return Task.FromResult(this.Messaging.LastErrorNumber); | ||
| 59 | } | ||
| 60 | |||
| 61 | public override bool TryParseArgument(ICommandLineParser parser, string argument) | ||
| 62 | { | ||
| 63 | if (parser.IsSwitch(argument)) | ||
| 64 | { | ||
| 65 | var parameter = argument.Substring(1); | ||
| 66 | switch (parameter.ToLowerInvariant()) | ||
| 67 | { | ||
| 68 | case "intermediatefolder": | ||
| 69 | this.IntermediateFolder = parser.GetNextArgumentAsDirectoryOrError(argument); | ||
| 70 | return true; | ||
| 71 | |||
| 72 | case "o": | ||
| 73 | this.ExtractPath = parser.GetNextArgumentAsDirectoryOrError(argument); | ||
| 74 | return true; | ||
| 75 | } | ||
| 76 | } | ||
| 77 | else if (String.IsNullOrEmpty(this.InputPath)) | ||
| 78 | { | ||
| 79 | this.InputPath = argument; | ||
| 80 | return true; | ||
| 81 | } | ||
| 82 | |||
| 83 | return false; | ||
| 84 | } | ||
| 85 | } | ||
| 86 | } | ||
