This repository was archived by the owner on Oct 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.cpp
More file actions
66 lines (54 loc) · 1.73 KB
/
config.cpp
File metadata and controls
66 lines (54 loc) · 1.73 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
#include "config.h"
LPCTSTR EmConfig::ROOT_KEY=_T("Software\\EmSoft\\EmEditor v3\\Config");
LPCTSTR EmConfig::CUST_VALUE=_T("Cust");
EmConfig::EmConfig(HWND view_handle)
: m_view_handle(view_handle)
{
if (RegOpenKeyEx(HKEY_CURRENT_USER,ROOT_KEY,0,KEY_READ,&m_root_key)!=ERROR_SUCCESS) {
m_root_key=NULL;
}
}
EmConfig::~EmConfig()
{
RegCloseKey(m_root_key);
}
bool EmConfig::GetConfig(CCustomizeInfo& info,LPCTSTR name)
{
bool result=false;
TCHAR buffer[MAX_CONFIG_NAME];
if (!name) {
// Get the name of the current configuration.
Editor_GetConfigW(m_view_handle,buffer);
name=buffer;
}
HKEY config_key;
if (RegOpenKeyEx(m_root_key,name,0,KEY_READ,&config_key)==ERROR_SUCCESS) {
DWORD type,count;
if (RegQueryValueEx(config_key,CUST_VALUE,NULL,&type,NULL,&count)==ERROR_SUCCESS) {
if (type==REG_BINARY && count==sizeof(CCustomizeInfo)) {
result=(RegQueryValueEx(config_key,CUST_VALUE,NULL,NULL,(LPBYTE)&info,&count)==ERROR_SUCCESS);
}
}
RegCloseKey(config_key);
}
return result;
}
bool EmConfig::SetConfig(CCustomizeInfo const& info,LPCTSTR name)
{
bool result=false;
TCHAR buffer[MAX_CONFIG_NAME];
if (!name) {
// Get the name of the current configuration.
Editor_GetConfigW(m_view_handle,buffer);
name=buffer;
}
HKEY config_key;
if (RegOpenKeyEx(m_root_key,name,0,KEY_WRITE,&config_key)==ERROR_SUCCESS) {
result=(RegSetValueEx(config_key,CUST_VALUE,0,REG_BINARY,(LPBYTE)&info,sizeof(CCustomizeInfo))==ERROR_SUCCESS);
RegCloseKey(config_key);
}
if (result) {
Editor_LoadConfigW(m_view_handle,name);
}
return result;
}