diff --git a/Dalamud.sln.DotSettings b/Dalamud.sln.DotSettings index af8f4d833..6a9bd9b76 100644 --- a/Dalamud.sln.DotSettings +++ b/Dalamud.sln.DotSettings @@ -48,4 +48,5 @@ True True True + True True \ No newline at end of file diff --git a/Dalamud/Configuration/DalamudConfiguration.cs b/Dalamud/Configuration/DalamudConfiguration.cs index 687f63179..23685901f 100644 --- a/Dalamud/Configuration/DalamudConfiguration.cs +++ b/Dalamud/Configuration/DalamudConfiguration.cs @@ -50,12 +50,12 @@ namespace Dalamud.Configuration /// /// Gets or sets a value indicating whether or not plugin testing builds should be shown. /// - public bool DoPluginTest { get; set; } = false; + public bool DoPluginTest { get; set; } /// /// Gets or sets a value indicating whether or not Dalamud testing builds should be used. /// - public bool DoDalamudTest { get; set; } = false; + public bool DoDalamudTest { get; set; } /// /// Gets or sets a list of custom repos. @@ -95,7 +95,7 @@ namespace Dalamud.Configuration /// /// Gets or sets a value indicating whether or not plugins should be auto-updated. /// - public bool AutoUpdatePlugins { get; set; } = false; + public bool AutoUpdatePlugins { get; set; } /// /// Gets or sets a value indicating whether or not the debug log should scroll automatically. diff --git a/Dalamud/Configuration/IPluginConfiguration.cs b/Dalamud/Configuration/IPluginConfiguration.cs index f2a782960..884e38871 100644 --- a/Dalamud/Configuration/IPluginConfiguration.cs +++ b/Dalamud/Configuration/IPluginConfiguration.cs @@ -1,13 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace Dalamud.Configuration { + /// + /// Configuration to store settings for a dalamud plugin. + /// public interface IPluginConfiguration { + /// + /// Gets or sets configuration version. + /// int Version { get; set; } } } diff --git a/Dalamud/Configuration/PluginConfigurations.cs b/Dalamud/Configuration/PluginConfigurations.cs index 139bc0df4..6a9c767f1 100644 --- a/Dalamud/Configuration/PluginConfigurations.cs +++ b/Dalamud/Configuration/PluginConfigurations.cs @@ -1,83 +1,115 @@ -using System; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; + using Newtonsoft.Json; namespace Dalamud.Configuration { - public class PluginConfigurations { - private DirectoryInfo configDirectory; + /// + /// Configuration to store settings for a dalamud plugin. + /// + public class PluginConfigurations + { + private readonly DirectoryInfo configDirectory; - public PluginConfigurations(string storageFolder) { + /// + /// Initializes a new instance of the class. + /// + /// Directory for storage of plugin configuration files. + public PluginConfigurations(string storageFolder) + { this.configDirectory = new DirectoryInfo(storageFolder); this.configDirectory.Create(); } - // NOTE: Save/Load are still using Type information for now, despite LoadForType<> superseding Load - // and not requiring or using it. It might be worth removing the Type info from Save, to strip it from - // all future saved configs, and then Load() can probably be removed entirey. - - public void Save(IPluginConfiguration config, string pluginName) { - File.WriteAllText(GetConfigFile(pluginName).FullName, JsonConvert.SerializeObject(config, Formatting.Indented, new JsonSerializerSettings + /// + /// Save/Load plugin configuration. + /// NOTE: Save/Load are still using Type information for now, + /// despite LoadForType superseding Load and not requiring or using it. + /// It might be worth removing the Type info from Save, to strip it from all future saved configs, + /// and then Load() can probably be removed entirely. + /// + /// Plugin configuration. + /// Plugin name. + public void Save(IPluginConfiguration config, string pluginName) + { + File.WriteAllText(this.GetConfigFile(pluginName).FullName, JsonConvert.SerializeObject(config, Formatting.Indented, new JsonSerializerSettings { TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple, - TypeNameHandling = TypeNameHandling.Objects + TypeNameHandling = TypeNameHandling.Objects, })); } - public IPluginConfiguration Load(string pluginName) { - var path = GetConfigFile(pluginName); + /// + /// Load plugin configuration. + /// + /// Plugin name. + /// Plugin configuration. + public IPluginConfiguration Load(string pluginName) + { + var path = this.GetConfigFile(pluginName); if (!path.Exists) return null; - return JsonConvert.DeserializeObject(File.ReadAllText(path.FullName), - new JsonSerializerSettings { - TypeNameAssemblyFormatHandling = - TypeNameAssemblyFormatHandling.Simple, - TypeNameHandling = TypeNameHandling.Objects - }); + return JsonConvert.DeserializeObject( + File.ReadAllText(path.FullName), + new JsonSerializerSettings + { + TypeNameAssemblyFormatHandling = + TypeNameAssemblyFormatHandling.Simple, + TypeNameHandling = TypeNameHandling.Objects, + }); } - public string GetDirectory(string pluginName) { - try { - var path = GetDirectoryPath(pluginName); - if (!path.Exists) { + /// + /// Get plugin directory. + /// + /// Plugin name. + /// Plugin directory path. + public string GetDirectory(string pluginName) + { + try + { + var path = this.GetDirectoryPath(pluginName); + if (!path.Exists) + { path.Create(); } + return path.FullName; - } catch { + } + catch + { return string.Empty; } } - // Parameterized deserialization - // Currently this is called via reflection from DalamudPluginInterface.GetPluginConfig() - // Eventually there may be an additional pluginInterface method that can call this directly - // without reflection - for now this is in support of the existing plugin api + /// + /// Load Plugin configuration. Parameterized deserialization. + /// Currently this is called via reflection from DalamudPluginInterface.GetPluginConfig(). + /// Eventually there may be an additional pluginInterface method that can call this directly + /// without reflection - for now this is in support of the existing plugin api. + /// + /// Plugin Name. + /// Configuration Type. + /// Plugin Configuration. public T LoadForType(string pluginName) where T : IPluginConfiguration { - var path = GetConfigFile(pluginName); + var path = this.GetConfigFile(pluginName); - if (!path.Exists) - return default(T); + return !path.Exists ? default : JsonConvert.DeserializeObject(File.ReadAllText(path.FullName)); // intentionally no type handling - it will break when updating a plugin at runtime // and turns out to be unnecessary when we fully qualify the object type - return JsonConvert.DeserializeObject(File.ReadAllText(path.FullName)); } /// /// Get FileInfo to plugin config file. /// /// InternalName of the plugin. - /// FileInfo of the config file + /// FileInfo of the config file. public FileInfo GetConfigFile(string pluginName) => new FileInfo(Path.Combine(this.configDirectory.FullName, $"{pluginName}.json")); private DirectoryInfo GetDirectoryPath(string pluginName) => new DirectoryInfo(Path.Combine(this.configDirectory.FullName, pluginName)); - } } diff --git a/Dalamud/Configuration/ThirdRepoSetting.cs b/Dalamud/Configuration/ThirdRepoSetting.cs index 3087059e2..63ab9f333 100644 --- a/Dalamud/Configuration/ThirdRepoSetting.cs +++ b/Dalamud/Configuration/ThirdRepoSetting.cs @@ -1,19 +1,30 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace Dalamud.Configuration { - class ThirdRepoSetting { + /// + /// Third party repository for dalamud plugins. + /// + internal class ThirdRepoSetting + { + /// + /// Gets or sets the third party repo url. + /// public string Url { get; set; } - public bool IsEnabled { get;set; } - public ThirdRepoSetting Clone() { - return new ThirdRepoSetting { + /// + /// Gets or sets a value indicating whether the third party repo is enabled. + /// + public bool IsEnabled { get; set; } + + /// + /// Create new instance of third party repo object. + /// + /// New instance of third party repo. + public ThirdRepoSetting Clone() + { + return new ThirdRepoSetting + { Url = this.Url, - IsEnabled = this.IsEnabled + IsEnabled = this.IsEnabled, }; } }