diff options
| author | a1xd <[email protected]> | 2020-09-27 23:04:29 -0400 |
|---|---|---|
| committer | a1xd <[email protected]> | 2020-09-27 23:04:29 -0400 |
| commit | 85aefb4ba131521595e48fe1a25f4db9a69e71e6 (patch) | |
| tree | f1c73a42b369f362a40ea251281d98ee02bf0a98 /grapher/Models/Serialized/SettingsManager.cs | |
| parent | add os detection to installer (diff) | |
| download | rawaccel-85aefb4ba131521595e48fe1a25f4db9a69e71e6.tar.xz rawaccel-85aefb4ba131521595e48fe1a25f4db9a69e71e6.zip | |
add arg checks in wrapper
minor changes to settings shape, requires driver reinstall
add error handling to writer
grapher changes:
add prettier serialization + comments
add elements for scale and separated limit/exp
reset irrelevant (invisible) arg input before checks/write
Diffstat (limited to 'grapher/Models/Serialized/SettingsManager.cs')
| -rw-r--r-- | grapher/Models/Serialized/SettingsManager.cs | 51 |
1 files changed, 34 insertions, 17 deletions
diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index 26160f5..93cf42b 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -47,28 +47,31 @@ namespace grapher.Models.Serialized #region Methods - public void UpdateActiveSettings(DriverSettings settings) + public SettingsErrors TryUpdateActiveSettings(DriverSettings settings) { - ActiveAccel.UpdateFromSettings(settings); - SendToDriver(settings); + var errors = TryUpdateAccel(settings); - RawAccelSettings.AccelerationSettings = settings; - RawAccelSettings.GUISettings = new GUISettings + if (errors.Empty()) { - AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked, - DPI = (int)DpiField.Data, - PollRate = (int)PollRateField.Data, - ShowLastMouseMove = ShowLastMouseMoveMenuItem.Checked, - ShowVelocityAndGain = ShowVelocityAndGainMoveMenuItem.Checked, - }; + 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.Save(); + RawAccelSettings.Save(); + } + + return errors; } public void UpdateActiveAccelFromFileSettings(DriverSettings settings) - { - ActiveAccel.UpdateFromSettings(settings); - SendToDriver(settings); + { + TryUpdateAccel(settings); DpiField.SetToEntered(RawAccelSettings.GUISettings.DPI); PollRateField.SetToEntered(RawAccelSettings.GUISettings.PollRate); @@ -77,9 +80,23 @@ namespace grapher.Models.Serialized ShowVelocityAndGainMoveMenuItem.Checked = RawAccelSettings.GUISettings.ShowVelocityAndGain; } + public SettingsErrors TryUpdateAccel(DriverSettings settings) + { + var errors = SendToDriverSafe(settings); + if (errors.Empty()) ActiveAccel.UpdateFromSettings(settings); + return errors; + } + public static void SendToDriver(DriverSettings settings) { - new Thread(() => DriverInterop.SetActiveSettings(settings)).Start(); + new Thread(() => DriverInterop.Write(settings)).Start(); + } + + public static SettingsErrors SendToDriverSafe(DriverSettings settings) + { + var errors = DriverInterop.GetSettingsErrors(settings); + if (errors.Empty()) SendToDriver(settings); + return errors; } public void Startup() @@ -95,7 +112,7 @@ namespace grapher.Models.Serialized } return; } - catch (JsonSerializationException e) + catch (JsonException e) { Console.WriteLine($"bad settings: {e}"); } |