44
Config/Configuration.cs
Normal file
44
Config/Configuration.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user