Added enum_values() function to the Registry name-space.
This commit is contained in:
parent
78fa3cf146
commit
2e385f8b27
@ -70,6 +70,7 @@ namespace MUtils
|
||||
bool value_read(const QString &valueName, quint32 &value) const;
|
||||
bool value_read(const QString &valueName, QString &value) const;
|
||||
|
||||
bool enum_values (QStringList &list) const;
|
||||
bool enum_subkeys(QStringList &list) const;
|
||||
|
||||
private:
|
||||
@ -82,7 +83,8 @@ namespace MUtils
|
||||
MUTILS_API bool reg_value_read (const int &rootKey, const QString &keyName, const QString &valueName, quint32 &value);
|
||||
MUTILS_API bool reg_value_read (const int &rootKey, const QString &keyName, const QString &valueName, QString &value);
|
||||
MUTILS_API bool reg_key_delete (const int &rootKey, const QString &keyName);
|
||||
MUTILS_API bool reg_enum_subkeys(const int &rootKey, const QString &keyName, QStringList &subkeys);
|
||||
MUTILS_API bool reg_enum_values (const int &rootKey, const QString &keyName, QStringList &list);
|
||||
MUTILS_API bool reg_enum_subkeys(const int &rootKey, const QString &keyName, QStringList &list);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -143,6 +143,7 @@ bool MUtils::Registry::RegistryKey::value_write(const QString &valueName, const
|
||||
|
||||
bool MUtils::Registry::RegistryKey::value_read(const QString &valueName, quint32 &value) const
|
||||
{
|
||||
value = 0;
|
||||
DWORD size = sizeof(quint32), type = -1;
|
||||
CHECK_STATUS(KEY_READ);
|
||||
return (RegQueryValueEx(p->m_hKey, valueName.isEmpty() ? NULL : MUTILS_WCHR(valueName), 0, &type, reinterpret_cast<BYTE*>(&value), &size) == ERROR_SUCCESS) && (type == REG_DWORD);
|
||||
@ -150,8 +151,8 @@ bool MUtils::Registry::RegistryKey::value_read(const QString &valueName, quint32
|
||||
|
||||
bool MUtils::Registry::RegistryKey::value_read(const QString &valueName, QString &value) const
|
||||
{
|
||||
wchar_t buffer[2048];
|
||||
DWORD size = sizeof(wchar_t) * 2048, type = -1;
|
||||
value = QString();
|
||||
wchar_t buffer[2048]; DWORD size = sizeof(wchar_t) * 2048, type = -1;
|
||||
CHECK_STATUS(KEY_READ);
|
||||
if((RegQueryValueEx(p->m_hKey, valueName.isEmpty() ? NULL : MUTILS_WCHR(valueName), 0, &type, reinterpret_cast<BYTE*>(&(buffer[0])), &size) == ERROR_SUCCESS) && ((type == REG_SZ) || (type == REG_EXPAND_SZ)))
|
||||
{
|
||||
@ -161,6 +162,25 @@ bool MUtils::Registry::RegistryKey::value_read(const QString &valueName, QString
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MUtils::Registry::RegistryKey::enum_values(QStringList &list) const
|
||||
{
|
||||
wchar_t buffer[2048];
|
||||
list.clear();
|
||||
CHECK_STATUS(KEY_QUERY_VALUE);
|
||||
for(DWORD i = 0; i < UINT_MAX; i++)
|
||||
{
|
||||
DWORD size = 2048;
|
||||
const DWORD ret = RegEnumValue(p->m_hKey, i, buffer, &size, NULL, NULL, NULL, NULL);
|
||||
if(ret == ERROR_SUCCESS)
|
||||
{
|
||||
list << QString::fromUtf16(reinterpret_cast<const ushort*>(buffer));
|
||||
continue;
|
||||
}
|
||||
return (ret == ERROR_NO_MORE_ITEMS);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MUtils::Registry::RegistryKey::enum_subkeys(QStringList &list) const
|
||||
{
|
||||
wchar_t buffer[2048];
|
||||
@ -223,6 +243,10 @@ bool MUtils::Registry::reg_value_read(const int &rootKey, const QString &keyName
|
||||
{
|
||||
success = regKey.value_read(valueName, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
@ -237,11 +261,33 @@ bool MUtils::Registry::reg_value_read(const int &rootKey, const QString &keyName
|
||||
{
|
||||
success = regKey.value_read(valueName, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
value = QString();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read registry value
|
||||
* Enumerate value names
|
||||
*/
|
||||
bool MUtils::Registry::reg_enum_values(const int &rootKey, const QString &keyName, QStringList &values)
|
||||
{
|
||||
bool success = false;
|
||||
RegistryKey regKey(rootKey, keyName, access_readonly);
|
||||
if(regKey.isOpen())
|
||||
{
|
||||
success = regKey.enum_values(values);
|
||||
}
|
||||
else
|
||||
{
|
||||
values.clear();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
/*
|
||||
* Enumerate subkey names
|
||||
*/
|
||||
bool MUtils::Registry::reg_enum_subkeys(const int &rootKey, const QString &keyName, QStringList &subkeys)
|
||||
{
|
||||
@ -251,6 +297,10 @@ bool MUtils::Registry::reg_enum_subkeys(const int &rootKey, const QString &keyNa
|
||||
{
|
||||
success = regKey.enum_subkeys(subkeys);
|
||||
}
|
||||
else
|
||||
{
|
||||
subkeys.clear();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user