-
Notifications
You must be signed in to change notification settings - Fork 4
/
Settings.cs
90 lines (81 loc) · 2.72 KB
/
Settings.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
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
using System.Text;
using Kbg.NppPluginNET.PluginInfrastructure;
using System.IO;
namespace ERPHelper
{
public enum IniSection
{
Connection,
Connections,
State,
WDStudio,
WDWebServices
}
public enum IniKey
{
Environment,
Names,
Password,
SavePassword,
Tenant,
URL,
Username,
Version,
Workspace,
WorkspaceFilter,
XSD
}
public static class Settings
{
public static string iniFilePath = null;
public static string Get(IniSection section, string key)
{
return Settings.Get(section.ToString(), key);
}
public static void Set(IniSection section, string key, string value)
{
Settings.Set(section.ToString(), key, value);
}
public static string Get(IniSection section, IniKey key)
{
return Settings.Get(section.ToString(), key.ToString());
}
public static void Set(IniSection section, IniKey key, string value)
{
Settings.Set(section.ToString(), key.ToString(), value);
}
public static string Get(IniSection section, string sectionSuffix, IniKey key)
{
return Settings.Get(section.ToString() + "." + sectionSuffix, key.ToString());
}
public static void Set(IniSection section, string sectionSuffix, IniKey key, string value)
{
Settings.Set(section.ToString() + "." + sectionSuffix, key.ToString(), value);
}
public static void DeleteSection(IniSection section, string sectionSuffix)
{
Settings.Set(section.ToString() + "." + sectionSuffix, null, null);
}
public static void Init(string pluginName)
{
StringBuilder sbIniFilePath = new StringBuilder(Win32.MAX_PATH);
Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETPLUGINSCONFIGDIR, Win32.MAX_PATH, sbIniFilePath);
iniFilePath = sbIniFilePath.ToString();
if (!Directory.Exists(iniFilePath)) Directory.CreateDirectory(iniFilePath);
iniFilePath = Path.Combine(iniFilePath, pluginName + ".ini");
}
public static void Cleanup()
{
}
public static void Set(string section, string key, string value)
{
Win32.WritePrivateProfileString(section, key, value, iniFilePath);
}
public static string Get(string section, string key)
{
StringBuilder ret = new StringBuilder(500);
Utils.GetPrivateProfileString(section, key, "", ret, (uint)ret.Capacity, iniFilePath);
return ret.ToString();
}
}
}