44 lines
913 B
C#
44 lines
913 B
C#
using Debugger;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace Shrink.Config;
|
|
|
|
public struct Config
|
|
{
|
|
public LogLevel LogLevel;
|
|
|
|
public Config(LogLevel logLevel)
|
|
{
|
|
LogLevel = logLevel;
|
|
}
|
|
}
|
|
|
|
public class Configuration
|
|
{
|
|
private static readonly Lazy<Configuration> _instance = new(() => new Configuration());
|
|
public static Configuration Instance => _instance.Value;
|
|
private const string ConfigFilePath = "Config.json";
|
|
|
|
public Config Config;
|
|
|
|
private Configuration()
|
|
{
|
|
}
|
|
|
|
public async Task Init()
|
|
{
|
|
if (!File.Exists(ConfigFilePath))
|
|
{
|
|
await Save();
|
|
}
|
|
else
|
|
{
|
|
Config = JsonConvert.DeserializeObject<Config>(await File.ReadAllTextAsync(ConfigFilePath));
|
|
}
|
|
}
|
|
|
|
public async Task Save()
|
|
{
|
|
await File.WriteAllTextAsync(ConfigFilePath, JsonConvert.SerializeObject(Config));
|
|
}
|
|
} |