-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSettings.cs
66 lines (56 loc) · 1.74 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
using System;
using System.IO;
using System.Reflection;
using System.Xml;
using System.Xml.Serialization;
namespace DeZogPlugin
{
/// <summary>
/// Debugger Settings
/// </summary>
public class Settings
{
/// <summary>The port that clients can connect to.</summary>
public int Port { get; set; } = 11000; // Default
/// <summary>If log is enabled.</summary>
public bool LogEnabled { get; set; } = false; // Default
/// <summary>Constructor.</summary>
public Settings(){ }
/// <summary>
/// Load the settings file.
/// </summary>
/// <returns></returns>
public static Settings Load()
{
Settings settings;
string fileName = GetFileName();
try
{
string xml = File.ReadAllText(fileName);
var reader = new StringReader(xml);
using (reader)
{
var serializer = new XmlSerializer(typeof(Settings));
settings = (Settings)serializer.Deserialize(reader);
reader.Close();
}
}
catch (Exception /*exc*/)
{
// Maybe file does not exist.
settings = new Settings();
}
return settings;
}
/**
* Returns the settings filename.
* I.e. DeZogpPlugin.dll.config
*/
protected static string GetFileName()
{
string path = AppDomain.CurrentDomain.BaseDirectory;
var dll = Assembly.GetAssembly(typeof(Settings)).ManifestModule.ScopeName + ".config";
return Path.Combine(path, dll);
}
}
}