mirror of
https://github.com/pocoproject/poco.git
synced 2025-11-02 14:03:41 +01:00
Make WinRegistryKey easier to extend
This commit is contained in:
@@ -46,6 +46,12 @@ public:
|
||||
REGT_STRING_EXPAND = 2,
|
||||
REGT_BINARY = 3,
|
||||
REGT_DWORD = 4,
|
||||
REGT_DWORD_BIG_ENDIAN = 5,
|
||||
REGT_LINK = 6,
|
||||
REGT_MULTI_STRING = 7,
|
||||
REGT_RESOURCE_LIST = 8,
|
||||
REGT_FULL_RESOURCE_DESCRIPTOR = 9,
|
||||
REGT_RESOURCE_REQUIREMENTS_LIST = 10,
|
||||
REGT_QWORD = 11
|
||||
};
|
||||
|
||||
@@ -162,6 +168,7 @@ protected:
|
||||
void close();
|
||||
std::string key() const;
|
||||
std::string key(const std::string& valueName) const;
|
||||
HKEY handle();
|
||||
void handleSetError(const std::string& name);
|
||||
static HKEY handleFor(const std::string& rootKey);
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ std::string WinRegistryKey::getString(const std::string& name)
|
||||
#if defined(POCO_WIN32_UTF8)
|
||||
std::wstring uname;
|
||||
Poco::UnicodeConverter::toUTF16(name, uname);
|
||||
if (RegQueryValueExW(_hKey, uname.c_str(), NULL, &type, NULL, &size) != ERROR_SUCCESS || type != REG_SZ && type != REG_EXPAND_SZ)
|
||||
if (RegQueryValueExW(_hKey, uname.c_str(), NULL, &type, NULL, &size) != ERROR_SUCCESS || (type != REG_SZ && type != REG_EXPAND_SZ && type != REG_LINK))
|
||||
throw NotFoundException(key(name));
|
||||
if (size > 0)
|
||||
{
|
||||
@@ -128,7 +128,7 @@ std::string WinRegistryKey::getString(const std::string& name)
|
||||
return result;
|
||||
}
|
||||
#else
|
||||
if (RegQueryValueExA(_hKey, name.c_str(), NULL, &type, NULL, &size) != ERROR_SUCCESS || type != REG_SZ && type != REG_EXPAND_SZ)
|
||||
if (RegQueryValueExA(_hKey, name.c_str(), NULL, &type, NULL, &size) != ERROR_SUCCESS || (type != REG_SZ && type != REG_EXPAND_SZ && type != REG_LINK))
|
||||
throw NotFoundException(key(name));
|
||||
if (size > 0)
|
||||
{
|
||||
@@ -168,7 +168,7 @@ std::string WinRegistryKey::getStringExpand(const std::string& name)
|
||||
#if defined(POCO_WIN32_UTF8)
|
||||
std::wstring uname;
|
||||
Poco::UnicodeConverter::toUTF16(name, uname);
|
||||
if (RegQueryValueExW(_hKey, uname.c_str(), NULL, &type, NULL, &size) != ERROR_SUCCESS || type != REG_SZ && type != REG_EXPAND_SZ)
|
||||
if (RegQueryValueExW(_hKey, uname.c_str(), NULL, &type, NULL, &size) != ERROR_SUCCESS || (type != REG_SZ && type != REG_EXPAND_SZ && type != REG_LINK))
|
||||
throw NotFoundException(key(name));
|
||||
if (size > 0)
|
||||
{
|
||||
@@ -190,7 +190,7 @@ std::string WinRegistryKey::getStringExpand(const std::string& name)
|
||||
return result;
|
||||
}
|
||||
#else
|
||||
if (RegQueryValueExA(_hKey, name.c_str(), NULL, &type, NULL, &size) != ERROR_SUCCESS || type != REG_SZ && type != REG_EXPAND_SZ)
|
||||
if (RegQueryValueExA(_hKey, name.c_str(), NULL, &type, NULL, &size) != ERROR_SUCCESS || (type != REG_SZ && type != REG_EXPAND_SZ && type != REG_LINK))
|
||||
throw NotFoundException(key(name));
|
||||
if (size > 0)
|
||||
{
|
||||
@@ -280,10 +280,10 @@ int WinRegistryKey::getInt(const std::string& name)
|
||||
#if defined(POCO_WIN32_UTF8)
|
||||
std::wstring uname;
|
||||
Poco::UnicodeConverter::toUTF16(name, uname);
|
||||
if (RegQueryValueExW(_hKey, uname.c_str(), NULL, &type, (BYTE*) &data, &size) != ERROR_SUCCESS || type != REG_DWORD)
|
||||
if (RegQueryValueExW(_hKey, uname.c_str(), NULL, &type, (BYTE*) &data, &size) != ERROR_SUCCESS || (type != REG_DWORD && type != REG_DWORD_BIG_ENDIAN))
|
||||
throw NotFoundException(key(name));
|
||||
#else
|
||||
if (RegQueryValueExA(_hKey, name.c_str(), NULL, &type, (BYTE*) &data, &size) != ERROR_SUCCESS || type != REG_DWORD)
|
||||
if (RegQueryValueExA(_hKey, name.c_str(), NULL, &type, (BYTE*) &data, &size) != ERROR_SUCCESS || (type != REG_DWORD && type != REG_DWORD_BIG_ENDIAN))
|
||||
throw NotFoundException(key(name));
|
||||
#endif
|
||||
return data;
|
||||
@@ -443,8 +443,6 @@ WinRegistryKey::Type WinRegistryKey::type(const std::string& name)
|
||||
if (RegQueryValueExA(_hKey, name.c_str(), NULL, &type, NULL, &size) != ERROR_SUCCESS)
|
||||
throw NotFoundException(key(name));
|
||||
#endif
|
||||
if (type != REG_SZ && type != REG_EXPAND_SZ && type != REG_DWORD && type != REG_QWORD && type != REG_BINARY)
|
||||
throw NotFoundException(key(name)+": type not supported");
|
||||
|
||||
Type aType = (Type)type;
|
||||
return aType;
|
||||
@@ -558,6 +556,13 @@ std::string WinRegistryKey::key(const std::string& valueName) const
|
||||
}
|
||||
|
||||
|
||||
HKEY WinRegistryKey::handle()
|
||||
{
|
||||
open();
|
||||
return _hKey;
|
||||
}
|
||||
|
||||
|
||||
HKEY WinRegistryKey::handleFor(const std::string& rootKey)
|
||||
{
|
||||
if (rootKey == "HKEY_CLASSES_ROOT")
|
||||
|
||||
Reference in New Issue
Block a user