From e1d0c281efe63faf417464bc2cf1e2ec2df15980 Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Fri, 10 Mar 2023 12:02:25 +0300 Subject: [PATCH] UI: Options: Add "Check password on Uninstall" flag --- src/ui/conf/confmanager.cpp | 6 ++++++ src/ui/conf/inioptions.h | 6 ++++++ src/ui/util/startuputil.cpp | 16 ++++++++++++++++ src/ui/util/startuputil.h | 2 ++ 4 files changed, 30 insertions(+) diff --git a/src/ui/conf/confmanager.cpp b/src/ui/conf/confmanager.cpp index 3f117509..353ef634 100644 --- a/src/ui/conf/confmanager.cpp +++ b/src/ui/conf/confmanager.cpp @@ -1321,6 +1321,12 @@ void ConfManager::saveExtFlags(const IniOptions &ini) if (ini.explorerIntegratedSet()) { StartupUtil::setExplorerIntegrated(ini.explorerIntegrated()); } + + // Check password on Uninstall + if (ini.checkPasswordOnUninstallSet() || ini.hasPasswordSet()) { + StartupUtil::setRegistryPasswordHash( + ini.checkPasswordOnUninstall() ? IoC()->passwordHash() : QString()); + } } void ConfManager::saveTasksByIni(const IniOptions &ini) diff --git a/src/ui/conf/inioptions.h b/src/ui/conf/inioptions.h index 6af8f1b5..53236f9e 100644 --- a/src/ui/conf/inioptions.h +++ b/src/ui/conf/inioptions.h @@ -22,6 +22,7 @@ public: void setLogConsole(bool v) { setValue("base/console", v); } bool hasPasswordSet() const { return contains("base/hasPassword_"); } + bool hasPassword() const { return valueBool("base/hasPassword_"); } void setHasPassword(bool v) { setValue("base/hasPassword_", v); } @@ -42,6 +43,11 @@ public: bool noServiceControl() const { return valueBool("protect/noServiceControl"); } void setNoServiceControl(bool v) { setValue("protect/noServiceControl", v); } + bool checkPasswordOnUninstallSet() const + { + return contains("protect/checkPasswordOnUninstall"); + } + bool checkPasswordOnUninstall() const { return valueBool("protect/checkPasswordOnUninstall"); } void setCheckPasswordOnUninstall(bool v) { setValue("protect/checkPasswordOnUninstall", v); } diff --git a/src/ui/util/startuputil.cpp b/src/ui/util/startuputil.cpp index 78b87051..6f988df2 100644 --- a/src/ui/util/startuputil.cpp +++ b/src/ui/util/startuputil.cpp @@ -269,6 +269,22 @@ void StartupUtil::setExplorerIntegrated(bool integrate) } } +void StartupUtil::setRegistryPasswordHash(const QString &passwordHash) +{ + const bool isAdding = !passwordHash.isEmpty(); + + RegKey regApp(RegKey::HKLM, R"(SOFTWARE)", + isAdding ? RegKey::DefaultCreate : RegKey::DefaultReadWrite); + + RegKey reg(regApp, APP_NAME, RegKey::DefaultCreate); + + if (isAdding) { + reg.setValue("passwordHash", passwordHash); + } else { + reg.removeValue("passwordHash"); + } +} + void StartupUtil::setPortable(bool portable) { const QString readmePortablePath = FileUtil::nativeAppBinLocation() + "/README.portable"; diff --git a/src/ui/util/startuputil.h b/src/ui/util/startuputil.h index 5f807b4b..1295c68d 100644 --- a/src/ui/util/startuputil.h +++ b/src/ui/util/startuputil.h @@ -21,6 +21,8 @@ public: static bool isExplorerIntegrated(); static void setExplorerIntegrated(bool integrate); + static void setRegistryPasswordHash(const QString &passwordHash); + static void setPortable(bool portable); };