Minor refactor

CheckForMissingFields -> CheckForChanges
anyMissingFields -> anyChanges
This commit is contained in:
Chris 2021-01-28 19:43:03 +10:30
parent 0012bf73da
commit b5ca015d26
4 changed files with 12 additions and 19 deletions

View file

@ -609,22 +609,18 @@ namespace TShockAPI
/// <summary>
/// Reads a configuration file from a given path
/// </summary>
/// <param name="path">string path</param>
/// <param name="path">The path to the config file</param>
/// <param name="anyMissingFields">
/// Whether the config object has any new files in it, meaning that the config file has to be
/// overwritten.
/// </param>
public static ConfigFile Read(string path, out bool anyMissingFields)
/// <param name="anyChanges"> Whether the config object required an upgrade or had unexpected fields added or missing</param>
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
/// </summary>
/// <param name="stream">stream</param>
/// <param name="anyMissingFields">
/// Whether the config object has any new fields in it, meaning that the config file has to be
/// overwritten.
/// </param>
/// <param name="anyChanges"> Whether the config object required an upgrade or had unexpected fields added or missing</param>
/// <returns>ConfigFile object</returns>
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<ConfigFile>(sr.ReadToEnd(), out anyMissingFields);
var cf = FileTools.LoadConfigAndCheckForChanges<ConfigFile>(sr.ReadToEnd(), out anyChanges);
ConfigRead?.Invoke(cf);
return cf;
}

View file

@ -67,7 +67,7 @@ namespace TShockAPI.Configuration
/// <returns>Settings object</returns>
public virtual TSettings ConvertJson(string json, out bool incompleteSettings)
{
var settings = FileTools.LoadConfigAndCheckForMissingFields<TSettings>(json, out incompleteSettings);
var settings = FileTools.LoadConfigAndCheckForChanges<TSettings>(json, out incompleteSettings);
Settings = settings;
OnConfigRead?.Invoke(this);

View file

@ -588,7 +588,7 @@ namespace TShockAPI.Configuration
/// <returns></returns>
public override TShockSettings ConvertJson(string json, out bool incompleteSettings)
{
var settings = FileTools.LoadConfigAndCheckForMissingFields<TShockSettings>(json, out incompleteSettings);
var settings = FileTools.LoadConfigAndCheckForChanges<TShockSettings>(json, out incompleteSettings);
Settings = settings;
OnConfigRead?.Invoke(this);

View file

@ -197,7 +197,7 @@ namespace TShockAPI
return cfg;
}
internal static TSettings LoadConfigAndCheckForMissingFields<TSettings>(string json, out bool writeConfig) where TSettings : new()
internal static TSettings LoadConfigAndCheckForChanges<TSettings>(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<TSettings>(JObject.Parse(json), out writeConfig);
return LoadConfigAndCheckForChanges<TSettings>(JObject.Parse(json), out writeConfig);
}
/// <summary>
@ -215,7 +215,7 @@ namespace TShockAPI
/// <param name="jObject">The json object to parse</param>
/// <param name="writeConfig">Whether the config needs to be written to disk again</param>
/// <returns>The config object</returns>
internal static TSettings LoadConfigAndCheckForMissingFields<TSettings>(JObject jObject, out bool writeConfig) where TSettings : new()
internal static TSettings LoadConfigAndCheckForChanges<TSettings>(JObject jObject, out bool writeConfig) where TSettings : new()
{
JObject cfg = AttemptConfigUpgrade(jObject, out bool requiredUpgrade);