From 187de539ea370210146c7f1bcf398c2a100f758f Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Tue, 6 Oct 2020 02:54:27 -0400 Subject: ease requirements for loading driver settings gui settings are no longer needed this covers edge case where interaccel converter is used but the gui does not run until after reboot --- grapher/Models/Serialized/RawAccelSettings.cs | 29 ++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'grapher/Models/Serialized/RawAccelSettings.cs') diff --git a/grapher/Models/Serialized/RawAccelSettings.cs b/grapher/Models/Serialized/RawAccelSettings.cs index 570a6c8..6f48d44 100644 --- a/grapher/Models/Serialized/RawAccelSettings.cs +++ b/grapher/Models/Serialized/RawAccelSettings.cs @@ -44,17 +44,36 @@ namespace grapher.Models.Serialized #region Methods - public static RawAccelSettings Load() + public static RawAccelSettings Load(Func DefaultGUISettingsSupplier) { - return Load(DefaultSettingsFile); + return Load(DefaultSettingsFile, DefaultGUISettingsSupplier); } - public static RawAccelSettings Load(string file) + public static RawAccelSettings Load(string file, Func DefaultGUISettingsSupplier) { try { - var settings = JsonConvert.DeserializeObject(File.ReadAllText(file), SerializerSettings); - if (settings is null) throw new JsonException($"{file} contains invalid JSON"); + RawAccelSettings settings = null; + + JObject jo = JObject.Parse(File.ReadAllText(file)); + if (jo.ContainsKey(DriverSettings.Key)) + { + settings = jo.ToObject(JsonSerializer.Create(SerializerSettings)); + } + else + { + settings = new RawAccelSettings + { + AccelerationSettings = jo.ToObject(), + GUISettings = DefaultGUISettingsSupplier() + }; + } + + if (settings is null || settings.AccelerationSettings is null) + { + throw new JsonException($"{file} contains invalid JSON"); + } + return settings; } catch (FileNotFoundException e) -- cgit v1.2.3