Some improvements to reg_key_delete() function.

This commit is contained in:
LoRd_MuldeR 2015-10-18 19:13:40 +02:00
parent 9038b60650
commit bd9519b60b
3 changed files with 24 additions and 4 deletions

View File

@ -83,7 +83,7 @@ namespace MUtils
MUTILS_API bool reg_value_read (const reg_root_t &rootKey, const QString &keyName, const QString &valueName, quint32 &value);
MUTILS_API bool reg_value_read (const reg_root_t &rootKey, const QString &keyName, const QString &valueName, QString &value);
MUTILS_API bool reg_key_exists (const reg_root_t &rootKey, const QString &keyName);
MUTILS_API bool reg_key_delete (const reg_root_t &rootKey, const QString &keyName);
MUTILS_API bool reg_key_delete (const reg_root_t &rootKey, const QString &keyName, const bool &recusrive = true, const bool &ascend = false);
MUTILS_API bool reg_enum_values (const reg_root_t &rootKey, const QString &keyName, QStringList &list);
MUTILS_API bool reg_enum_subkeys(const reg_root_t &rootKey, const QString &keyName, QStringList &list);
}

View File

@ -357,7 +357,27 @@ bool MUtils::Registry::reg_key_exists(const reg_root_t &rootKey, const QString &
/*
* Delete registry key
*/
bool MUtils::Registry::reg_key_delete(const reg_root_t &rootKey, const QString &keyName)
bool MUtils::Registry::reg_key_delete(const reg_root_t &rootKey, const QString &keyName, const bool &recusrive, const bool &ascend)
{
return (SHDeleteKey(registry_root(rootKey), MUTILS_WCHR(keyName)) == ERROR_SUCCESS);
bool okay = false;
if(recusrive)
{
okay = (SHDeleteKey(registry_root(rootKey), MUTILS_WCHR(keyName)) == ERROR_SUCCESS);
}
else
{
okay = (RegDeleteKey(registry_root(rootKey), MUTILS_WCHR(keyName)) == ERROR_SUCCESS);
}
if(ascend && okay)
{
const int pos = qMax(keyName.lastIndexOf(QLatin1Char('/')), keyName.lastIndexOf(QLatin1Char('\\')));
if(pos > 0)
{
reg_key_delete(rootKey, keyName.left(pos), false, true);
}
}
return okay;
}

View File

@ -222,7 +222,7 @@ static void qt_registry_cleanup(void)
wchar_t key[256];
if(_snwprintf_s(key, 256, _TRUNCATE, KEYS[i], version) > 0)
{
MUtils::Registry::reg_key_delete(MUtils::Registry::root_user, MUTILS_QSTR(key));
MUtils::Registry::reg_key_delete(MUtils::Registry::root_user, MUTILS_QSTR(key), true, true);
}
}
}