forked from wakatime/visualstudio-wakatime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWakaTimeConfigFile.cs
56 lines (46 loc) · 1.8 KB
/
WakaTimeConfigFile.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.Text;
namespace WakaTime
{
class WakaTimeConfigFile
{
internal string ApiKey { get; set; }
internal string Proxy { get; set; }
internal bool Debug { get; set; }
private readonly string _configFilepath;
internal WakaTimeConfigFile()
{
_configFilepath = GetConfigFilePath();
Read();
}
internal void Read()
{
var ret = new StringBuilder(2083);
ApiKey = NativeMethods.GetPrivateProfileString("settings", "api_key", "", ret, 2083, _configFilepath) > 0
? ret.ToString()
: string.Empty;
Proxy = NativeMethods.GetPrivateProfileString("settings", "proxy", "", ret, 2083, _configFilepath) > 0
? ret.ToString()
: string.Empty;
// ReSharper disable once InvertIf
if (NativeMethods.GetPrivateProfileString("settings", "debug", "", ret, 2083, _configFilepath) > 0)
{
bool debug;
if (bool.TryParse(ret.ToString(), out debug))
Debug = debug;
}
}
internal void Save()
{
if (!string.IsNullOrEmpty(ApiKey))
NativeMethods.WritePrivateProfileString("settings", "api_key", ApiKey.Trim(), _configFilepath);
NativeMethods.WritePrivateProfileString("settings", "proxy", Proxy.Trim(), _configFilepath);
NativeMethods.WritePrivateProfileString("settings", "debug", Debug.ToString().ToLower(), _configFilepath);
}
static string GetConfigFilePath()
{
var userHomeDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
return userHomeDir + "\\.wakatime.cfg";
}
}
}