From bd9519b60bb545f8a01ecadcde7942974c5d70c3 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Sun, 18 Oct 2015 19:13:40 +0200 Subject: [PATCH] Some improvements to reg_key_delete() function. --- include/MUtils/Registry.h | 2 +- src/Registry_Win32.cpp | 24 ++++++++++++++++++++++-- src/Startup.cpp | 2 +- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/include/MUtils/Registry.h b/include/MUtils/Registry.h index 3413034..a6824b8 100644 --- a/include/MUtils/Registry.h +++ b/include/MUtils/Registry.h @@ -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); } diff --git a/src/Registry_Win32.cpp b/src/Registry_Win32.cpp index 9df56db..42bcf8b 100644 --- a/src/Registry_Win32.cpp +++ b/src/Registry_Win32.cpp @@ -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; } diff --git a/src/Startup.cpp b/src/Startup.cpp index b4295bc..0b9137f 100644 --- a/src/Startup.cpp +++ b/src/Startup.cpp @@ -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); } } }