Repository navigation
Expand file tree
/
Copy pathConfigHelper.cs
More file actions
executable file
·91 lines (83 loc) · 2.28 KB
/
Copy pathConfigHelper.cs
File metadata and controls
executable file
·91 lines (83 loc) · 2.28 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace Plugin
{
public class ConfigHelper
{
public string Path { get;private set; }
private List<string> keys = new List<string>();
private List<string> values = new List<string>();
public ConfigHelper(string path)
{
Path = path;
load();
}
private void load()
{
if(File.Exists(Path))
{
using (StreamReader sr = new StreamReader(Path))
{
while(!sr.EndOfStream)
{
string str = sr.ReadLine();
int i = str.IndexOf(":");
if(i>0)
{
keys.Add(str.Substring(0,i));
values.Add(str.Substring(i + 1));
}
}
}
}
}
public void Put(string key,string value)
{
if(string.IsNullOrEmpty(key)||string.IsNullOrEmpty(value))
{
}
else
{
int index=keys.IndexOf(key);
if (index < 0)
{
keys.Add(key);
values.Add(value);
}else
{
keys[index] = key;
values[index] = value;
}
}
}
public void Commit()
{
try
{
using (StreamWriter sw = new StreamWriter(Path))
{
for(int i=0;i<keys.Count;i++)
{
sw.WriteLine(keys[i] + ":" + values[i]);
}
}
}
catch
{
throw;
}
}
public string Get(string key,string defaultValue)
{
int index=keys.IndexOf(key);
if(index>=0)
{
return values[index];
}
return defaultValue;
}
}
}