diff --git a/App.config b/App.config index 362d76f..b49cb53 100644 --- a/App.config +++ b/App.config @@ -5,7 +5,7 @@ - - + + \ No newline at end of file diff --git a/FodyWeavers.xml b/FodyWeavers.xml new file mode 100644 index 0000000..5029e70 --- /dev/null +++ b/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/FodyWeavers.xsd b/FodyWeavers.xsd new file mode 100644 index 0000000..05e92c1 --- /dev/null +++ b/FodyWeavers.xsd @@ -0,0 +1,141 @@ + + + + + + + + + + + + A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks + + + + + A list of assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks. + + + + + A list of runtime assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks + + + + + A list of runtime assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks. + + + + + A list of unmanaged 32 bit assembly names to include, delimited with line breaks. + + + + + A list of unmanaged 64 bit assembly names to include, delimited with line breaks. + + + + + The order of preloaded assemblies, delimited with line breaks. + + + + + + This will copy embedded files to disk before loading them into memory. This is helpful for some scenarios that expected an assembly to be loaded from a physical file. + + + + + Controls if .pdbs for reference assemblies are also embedded. + + + + + Controls if runtime assemblies are also embedded. + + + + + Controls whether the runtime assemblies are embedded with their full path or only with their assembly name. + + + + + Embedded assemblies are compressed by default, and uncompressed when they are loaded. You can turn compression off with this option. + + + + + As part of Costura, embedded assemblies are no longer included as part of the build. This cleanup can be turned off. + + + + + Costura by default will load as part of the module initialization. This flag disables that behavior. Make sure you call CosturaUtility.Initialize() somewhere in your code. + + + + + Costura will by default use assemblies with a name like 'resources.dll' as a satellite resource and prepend the output path. This flag disables that behavior. + + + + + A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with | + + + + + A list of assembly names to include from the default action of "embed all Copy Local references", delimited with |. + + + + + A list of runtime assembly names to exclude from the default action of "embed all Copy Local references", delimited with | + + + + + A list of runtime assembly names to include from the default action of "embed all Copy Local references", delimited with |. + + + + + A list of unmanaged 32 bit assembly names to include, delimited with |. + + + + + A list of unmanaged 64 bit assembly names to include, delimited with |. + + + + + The order of preloaded assemblies, delimited with |. + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/Program.cs b/Program.cs index 6f8d8d4..6d1e352 100644 --- a/Program.cs +++ b/Program.cs @@ -1,5 +1,10 @@ using System; using System.Collections.Generic; +using System.CommandLine; +using System.CommandLine.Binding; +using System.CommandLine.Builder; +using System.CommandLine.Help; +using System.CommandLine.Parsing; using System.Configuration; using System.IO; using System.Linq; @@ -7,6 +12,7 @@ using System.Reflection; using System.Runtime.InteropServices; using System.Threading; +using System.Threading.Tasks; using System.Windows.Forms; namespace Stateus { @@ -26,15 +32,15 @@ static String HandleUnknown(Object val) { static String MemTypeMap(Int32 memType) { switch (memType) { - case 1: return "Other"; - case 2: return "DRAM"; - case 3: return "DRAM (Synchronous)"; - case 4: return "DRAM (Cache)"; - case 5: return "EDO"; - case 6: return "EDRAM"; - case 7: return "VRAM"; - case 8: return "SRAM"; - case 9: return "RAM"; + case 1: return "Other"; + case 2: return "DRAM"; + case 3: return "DRAM (Synchronous)"; + case 4: return "DRAM (Cache)"; + case 5: return "EDO"; + case 6: return "EDRAM"; + case 7: return "VRAM"; + case 8: return "SRAM"; + case 9: return "RAM"; case 10: return "ROM"; case 11: return "FLASH"; case 12: return "EEPROM"; @@ -88,22 +94,93 @@ static String KeyCodeMap(Keys keyCode, Boolean showCode) { return keyFace; } - static void Main(String[] args) { - //Process Config Options - Int32 PollingRate; - if (Int32.TryParse(ConfigurationManager.AppSettings["PollingRate.ms"], out PollingRate)) { - if (PollingRate <= 0) { - PollingRate = 5; - } - } else { - PollingRate = 5; + + public class AppOptions { + public Int32 PollingRate { get; set; } + public Boolean DisplayInfo { get; set; } + } + + public class AppOptionsBinder : BinderBase { + private readonly Option _pollingRateOption; + private readonly Option _displayInfoOption; + + public AppOptionsBinder(Option pollingRateOption, Option displayInfoOption) { + _pollingRateOption = pollingRateOption; + _displayInfoOption = displayInfoOption; } - Boolean SystemInfo; - if (!Boolean.TryParse(ConfigurationManager.AppSettings["SystemInfo.show"], out SystemInfo)) { - SystemInfo = false; + protected override AppOptions GetBoundValue(System.CommandLine.Binding.BindingContext bindingContext) { + return new AppOptions { + PollingRate = bindingContext.ParseResult.GetValueForOption(_pollingRateOption), + DisplayInfo = Boolean.Parse(bindingContext.ParseResult.GetValueForOption(_displayInfoOption)) + }; } - + } + + static async Task Main(String[] args) { + Option pollingRateOption = new Option( + aliases: new[] { "-r", "--Polling-Rate" }, + description: "Millisecond interval at which devices are polled", + isDefault: true, + parseArgument: result => { + Int32 pr; + if (!result.Tokens.Any()) { //No value passed to option (or option not specified) + if (!Int32.TryParse(ConfigurationManager.AppSettings["Polling-Rate"], out pr)) { + pr = 5; + } + } else { + if (!Int32.TryParse(result.Tokens.Single().Value, out pr)) { + result.ErrorMessage = "Polling-Rate must be an integer from 1-1000"; + } + } + if (pr < 1 || pr > 1000) { + result.ErrorMessage = "Polling-Rate must be an integer from 1-1000"; + } + return pr; + } + ); + pollingRateOption.ArgumentHelpName = "1-1000"; + pollingRateOption.Arity = ArgumentArity.ExactlyOne; + + Option displayInfoOption = new Option( + aliases: new[] { "-i", "--Display-Info" }, + description: "Flag to show or hide hardware information header", + isDefault: true, + parseArgument: result => { + Boolean di; + if (!result.Tokens.Any()) { + if (!Boolean.TryParse(ConfigurationManager.AppSettings["Display-Info"], out di)) { + di = true; + } + } else { + if (!Boolean.TryParse(result.Tokens.Single().Value, out di)) { + result.ErrorMessage = "Display-Info must be True or False"; + } + } + return di.ToString(); + } + ); + displayInfoOption.ArgumentHelpName = "True|False"; + displayInfoOption.Arity = ArgumentArity.ExactlyOne; + + RootCommand rootCommand = new RootCommand("Simple Windows Keyboard & Mouse \"State Monitor\" with Logging"); + rootCommand.AddOption(pollingRateOption); + rootCommand.AddOption(displayInfoOption); + rootCommand.SetHandler((appOptions) => { + Run(appOptions); + }, new AppOptionsBinder(pollingRateOption, displayInfoOption)); + + Parser parser = new CommandLineBuilder(rootCommand) + .UseDefaults() + .UseHelp(ctx => { + ctx.HelpBuilder.CustomizeSymbol(pollingRateOption, secondColumnText: $"{pollingRateOption.Description} [default: 5]"); + ctx.HelpBuilder.CustomizeSymbol(displayInfoOption, secondColumnText: $"{displayInfoOption.Description} [default: True]"); + }).Build(); + + return await parser.InvokeAsync(args); + } + + static void Run(AppOptions appOptions) { //Read Assembly Info String AppName = Assembly.GetEntryAssembly().GetName().Name; String AppVers = Assembly.GetEntryAssembly().GetName().Version.ToString(); @@ -116,7 +193,7 @@ static void Main(String[] args) { File.AppendAllText(FileName, initString + Environment.NewLine + Environment.NewLine); //System Information - if (SystemInfo) { + if (appOptions.DisplayInfo) { String info = String.Empty; using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from Win32_BaseBoard")) { foreach (ManagementObject obj in searcher.Get()) { @@ -185,12 +262,12 @@ static void Main(String[] args) { IEnumerable scanCodes = Enum.GetValues(typeof(Keys)).Cast().Except(new Keys[] { Keys.Menu, Keys.ControlKey, Keys.ShiftKey }); //Start main polling loop - String pollString = $"Started! Monitoring {scanCodes.Count()} possible scan codes... (polling rate = {PollingRate}ms)"; + String pollString = $"Started! Monitoring {scanCodes.Count()} possible scan codes... (polling rate = {appOptions.PollingRate}ms)"; Console.WriteLine(pollString + Environment.NewLine); File.AppendAllText(FileName, pollString + Environment.NewLine + Environment.NewLine); while (true) { //Sleep based on polling rate - Thread.Sleep(PollingRate); + Thread.Sleep(appOptions.PollingRate); //Read current input state foreach (Keys k in scanCodes) { diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 612042a..b27f59a 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.1.0")] -[assembly: AssemblyFileVersion("1.2.1.0")] +[assembly: AssemblyVersion("1.3.0.0")] +[assembly: AssemblyFileVersion("1.3.0.0")] diff --git a/Stateus.csproj b/Stateus.csproj index 20c6a68..21d96da 100644 --- a/Stateus.csproj +++ b/Stateus.csproj @@ -25,6 +25,7 @@ AnyCPU + false none true bin\Release\ @@ -40,6 +41,7 @@ + @@ -59,5 +61,15 @@ + + + 5.7.0 + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + 2.0.0-beta4.22272.1 + + \ No newline at end of file diff --git a/Stateus.sln b/Stateus.sln index 77b9f74..ade297b 100644 --- a/Stateus.sln +++ b/Stateus.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.31515.178 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.34928.147 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Stateus", "Stateus.csproj", "{EE427169-8088-472C-8821-508152B488DC}" EndProject