|
1 | | -using System; |
2 | | -using System.Diagnostics.Contracts; |
| 1 | +using System.Collections.Generic; |
3 | 2 | using System.Drawing; |
4 | | -using System.IO; |
5 | | -using System.Xml; |
6 | | -using System.Xml.Schema; |
7 | | -using System.Xml.Serialization; |
8 | | -using ReClassNET.Util; |
9 | 3 |
|
10 | 4 | namespace ReClassNET |
11 | 5 | { |
12 | 6 | public class Settings |
13 | 7 | { |
14 | | - public static Settings Load() |
15 | | - { |
16 | | - EnsureSettingsDirectoryAvailable(); |
17 | | - |
18 | | - try |
19 | | - { |
20 | | - var path = Path.Combine(PathUtil.SettingsFolderPath, Constants.SettingsFile); |
21 | | - |
22 | | - if (File.Exists(path)) |
23 | | - { |
24 | | - using (var sr = new StreamReader(path)) |
25 | | - { |
26 | | - return (Settings)new XmlSerializer(typeof(Settings)).Deserialize(sr); |
27 | | - } |
28 | | - } |
29 | | - } |
30 | | - catch |
31 | | - { |
32 | | - |
33 | | - } |
34 | | - |
35 | | - return new Settings(); |
36 | | - } |
37 | | - |
38 | | - public static void Save(Settings settings) |
39 | | - { |
40 | | - Contract.Requires(settings != null); |
41 | | - |
42 | | - EnsureSettingsDirectoryAvailable(); |
43 | | - |
44 | | - var path = Path.Combine(PathUtil.SettingsFolderPath, Constants.SettingsFile); |
45 | | - |
46 | | - using (var sr = new StreamWriter(path)) |
47 | | - { |
48 | | - new XmlSerializer(typeof(Settings)).Serialize(sr, settings); |
49 | | - } |
50 | | - } |
51 | | - |
52 | | - private static void EnsureSettingsDirectoryAvailable() |
53 | | - { |
54 | | - try |
55 | | - { |
56 | | - if (Directory.Exists(PathUtil.SettingsFolderPath) == false) |
57 | | - { |
58 | | - Directory.CreateDirectory(PathUtil.SettingsFolderPath); |
59 | | - } |
60 | | - } |
61 | | - catch (Exception) |
62 | | - { |
63 | | - |
64 | | - } |
65 | | - } |
66 | | - |
67 | 8 | // Application Settings |
68 | 9 |
|
69 | 10 | public string LastProcess { get; set; } = string.Empty; |
@@ -98,55 +39,37 @@ private static void EnsureSettingsDirectoryAvailable() |
98 | 39 |
|
99 | 40 | // Colors |
100 | 41 |
|
101 | | - [XmlElement(Type = typeof(XmlColorWrapper))] |
102 | 42 | public Color BackgroundColor { get; set; } = Color.FromArgb(255, 255, 255); |
103 | 43 |
|
104 | | - [XmlElement(Type = typeof(XmlColorWrapper))] |
105 | 44 | public Color SelectedColor { get; set; } = Color.FromArgb(240, 240, 240); |
106 | 45 |
|
107 | | - [XmlElement(Type = typeof(XmlColorWrapper))] |
108 | 46 | public Color HiddenColor { get; set; } = Color.FromArgb(240, 240, 240); |
109 | 47 |
|
110 | | - [XmlElement(Type = typeof(XmlColorWrapper))] |
111 | 48 | public Color OffsetColor { get; set; } = Color.FromArgb(255, 0, 0); |
112 | 49 |
|
113 | | - [XmlElement(Type = typeof(XmlColorWrapper))] |
114 | 50 | public Color AddressColor { get; set; } = Color.FromArgb(0, 200, 0); |
115 | 51 |
|
116 | | - [XmlElement(Type = typeof(XmlColorWrapper))] |
117 | 52 | public Color HexColor { get; set; } = Color.FromArgb(0, 0, 0); |
118 | 53 |
|
119 | | - [XmlElement(Type = typeof(XmlColorWrapper))] |
120 | 54 | public Color TypeColor { get; set; } = Color.FromArgb(0, 0, 255); |
121 | 55 |
|
122 | | - [XmlElement(Type = typeof(XmlColorWrapper))] |
123 | 56 | public Color NameColor { get; set; } = Color.FromArgb(32, 32, 128); |
124 | 57 |
|
125 | | - [XmlElement(Type = typeof(XmlColorWrapper))] |
126 | 58 | public Color ValueColor { get; set; } = Color.FromArgb(255, 128, 0); |
127 | 59 |
|
128 | | - [XmlElement(Type = typeof(XmlColorWrapper))] |
129 | 60 | public Color IndexColor { get; set; } = Color.FromArgb(32, 200, 200); |
130 | 61 |
|
131 | | - [XmlElement(Type = typeof(XmlColorWrapper))] |
132 | 62 | public Color CommentColor { get; set; } = Color.FromArgb(0, 200, 0); |
133 | 63 |
|
134 | | - [XmlElement(Type = typeof(XmlColorWrapper))] |
135 | 64 | public Color TextColor { get; set; } = Color.FromArgb(0, 0, 255); |
136 | 65 |
|
137 | | - [XmlElement(Type = typeof(XmlColorWrapper))] |
138 | 66 | public Color VTableColor { get; set; } = Color.FromArgb(0, 255, 0); |
139 | 67 |
|
140 | | - [XmlElement(Type = typeof(XmlColorWrapper))] |
141 | 68 | public Color PluginColor { get; set; } = Color.FromArgb(255, 0, 255); |
142 | 69 |
|
143 | | - [XmlElement(Type = typeof(XmlColorWrapper))] |
144 | | - public Color CustomColor { get; set; } = Color.FromArgb(64, 128, 64); |
145 | | - |
146 | 70 | private static readonly Color[] highlightColors = { |
147 | 71 | Color.Aqua, Color.Aquamarine, Color.Blue, Color.BlueViolet, Color.Chartreuse, Color.Crimson, Color.LawnGreen, Color.Magenta |
148 | 72 | }; |
149 | | - [XmlIgnore] |
150 | 73 | public Color HighlightColor => highlightColors[Program.GlobalRandom.Next(highlightColors.Length)]; |
151 | 74 |
|
152 | 75 | // Type Definitions |
@@ -181,62 +104,12 @@ private static void EnsureSettingsDirectoryAvailable() |
181 | 104 | public string TypeUTF16Text { get; set; } = "wchar_t"; // Should be char16_t, but this type isn't well supported at the moment. |
182 | 105 | public string TypeUTF16TextPtr { get; set; } = "wchar_t*"; |
183 | 106 | public string TypeUTF32Text { get; set; } = "char32_t"; |
184 | | - public string TypeUTF32PtrText { get; set; } = "char32_t*"; |
| 107 | + public string TypeUTF32TextPtr { get; set; } = "char32_t*"; |
185 | 108 |
|
186 | 109 | public string TypeFunctionPtr { get; set; } = "void*"; |
187 | 110 |
|
188 | | - public Settings Clone() => MemberwiseClone() as Settings; |
189 | | - } |
| 111 | + public Dictionary<string, string> CustomData { get; } = new Dictionary<string, string>(); |
190 | 112 |
|
191 | | - public class XmlColorWrapper : IXmlSerializable |
192 | | - { |
193 | | - private Color color; |
194 | | - |
195 | | - public XmlColorWrapper() |
196 | | - : this(Color.Empty) |
197 | | - { |
198 | | - |
199 | | - } |
200 | | - |
201 | | - public XmlColorWrapper(Color color) |
202 | | - { |
203 | | - this.color = color; |
204 | | - } |
205 | | - |
206 | | - public XmlSchema GetSchema() |
207 | | - { |
208 | | - return null; |
209 | | - } |
210 | | - |
211 | | - public void ReadXml(XmlReader reader) |
212 | | - { |
213 | | - color = Color.FromArgb((int)(0xFF000000 | reader.ReadElementContentAsInt())); |
214 | | - } |
215 | | - |
216 | | - public void WriteXml(XmlWriter writer) |
217 | | - { |
218 | | - writer.WriteString(color.ToRgb().ToString()); |
219 | | - } |
220 | | - |
221 | | - |
222 | | - public static implicit operator XmlColorWrapper(Color color) |
223 | | - { |
224 | | - if (color != Color.Empty) |
225 | | - { |
226 | | - return new XmlColorWrapper(color); |
227 | | - } |
228 | | - |
229 | | - return null; |
230 | | - } |
231 | | - |
232 | | - public static implicit operator Color(XmlColorWrapper wrapper) |
233 | | - { |
234 | | - if (wrapper != null) |
235 | | - { |
236 | | - return wrapper.color; |
237 | | - } |
238 | | - |
239 | | - return Color.Empty; |
240 | | - } |
| 113 | + public Settings Clone() => MemberwiseClone() as Settings; |
241 | 114 | } |
242 | 115 | } |
0 commit comments