// 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.Tools.WixCop { using System; using System.Diagnostics; using WixToolset.Core; using WixToolset.Extensibility; using WixToolset.Extensibility.Data; using WixToolset.Extensibility.Services; using WixToolset.Tools.Core; using WixToolset.Tools.WixCop.CommandLine; using WixToolset.Tools.WixCop.Interfaces; /// /// Wix source code style inspector and converter. /// public sealed class Program { /// /// The main entry point for the application. /// /// The commandline arguments. /// The number of errors that were found. [STAThread] public static int Main(string[] args) { var serviceProvider = WixToolsetServiceProviderFactory.CreateServiceProvider(); var listener = new ConsoleMessageListener("WXCP", "wixcop.exe"); serviceProvider.AddService((x, y) => listener); serviceProvider.AddService((x, y) => new WixCopCommandLineParser(x)); var program = new Program(); return program.Run(serviceProvider, args); } /// /// Run the application with the given arguments. /// /// Service provider to use throughout this execution. /// The commandline arguments. /// The number of errors that were found. public int Run(IWixToolsetServiceProvider serviceProvider, string[] args) { try { var listener = serviceProvider.GetService(); var messaging = serviceProvider.GetService(); messaging.SetListener(listener); var arguments = serviceProvider.GetService(); arguments.Populate(args); var commandLine = serviceProvider.GetService(); commandLine.Arguments = arguments; var command = commandLine.ParseWixCopCommandLine(); if (command.ShowLogo) { var wixcopAssembly = this.GetType().Assembly; var fv = FileVersionInfo.GetVersionInfo(wixcopAssembly.Location); Console.WriteLine("WiX Cop version {0}", fv.FileVersion); Console.WriteLine("Copyright (C) .NET Foundation and contributors. All rights reserved."); Console.WriteLine(); } return command?.Execute() ?? 1; } catch (Exception e) { Console.Error.WriteLine("wixcop.exe : fatal error WXCP0001 : {0}\r\n\n\nStack Trace:\r\n{1}", e.Message, e.StackTrace); return 1; } } } }