WinRegistryKey::getInt64 failed to read QWORD type from the windows registry.
BINARY data type support for WinRegistryKey
This commit is contained in:
Родитель
67b206f663
Коммит
93ed40c785
|
@ -44,6 +44,7 @@ public:
|
|||
REGT_NONE = 0,
|
||||
REGT_STRING = 1,
|
||||
REGT_STRING_EXPAND = 2,
|
||||
REGT_BINARY = 3,
|
||||
REGT_DWORD = 4,
|
||||
REGT_QWORD = 11
|
||||
};
|
||||
|
@ -96,6 +97,16 @@ public:
|
|||
///
|
||||
/// Throws a NotFoundException if the value does not exist.
|
||||
|
||||
void setBinary(const std::string& name, const std::string& value);
|
||||
/// Sets the string value (REG_BINARY) with the given name.
|
||||
/// An empty name denotes the default value.
|
||||
|
||||
std::string getBinary(const std::string& name);
|
||||
/// Returns the string value (REG_BINARY) with the given name.
|
||||
/// An empty name denotes the default value.
|
||||
///
|
||||
/// Throws a NotFoundException if the value does not exist.
|
||||
|
||||
void setInt(const std::string& name, int value);
|
||||
/// Sets the numeric (REG_DWORD) value with the given name.
|
||||
/// An empty name denotes the default value.
|
||||
|
@ -108,6 +119,10 @@ public:
|
|||
|
||||
#if defined(POCO_HAVE_INT64)
|
||||
|
||||
void setInt64(const std::string& name, Poco::Int64 value);
|
||||
/// Sets the numeric (REG_QWORD) value with the given name.
|
||||
/// An empty name denotes the default value.
|
||||
|
||||
Poco::Int64 getInt64(const std::string& name);
|
||||
/// Returns the numeric value (REG_QWORD) with the given name.
|
||||
/// An empty name denotes the default value.
|
||||
|
|
|
@ -62,6 +62,9 @@ bool WinRegistryConfiguration::getRaw(const std::string& key, std::string& value
|
|||
case WinRegistryKey::REGT_STRING_EXPAND:
|
||||
value = aKey.getStringExpand(keyName);
|
||||
break;
|
||||
case WinRegistryKey::REGT_BINARY:
|
||||
value = aKey.getBinary(keyName);
|
||||
break;
|
||||
case WinRegistryKey::REGT_DWORD:
|
||||
value = Poco::NumberFormatter::format(aKey.getInt(keyName));
|
||||
break;
|
||||
|
|
|
@ -212,6 +212,56 @@ std::string WinRegistryKey::getStringExpand(const std::string& name)
|
|||
}
|
||||
|
||||
|
||||
|
||||
void WinRegistryKey::setBinary( const std::string& name, const std::string& value )
|
||||
{
|
||||
open();
|
||||
#if defined(POCO_WIN32_UTF8)
|
||||
std::wstring uname;
|
||||
Poco::UnicodeConverter::toUTF16(name, uname);
|
||||
if (RegSetValueExW(_hKey, uname.c_str(), 0, REG_BINARY, (CONST BYTE*) value.c_str(), (DWORD) value.size()) != ERROR_SUCCESS)
|
||||
handleSetError(name);
|
||||
#else
|
||||
if (RegSetValueExA(_hKey, name.c_str(), 0, REG_BINARY, (CONST BYTE*) value.c_str(), (DWORD) value.size()) != ERROR_SUCCESS)
|
||||
handleSetError(name);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
std::string WinRegistryKey::getBinary( const std::string& name )
|
||||
{
|
||||
open();
|
||||
DWORD type;
|
||||
DWORD size;
|
||||
#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_BINARY)
|
||||
throw NotFoundException(key(name));
|
||||
if (size > 0)
|
||||
{
|
||||
char* buffer = new char[size];
|
||||
RegQueryValueExW(_hKey, uname.c_str(), NULL, NULL, (BYTE*) buffer, &size);
|
||||
std::string result(buffer, size);
|
||||
delete [] buffer;
|
||||
return result;
|
||||
}
|
||||
#else
|
||||
if (RegQueryValueExA(_hKey, name.c_str(), NULL, &type, NULL, &size) != ERROR_SUCCESS || type != REG_BINARY)
|
||||
throw NotFoundException(key(name));
|
||||
if (size > 0)
|
||||
{
|
||||
char* buffer = new char[size];
|
||||
RegQueryValueExA(_hKey, name.c_str(), NULL, NULL, (BYTE*) buffer, &size);
|
||||
std::string result(buffer, size);
|
||||
delete [] buffer;
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
return std::string();
|
||||
}
|
||||
|
||||
|
||||
void WinRegistryKey::setInt(const std::string& name, int value)
|
||||
{
|
||||
open();
|
||||
|
@ -248,6 +298,20 @@ int WinRegistryKey::getInt(const std::string& name)
|
|||
|
||||
#if defined(POCO_HAVE_INT64)
|
||||
|
||||
void WinRegistryKey::setInt64(const std::string& name, Poco::Int64 value)
|
||||
{
|
||||
open();
|
||||
#if defined(POCO_WIN32_UTF8)
|
||||
std::wstring uname;
|
||||
Poco::UnicodeConverter::toUTF16(name, uname);
|
||||
if (RegSetValueExW(_hKey, uname.c_str(), 0, REG_QWORD, (CONST BYTE*) &value, sizeof(value)) != ERROR_SUCCESS)
|
||||
handleSetError(name);
|
||||
#else
|
||||
if (RegSetValueExA(_hKey, name.c_str(), 0, REG_QWORD, (CONST BYTE*) &value, sizeof(value)) != ERROR_SUCCESS)
|
||||
handleSetError(name);
|
||||
#endif
|
||||
}
|
||||
|
||||
Poco::Int64 WinRegistryKey::getInt64(const std::string& name)
|
||||
{
|
||||
open();
|
||||
|
@ -257,10 +321,10 @@ Poco::Int64 WinRegistryKey::getInt64(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_QWORD)
|
||||
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_QWORD)
|
||||
throw NotFoundException(key(name));
|
||||
#endif
|
||||
return data;
|
||||
|
@ -380,7 +444,7 @@ 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)
|
||||
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;
|
||||
|
|
Загрузка…
Ссылка в новой задаче