From 14bde56daf188bfc027dc8ead5b45ec0aa1109d6 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 1 Apr 2021 01:51:31 -0400 Subject: update rest grapher is still broken refactored io / error handling a bit --- writer/Program.cs | 38 ++++++++++---------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) (limited to 'writer/Program.cs') diff --git a/writer/Program.cs b/writer/Program.cs index 37e384c..d381c16 100644 --- a/writer/Program.cs +++ b/writer/Program.cs @@ -16,27 +16,13 @@ namespace writer MessageBox.Show(msg, "Raw Accel writer"); } - static void Send(JToken settingsToken) - { - var settings = settingsToken.ToObject(); - - var errors = DriverInterop.GetSettingsErrors(settings); - if (errors.Empty()) - { - DriverInterop.Write(settings); - return; - } - - Show($"Bad settings:\n\n{errors}"); - } - static void Main(string[] args) { try { - VersionHelper.ValidateAndGetDriverVersion(typeof(Program).Assembly.GetName().Version); + VersionHelper.ValidOrThrow(); } - catch (VersionException e) + catch (InteropException e) { Show(e.Message); return; @@ -48,23 +34,19 @@ namespace writer return; } - if (!File.Exists(args[0])) - { - Show($"Settings file not found at {args[0]}"); - return; - } - try { - var JO = JObject.Parse(File.ReadAllText(args[0])); + var settings = DriverSettings.FromFile(args[0]); + var errors = new SettingsErrors(settings); - if (JO.ContainsKey(DriverSettings.Key)) + if (errors.Empty()) { - Send(JO[DriverSettings.Key]); - return; + new ManagedAccel(settings).Activate(); + } + else + { + Show($"Bad settings:\n\n{errors}"); } - - Send(JO); } catch (JsonException e) { -- cgit v1.2.3 From 7c1f14845bc948e9ea25908e96099203d9433a69 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Tue, 6 Apr 2021 01:21:42 -0400 Subject: update wrapper + writer to handle lut grapher is building but applying options still broken for the most part --- writer/Program.cs | 88 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 74 insertions(+), 14 deletions(-) (limited to 'writer/Program.cs') diff --git a/writer/Program.cs b/writer/Program.cs index d381c16..6cbcf8e 100644 --- a/writer/Program.cs +++ b/writer/Program.cs @@ -1,8 +1,9 @@ using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using System; +using System.Collections.Generic; using System.IO; +using System.Linq; using System.Windows.Forms; namespace writer @@ -11,9 +12,71 @@ namespace writer class Program { - static void Show(string msg) + static void ExitWithMessage(string msg) { MessageBox.Show(msg, "Raw Accel writer"); + Environment.Exit(1); + } + + static void ExitWithUsage() + { + ExitWithMessage($"Usage: {System.AppDomain.CurrentDomain.FriendlyName} "); + } + + delegate string PopOption(params string[] aliases); + + static string Read(string path) + { + return path == null ? null : File.ReadAllText(path); + } + + static ExtendedSettings Parse(List args) + { + PopOption maybePop = aliases => + { + int idx = args.FindIndex(aliases.Contains); + + if (idx == -1) return null; + + if (idx == args.Count - 1) ExitWithUsage(); + + string val = args[idx + 1]; + args.RemoveRange(idx, 2); + return val; + }; + + string settingsPath = null; + + string tablePath = maybePop("table", "t"); + + if (tablePath != null) + { + if (args.Count > 1) ExitWithUsage(); + else if (args.Count == 1) settingsPath = args[0]; + + return new ExtendedSettings(Read(settingsPath), Read(tablePath)); + } + + string xTablePath = maybePop("xtable", "xt"); + string yTablePath = maybePop("ytable", "yt"); + + if (args.Count > 1) ExitWithUsage(); + else if (args.Count == 1) settingsPath = args[0]; + else if (xTablePath == null && yTablePath == null) ExitWithUsage(); + + string xTableJson = Read(xTablePath); + string yTableJson = null; + + if (xTablePath != null && xTablePath.Equals(yTablePath)) + { + yTableJson = xTableJson; + } + else + { + yTableJson = Read(yTablePath); + } + + return new ExtendedSettings(Read(settingsPath), xTableJson, yTableJson); } static void Main(string[] args) @@ -24,19 +87,12 @@ namespace writer } catch (InteropException e) { - Show(e.Message); - return; - } - - if (args.Length != 1) - { - Show($"Usage: {System.AppDomain.CurrentDomain.FriendlyName} "); - return; + ExitWithMessage(e.Message); } try { - var settings = DriverSettings.FromFile(args[0]); + var settings = Parse(new List(args)); var errors = new SettingsErrors(settings); if (errors.Empty()) @@ -45,16 +101,20 @@ namespace writer } else { - Show($"Bad settings:\n\n{errors}"); + ExitWithMessage($"Bad settings:\n\n{errors}"); } } + catch (System.IO.FileNotFoundException e) + { + ExitWithMessage(e.Message); + } catch (JsonException e) { - Show($"Settings invalid:\n\n{e.Message}"); + ExitWithMessage($"Settings invalid:\n\n{e.Message}"); } catch (Exception e) { - Show($"Error:\n\n{e}"); + ExitWithMessage($"Error:\n\n{e}"); } } } -- cgit v1.2.3