-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettings.cs
95 lines (84 loc) · 2.67 KB
/
Settings.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#region
using System;
using System.IO;
using System.Windows.Forms;
using System.Xml.Serialization;
using Styx.Common;
using Styx.Helpers;
#endregion
namespace Simcraft
{
public class SimCSettings
{
[XmlIgnore] private static SimCSettings _currentSettings;
[XmlIgnore]
public static SimCSettings currentSettings
{
get
{
if (_currentSettings == null)
{
Load();
}
return _currentSettings;
}
set { _currentSettings = value; }
}
public Hotkey Cooldowns { get; set; }
public Hotkey Aoe { get; set; }
public Hotkey Burst { get; set; }
public Hotkey Execution { get; set; }
private static SimCSettings DefaultConfig()
{
var ret = new SimCSettings
{
Cooldowns = new Hotkey(),
Aoe = new Hotkey(),
Burst = new Hotkey(),
Execution = new Hotkey()
};
ret.Cooldowns.key = Keys.C;
ret.Cooldowns.mod = ModifierKeys.NoRepeat;
ret.Aoe.key = Keys.A;
ret.Aoe.mod = ModifierKeys.NoRepeat;
ret.Burst.key = Keys.B;
ret.Burst.mod = ModifierKeys.NoRepeat;
ret.Execution.key = Keys.X;
ret.Execution.mod = ModifierKeys.NoRepeat;
return ret;
}
public static void Save()
{
var writer =
new XmlSerializer(typeof (SimCSettings));
var file =
new StreamWriter(Path.Combine(Settings.CharacterSettingsDirectory, "SimCSettings.xml"), false);
writer.Serialize(file, currentSettings);
file.Close();
}
public static void Load()
{
try
{
Logging.Write("Loading configuration");
var reader =
new XmlSerializer(typeof (SimCSettings));
var file =
new StreamReader(Path.Combine(Settings.CharacterSettingsDirectory, "SimCSettings.xml"));
currentSettings = (SimCSettings) reader.Deserialize(file);
Logging.Write("Configuration successfully loaded.");
}
catch (Exception e)
{
Logging.Write("Failed to load configuration, creating default configuration.");
//Logging.Write("Exception: " + e);
_currentSettings = DefaultConfig();
}
}
public class Hotkey
{
public Keys key;
public ModifierKeys mod;
}
}
}