summaryrefslogtreecommitdiff
path: root/writer
diff options
context:
space:
mode:
authora1xd <[email protected]>2021-09-22 20:49:04 -0400
committerGitHub <[email protected]>2021-09-22 20:49:04 -0400
commit8a4b6f57758338d5537d4671184099a4728a8cdd (patch)
treedf36529a344d5d21ff11f5ba021ec80afb4b68a4 /writer
parentMerge pull request #87 from matthewstrasiotto/streamer_mode (diff)
parentimprove converter + docs (diff)
downloadrawaccel-8a4b6f57758338d5537d4671184099a4728a8cdd.tar.xz
rawaccel-8a4b6f57758338d5537d4671184099a4728a8cdd.zip
Merge pull request #105 from a1xd/1.5.x
v1.5
Diffstat (limited to 'writer')
-rw-r--r--writer/Program.cs106
-rw-r--r--writer/Properties/AssemblyInfo.cs4
2 files changed, 76 insertions, 34 deletions
diff --git a/writer/Program.cs b/writer/Program.cs
index 37e384c..724fa23 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,68 +12,109 @@ 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 Send(JToken settingsToken)
+ static void ExitWithUsage()
{
- var settings = settingsToken.ToObject<DriverSettings>();
+ ExitWithMessage($"Usage: {System.AppDomain.CurrentDomain.FriendlyName} <settings file path>");
+ }
- var errors = DriverInterop.GetSettingsErrors(settings);
- if (errors.Empty())
- {
- DriverInterop.Write(settings);
- return;
- }
+ delegate string PopOption(params string[] aliases);
- Show($"Bad settings:\n\n{errors}");
+ static string Read(string path)
+ {
+ return path == null ? null : File.ReadAllText(path);
}
- static void Main(string[] args)
+ static ExtendedSettings Parse(List<string> args)
{
- try
+ PopOption maybePop = aliases =>
{
- VersionHelper.ValidateAndGetDriverVersion(typeof(Program).Assembly.GetName().Version);
- }
- catch (VersionException e)
+ 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)
{
- Show(e.Message);
- return;
+ if (args.Count > 1) ExitWithUsage();
+ else if (args.Count == 1) settingsPath = args[0];
+
+ return new ExtendedSettings(Read(settingsPath), Read(tablePath));
}
- if (args.Length != 1)
+ 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
{
- Show($"Usage: {System.AppDomain.CurrentDomain.FriendlyName} <settings file path>");
- return;
+ yTableJson = Read(yTablePath);
}
- if (!File.Exists(args[0]))
+ return new ExtendedSettings(Read(settingsPath), xTableJson, yTableJson);
+ }
+
+ static void Main(string[] args)
+ {
+ try
{
- Show($"Settings file not found at {args[0]}");
- return;
+ VersionHelper.ValidOrThrow();
+ }
+ catch (InteropException e)
+ {
+ ExitWithMessage(e.Message);
}
try
{
- var JO = JObject.Parse(File.ReadAllText(args[0]));
+ var settings = Parse(new List<string>(args));
+ var errors = new SettingsErrors(settings);
- if (JO.ContainsKey(DriverSettings.Key))
+ if (errors.Empty())
{
- Send(JO[DriverSettings.Key]);
- return;
+ new ManagedAccel(settings).Activate();
}
-
- Send(JO);
+ else
+ {
+ 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}");
}
}
}
diff --git a/writer/Properties/AssemblyInfo.cs b/writer/Properties/AssemblyInfo.cs
index fc6a1ca..7f47c6d 100644
--- a/writer/Properties/AssemblyInfo.cs
+++ b/writer/Properties/AssemblyInfo.cs
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// 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(RawAccelVersion.value)]
-[assembly: AssemblyFileVersion(RawAccelVersion.value)]
+[assembly: AssemblyVersion(VersionHelper.VersionString)]
+[assembly: AssemblyFileVersion(VersionHelper.VersionString)] \ No newline at end of file