From e3eaa137ff8b4e47e2afa0b5f5d310872bed1003 Mon Sep 17 00:00:00 2001 From: pongo1231 Date: Sun, 27 Aug 2023 18:56:17 +0000 Subject: [PATCH] Shared: Write config option even if null & refactor Otherwise it will potentially fall back to compat options if existent --- Shared/OptionsFile.cs | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/Shared/OptionsFile.cs b/Shared/OptionsFile.cs index dbd15e5da..c0d97e341 100644 --- a/Shared/OptionsFile.cs +++ b/Shared/OptionsFile.cs @@ -42,7 +42,7 @@ public string ReadValue(string key, string defaultValue = null, params string[] var keys = compatKeys.Prepend(key); foreach (var _key in keys) { - if (!m_Options.ContainsKey(_key)) + if (!m_Options.ContainsKey(_key) || m_Options[_key] == null) { continue; } @@ -80,7 +80,7 @@ public bool ReadValueBool(string key, bool defaultValue, params string[] compatK var keys = compatKeys.Prepend(key); foreach (var _key in keys) { - if (!m_Options.ContainsKey(_key)) + if (!m_Options.ContainsKey(_key) || m_Options[_key] == null) { continue; } @@ -96,14 +96,7 @@ public bool ReadValueBool(string key, bool defaultValue, params string[] compatK public void WriteValue(string key, string value) { - if (value != null && value.Trim().Length > 0) - { - m_Options[key] = value; - } - else - { - m_Options.Remove(key); - } + m_Options[key] = value; } public void WriteValue(string key, int value) @@ -157,13 +150,15 @@ string readData(string fileName) foreach (string line in data.Split('\n')) { - var keyValuePair = line.Split('='); - if (keyValuePair.Length != 2) + if (!line.Contains("=")) { continue; } - m_Options[keyValuePair[0].Trim()] = keyValuePair[1].Trim(); + var keyValuePair = line.Split('=', 2, System.StringSplitOptions.RemoveEmptyEntries + | System.StringSplitOptions.TrimEntries); + + m_Options[keyValuePair[0]] = keyValuePair.Length == 2 ? keyValuePair[1] : null; } }