-
Notifications
You must be signed in to change notification settings - Fork 0
/
registry.cpp
54 lines (47 loc) · 1.49 KB
/
registry.cpp
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
#include "stdafx.h"
#define EE_EXTERN_ONLY
#define ETL_FRAME_CLASS_NAME CMyFrame
#include "template/etlframe.h"
#include "CMyFrame.h"
#include "settings.h"
#include "registry.h"
namespace settings {
// Reads settings from registry.
std::array<unsigned char, settingsSize> readSettings(HWND editor) {
DWORD dataSize = settingsSize;
BYTE readData[settingsSize];
if (Editor_RegQueryValue(editor, EEREG_EMEDITORPLUGIN, L"CharacterCount", L"settings",
REG_BINARY, readData, &dataSize, 0)
!= ERROR_SUCCESS) {
return defaultSettings;
};
if (dataSize != settingsSize)
return defaultSettings;
std::array<unsigned char, settingsSize> loadSettings = {0};
for (unsigned char i = 0; i < settingsSize; ++i) {
if (std::find(menus[i].begin(), menus[i].end(), readData[i]) != menus[i].end()) {
loadSettings[i] = readData[i];
} else {
return defaultSettings;
}
}
return loadSettings;
}
// Writes settings to registry and returns true if successful.
bool writeSettings(HWND editor, const std::array<unsigned char, settingsSize>& settings) {
return Editor_RegSetValue(editor, EEREG_EMEDITORPLUGIN, L"CharacterCount", L"settings",
REG_BINARY, settings.data(), static_cast<DWORD>(settings.size()), EE_REG_VARIABLE_SIZE)
== ERROR_SUCCESS;
}
// Deletes registry key.
void deleteSettings() {
HKEY key;
RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\EmSoft\\EmEditorPlugIns",
0, KEY_SET_VALUE, &key);
if (key != NULL) {
RegDeleteKey(key, L"CharacterCount");
RegFlushKey(key);
RegCloseKey(key);
}
}
}