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/RawAccelSettings.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/RawAccelSettings.cs')
| -rw-r--r-- | grapher/Models/Serialized/RawAccelSettings.cs | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/grapher/Models/Serialized/RawAccelSettings.cs b/grapher/Models/Serialized/RawAccelSettings.cs index 3f5aebc..570a6c8 100644 --- a/grapher/Models/Serialized/RawAccelSettings.cs +++ b/grapher/Models/Serialized/RawAccelSettings.cs @@ -1,6 +1,8 @@ using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using System; using System.IO; +using System.Linq; namespace grapher.Models.Serialized { @@ -13,9 +15,8 @@ namespace grapher.Models.Serialized public static readonly string DefaultSettingsFile = Path.Combine(ExecutingDirectory, Constants.DefaultSettingsFileName); public static readonly JsonSerializerSettings SerializerSettings = new JsonSerializerSettings { - MissingMemberHandling = MissingMemberHandling.Error, + MissingMemberHandling = MissingMemberHandling.Ignore, }; - #endregion Fields #region Constructors @@ -33,9 +34,10 @@ namespace grapher.Models.Serialized #endregion Constructors #region Properties - + [JsonProperty(Required = Required.Always)] public GUISettings GUISettings { get; set; } + [JsonProperty(DriverSettings.Key, Required = Required.Always)] public DriverSettings AccelerationSettings { get; set; } #endregion Properties @@ -51,15 +53,17 @@ namespace grapher.Models.Serialized { try { - return JsonConvert.DeserializeObject<RawAccelSettings>(File.ReadAllText(file), SerializerSettings); + var settings = JsonConvert.DeserializeObject<RawAccelSettings>(File.ReadAllText(file), SerializerSettings); + if (settings is null) throw new JsonException($"{file} contains invalid JSON"); + return settings; } catch (FileNotFoundException e) { throw new FileNotFoundException($"Settings file does not exist at {file}", e); } - catch (JsonSerializationException e) + catch (JsonException e) { - throw new JsonSerializationException($"Settings file at {file} does not contain valid Raw Accel Settings.", e); + throw new JsonException($"Settings file at {file} does not contain valid Raw Accel Settings.", e); } } @@ -80,7 +84,16 @@ namespace grapher.Models.Serialized public void Save(string file) { - File.WriteAllText(file, JsonConvert.SerializeObject(this, Formatting.Indented)); + JObject thisJO = JObject.FromObject(this); + AddComments(thisJO); + File.WriteAllText(file, thisJO.ToString(Formatting.Indented)); + } + + private void AddComments(JObject thisJO) + { + string modes = string.Join(" | ", Enum.GetNames(typeof(AccelMode))); + ((JObject)thisJO[DriverSettings.Key]) + .AddFirst(new JProperty("### Mode Types ###", modes)); } #endregion Methods |