From ba74db5d4f8e82b856dea2f5f6657ea5b05754ea Mon Sep 17 00:00:00 2001 From: thewhobox <45664417+thewhobox@users.noreply.github.com> Date: Mon, 18 Dec 2023 20:37:44 +0100 Subject: [PATCH] added isLoaded --- ShareLoader.Share/SettingsHelper.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ShareLoader.Share/SettingsHelper.cs b/ShareLoader.Share/SettingsHelper.cs index d8b3afe..0c71a52 100644 --- a/ShareLoader.Share/SettingsHelper.cs +++ b/ShareLoader.Share/SettingsHelper.cs @@ -2,21 +2,22 @@ namespace ShareLoader.Share; public class SettingsHelper { + private static bool isLoaded = false; public static string FilePath { get; set; } = "/shareloader/settings.txt"; public static Dictionary Settings { get; set; } = new Dictionary(); public static T? GetSetting(string name) { - if(Settings == null) Load(); - if(Settings == null || !Settings.ContainsKey(name)) return (T?)Convert.ChangeType(null, typeof(T?)); + if(!isLoaded) Load(); + if(!Settings.ContainsKey(name)) return (T?)Convert.ChangeType(null, typeof(T?)); return Newtonsoft.Json.JsonConvert.DeserializeObject(Settings[name]); } public static string GetSetting(string name) { - if(Settings == null) Load(); - if(Settings == null || !Settings.ContainsKey(name)) return ""; + if(!isLoaded) Load(); + if(!Settings.ContainsKey(name)) return ""; return Settings[name]; } @@ -44,6 +45,7 @@ public static void SetSetting(string name, string value) public static void Load() { + isLoaded = true; if(!Directory.Exists("/shareloader")) { Console.WriteLine("/shareloader/ doesnt exist");