From b5ca015d2629c3d740e2c5a1f37e3ad45cf17ef9 Mon Sep 17 00:00:00 2001 From: Chris <2648373+QuiCM@users.noreply.github.com> Date: Thu, 28 Jan 2021 19:43:03 +1030 Subject: [PATCH] Minor refactor CheckForMissingFields -> CheckForChanges anyMissingFields -> anyChanges --- TShockAPI/ConfigFile.cs | 21 +++++++-------------- TShockAPI/Configuration/ConfigFile.cs | 2 +- TShockAPI/Configuration/TShockConfig.cs | 2 +- TShockAPI/FileTools.cs | 6 +++--- 4 files changed, 12 insertions(+), 19 deletions(-) diff --git a/TShockAPI/ConfigFile.cs b/TShockAPI/ConfigFile.cs index fd148a1e..47a45aff 100644 --- a/TShockAPI/ConfigFile.cs +++ b/TShockAPI/ConfigFile.cs @@ -609,22 +609,18 @@ namespace TShockAPI /// /// Reads a configuration file from a given path /// - /// string path /// The path to the config file - /// - /// Whether the config object has any new files in it, meaning that the config file has to be - /// overwritten. - /// - public static ConfigFile Read(string path, out bool anyMissingFields) + /// Whether the config object required an upgrade or had unexpected fields added or missing + public static ConfigFile Read(string path, out bool anyChanges) { if (!File.Exists(path)) { - anyMissingFields = true; + anyChanges = true; return new ConfigFile(); } using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) { - return Read(fs, out anyMissingFields); + return Read(fs, out anyChanges); } } @@ -632,16 +628,13 @@ namespace TShockAPI /// Reads the configuration file from a stream /// /// stream - /// - /// Whether the config object has any new fields in it, meaning that the config file has to be - /// overwritten. - /// + /// Whether the config object required an upgrade or had unexpected fields added or missing /// ConfigFile object - public static ConfigFile Read(Stream stream, out bool anyMissingFields) + public static ConfigFile Read(Stream stream, out bool anyChanges) { using (var sr = new StreamReader(stream)) { - var cf = FileTools.LoadConfigAndCheckForMissingFields(sr.ReadToEnd(), out anyMissingFields); + var cf = FileTools.LoadConfigAndCheckForChanges(sr.ReadToEnd(), out anyChanges); ConfigRead?.Invoke(cf); return cf; } diff --git a/TShockAPI/Configuration/ConfigFile.cs b/TShockAPI/Configuration/ConfigFile.cs index de0da0fe..ef08a696 100644 --- a/TShockAPI/Configuration/ConfigFile.cs +++ b/TShockAPI/Configuration/ConfigFile.cs @@ -67,7 +67,7 @@ namespace TShockAPI.Configuration /// Settings object public virtual TSettings ConvertJson(string json, out bool incompleteSettings) { - var settings = FileTools.LoadConfigAndCheckForMissingFields(json, out incompleteSettings); + var settings = FileTools.LoadConfigAndCheckForChanges(json, out incompleteSettings); Settings = settings; OnConfigRead?.Invoke(this); diff --git a/TShockAPI/Configuration/TShockConfig.cs b/TShockAPI/Configuration/TShockConfig.cs index 0306ec7f..0f1139e6 100644 --- a/TShockAPI/Configuration/TShockConfig.cs +++ b/TShockAPI/Configuration/TShockConfig.cs @@ -588,7 +588,7 @@ namespace TShockAPI.Configuration /// public override TShockSettings ConvertJson(string json, out bool incompleteSettings) { - var settings = FileTools.LoadConfigAndCheckForMissingFields(json, out incompleteSettings); + var settings = FileTools.LoadConfigAndCheckForChanges(json, out incompleteSettings); Settings = settings; OnConfigRead?.Invoke(this); diff --git a/TShockAPI/FileTools.cs b/TShockAPI/FileTools.cs index 9c983369..3f8095ef 100644 --- a/TShockAPI/FileTools.cs +++ b/TShockAPI/FileTools.cs @@ -197,7 +197,7 @@ namespace TShockAPI return cfg; } - internal static TSettings LoadConfigAndCheckForMissingFields(string json, out bool writeConfig) where TSettings : new() + internal static TSettings LoadConfigAndCheckForChanges(string json, out bool writeConfig) where TSettings : new() { //If an empty file is attempting to be loaded as a config, instead use an empty json object. Otherwise Newtonsoft throws an exception here if (string.IsNullOrWhiteSpace(json)) @@ -205,7 +205,7 @@ namespace TShockAPI json = "{}"; } - return LoadConfigAndCheckForMissingFields(JObject.Parse(json), out writeConfig); + return LoadConfigAndCheckForChanges(JObject.Parse(json), out writeConfig); } /// @@ -215,7 +215,7 @@ namespace TShockAPI /// The json object to parse /// Whether the config needs to be written to disk again /// The config object - internal static TSettings LoadConfigAndCheckForMissingFields(JObject jObject, out bool writeConfig) where TSettings : new() + internal static TSettings LoadConfigAndCheckForChanges(JObject jObject, out bool writeConfig) where TSettings : new() { JObject cfg = AttemptConfigUpgrade(jObject, out bool requiredUpgrade);