Repository navigation
Expand file tree
/
Copy pathIniFile.cs
More file actions
50 lines (44 loc) · 1.94 KB
/
Copy pathIniFile.cs
File metadata and controls
50 lines (44 loc) · 1.94 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
using System.Collections.Generic;
using System.IO;
namespace Selenium.Internal {
class IniFile {
/// <summary>
/// Parse a Windows ini file without marshaling the values.
/// Multiline values are not supported
/// Incorrect sections or properties are silently skipped
/// </summary>
/// <param name="filePath">File path</param>
/// <returns>IniFile</returns>
public static Dictionary<string, Dictionary<string, string>> Load(string filePath) {
var sections = new Dictionary<string, Dictionary<string, string>>();
using (var reader = new StreamReader(filePath)) {
Dictionary<string, string> section = null;
string section_key = null;
while (!reader.EndOfStream) {
string line = reader.ReadLine().Trim();
if (line.Length == 0 || line[0] == ';')
continue;
if (line[0] == '[' && line[line.Length - 1] == ']') {
if (section != null)
sections.Add(section_key, section);
section = new Dictionary<string, string>();
section_key = line.Substring(1, line.Length - 2);
} else if (section != null) {
int i = line.IndexOf('=');
if (i > 0) {
string prop_key = line.Substring(0, i).Trim();
if (++i < line.Length) {
section[prop_key] = line.Substring(i).Trim();
} else {
section[prop_key] = string.Empty;
}
}
}
}
if (section != null)
sections.Add(section_key, section);
}
return sections;
}
}
}