-
Notifications
You must be signed in to change notification settings - Fork 0
/
Config.cs
50 lines (40 loc) · 1.25 KB
/
Config.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
using System;
using System.Collections.Generic;
using System.IO;
using fastJSON;
namespace oftc_ircd_cs
{
[Serializable]
public class Config
{
private static readonly Dictionary<string, IConfigSection> ConfigSections =
new Dictionary<string, IConfigSection>();
public static void Load()
{
string json;
foreach (var section in ConfigSections.Values)
{
section.SetDefaults();
}
using (TextReader reader = File.OpenText("ircd.conf"))
{
json = reader.ReadToEnd();
}
var tmp = JSON.Instance.Parse(json);
var root = tmp as Dictionary<string, object>;
if (root == null)
throw new Exception("Config root is not an object");
foreach (var element in root)
{
IConfigSection section;
if (!ConfigSections.TryGetValue(element.Key, out section))
continue;
section.Process(element.Value);
}
}
public static void AddSection(string name, IConfigSection section)
{
ConfigSections.Add(name, section);
}
}
}