|
@@ -15,20 +15,40 @@ namespace BepInEx.Configuration
|
|
|
{
|
|
|
internal static ConfigFile CoreConfig { get; } = new ConfigFile(Paths.BepInExConfigPath, true);
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
protected Dictionary<ConfigDefinition, ConfigEntry> Entries { get; } = new Dictionary<ConfigDefinition, ConfigEntry>();
|
|
|
|
|
|
- [Obsolete("Use ConfigEntries instead")]
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ [Obsolete("Use GetConfigEntries instead")]
|
|
|
public ReadOnlyCollection<ConfigDefinition> ConfigDefinitions => Entries.Keys.ToList().AsReadOnly();
|
|
|
|
|
|
- public ReadOnlyCollection<ConfigEntry> ConfigEntries => Entries.Values.ToList().AsReadOnly();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public ConfigEntry[] GetConfigEntries() => Entries.Values.ToArray();
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
public string ConfigFilePath { get; }
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
|
|
|
public bool SaveOnConfigSet { get; set; } = true;
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
public ConfigFile(string configPath, bool saveOnInit)
|
|
|
{
|
|
|
if (configPath == null) throw new ArgumentNullException(nameof(configPath));
|
|
@@ -138,6 +158,16 @@ namespace BepInEx.Configuration
|
|
|
|
|
|
#region Wraps
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
public ConfigWrapper<T> Wrap<T>(ConfigDefinition configDefinition, T defaultValue, ConfigDescription configDescription = null)
|
|
|
{
|
|
|
if (!TomlTypeConverter.CanConvert(typeof(T)))
|
|
@@ -166,10 +196,26 @@ namespace BepInEx.Configuration
|
|
|
return new ConfigWrapper<T>(entry);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
[Obsolete("Use other Wrap overloads instead")]
|
|
|
public ConfigWrapper<T> Wrap<T>(string section, string key, string description = null, T defaultValue = default(T))
|
|
|
=> Wrap(new ConfigDefinition(section, key), defaultValue, string.IsNullOrEmpty(description) ? null : new ConfigDescription(description));
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
public ConfigWrapper<T> Wrap<T>(string section, string key, T defaultValue, ConfigDescription configDescription = null)
|
|
|
=> Wrap(new ConfigDefinition(section, key), defaultValue, configDescription);
|
|
|
|
|
@@ -187,7 +233,7 @@ namespace BepInEx.Configuration
|
|
|
|
|
|
public event EventHandler<SettingChangedEventArgs> SettingChanged;
|
|
|
|
|
|
- protected internal void OnSettingChanged(object sender, ConfigEntry changedEntry)
|
|
|
+ internal void OnSettingChanged(object sender, ConfigEntry changedEntry)
|
|
|
{
|
|
|
if (changedEntry == null) throw new ArgumentNullException(nameof(changedEntry));
|
|
|
|
|
@@ -208,12 +254,13 @@ namespace BepInEx.Configuration
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
if (sender != this && SaveOnConfigSet)
|
|
|
Save();
|
|
|
}
|
|
|
|
|
|
- protected void OnConfigReloaded()
|
|
|
+ private void OnConfigReloaded()
|
|
|
{
|
|
|
if (ConfigReloaded != null)
|
|
|
{
|
|
@@ -266,11 +313,16 @@ namespace BepInEx.Configuration
|
|
|
{
|
|
|
lock (_ioLock)
|
|
|
{
|
|
|
- _watcher?.Dispose();
|
|
|
- _watcher = null;
|
|
|
+ if (_watcher != null)
|
|
|
+ {
|
|
|
+ _watcher.EnableRaisingEvents = false;
|
|
|
+ _watcher.Dispose();
|
|
|
+ _watcher = null;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
~ConfigFile()
|
|
|
{
|
|
|
StopWatching();
|