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 +++++++++++++++++++----- grapher/Models/Serialized/SettingsManager.cs | 32 +++++++++++++-------------- 2 files changed, 39 insertions(+), 22 deletions(-) (limited to 'grapher/Models/Serialized') 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) 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(); } -- cgit v1.2.3 From 2be0106211cb4ce30036fc0c8e84ae70dff68c87 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 8 Oct 2020 02:07:56 -0400 Subject: add toggle button + save gui settings on close remove option to disable write on startup --- grapher/Models/Serialized/GUISettings.cs | 27 +++++++++++++++------------ grapher/Models/Serialized/RawAccelSettings.cs | 12 ++++++++++++ grapher/Models/Serialized/SettingsManager.cs | 22 +++++++++------------- 3 files changed, 36 insertions(+), 25 deletions(-) (limited to 'grapher/Models/Serialized') diff --git a/grapher/Models/Serialized/GUISettings.cs b/grapher/Models/Serialized/GUISettings.cs index 84e681b..f9e5755 100644 --- a/grapher/Models/Serialized/GUISettings.cs +++ b/grapher/Models/Serialized/GUISettings.cs @@ -10,32 +10,35 @@ namespace grapher.Models.Serialized public GUISettings() {} - public GUISettings(bool autoWrite, int dpi, int pollRate) - { - AutoWriteToDriverOnStartup = autoWrite; - DPI = dpi; - PollRate = pollRate; - } - #endregion Constructors #region Properties - [JsonProperty(Order = 1)] - public bool AutoWriteToDriverOnStartup { get; set; } - [JsonProperty(Order = 2)] + [JsonProperty(Order = 1)] public int DPI { get; set; } - [JsonProperty(Order = 3)] + [JsonProperty(Order = 2)] public int PollRate { get; set; } - [JsonProperty(Order = 4)] + [JsonProperty(Order = 3)] public bool ShowLastMouseMove { get; set; } [JsonProperty(Order = 4)] public bool ShowVelocityAndGain { get; set; } #endregion Properties + + #region Methods + + public bool ValueEquals(GUISettings other) + { + return DPI == other.DPI && + PollRate == other.PollRate && + ShowLastMouseMove == other.ShowLastMouseMove && + ShowVelocityAndGain == other.ShowVelocityAndGain; + } + + #endregion Methods } } diff --git a/grapher/Models/Serialized/RawAccelSettings.cs b/grapher/Models/Serialized/RawAccelSettings.cs index 6f48d44..e0362ff 100644 --- a/grapher/Models/Serialized/RawAccelSettings.cs +++ b/grapher/Models/Serialized/RawAccelSettings.cs @@ -115,6 +115,18 @@ namespace grapher.Models.Serialized .AddFirst(new JProperty("### Mode Types ###", modes)); } + public bool IsDefaultEquivalent() + { + bool wholeOrNoY = AccelerationSettings.combineMagnitudes || + AccelerationSettings.modes.y == AccelMode.noaccel; + + return AccelerationSettings.sensitivity.x == 1 && + AccelerationSettings.sensitivity.y == 1 && + AccelerationSettings.rotation == 0 && + AccelerationSettings.modes.x == AccelMode.noaccel && + wholeOrNoY; + } + #endregion Methods } } diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index f53c9c9..8712c87 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -14,14 +14,12 @@ namespace grapher.Models.Serialized ManagedAccel activeAccel, Field dpiField, Field pollRateField, - ToolStripMenuItem autoWrite, ToolStripMenuItem showLastMouseMove, ToolStripMenuItem showVelocityAndGain) { ActiveAccel = activeAccel; DpiField = dpiField; PollRateField = pollRateField; - AutoWriteMenuItem = autoWrite; ShowLastMouseMoveMenuItem = showLastMouseMove; ShowVelocityAndGainMoveMenuItem = showVelocityAndGain; } @@ -38,8 +36,6 @@ namespace grapher.Models.Serialized private Field PollRateField { get; set; } - private ToolStripMenuItem AutoWriteMenuItem { get; set; } - private ToolStripMenuItem ShowLastMouseMoveMenuItem { get; set; } private ToolStripMenuItem ShowVelocityAndGainMoveMenuItem { get; set; } @@ -90,17 +86,20 @@ namespace grapher.Models.Serialized return errors; } - public void UpdateActiveAccelFromFileSettings(DriverSettings settings) + public void UpdateFieldsFromGUISettings() { - TryUpdateAccel(settings); - DpiField.SetToEntered(RawAccelSettings.GUISettings.DPI); PollRateField.SetToEntered(RawAccelSettings.GUISettings.PollRate); - AutoWriteMenuItem.Checked = RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup; ShowLastMouseMoveMenuItem.Checked = RawAccelSettings.GUISettings.ShowLastMouseMove; ShowVelocityAndGainMoveMenuItem.Checked = RawAccelSettings.GUISettings.ShowVelocityAndGain; } + public void UpdateActiveAccelFromFileSettings(DriverSettings settings) + { + TryUpdateAccel(settings); + UpdateFieldsFromGUISettings(); + } + public SettingsErrors TryUpdateAccel(DriverSettings settings) { var errors = SendToDriverSafe(settings); @@ -124,7 +123,6 @@ namespace grapher.Models.Serialized { return new GUISettings { - AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked, DPI = (int)DpiField.Data, PollRate = (int)PollRateField.Data, ShowLastMouseMove = ShowLastMouseMoveMenuItem.Checked, @@ -139,10 +137,8 @@ namespace grapher.Models.Serialized try { RawAccelSettings = RawAccelSettings.Load(() => MakeGUISettingsFromFields()); - if (RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup) - { - UpdateActiveAccelFromFileSettings(RawAccelSettings.AccelerationSettings); - } + UpdateFieldsFromGUISettings(); + UpdateActiveAccelFromFileSettings(RawAccelSettings.AccelerationSettings); return; } catch (JsonException e) -- cgit v1.2.3 From 0039d6e84d4e05e842542ad021a9c21e619c69c2 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 8 Oct 2020 19:44:40 -0700 Subject: Follow full C# convention --- grapher/Models/Serialized/GUISettings.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'grapher/Models/Serialized') diff --git a/grapher/Models/Serialized/GUISettings.cs b/grapher/Models/Serialized/GUISettings.cs index f9e5755..c8f87ae 100644 --- a/grapher/Models/Serialized/GUISettings.cs +++ b/grapher/Models/Serialized/GUISettings.cs @@ -31,7 +31,19 @@ namespace grapher.Models.Serialized #region Methods - public bool ValueEquals(GUISettings other) + public override bool Equals(object obj) + { + var other = obj as GUISettings; + + if (other == null) + { + return false; + } + + return Equals(other); + } + + public bool Equals(GUISettings other) { return DPI == other.DPI && PollRate == other.PollRate && @@ -39,6 +51,14 @@ namespace grapher.Models.Serialized ShowVelocityAndGain == other.ShowVelocityAndGain; } + public override int GetHashCode() + { + return DPI.GetHashCode() ^ + PollRate.GetHashCode() ^ + ShowLastMouseMove.GetHashCode() ^ + ShowVelocityAndGain.GetHashCode(); + } + #endregion Methods } } -- cgit v1.2.3 From a44294e7e689e43417323d6b1684f7462d113cb1 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 8 Oct 2020 22:53:31 -0400 Subject: improve comments, variable names --- grapher/Models/Serialized/RawAccelSettings.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'grapher/Models/Serialized') diff --git a/grapher/Models/Serialized/RawAccelSettings.cs b/grapher/Models/Serialized/RawAccelSettings.cs index e0362ff..818bfb6 100644 --- a/grapher/Models/Serialized/RawAccelSettings.cs +++ b/grapher/Models/Serialized/RawAccelSettings.cs @@ -55,16 +55,16 @@ namespace grapher.Models.Serialized { RawAccelSettings settings = null; - JObject jo = JObject.Parse(File.ReadAllText(file)); - if (jo.ContainsKey(DriverSettings.Key)) + JObject settingsJObject = JObject.Parse(File.ReadAllText(file)); + if (settingsJObject.ContainsKey(DriverSettings.Key)) { - settings = jo.ToObject(JsonSerializer.Create(SerializerSettings)); + settings = settingsJObject.ToObject(JsonSerializer.Create(SerializerSettings)); } else { settings = new RawAccelSettings { - AccelerationSettings = jo.ToObject(), + AccelerationSettings = settingsJObject.ToObject(), GUISettings = DefaultGUISettingsSupplier() }; } -- cgit v1.2.3