-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathConfig.cs
57 lines (48 loc) · 1.68 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
51
52
53
54
55
56
57
using System;
using System.Configuration;
using System.Reflection;
using System.IO;
namespace GitSvnAuthManager
{
internal static class Config
{
private static readonly Lazy<Configuration> _config = new Lazy<Configuration> (() => {
ExeConfigurationFileMap config_map = new ExeConfigurationFileMap ();
config_map.ExeConfigFilename = Path.Combine (ConfigDir, "config");
return ConfigurationManager.OpenMappedExeConfiguration (config_map, ConfigurationUserLevel.None);
});
private static readonly Lazy<string> _config_dir = new Lazy<string> (() => {
string appdata_dir = Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData);
object[] attrs = System.Reflection.Assembly.GetExecutingAssembly ().GetCustomAttributes (typeof(AssemblyProductAttribute), false);
// in general attrs could be null or Length == 0, but we have the set in AssemblyInfo.cs
string product_name = ((AssemblyProductAttribute)attrs [0]).Product;
return Path.Combine (appdata_dir, product_name);
});
internal interface IConfigKeyValueCollection
{
string this [string key] {
get;
}
}
private class SettingsHelper : IConfigKeyValueCollection
{
private readonly KeyValueConfigurationCollection _settings;
public SettingsHelper (KeyValueConfigurationCollection settings)
{
_settings = settings;
}
public string this [string key] {
get {
var element = _settings [key];
return element == null ? null : element.Value;
}
}
}
public static string ConfigDir {
get { return _config_dir.Value; }
}
public static IConfigKeyValueCollection Settings {
get { return new SettingsHelper (_config.Value.AppSettings.Settings); }
}
}
}