diff --git a/Config/Configuration.cs b/Config/Configuration.cs new file mode 100644 index 0000000..e601b1c --- /dev/null +++ b/Config/Configuration.cs @@ -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 _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(await File.ReadAllTextAsync(ConfigFilePath)); + } + } + + public async Task Save() + { + await File.WriteAllTextAsync(ConfigFilePath, JsonConvert.SerializeObject(Config)); + } +} \ No newline at end of file