|
@@ -1,18 +1,22 @@
|
|
using BepInEx.Common;
|
|
using BepInEx.Common;
|
|
-using System;
|
|
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
-using System.Text;
|
|
|
|
|
|
|
|
namespace BepInEx
|
|
namespace BepInEx
|
|
{
|
|
{
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// A helper class to handle persistent data.
|
|
|
|
+ /// </summary>
|
|
public static class Config
|
|
public static class Config
|
|
{
|
|
{
|
|
private static Dictionary<string, string> cache = new Dictionary<string, string>();
|
|
private static Dictionary<string, string> cache = new Dictionary<string, string>();
|
|
|
|
|
|
private static string configPath => Path.Combine(Utility.PluginsDirectory, "config.ini");
|
|
private static string configPath => Path.Combine(Utility.PluginsDirectory, "config.ini");
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// If enabled, writes the config to disk every time a value is set.
|
|
|
|
+ /// </summary>
|
|
public static bool SaveOnConfigSet { get; set; } = true;
|
|
public static bool SaveOnConfigSet { get; set; } = true;
|
|
|
|
|
|
static Config()
|
|
static Config()
|
|
@@ -27,6 +31,9 @@ namespace BepInEx
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Reloads the config from disk. Unwritten changes are lost.
|
|
|
|
+ /// </summary>
|
|
public static void ReloadConfig()
|
|
public static void ReloadConfig()
|
|
{
|
|
{
|
|
cache.Clear();
|
|
cache.Clear();
|
|
@@ -41,11 +48,20 @@ namespace BepInEx
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Writes the config to disk.
|
|
|
|
+ /// </summary>
|
|
public static void SaveConfig()
|
|
public static void SaveConfig()
|
|
{
|
|
{
|
|
File.WriteAllLines(configPath, cache.Select(x => $"{x.Key}={x.Value}").ToArray());
|
|
File.WriteAllLines(configPath, cache.Select(x => $"{x.Key}={x.Value}").ToArray());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Returns the value of the key if found, otherwise returns the default value.
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="key">The key to search for.</param>
|
|
|
|
+ /// <param name="defaultValue">The default value to return if the key is not found.</param>
|
|
|
|
+ /// <returns>The value of the key.</returns>
|
|
public static string GetEntry(string key, string defaultValue)
|
|
public static string GetEntry(string key, string defaultValue)
|
|
{
|
|
{
|
|
if (cache.TryGetValue(key, out string value))
|
|
if (cache.TryGetValue(key, out string value))
|
|
@@ -54,6 +70,11 @@ namespace BepInEx
|
|
return defaultValue;
|
|
return defaultValue;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Sets the value of the key in the config.
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="key">The key to set the value to.</param>
|
|
|
|
+ /// <param name="value">The value to set.</param>
|
|
public static void SetEntry(string key, string value)
|
|
public static void SetEntry(string key, string value)
|
|
{
|
|
{
|
|
cache[key] = value;
|
|
cache[key] = value;
|