Skip to content

Commit 918d447

Browse files
committed
Seperate serialization of settings.
Added custom data to settings.
1 parent 12b6476 commit 918d447

5 files changed

Lines changed: 261 additions & 135 deletions

File tree

ReClass.NET/CodeGenerator/CppCodeGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class CppCodeGenerator : ICodeGenerator
3333
[typeof(Utf16TextNode)] = Program.Settings.TypeUTF16Text,
3434
[typeof(Utf16TextPtrNode)] = Program.Settings.TypeUTF16TextPtr,
3535
[typeof(Utf32TextNode)] = Program.Settings.TypeUTF32Text,
36-
[typeof(Utf32TextPtrNode)] = Program.Settings.TypeUTF32PtrText,
36+
[typeof(Utf32TextPtrNode)] = Program.Settings.TypeUTF32TextPtr,
3737
[typeof(Vector2Node)] = Program.Settings.TypeVector2,
3838
[typeof(Vector3Node)] = Program.Settings.TypeVector3,
3939
[typeof(Vector4Node)] = Program.Settings.TypeVector4

ReClass.NET/Program.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Windows.Forms;
55
using Microsoft.SqlServer.MessageBox;
66
using ReClassNET.Core;
7-
using ReClassNET.DataExchange.ReClass;
87
using ReClassNET.Forms;
98
using ReClassNET.Logger;
109
using ReClassNET.Memory;
@@ -64,7 +63,7 @@ static void Main(string[] args)
6463

6564
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
6665

67-
Settings = Settings.Load();
66+
Settings = SettingsSerializer.Load();
6867
Logger = new GuiLogger();
6968
#if DEBUG
7069
using (var coreFunctions = new CoreFunctionsManager())
@@ -97,7 +96,7 @@ static void Main(string[] args)
9796
}
9897
#endif
9998

100-
Settings.Save(Settings);
99+
SettingsSerializer.Save(Settings);
101100
}
102101

103102
/// <summary>Shows the exception in a special form.</summary>

ReClass.NET/ReClass.NET.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@
456456
<Compile Include="Util\Rtf\RtfBuilder.RtfFormatLock.cs" />
457457
<Compile Include="Util\Rtf\RtfBuilder.RtfFormatWrapper.cs" />
458458
<Compile Include="Util\Rtf\RtfFont.cs" />
459+
<Compile Include="Util\SettingsSerializer.cs" />
459460
<Compile Include="Util\Util.cs" />
460461
<Compile Include="Util\ValueTypeWrapper.cs" />
461462
<Compile Include="Util\WinUtil.cs" />

ReClass.NET/Settings.cs

Lines changed: 4 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,10 @@
1-
using System;
2-
using System.Diagnostics.Contracts;
1+
using System.Collections.Generic;
32
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;
93

104
namespace ReClassNET
115
{
126
public class Settings
137
{
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-
678
// Application Settings
689

6910
public string LastProcess { get; set; } = string.Empty;
@@ -98,55 +39,37 @@ private static void EnsureSettingsDirectoryAvailable()
9839

9940
// Colors
10041

101-
[XmlElement(Type = typeof(XmlColorWrapper))]
10242
public Color BackgroundColor { get; set; } = Color.FromArgb(255, 255, 255);
10343

104-
[XmlElement(Type = typeof(XmlColorWrapper))]
10544
public Color SelectedColor { get; set; } = Color.FromArgb(240, 240, 240);
10645

107-
[XmlElement(Type = typeof(XmlColorWrapper))]
10846
public Color HiddenColor { get; set; } = Color.FromArgb(240, 240, 240);
10947

110-
[XmlElement(Type = typeof(XmlColorWrapper))]
11148
public Color OffsetColor { get; set; } = Color.FromArgb(255, 0, 0);
11249

113-
[XmlElement(Type = typeof(XmlColorWrapper))]
11450
public Color AddressColor { get; set; } = Color.FromArgb(0, 200, 0);
11551

116-
[XmlElement(Type = typeof(XmlColorWrapper))]
11752
public Color HexColor { get; set; } = Color.FromArgb(0, 0, 0);
11853

119-
[XmlElement(Type = typeof(XmlColorWrapper))]
12054
public Color TypeColor { get; set; } = Color.FromArgb(0, 0, 255);
12155

122-
[XmlElement(Type = typeof(XmlColorWrapper))]
12356
public Color NameColor { get; set; } = Color.FromArgb(32, 32, 128);
12457

125-
[XmlElement(Type = typeof(XmlColorWrapper))]
12658
public Color ValueColor { get; set; } = Color.FromArgb(255, 128, 0);
12759

128-
[XmlElement(Type = typeof(XmlColorWrapper))]
12960
public Color IndexColor { get; set; } = Color.FromArgb(32, 200, 200);
13061

131-
[XmlElement(Type = typeof(XmlColorWrapper))]
13262
public Color CommentColor { get; set; } = Color.FromArgb(0, 200, 0);
13363

134-
[XmlElement(Type = typeof(XmlColorWrapper))]
13564
public Color TextColor { get; set; } = Color.FromArgb(0, 0, 255);
13665

137-
[XmlElement(Type = typeof(XmlColorWrapper))]
13866
public Color VTableColor { get; set; } = Color.FromArgb(0, 255, 0);
13967

140-
[XmlElement(Type = typeof(XmlColorWrapper))]
14168
public Color PluginColor { get; set; } = Color.FromArgb(255, 0, 255);
14269

143-
[XmlElement(Type = typeof(XmlColorWrapper))]
144-
public Color CustomColor { get; set; } = Color.FromArgb(64, 128, 64);
145-
14670
private static readonly Color[] highlightColors = {
14771
Color.Aqua, Color.Aquamarine, Color.Blue, Color.BlueViolet, Color.Chartreuse, Color.Crimson, Color.LawnGreen, Color.Magenta
14872
};
149-
[XmlIgnore]
15073
public Color HighlightColor => highlightColors[Program.GlobalRandom.Next(highlightColors.Length)];
15174

15275
// Type Definitions
@@ -181,62 +104,12 @@ private static void EnsureSettingsDirectoryAvailable()
181104
public string TypeUTF16Text { get; set; } = "wchar_t"; // Should be char16_t, but this type isn't well supported at the moment.
182105
public string TypeUTF16TextPtr { get; set; } = "wchar_t*";
183106
public string TypeUTF32Text { get; set; } = "char32_t";
184-
public string TypeUTF32PtrText { get; set; } = "char32_t*";
107+
public string TypeUTF32TextPtr { get; set; } = "char32_t*";
185108

186109
public string TypeFunctionPtr { get; set; } = "void*";
187110

188-
public Settings Clone() => MemberwiseClone() as Settings;
189-
}
111+
public Dictionary<string, string> CustomData { get; } = new Dictionary<string, string>();
190112

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;
241114
}
242115
}

0 commit comments

Comments
 (0)