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);
212 return !
get(key).isnull();
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) virtual bool haschildren(const UniConfKey &key)
Returns true if a key has children.
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
Represents a UniConf key which is a path in a hierarchy structured much like the traditional Unix fil...
The basic interface which is included by all other XPLC interfaces and objects.
void delta(const UniConfKey &key, WvStringParm value)
Call this when a key's value or children have possibly changed.
UniConfKey first(int n=1) const
Returns the path formed by the n first segments of this path.
virtual void set(const UniConfKey &key, WvStringParm value)
Stores a string value for a key into the registry.
An abstract data container that backs a UniConf tree.
UniConfKey segment(int n) const
Returns the specified segment of the path.
virtual Iter * iterator(const UniConfKey &key)
Returns an iterator over the children of the specified key.
An abstract iterator over keys and values in a generator.
UniConfKey last(int n=1) const
Returns the path formed by the n last segments of this path.
bool isnull() const
returns true if this string is null
UniConfKey range(int i, int j) const
Returns a range of segments.
const char * cstr() const
return a (const char *) for this string.
virtual UniConfKey key() const
Returns the current key.
A generator that exposes the windows registry.
virtual void rewind()
Rewinds the iterator.
virtual WvString get(const UniConfKey &key)
Fetches a string value for a key from the registry.
A type-safe version of WvMonikerBase that lets you provide create functions for object types other th...
int numsegments() const
Returns the number of segments in this path.
char * edit()
make the string editable, and return a non-const (char*)
virtual bool next()
Seeks to the next element in the sequence.
virtual ~UniRegistryGenIter()
Destroys the iterator.
virtual void setv(const UniConfPairList &pairs)
Stores multiple key-value pairs into the registry.
virtual bool exists(const UniConfKey &key)
Without fetching its value, returns true if a key exists.
virtual bool isok()
Determines if the generator is usable and working properly.
virtual WvString value() const
Returns the value of the current key.
WvString printable() const
Returns the canonical string representation of the path.
WvString is an implementation of a simple and efficient printable-string class.