mirror of
https://github.com/pocoproject/poco.git
synced 2025-11-07 14:37:32 +01:00
Make WinRegistryKey easier to extend
This commit is contained in:
@@ -46,6 +46,12 @@ public:
|
|||||||
REGT_STRING_EXPAND = 2,
|
REGT_STRING_EXPAND = 2,
|
||||||
REGT_BINARY = 3,
|
REGT_BINARY = 3,
|
||||||
REGT_DWORD = 4,
|
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
|
REGT_QWORD = 11
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -162,6 +168,7 @@ protected:
|
|||||||
void close();
|
void close();
|
||||||
std::string key() const;
|
std::string key() const;
|
||||||
std::string key(const std::string& valueName) const;
|
std::string key(const std::string& valueName) const;
|
||||||
|
HKEY handle();
|
||||||
void handleSetError(const std::string& name);
|
void handleSetError(const std::string& name);
|
||||||
static HKEY handleFor(const std::string& rootKey);
|
static HKEY handleFor(const std::string& rootKey);
|
||||||
|
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ std::string WinRegistryKey::getString(const std::string& name)
|
|||||||
#if defined(POCO_WIN32_UTF8)
|
#if defined(POCO_WIN32_UTF8)
|
||||||
std::wstring uname;
|
std::wstring uname;
|
||||||
Poco::UnicodeConverter::toUTF16(name, 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));
|
throw NotFoundException(key(name));
|
||||||
if (size > 0)
|
if (size > 0)
|
||||||
{
|
{
|
||||||
@@ -128,7 +128,7 @@ std::string WinRegistryKey::getString(const std::string& name)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
#else
|
#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));
|
throw NotFoundException(key(name));
|
||||||
if (size > 0)
|
if (size > 0)
|
||||||
{
|
{
|
||||||
@@ -168,7 +168,7 @@ std::string WinRegistryKey::getStringExpand(const std::string& name)
|
|||||||
#if defined(POCO_WIN32_UTF8)
|
#if defined(POCO_WIN32_UTF8)
|
||||||
std::wstring uname;
|
std::wstring uname;
|
||||||
Poco::UnicodeConverter::toUTF16(name, 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));
|
throw NotFoundException(key(name));
|
||||||
if (size > 0)
|
if (size > 0)
|
||||||
{
|
{
|
||||||
@@ -190,7 +190,7 @@ std::string WinRegistryKey::getStringExpand(const std::string& name)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
#else
|
#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));
|
throw NotFoundException(key(name));
|
||||||
if (size > 0)
|
if (size > 0)
|
||||||
{
|
{
|
||||||
@@ -280,10 +280,10 @@ int WinRegistryKey::getInt(const std::string& name)
|
|||||||
#if defined(POCO_WIN32_UTF8)
|
#if defined(POCO_WIN32_UTF8)
|
||||||
std::wstring uname;
|
std::wstring uname;
|
||||||
Poco::UnicodeConverter::toUTF16(name, 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));
|
throw NotFoundException(key(name));
|
||||||
#else
|
#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));
|
throw NotFoundException(key(name));
|
||||||
#endif
|
#endif
|
||||||
return data;
|
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)
|
if (RegQueryValueExA(_hKey, name.c_str(), NULL, &type, NULL, &size) != ERROR_SUCCESS)
|
||||||
throw NotFoundException(key(name));
|
throw NotFoundException(key(name));
|
||||||
#endif
|
#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;
|
Type aType = (Type)type;
|
||||||
return aType;
|
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)
|
HKEY WinRegistryKey::handleFor(const std::string& rootKey)
|
||||||
{
|
{
|
||||||
if (rootKey == "HKEY_CLASSES_ROOT")
|
if (rootKey == "HKEY_CLASSES_ROOT")
|
||||||
|
|||||||
Reference in New Issue
Block a user