Files
@ f1323ba34306
Branch filter:
Location: ATITD-Tools/Desert-Paint-Lab/Settings.cs - annotation
f1323ba34306
2.8 KiB
text/x-csharp
Improved logging, sanity checking of settings (especially pixel multiplier), updated readme with some additional details on advanced settings.
83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 5d0a31247a93 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 5d0a31247a93 83ddf0ac052f f1323ba34306 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f f1323ba34306 f1323ba34306 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f f1323ba34306 83ddf0ac052f f1323ba34306 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f f1323ba34306 f1323ba34306 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f f1323ba34306 83ddf0ac052f 5d0a31247a93 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 5d0a31247a93 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 5d0a31247a93 83ddf0ac052f 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 5d0a31247a93 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 5d0a31247a93 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f 83ddf0ac052f | using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
namespace DesertPaintLab
{
public class Settings
{
public Settings()
{
}
private Dictionary<string, string> _settings = new Dictionary<string, string>();
public bool TryGet(string key, out int value)
{
value = 0;
string valStr;
bool found = _settings.TryGetValue(key.ToLower(), out valStr);
if (found)
{
Int32.TryParse(valStr, out value);
}
return found;
}
public bool TryGet(string key, out bool value)
{
value = false;
string valStr;
bool found = _settings.TryGetValue(key.ToLower(), out valStr);
if (found)
{
Boolean.TryParse(valStr, out value);
}
return found;
}
public void Set(string key, int value)
{
_settings[key.ToLower()] = value.ToString();
}
public void Set(string key, bool value)
{
_settings[key.ToLower()] = value.ToString();
}
public void Reset()
{
_settings.Clear();
}
public void Save(string settingsPath)
{
using (StreamWriter writer = new StreamWriter(settingsPath))
{
foreach (KeyValuePair<string, string> pair in _settings)
{
writer.WriteLine("{0}={1}", pair.Key, pair.Value);
}
}
}
static Regex optionEntry = new Regex(@"(?<opt>[^#=][^=]*)=(?<optval>.*)$");
public bool Load(string settingsPath)
{
if (System.IO.File.Exists(settingsPath))
{
string line;
Match match;
using (StreamReader reader = new StreamReader(settingsPath))
{
while ((line = reader.ReadLine()) != null)
{
match = optionEntry.Match(line);
if (match.Success)
{
String optName = match.Groups["opt"].Value.ToLower();
String optVal = match.Groups["optval"].Value.Trim();
if (optName.Equals("debug"))
{
// convert
optName = "enabledebugmenu";
}
_settings[optName.ToLower()] = optVal;
}
}
}
return true;
}
return false;
}
}
}
|