forked from maziac/DeZogPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettings.cs
70 lines (60 loc) · 1.65 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
using System;
using System.IO;
using System.Reflection;
using System.Xml;
using System.Xml.Serialization;
namespace DeZogPlugin
{
public class Settings
{
/**
* The port that clients can connect to.
*/
public int Port { get; set; } = 11000; // Default
/**
* If log is enabled.
*/
public bool LogEnabled { get; set; } = false; // Default
/**
* Constructor.
*/
public Settings()
{
}
/**
* Load the settings file.
*/
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);
}
}
}