Files
@ c9ad5ae6640a
Branch filter:
Location: ATITD-Tools/Desert-Paint-Lab/Settings.cs - annotation
c9ad5ae6640a
2.8 KiB
text/x-csharp
Add a thread count for paint recipe generation to settings
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 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 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
{
private Settings()
{
}
private static Dictionary<string, string> _settings = new Dictionary<string, string>();
public static void Get(string key, out int value)
{
value = 0;
string valStr;
if ( _settings.TryGetValue(key.ToLower(), out valStr) )
{
Int32.TryParse(valStr, out value);
}
}
public static void Get(string key, out bool value)
{
value = false;
string valStr;
if ( _settings.TryGetValue(key.ToLower(), out valStr) )
{
Boolean.TryParse(valStr, out value);
}
}
public static void Set(string key, int value)
{
_settings[key.ToLower()] = value.ToString();
}
public static void Get(string key, bool value)
{
_settings[key.ToLower()] = value.ToString();
}
public static void Save()
{
string settingsPath = System.IO.Path.Combine(FileUtils.AppDataPath, "settings");
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 static bool Load()
{
string settingsPath = System.IO.Path.Combine(FileUtils.AppDataPath, "settings");
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;
}
}
}
|