-
Notifications
You must be signed in to change notification settings - Fork 0
/
DXIWSettings.cs
70 lines (55 loc) · 2.55 KB
/
DXIWSettings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Reflection;
using System.Windows.Forms;
using System.Xml;
namespace LiveSplit.DXIW
{
public partial class DXIWSettings : UserControl
{
public bool AutoReset { get; set; }
public bool AutoStart { get; set; }
public bool UseNonSafeMemoryReading { get; set; }
private const bool DEFAULT_AUTORESET = false;
private const bool DEFAULT_AUTOSTART = true;
private const bool DEFAULT_UNSAFEREADER = true;
public DXIWSettings()
{
InitializeComponent();
this.chkUnsafeReading.DataBindings.Add("Checked", this, "UseNonSafeMemoryReading", false, DataSourceUpdateMode.OnPropertyChanged);
this.chkAutoReset.DataBindings.Add("Checked", this, "AutoReset", false, DataSourceUpdateMode.OnPropertyChanged);
this.chkAutoStart.DataBindings.Add("Checked", this, "AutoStart", false, DataSourceUpdateMode.OnPropertyChanged);
// defaults
this.UseNonSafeMemoryReading = DEFAULT_UNSAFEREADER;
this.AutoReset = DEFAULT_AUTORESET;
this.AutoStart = DEFAULT_AUTOSTART;
}
public XmlNode GetSettings(XmlDocument doc)
{
XmlElement settingsNode = doc.CreateElement("Settings");
settingsNode.AppendChild(ToElement(doc, "Version", Assembly.GetExecutingAssembly().GetName().Version.ToString(3)));
settingsNode.AppendChild(ToElement(doc, "NonSafeMemoryReader", this.UseNonSafeMemoryReading));
settingsNode.AppendChild(ToElement(doc, "AutoReset", this.AutoReset));
settingsNode.AppendChild(ToElement(doc, "AutoStart", this.AutoStart));
return settingsNode;
}
public void SetSettings(XmlNode settings)
{
this.UseNonSafeMemoryReading = ParseBool(settings, "NonSafeMemoryReader", DEFAULT_UNSAFEREADER);
this.AutoReset = ParseBool(settings, "AutoReset", DEFAULT_AUTORESET);
this.AutoStart = ParseBool(settings, "AutoStart", DEFAULT_AUTOSTART);
}
static bool ParseBool(XmlNode settings, string setting, bool default_ = false)
{
bool val;
return settings[setting] != null ?
(Boolean.TryParse(settings[setting].InnerText, out val) ? val : default_)
: default_;
}
static XmlElement ToElement<T>(XmlDocument document, string name, T value)
{
XmlElement str = document.CreateElement(name);
str.InnerText = value.ToString();
return str;
}
}
}