From 2537d11f53214123c47cf3594840a20af183788e Mon Sep 17 00:00:00 2001 From: Eicy Date: Sat, 21 Dec 2024 01:03:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EConfig=E4=BE=9B=E8=BF=87?= =?UTF-8?q?=E6=BB=A4=E8=BE=93=E5=87=BA=E4=BB=A5=E5=8F=8A=E5=B0=86=E6=9D=A5?= =?UTF-8?q?=E7=9A=84=E5=85=B6=E4=BB=96=E5=8A=9F=E8=83=BD=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Eicy --- Config/Configuration.cs | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Config/Configuration.cs 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