forked from ambilight-4-mediaportal/AtmoWin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAtmoRegistry.cpp
More file actions
154 lines (134 loc) · 4.93 KB
/
Copy pathAtmoRegistry.cpp
File metadata and controls
154 lines (134 loc) · 4.93 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include "StdAfx.h"
#include "atmoregistry.h"
CAtmoRegistry::CAtmoRegistry(HKEY rootKey)
{
this->m_RootKey = rootKey;
}
CAtmoRegistry::~CAtmoRegistry(void)
{
}
int CAtmoRegistry::RegistryKeyExists(char *path) {
HKEY keyHandle;
if( RegOpenKeyEx(m_RootKey, path, 0, KEY_READ, &keyHandle) == ERROR_SUCCESS) {
RegCloseKey(keyHandle);
return 1;
}
return 0;
}
int CAtmoRegistry::RegistryValueExists(char *path, char *valueName) {
HKEY keyHandle;
int temp = 0;
DWORD size1;
DWORD valueType;
if( RegOpenKeyEx(m_RootKey, path, 0, KEY_READ, &keyHandle) == ERROR_SUCCESS) {
if(RegQueryValueEx( keyHandle, valueName, NULL, &valueType, NULL, &size1) == ERROR_SUCCESS) {
temp = 1;
}
RegCloseKey(keyHandle);
}
return temp;
}
long CAtmoRegistry::DeleteValue(char *path, char *valueName)
{
HKEY keyHandle;
long result;
if( (result = RegOpenKeyEx(m_RootKey, path, 0, KEY_WRITE, &keyHandle)) == ERROR_SUCCESS) {
result = RegDeleteValue(keyHandle, valueName);
RegCloseKey(keyHandle);
}
//ERROR_SUCCESS = ok everything else you have a problem*g*,
return result;
}
long CAtmoRegistry::DeleteKey(char *path, char *keyName)
{
HKEY keyHandle;
long result;
if( (result = RegOpenKeyEx(m_RootKey, path, 0, KEY_WRITE, &keyHandle)) == ERROR_SUCCESS) {
// be warned the key "keyName" will not be deleted if there are subkeys below him, values
// I think are ok and will be recusively deleted, but not keys...
// for this case we have to do a little bit more work!
result = RegDeleteKey(keyHandle, keyName);
RegCloseKey(keyHandle);
}
//ERROR_SUCCESS = ok everything else you have a problem*g*,
return result;
}
void CAtmoRegistry::WriteRegistryInt(char *path, char *valueName, int value) {
HKEY keyHandle;
if( RegCreateKeyEx(m_RootKey, path, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &keyHandle, NULL) == ERROR_SUCCESS) {
RegSetValueEx(keyHandle,valueName,0,REG_DWORD,(LPBYTE)&value,sizeof(int));
RegCloseKey(keyHandle);
}
}
void CAtmoRegistry::WriteRegistryString(char *path, char *valueName, char *value) {
HKEY keyHandle;
if( RegCreateKeyEx(m_RootKey, path, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &keyHandle, NULL) == ERROR_SUCCESS) {
RegSetValueEx(keyHandle,valueName,0,REG_SZ,(LPBYTE)value,(DWORD)(strlen(value)+1));
RegCloseKey(keyHandle);
}
}
void CAtmoRegistry::WriteRegistryDouble(char *path, char *valueName, double value) {
HKEY keyHandle;
if( RegCreateKeyEx(m_RootKey, path, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &keyHandle, NULL) == ERROR_SUCCESS) {
RegSetValueEx(keyHandle,valueName,0,REG_BINARY,(LPBYTE)&value,sizeof(double));
RegCloseKey(keyHandle);
}
}
int CAtmoRegistry::ReadRegistryInt(char *path, char *valueName, int default_value) {
HKEY keyHandle;
int tempValue;
DWORD size1;
DWORD valueType;
if( RegOpenKeyEx(m_RootKey, path, 0, KEY_READ, &keyHandle) == ERROR_SUCCESS) {
if(RegQueryValueEx( keyHandle, valueName, NULL, &valueType, NULL, &size1) == ERROR_SUCCESS) {
if(valueType == REG_DWORD) {
if(RegQueryValueEx( keyHandle, valueName, NULL, &valueType, (LPBYTE)&tempValue, &size1) == ERROR_SUCCESS) {
default_value = tempValue;
};
}
}
RegCloseKey(keyHandle);
}
return default_value;
}
char * CAtmoRegistry::ReadRegistryString(char *path, char *valueName, char *default_value) {
HKEY keyHandle;
char *tempValue = NULL;
DWORD size1;
DWORD valueType;
if( RegOpenKeyEx(m_RootKey, path, 0, KEY_READ, &keyHandle) == ERROR_SUCCESS) {
if(RegQueryValueEx( keyHandle, valueName, NULL, &valueType, NULL, &size1) == ERROR_SUCCESS) {
if((valueType == REG_SZ) && (size1>1)) {
// free
tempValue = (char *)malloc(size1+1); // +1 für NullByte`?
if(RegQueryValueEx( keyHandle, valueName, NULL, &valueType, (LPBYTE)tempValue, &size1) == ERROR_SUCCESS) {
default_value = tempValue;
};
}
}
RegCloseKey(keyHandle);
}
if(tempValue == NULL) {
// wenn tempValue nicht aus registry gelesen wurde dafür sorgen das ein neuer String mit der Kopie von DefaultValue
// geliefert wird - das macht das Handling des Rückgabewertes der Funktion einfacher - immer schön mit free freigeben!
default_value = strdup(default_value);
}
return default_value;
}
double CAtmoRegistry::ReadRegistryDouble(char *path, char *valueName, double default_value) {
HKEY keyHandle;
double tempValue;
DWORD size1;
DWORD valueType;
if( RegOpenKeyEx(m_RootKey, path, 0, KEY_READ, &keyHandle) == ERROR_SUCCESS) {
if(RegQueryValueEx( keyHandle, valueName, NULL, &valueType, NULL, &size1) == ERROR_SUCCESS) {
if((valueType == REG_BINARY) && (size1 == sizeof(double))) {
if(RegQueryValueEx( keyHandle, valueName, NULL, &valueType, (LPBYTE)&tempValue, &size1) == ERROR_SUCCESS) {
default_value = tempValue;
};
}
}
RegCloseKey(keyHandle);
}
return default_value;
}