From 255ad0993d4334e306eb5475cee2cf82778dcecd Mon Sep 17 00:00:00 2001 From: RogueAI42 Date: Sun, 25 Jun 2017 15:35:03 +1000 Subject: refactoring a few server-related things --- ShiftOS.Objects/UserConfig.cs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'ShiftOS.Objects') diff --git a/ShiftOS.Objects/UserConfig.cs b/ShiftOS.Objects/UserConfig.cs index 579ce00..8232230 100644 --- a/ShiftOS.Objects/UserConfig.cs +++ b/ShiftOS.Objects/UserConfig.cs @@ -14,24 +14,27 @@ namespace ShiftOS.Objects public string DigitalSocietyAddress { get; set; } public int DigitalSocietyPort { get; set; } - public static UserConfig Get() - { - var conf = new UserConfig + private static UserConfig def = new UserConfig { Language = "english", DigitalSocietyAddress = "michaeltheshifter.me", DigitalSocietyPort = 13370 }; - if (!File.Exists("servers.json")) - { - File.WriteAllText("servers.json", JsonConvert.SerializeObject(conf, Formatting.Indented)); - } + public static UserConfig current = null; + + public static UserConfig Get() + { + if (current != null) + return current; + if (File.Exists("servers.json")) + current = JsonConvert.DeserializeObject(File.ReadAllText("servers.json")); else { - conf = JsonConvert.DeserializeObject(File.ReadAllText("servers.json")); + File.WriteAllText("servers.json", JsonConvert.SerializeObject(def, Formatting.Indented)); + current = def; } - return conf; + return current; } } } -- cgit v1.2.3