From 647f6bc49ecf035add9d41bd2bc0625cd8cb27da Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Fri, 4 Feb 2022 10:24:51 -0800 Subject: Move command-line handling into CommandLine namespace --- src/wix/WixToolset.Core.Burn/BurnCommand.cs | 78 ---------------- .../BurnExtensionCommandLine.cs | 3 +- src/wix/WixToolset.Core.Burn/BurnSubcommandBase.cs | 15 --- .../CommandLine/BurnCommand.cs | 78 ++++++++++++++++ .../CommandLine/BurnSubcommandBase.cs | 15 +++ .../CommandLine/DetachSubcommand.cs | 80 ++++++++++++++++ .../CommandLine/ReattachSubcommand.cs | 101 +++++++++++++++++++++ src/wix/WixToolset.Core.Burn/DetachSubcommand.cs | 80 ---------------- src/wix/WixToolset.Core.Burn/ReattachSubcommand.cs | 101 --------------------- .../CommandLine/InscribeSubcommand.cs | 80 ++++++++++++++++ .../CommandLine/WindowsInstallerCommand.cs | 73 +++++++++++++++ .../CommandLine/WindowsInstallerSubcommandBase.cs | 15 +++ .../InscribeSubcommand.cs | 80 ---------------- .../WindowsInstallerCommand.cs | 73 --------------- .../WindowsInstallerExtensionCommandLine.cs | 1 + .../WindowsInstallerSubcommandBase.cs | 15 --- 16 files changed, 445 insertions(+), 443 deletions(-) delete mode 100644 src/wix/WixToolset.Core.Burn/BurnCommand.cs delete mode 100644 src/wix/WixToolset.Core.Burn/BurnSubcommandBase.cs create mode 100644 src/wix/WixToolset.Core.Burn/CommandLine/BurnCommand.cs create mode 100644 src/wix/WixToolset.Core.Burn/CommandLine/BurnSubcommandBase.cs create mode 100644 src/wix/WixToolset.Core.Burn/CommandLine/DetachSubcommand.cs create mode 100644 src/wix/WixToolset.Core.Burn/CommandLine/ReattachSubcommand.cs delete mode 100644 src/wix/WixToolset.Core.Burn/DetachSubcommand.cs delete mode 100644 src/wix/WixToolset.Core.Burn/ReattachSubcommand.cs create mode 100644 src/wix/WixToolset.Core.WindowsInstaller/CommandLine/InscribeSubcommand.cs create mode 100644 src/wix/WixToolset.Core.WindowsInstaller/CommandLine/WindowsInstallerCommand.cs create mode 100644 src/wix/WixToolset.Core.WindowsInstaller/CommandLine/WindowsInstallerSubcommandBase.cs delete mode 100644 src/wix/WixToolset.Core.WindowsInstaller/InscribeSubcommand.cs delete mode 100644 src/wix/WixToolset.Core.WindowsInstaller/WindowsInstallerCommand.cs delete mode 100644 src/wix/WixToolset.Core.WindowsInstaller/WindowsInstallerSubcommandBase.cs (limited to 'src') diff --git a/src/wix/WixToolset.Core.Burn/BurnCommand.cs b/src/wix/WixToolset.Core.Burn/BurnCommand.cs deleted file mode 100644 index 3835bf2e..00000000 --- a/src/wix/WixToolset.Core.Burn/BurnCommand.cs +++ /dev/null @@ -1,78 +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.Core.Burn -{ - using System; - using System.Threading; - using System.Threading.Tasks; - using WixToolset.Extensibility.Data; - using WixToolset.Extensibility.Services; - - /// - /// Burn specialized command. - /// - internal class BurnCommand : ICommandLineCommand - { - public BurnCommand(IServiceProvider serviceProvider) - { - this.ServiceProvider = serviceProvider; - } - - public bool ShowHelp { get; set; } - - public bool ShowLogo { get; set; } - - public bool StopParsing { get; set; } - - private IServiceProvider ServiceProvider { get; } - - private BurnSubcommandBase Subcommand { get; set; } - - public Task ExecuteAsync(CancellationToken cancellationToken) - { - if (this.ShowHelp || this.Subcommand is null) - { - DisplayHelp(); - return Task.FromResult(1); - } - - return this.Subcommand.ExecuteAsync(cancellationToken); - } - - public bool TryParseArgument(ICommandLineParser parser, string argument) - { - if (this.Subcommand is null) - { - switch (argument.ToLowerInvariant()) - { - case "detach": - this.Subcommand = new DetachSubcommand(this.ServiceProvider); - return true; - - case "reattach": - this.Subcommand = new ReattachSubcommand(this.ServiceProvider); - return true; - } - - return false; - } - - return this.Subcommand.TryParseArgument(parser, argument); - } - - private static void DisplayHelp() - { - Console.WriteLine(); - Console.WriteLine("Usage: wix burn detach|reattach bundle.exe -out engine.exe"); - Console.WriteLine(); - Console.WriteLine("Options:"); - Console.WriteLine(" -h|--help Show command line help."); - Console.WriteLine(" --nologo Suppress displaying the logo information."); - Console.WriteLine(); - Console.WriteLine("Commands:"); - Console.WriteLine(); - Console.WriteLine(" detach Detaches the burn engine from a bundle so it can be signed."); - Console.WriteLine(" reattach Reattaches a signed burn engine to a bundle."); - } - } -} diff --git a/src/wix/WixToolset.Core.Burn/BurnExtensionCommandLine.cs b/src/wix/WixToolset.Core.Burn/BurnExtensionCommandLine.cs index 66e77888..b306199d 100644 --- a/src/wix/WixToolset.Core.Burn/BurnExtensionCommandLine.cs +++ b/src/wix/WixToolset.Core.Burn/BurnExtensionCommandLine.cs @@ -4,12 +4,13 @@ namespace WixToolset.Core.Burn { using System; using System.Collections.Generic; + using WixToolset.Core.Burn.CommandLine; using WixToolset.Extensibility; using WixToolset.Extensibility.Data; using WixToolset.Extensibility.Services; /// - /// Parses the "msi" command-line command. See WindowsInstallerCommand + /// Parses the "burn" command-line command. See BurnCommand /// for the bulk of the command-line processing. /// internal class BurnExtensionCommandLine : BaseExtensionCommandLine diff --git a/src/wix/WixToolset.Core.Burn/BurnSubcommandBase.cs b/src/wix/WixToolset.Core.Burn/BurnSubcommandBase.cs deleted file mode 100644 index 62d69d4a..00000000 --- a/src/wix/WixToolset.Core.Burn/BurnSubcommandBase.cs +++ /dev/null @@ -1,15 +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.Core.Burn -{ - using System.Threading; - using System.Threading.Tasks; - using WixToolset.Extensibility.Services; - - internal abstract class BurnSubcommandBase - { - public abstract bool TryParseArgument(ICommandLineParser parser, string argument); - - public abstract Task ExecuteAsync(CancellationToken cancellationToken); - } -} diff --git a/src/wix/WixToolset.Core.Burn/CommandLine/BurnCommand.cs b/src/wix/WixToolset.Core.Burn/CommandLine/BurnCommand.cs new file mode 100644 index 00000000..a50fb7cd --- /dev/null +++ b/src/wix/WixToolset.Core.Burn/CommandLine/BurnCommand.cs @@ -0,0 +1,78 @@ +// 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.Core.Burn.CommandLine +{ + using System; + using System.Threading; + using System.Threading.Tasks; + using WixToolset.Extensibility.Data; + using WixToolset.Extensibility.Services; + + /// + /// Burn specialized command. + /// + internal class BurnCommand : ICommandLineCommand + { + public BurnCommand(IServiceProvider serviceProvider) + { + this.ServiceProvider = serviceProvider; + } + + public bool ShowHelp { get; set; } + + public bool ShowLogo { get; set; } + + public bool StopParsing { get; set; } + + private IServiceProvider ServiceProvider { get; } + + private BurnSubcommandBase Subcommand { get; set; } + + public Task ExecuteAsync(CancellationToken cancellationToken) + { + if (this.ShowHelp || this.Subcommand is null) + { + DisplayHelp(); + return Task.FromResult(1); + } + + return this.Subcommand.ExecuteAsync(cancellationToken); + } + + public bool TryParseArgument(ICommandLineParser parser, string argument) + { + if (this.Subcommand is null) + { + switch (argument.ToLowerInvariant()) + { + case "detach": + this.Subcommand = new DetachSubcommand(this.ServiceProvider); + return true; + + case "reattach": + this.Subcommand = new ReattachSubcommand(this.ServiceProvider); + return true; + } + + return false; + } + + return this.Subcommand.TryParseArgument(parser, argument); + } + + private static void DisplayHelp() + { + Console.WriteLine(); + Console.WriteLine("Usage: wix burn detach|reattach bundle.exe -out engine.exe"); + Console.WriteLine(); + Console.WriteLine("Options:"); + Console.WriteLine(" -h|--help Show command line help."); + Console.WriteLine(" --nologo Suppress displaying the logo information."); + Console.WriteLine(); + Console.WriteLine("Commands:"); + Console.WriteLine(); + Console.WriteLine(" detach Detaches the burn engine from a bundle so it can be signed."); + Console.WriteLine(" reattach Reattaches a signed burn engine to a bundle."); + } + } +} diff --git a/src/wix/WixToolset.Core.Burn/CommandLine/BurnSubcommandBase.cs b/src/wix/WixToolset.Core.Burn/CommandLine/BurnSubcommandBase.cs new file mode 100644 index 00000000..cf2da708 --- /dev/null +++ b/src/wix/WixToolset.Core.Burn/CommandLine/BurnSubcommandBase.cs @@ -0,0 +1,15 @@ +// 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.Core.Burn.CommandLine +{ + using System.Threading; + using System.Threading.Tasks; + using WixToolset.Extensibility.Services; + + internal abstract class BurnSubcommandBase + { + public abstract bool TryParseArgument(ICommandLineParser parser, string argument); + + public abstract Task ExecuteAsync(CancellationToken cancellationToken); + } +} diff --git a/src/wix/WixToolset.Core.Burn/CommandLine/DetachSubcommand.cs b/src/wix/WixToolset.Core.Burn/CommandLine/DetachSubcommand.cs new file mode 100644 index 00000000..3f958c81 --- /dev/null +++ b/src/wix/WixToolset.Core.Burn/CommandLine/DetachSubcommand.cs @@ -0,0 +1,80 @@ +// 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.Core.Burn.CommandLine +{ + using System; + using System.IO; + using System.Threading; + using System.Threading.Tasks; + using WixToolset.Core.Burn.Inscribe; + using WixToolset.Extensibility.Services; + + internal class DetachSubcommand : BurnSubcommandBase + { + public DetachSubcommand(IServiceProvider serviceProvider) + { + this.ServiceProvider = serviceProvider; + this.Messaging = serviceProvider.GetService(); + } + + private IServiceProvider ServiceProvider { get; } + + private IMessaging Messaging { get; } + + private string InputPath { get; set; } + + private string IntermediateFolder { get; set; } + + private string EngineOutputPath { get; set; } + + public override Task ExecuteAsync(CancellationToken cancellationToken) + { + if (String.IsNullOrEmpty(this.InputPath)) + { + Console.Error.WriteLine("Path to input bundle is required"); + return Task.FromResult(-1); + } + + if (String.IsNullOrEmpty(this.EngineOutputPath)) + { + Console.Error.WriteLine("Path to output the bundle engine is required"); + return Task.FromResult(-1); + } + + if (String.IsNullOrEmpty(this.IntermediateFolder)) + { + this.IntermediateFolder = Path.GetTempPath(); + } + + var command = new InscribeBundleEngineCommand(this.ServiceProvider, this.InputPath, this.EngineOutputPath, this.IntermediateFolder); + command.Execute(); + + return Task.FromResult(this.Messaging.LastErrorNumber); + } + + public override bool TryParseArgument(ICommandLineParser parser, string argument) + { + if (parser.IsSwitch(argument)) + { + var parameter = argument.Substring(1); + switch (parameter.ToLowerInvariant()) + { + case "intermediatefolder": + this.IntermediateFolder = parser.GetNextArgumentAsDirectoryOrError(argument); + return true; + + case "engine": + this.EngineOutputPath = parser.GetNextArgumentAsFilePathOrError(argument); + return true; + } + } + else if (String.IsNullOrEmpty(this.InputPath)) + { + this.InputPath = argument; + return true; + } + + return false; + } + } +} diff --git a/src/wix/WixToolset.Core.Burn/CommandLine/ReattachSubcommand.cs b/src/wix/WixToolset.Core.Burn/CommandLine/ReattachSubcommand.cs new file mode 100644 index 00000000..ba034973 --- /dev/null +++ b/src/wix/WixToolset.Core.Burn/CommandLine/ReattachSubcommand.cs @@ -0,0 +1,101 @@ +// 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.Core.Burn.CommandLine +{ + using System; + using System.IO; + using System.Threading; + using System.Threading.Tasks; + using WixToolset.Core.Burn.Inscribe; + using WixToolset.Extensibility.Services; + + internal class ReattachSubcommand : BurnSubcommandBase + { + public ReattachSubcommand(IServiceProvider serviceProvider) + { + this.ServiceProvider = serviceProvider; + this.Messaging = serviceProvider.GetService(); + } + + private IServiceProvider ServiceProvider { get; } + + private IMessaging Messaging { get; } + + private string InputPath { get; set; } + + private string SignedEnginePath { get; set; } + + private string IntermediateFolder { get; set; } + + private string OutputPath { get; set; } + + public override Task ExecuteAsync(CancellationToken cancellationToken) + { + if (String.IsNullOrEmpty(this.InputPath)) + { + Console.Error.WriteLine("Path to input bundle is required"); + return Task.FromResult(-1); + } + + if (String.IsNullOrEmpty(this.SignedEnginePath)) + { + Console.Error.WriteLine("Path to detached signed bundle engine is required"); + return Task.FromResult(-1); + } + + if (String.IsNullOrEmpty(this.IntermediateFolder)) + { + this.IntermediateFolder = Path.GetTempPath(); + } + + if (String.IsNullOrEmpty(this.OutputPath)) + { + this.OutputPath = this.InputPath; + } + + var command = new InscribeBundleCommand(this.ServiceProvider, this.InputPath, this.SignedEnginePath, this.OutputPath, this.IntermediateFolder); + var didWork = command.Execute(); + + // If the detach subcommand did not encounter an error but did no work + // then return the special exit code that indicates no work was done (-1000). + var exitCode = this.Messaging.LastErrorNumber; + + if (!didWork && exitCode == 0) + { + exitCode = -1000; + } + + return Task.FromResult(exitCode); + } + + public override bool TryParseArgument(ICommandLineParser parser, string argument) + { + if (parser.IsSwitch(argument)) + { + var parameter = argument.Substring(1); + switch (parameter.ToLowerInvariant()) + { + case "engine": + this.SignedEnginePath = parser.GetNextArgumentAsFilePathOrError(argument); + return true; + + case "intermediatefolder": + this.IntermediateFolder = parser.GetNextArgumentAsDirectoryOrError(argument); + return true; + + case "o": + case "out": + this.OutputPath = parser.GetNextArgumentAsFilePathOrError(argument); + return true; + } + } + else if (String.IsNullOrEmpty(this.InputPath)) + { + this.InputPath = argument; + return true; + } + + return false; + } + } +} diff --git a/src/wix/WixToolset.Core.Burn/DetachSubcommand.cs b/src/wix/WixToolset.Core.Burn/DetachSubcommand.cs deleted file mode 100644 index a1614a85..00000000 --- a/src/wix/WixToolset.Core.Burn/DetachSubcommand.cs +++ /dev/null @@ -1,80 +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.Core.Burn -{ - using System; - using System.IO; - using System.Threading; - using System.Threading.Tasks; - using WixToolset.Core.Burn.Inscribe; - using WixToolset.Extensibility.Services; - - internal class DetachSubcommand : BurnSubcommandBase - { - public DetachSubcommand(IServiceProvider serviceProvider) - { - this.ServiceProvider = serviceProvider; - this.Messaging = serviceProvider.GetService(); - } - - private IServiceProvider ServiceProvider { get; } - - private IMessaging Messaging { get; } - - private string InputPath { get; set; } - - private string IntermediateFolder { get; set; } - - private string EngineOutputPath { get; set; } - - public override Task ExecuteAsync(CancellationToken cancellationToken) - { - if (String.IsNullOrEmpty(this.InputPath)) - { - Console.Error.WriteLine("Path to input bundle is required"); - return Task.FromResult(-1); - } - - if (String.IsNullOrEmpty(this.EngineOutputPath)) - { - Console.Error.WriteLine("Path to output the bundle engine is required"); - return Task.FromResult(-1); - } - - if (String.IsNullOrEmpty(this.IntermediateFolder)) - { - this.IntermediateFolder = Path.GetTempPath(); - } - - var command = new InscribeBundleEngineCommand(this.ServiceProvider, this.InputPath, this.EngineOutputPath, this.IntermediateFolder); - command.Execute(); - - return Task.FromResult(this.Messaging.LastErrorNumber); - } - - public override bool TryParseArgument(ICommandLineParser parser, string argument) - { - if (parser.IsSwitch(argument)) - { - var parameter = argument.Substring(1); - switch (parameter.ToLowerInvariant()) - { - case "intermediatefolder": - this.IntermediateFolder = parser.GetNextArgumentAsDirectoryOrError(argument); - return true; - - case "engine": - this.EngineOutputPath = parser.GetNextArgumentAsFilePathOrError(argument); - return true; - } - } - else if (String.IsNullOrEmpty(this.InputPath)) - { - this.InputPath = argument; - return true; - } - - return false; - } - } -} diff --git a/src/wix/WixToolset.Core.Burn/ReattachSubcommand.cs b/src/wix/WixToolset.Core.Burn/ReattachSubcommand.cs deleted file mode 100644 index ce2af2d3..00000000 --- a/src/wix/WixToolset.Core.Burn/ReattachSubcommand.cs +++ /dev/null @@ -1,101 +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.Core.Burn -{ - using System; - using System.IO; - using System.Threading; - using System.Threading.Tasks; - using WixToolset.Core.Burn.Inscribe; - using WixToolset.Extensibility.Services; - - internal class ReattachSubcommand : BurnSubcommandBase - { - public ReattachSubcommand(IServiceProvider serviceProvider) - { - this.ServiceProvider = serviceProvider; - this.Messaging = serviceProvider.GetService(); - } - - private IServiceProvider ServiceProvider { get; } - - private IMessaging Messaging { get; } - - private string InputPath { get; set; } - - private string SignedEnginePath { get; set; } - - private string IntermediateFolder { get; set; } - - private string OutputPath { get; set; } - - public override Task ExecuteAsync(CancellationToken cancellationToken) - { - if (String.IsNullOrEmpty(this.InputPath)) - { - Console.Error.WriteLine("Path to input bundle is required"); - return Task.FromResult(-1); - } - - if (String.IsNullOrEmpty(this.SignedEnginePath)) - { - Console.Error.WriteLine("Path to detached signed bundle engine is required"); - return Task.FromResult(-1); - } - - if (String.IsNullOrEmpty(this.IntermediateFolder)) - { - this.IntermediateFolder = Path.GetTempPath(); - } - - if (String.IsNullOrEmpty(this.OutputPath)) - { - this.OutputPath = this.InputPath; - } - - var command = new InscribeBundleCommand(this.ServiceProvider, this.InputPath, this.SignedEnginePath, this.OutputPath, this.IntermediateFolder); - var didWork = command.Execute(); - - // If the detach subcommand did not encounter an error but did no work - // then return the special exit code that indicates no work was done (-1000). - var exitCode = this.Messaging.LastErrorNumber; - - if (!didWork && exitCode == 0) - { - exitCode = -1000; - } - - return Task.FromResult(exitCode); - } - - public override bool TryParseArgument(ICommandLineParser parser, string argument) - { - if (parser.IsSwitch(argument)) - { - var parameter = argument.Substring(1); - switch (parameter.ToLowerInvariant()) - { - case "engine": - this.SignedEnginePath = parser.GetNextArgumentAsFilePathOrError(argument); - return true; - - case "intermediatefolder": - this.IntermediateFolder = parser.GetNextArgumentAsDirectoryOrError(argument); - return true; - - case "o": - case "out": - this.OutputPath = parser.GetNextArgumentAsFilePathOrError(argument); - return true; - } - } - else if (String.IsNullOrEmpty(this.InputPath)) - { - this.InputPath = argument; - return true; - } - - return false; - } - } -} diff --git a/src/wix/WixToolset.Core.WindowsInstaller/CommandLine/InscribeSubcommand.cs b/src/wix/WixToolset.Core.WindowsInstaller/CommandLine/InscribeSubcommand.cs new file mode 100644 index 00000000..ebc4673d --- /dev/null +++ b/src/wix/WixToolset.Core.WindowsInstaller/CommandLine/InscribeSubcommand.cs @@ -0,0 +1,80 @@ +// 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.Core.WindowsInstaller.CommandLine +{ + using System; + using System.IO; + using System.Threading; + using System.Threading.Tasks; + using WixToolset.Core.WindowsInstaller.Inscribe; + using WixToolset.Extensibility.Services; + + internal class InscribeSubcommand : WindowsInstallerSubcommandBase + { + public InscribeSubcommand(IServiceProvider serviceProvider) + { + this.ServiceProvider = serviceProvider; + this.Messaging = serviceProvider.GetService(); + } + + private IServiceProvider ServiceProvider { get; } + + private IMessaging Messaging { get; } + + private string InputPath { get; set; } + + private string IntermediateFolder { get; set; } + + private string OutputPath { get; set; } + + public override Task ExecuteAsync(CancellationToken cancellationToken) + { + if (String.IsNullOrEmpty(this.InputPath)) + { + Console.Error.WriteLine("Input MSI database is required"); + return Task.FromResult(-1); + } + + if (String.IsNullOrEmpty(this.IntermediateFolder)) + { + this.IntermediateFolder = Path.GetTempPath(); + } + + if (String.IsNullOrEmpty(this.OutputPath)) + { + this.OutputPath = this.InputPath; + } + + var command = new InscribeMsiPackageCommand(this.ServiceProvider, this.InputPath, this.IntermediateFolder, this.OutputPath); + command.Execute(); + + return Task.FromResult(this.Messaging.LastErrorNumber); + } + + public override bool TryParseArgument(ICommandLineParser parser, string argument) + { + if (parser.IsSwitch(argument)) + { + var parameter = argument.Substring(1); + switch (parameter.ToLowerInvariant()) + { + case "intermediatefolder": + this.IntermediateFolder = parser.GetNextArgumentAsDirectoryOrError(argument); + return true; + + case "o": + case "out": + this.OutputPath = parser.GetNextArgumentAsFilePathOrError(argument); + return true; + } + } + else if (String.IsNullOrEmpty(this.InputPath)) + { + this.InputPath = argument; + return true; + } + + return false; + } + } +} diff --git a/src/wix/WixToolset.Core.WindowsInstaller/CommandLine/WindowsInstallerCommand.cs b/src/wix/WixToolset.Core.WindowsInstaller/CommandLine/WindowsInstallerCommand.cs new file mode 100644 index 00000000..db178ddf --- /dev/null +++ b/src/wix/WixToolset.Core.WindowsInstaller/CommandLine/WindowsInstallerCommand.cs @@ -0,0 +1,73 @@ +// 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.Core.WindowsInstaller.CommandLine +{ + using System; + using System.Threading; + using System.Threading.Tasks; + using WixToolset.Extensibility.Data; + using WixToolset.Extensibility.Services; + + /// + /// Windows Installer specialized command. + /// + internal class WindowsInstallerCommand : ICommandLineCommand + { + public WindowsInstallerCommand(IServiceProvider serviceProvider) + { + this.ServiceProvider = serviceProvider; + } + + public bool ShowHelp { get; set; } + + public bool ShowLogo { get; set; } + + public bool StopParsing { get; set; } + + private IServiceProvider ServiceProvider { get; } + + private WindowsInstallerSubcommandBase Subcommand { get; set; } + + public Task ExecuteAsync(CancellationToken cancellationToken) + { + if (this.ShowHelp || this.Subcommand is null) + { + DisplayHelp(); + return Task.FromResult(1); + } + + return this.Subcommand.ExecuteAsync(cancellationToken); + } + + public bool TryParseArgument(ICommandLineParser parser, string argument) + { + if (this.Subcommand is null) + { + switch (argument.ToLowerInvariant()) + { + case "inscribe": + this.Subcommand = new InscribeSubcommand(this.ServiceProvider); + return true; + } + + return false; + } + + return this.Subcommand.TryParseArgument(parser, argument); + } + + private static void DisplayHelp() + { + Console.WriteLine(); + Console.WriteLine("Usage: wix msi inscribe input.msi [-intermedidateFolder folder] [-out output.msi]"); + Console.WriteLine(); + Console.WriteLine("Options:"); + Console.WriteLine(" -h|--help Show command line help."); + Console.WriteLine(" --nologo Suppress displaying the logo information."); + Console.WriteLine(); + Console.WriteLine("Commands:"); + Console.WriteLine(); + Console.WriteLine(" inscribe Updates MSI database with cabinet signature information."); + } + } +} diff --git a/src/wix/WixToolset.Core.WindowsInstaller/CommandLine/WindowsInstallerSubcommandBase.cs b/src/wix/WixToolset.Core.WindowsInstaller/CommandLine/WindowsInstallerSubcommandBase.cs new file mode 100644 index 00000000..e3f26296 --- /dev/null +++ b/src/wix/WixToolset.Core.WindowsInstaller/CommandLine/WindowsInstallerSubcommandBase.cs @@ -0,0 +1,15 @@ +// 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.Core.WindowsInstaller.CommandLine +{ + using System.Threading; + using System.Threading.Tasks; + using WixToolset.Extensibility.Services; + + internal abstract class WindowsInstallerSubcommandBase + { + public abstract bool TryParseArgument(ICommandLineParser parser, string argument); + + public abstract Task ExecuteAsync(CancellationToken cancellationToken); + } +} diff --git a/src/wix/WixToolset.Core.WindowsInstaller/InscribeSubcommand.cs b/src/wix/WixToolset.Core.WindowsInstaller/InscribeSubcommand.cs deleted file mode 100644 index d44fb0bd..00000000 --- a/src/wix/WixToolset.Core.WindowsInstaller/InscribeSubcommand.cs +++ /dev/null @@ -1,80 +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.Core.WindowsInstaller -{ - using System; - using System.IO; - using System.Threading; - using System.Threading.Tasks; - using WixToolset.Core.WindowsInstaller.Inscribe; - using WixToolset.Extensibility.Services; - - internal class InscribeSubcommand : WindowsInstallerSubcommandBase - { - public InscribeSubcommand(IServiceProvider serviceProvider) - { - this.ServiceProvider = serviceProvider; - this.Messaging = serviceProvider.GetService(); - } - - private IServiceProvider ServiceProvider { get; } - - private IMessaging Messaging { get; } - - private string InputPath { get; set; } - - private string IntermediateFolder { get; set; } - - private string OutputPath { get; set; } - - public override Task ExecuteAsync(CancellationToken cancellationToken) - { - if (String.IsNullOrEmpty(this.InputPath)) - { - Console.Error.WriteLine("Input MSI database is required"); - return Task.FromResult(-1); - } - - if (String.IsNullOrEmpty(this.IntermediateFolder)) - { - this.IntermediateFolder = Path.GetTempPath(); - } - - if (String.IsNullOrEmpty(this.OutputPath)) - { - this.OutputPath = this.InputPath; - } - - var command = new InscribeMsiPackageCommand(this.ServiceProvider, this.InputPath, this.IntermediateFolder, this.OutputPath); - command.Execute(); - - return Task.FromResult(this.Messaging.LastErrorNumber); - } - - public override bool TryParseArgument(ICommandLineParser parser, string argument) - { - if (parser.IsSwitch(argument)) - { - var parameter = argument.Substring(1); - switch (parameter.ToLowerInvariant()) - { - case "intermediatefolder": - this.IntermediateFolder = parser.GetNextArgumentAsDirectoryOrError(argument); - return true; - - case "o": - case "out": - this.OutputPath = parser.GetNextArgumentAsFilePathOrError(argument); - return true; - } - } - else if (String.IsNullOrEmpty(this.InputPath)) - { - this.InputPath = argument; - return true; - } - - return false; - } - } -} diff --git a/src/wix/WixToolset.Core.WindowsInstaller/WindowsInstallerCommand.cs b/src/wix/WixToolset.Core.WindowsInstaller/WindowsInstallerCommand.cs deleted file mode 100644 index cedc65b2..00000000 --- a/src/wix/WixToolset.Core.WindowsInstaller/WindowsInstallerCommand.cs +++ /dev/null @@ -1,73 +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.Core.WindowsInstaller -{ - using System; - using System.Threading; - using System.Threading.Tasks; - using WixToolset.Extensibility.Data; - using WixToolset.Extensibility.Services; - - /// - /// Windows Installer specialized command. - /// - internal class WindowsInstallerCommand : ICommandLineCommand - { - public WindowsInstallerCommand(IServiceProvider serviceProvider) - { - this.ServiceProvider = serviceProvider; - } - - public bool ShowHelp { get; set; } - - public bool ShowLogo { get; set; } - - public bool StopParsing { get; set; } - - private IServiceProvider ServiceProvider { get; } - - private WindowsInstallerSubcommandBase Subcommand { get; set; } - - public Task ExecuteAsync(CancellationToken cancellationToken) - { - if (this.ShowHelp || this.Subcommand is null) - { - DisplayHelp(); - return Task.FromResult(1); - } - - return this.Subcommand.ExecuteAsync(cancellationToken); - } - - public bool TryParseArgument(ICommandLineParser parser, string argument) - { - if (this.Subcommand is null) - { - switch (argument.ToLowerInvariant()) - { - case "inscribe": - this.Subcommand = new InscribeSubcommand(this.ServiceProvider); - return true; - } - - return false; - } - - return this.Subcommand.TryParseArgument(parser, argument); - } - - private static void DisplayHelp() - { - Console.WriteLine(); - Console.WriteLine("Usage: wix msi inscribe input.msi [-intermedidateFolder folder] [-out output.msi]"); - Console.WriteLine(); - Console.WriteLine("Options:"); - Console.WriteLine(" -h|--help Show command line help."); - Console.WriteLine(" --nologo Suppress displaying the logo information."); - Console.WriteLine(); - Console.WriteLine("Commands:"); - Console.WriteLine(); - Console.WriteLine(" inscribe Updates MSI database with cabinet signature information."); - } - } -} diff --git a/src/wix/WixToolset.Core.WindowsInstaller/WindowsInstallerExtensionCommandLine.cs b/src/wix/WixToolset.Core.WindowsInstaller/WindowsInstallerExtensionCommandLine.cs index 4c516d0d..ae8f0a94 100644 --- a/src/wix/WixToolset.Core.WindowsInstaller/WindowsInstallerExtensionCommandLine.cs +++ b/src/wix/WixToolset.Core.WindowsInstaller/WindowsInstallerExtensionCommandLine.cs @@ -4,6 +4,7 @@ namespace WixToolset.Core.WindowsInstaller { using System; using System.Collections.Generic; + using WixToolset.Core.WindowsInstaller.CommandLine; using WixToolset.Extensibility; using WixToolset.Extensibility.Data; using WixToolset.Extensibility.Services; diff --git a/src/wix/WixToolset.Core.WindowsInstaller/WindowsInstallerSubcommandBase.cs b/src/wix/WixToolset.Core.WindowsInstaller/WindowsInstallerSubcommandBase.cs deleted file mode 100644 index c5156a1d..00000000 --- a/src/wix/WixToolset.Core.WindowsInstaller/WindowsInstallerSubcommandBase.cs +++ /dev/null @@ -1,15 +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.Core.WindowsInstaller -{ - using System.Threading; - using System.Threading.Tasks; - using WixToolset.Extensibility.Services; - - internal abstract class WindowsInstallerSubcommandBase - { - public abstract bool TryParseArgument(ICommandLineParser parser, string argument); - - public abstract Task ExecuteAsync(CancellationToken cancellationToken); - } -} -- cgit v1.2.3-55-g6feb