diff options
| author | a1xd <[email protected]> | 2020-10-06 02:54:27 -0400 |
|---|---|---|
| committer | a1xd <[email protected]> | 2020-10-07 05:31:24 -0400 |
| commit | 187de539ea370210146c7f1bcf398c2a100f758f (patch) | |
| tree | 2df7d336d62e221995fc76684fef8b6973a41889 | |
| parent | add static default settings in wrapper (diff) | |
| download | rawaccel-187de539ea370210146c7f1bcf398c2a100f758f.tar.xz rawaccel-187de539ea370210146c7f1bcf398c2a100f758f.zip | |
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
| -rw-r--r-- | grapher/Models/Serialized/RawAccelSettings.cs | 29 | ||||
| -rw-r--r-- | grapher/Models/Serialized/SettingsManager.cs | 32 |
2 files changed, 39 insertions, 22 deletions
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<GUISettings> DefaultGUISettingsSupplier) { - return Load(DefaultSettingsFile); + return Load(DefaultSettingsFile, DefaultGUISettingsSupplier); } - public static RawAccelSettings Load(string file) + public static RawAccelSettings Load(string file, Func<GUISettings> DefaultGUISettingsSupplier) { try { - var settings = JsonConvert.DeserializeObject<RawAccelSettings>(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<RawAccelSettings>(JsonSerializer.Create(SerializerSettings)); + } + else + { + settings = new RawAccelSettings + { + AccelerationSettings = jo.ToObject<DriverSettings>(), + GUISettings = DefaultGUISettingsSupplier() + }; + } + + if (settings is null || settings.AccelerationSettings is null) + { + throw new JsonException($"{file} contains invalid JSON"); + } + return settings; } catch (FileNotFoundException e) diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index 416823e..f53c9c9 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -83,15 +83,7 @@ namespace grapher.Models.Serialized if (errors.Empty()) { RawAccelSettings.AccelerationSettings = settings; - RawAccelSettings.GUISettings = new GUISettings - { - AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked, - DPI = (int)DpiField.Data, - PollRate = (int)PollRateField.Data, - ShowLastMouseMove = ShowLastMouseMoveMenuItem.Checked, - ShowVelocityAndGain = ShowVelocityAndGainMoveMenuItem.Checked, - }; - + RawAccelSettings.GUISettings = MakeGUISettingsFromFields(); RawAccelSettings.Save(); } @@ -128,13 +120,25 @@ namespace grapher.Models.Serialized return errors; } + public GUISettings MakeGUISettingsFromFields() + { + return new GUISettings + { + AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked, + DPI = (int)DpiField.Data, + PollRate = (int)PollRateField.Data, + ShowLastMouseMove = ShowLastMouseMoveMenuItem.Checked, + ShowVelocityAndGain = ShowVelocityAndGainMoveMenuItem.Checked + }; + } + public void Startup() { if (RawAccelSettings.Exists()) { try { - RawAccelSettings = RawAccelSettings.Load(); + RawAccelSettings = RawAccelSettings.Load(() => MakeGUISettingsFromFields()); if (RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup) { UpdateActiveAccelFromFileSettings(RawAccelSettings.AccelerationSettings); @@ -149,13 +153,7 @@ namespace grapher.Models.Serialized RawAccelSettings = new RawAccelSettings( DriverInterop.GetActiveSettings(), - new GUISettings - { - AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked, - DPI = (int)DpiField.Data, - PollRate = (int)PollRateField.Data, - ShowLastMouseMove = ShowLastMouseMoveMenuItem.Checked, - }); + MakeGUISettingsFromFields()); RawAccelSettings.Save(); } |