forked from const586/p2pproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SettingManager.cs
56 lines (50 loc) · 1.56 KB
/
SettingManager.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using P2pProxy;
namespace P2pProxy
{
public class SettingManager
{
private XmlSettings.Settings _settings;
public SettingManager(string path)
{
_settings = new XmlSettings.Settings(path);
}
public int GetSetting(string section, string key, int defvalue)
{
int res;
if (!int.TryParse(_settings.GetValue(section, key), out res))
{
res = defvalue;
_settings.SetValue(section, key, defvalue.ToString());
}
return res;
}
public string GetSetting(string section, string key, string defvalue = null)
{
string res = _settings.GetValue(section, key);
if (!string.IsNullOrEmpty(defvalue) && string.IsNullOrEmpty(res) && defvalue != null)
{
res = defvalue;
_settings.SetValue(section, key, defvalue);
}
return res;
}
public bool GetSetting(string section, string key, bool defvalue)
{
bool res;
if (!bool.TryParse(_settings.GetValue(section, key), out res))
{
res = defvalue;
_settings.SetValue(section, key, defvalue.ToString());
}
return res;
}
public void SetSetting(string section, string key, object value)
{
_settings.SetValue(section, key, value.ToString());
}
}
}