7 #include "uniregistrygen.h"
9 #include "wvlinkerhack.h"
16 static HKEY follow_path(HKEY from,
const UniConfKey &key,
17 bool create,
bool *isValue)
19 const REGSAM samDesired = KEY_READ | KEY_WRITE;
24 if (isValue) *isValue =
false;
33 result = RegCreateKeyEx(hLastKey, subkey, 0, NULL, 0, samDesired,
34 NULL, &hNextKey, NULL);
38 result = RegOpenKeyEx(hLastKey, subkey, 0, samDesired, &hNextKey);
41 if ((result == ERROR_FILE_NOT_FOUND) && (i == n-1))
43 WvString xsub(subkey==
"." ? WvString::null : subkey);
46 if (RegQueryValueEx(hLastKey, xsub, 0, NULL, NULL, NULL) == ERROR_SUCCESS)
49 if (isValue) *isValue =
true;
53 if (result != ERROR_SUCCESS)
61 RegCloseKey(hLastKey);
70 UniRegistryGen::UniRegistryGen(
WvString _moniker) :
71 m_log(_moniker), m_hRoot(0)
75 if (strcmp(
"HKEY_CLASSES_ROOT", hive) == 0)
77 m_hRoot = HKEY_CLASSES_ROOT;
79 else if (strcmp(
"HKEY_CURRENT_USER", hive) == 0)
81 m_hRoot = HKEY_CURRENT_USER;
83 else if (strcmp(
"HKEY_LOCAL_MACHINE", hive) == 0)
85 m_hRoot = HKEY_LOCAL_MACHINE;
87 else if (strcmp(
"HKEY_USERS", hive) == 0)
97 hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
98 RegNotifyChangeKeyValue(
101 REG_NOTIFY_CHANGE_NAME | REG_NOTIFY_CHANGE_ATTRIBUTES |
102 REG_NOTIFY_CHANGE_LAST_SET | REG_NOTIFY_CHANGE_SECURITY,
109 UniRegistryGen::~UniRegistryGen()
113 RegCloseKey(m_hRoot);
127 HKEY hKey = follow_path(m_hRoot, key,
false, &isvalue);
134 if (value ==
".") value = WvString::null;
139 value = WvString::null;
144 DWORD size =
sizeof(data) /
sizeof(data[0]);
145 LONG result = RegQueryValueEx(
154 if (result == ERROR_SUCCESS)
160 itoa(*((
int *) data), retval.
edit(), 10);
170 if (hKey != m_hRoot) RegCloseKey(hKey);
177 HKEY hKey = follow_path(m_hRoot, key.
first( key.
numsegments()-1 ),
true, NULL);
187 if (last ==
".") last = WvString::null;
188 result = RegSetValueEx(
193 (BYTE *) value.
cstr(),
197 if (result == ERROR_SUCCESS)
202 if (hKey != m_hRoot) RegCloseKey(hKey);
231 : m_hKey(0), m_enumerating(KEYS), m_index(0), gen(gen), parent(key),
235 HKEY hKey = follow_path(base, key,
false, &isValue);
243 if (hKey != m_dontClose) RegCloseKey(hKey);
244 m_enumerating = VALUES;
253 if (m_hKey && m_hKey != m_dontClose)
260 current_key =
"YOU HAVE TO REWIND, DUMMY!";
261 m_enumerating = KEYS;
268 if (m_enumerating == KEYS)
270 LONG result = next_key();
271 if (result == ERROR_SUCCESS)
273 else if (result == ERROR_NO_MORE_ITEMS)
276 m_enumerating = VALUES;
281 fprintf(stderr,
"KEY_ENUM result: %ld\n", result);
286 assert(m_enumerating == VALUES);
287 LONG result = next_value();
288 if (result == ERROR_SUCCESS)
306 LONG UniRegistryGenIter::next_key()
309 return ERROR_NO_MORE_ITEMS;
313 DWORD size =
sizeof(data) /
sizeof(data[0]);
314 LONG result = RegEnumKeyEx(m_hKey, m_index++, data, &size, 0, 0, 0, &dontcare);
315 if (result == ERROR_SUCCESS)
321 LONG UniRegistryGenIter::next_value()
324 return ERROR_NO_MORE_ITEMS;
326 TCHAR data[1024] =
"";
327 DWORD size =
sizeof(data) /
sizeof(data[0]);
330 LONG result = RegEnumValue(m_hKey, m_index++, data, &size, 0, 0, 0, 0);
331 if (result != ERROR_SUCCESS)
335 return ERROR_SUCCESS;
344 #pragma warning(disable : 4073)
345 #pragma init_seg(lib)