Skip to content

Commit

Permalink
Shared: Write config option even if null & refactor
Browse files Browse the repository at this point in the history
Otherwise it will potentially fall back to compat options if existent
  • Loading branch information
pongo1231 committed Aug 27, 2023
1 parent b2b50cd commit e3eaa13
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions Shared/OptionsFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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)
Expand Down Expand Up @@ -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;
}
}

Expand Down

0 comments on commit e3eaa13

Please sign in to comment.