From 8cc04a5f22ae4bdd5c7db268a78ff90c27cdc258 Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Fri, 24 Mar 2023 13:05:18 +0300 Subject: [PATCH] UI: Load password from registry when "Check Password on Uninstalll" enabled --- src/ui/fortsettings.cpp | 14 ++++++++++++++ src/ui/fortsettings.h | 6 ++++-- src/ui/util/startuputil.cpp | 11 ++++++++++- src/ui/util/startuputil.h | 1 + 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/ui/fortsettings.cpp b/src/ui/fortsettings.cpp index 8ea8e8a5..eb040de3 100644 --- a/src/ui/fortsettings.cpp +++ b/src/ui/fortsettings.cpp @@ -328,6 +328,19 @@ void FortSettings::readConfIni(FirewallConf &conf) const conf.setActivePeriodFrom(DateUtil::reformatTime(iniText("activePeriodFrom"))); conf.setActivePeriodTo(DateUtil::reformatTime(iniText("activePeriodTo"))); ini()->endGroup(); + + // Ini Options + { + const IniOptions &ini = conf.ini(); + + // Password + if (ini.checkPasswordOnUninstall()) { + const QString regPasswordHash = StartupUtil::registryPasswordHash(); + if (!regPasswordHash.isEmpty()) { + setCacheValue(passwordHashKey(), regPasswordHash); + } + } + } } void FortSettings::writeConfIni(const FirewallConf &conf) @@ -362,6 +375,7 @@ void FortSettings::writeConfIni(const FirewallConf &conf) changed = true; } + // Ini Options if (conf.iniEdited()) { const IniOptions &ini = conf.ini(); diff --git a/src/ui/fortsettings.h b/src/ui/fortsettings.h index d8ef1047..5f744373 100644 --- a/src/ui/fortsettings.h +++ b/src/ui/fortsettings.h @@ -13,8 +13,10 @@ class FortSettings : public Settings public: explicit FortSettings(QObject *parent = nullptr); - QString passwordHash() const { return iniText("base/passwordHash"); } - void setPasswordHash(const QString &v) { setIniValue("base/passwordHash", v); } + static QString passwordHashKey() { return "base/passwordHash"; } + + QString passwordHash() const { return iniText(passwordHashKey()); } + void setPasswordHash(const QString &v) { setIniValue(passwordHashKey(), v); } bool isDefaultProfilePath() const { return m_isDefaultProfilePath; } bool noCache() const { return m_noCache; } diff --git a/src/ui/util/startuputil.cpp b/src/ui/util/startuputil.cpp index 8ae894f4..66fee483 100644 --- a/src/ui/util/startuputil.cpp +++ b/src/ui/util/startuputil.cpp @@ -282,11 +282,20 @@ void StartupUtil::setExplorerIntegrated(bool integrate) } } +QString StartupUtil::registryPasswordHash() +{ + const RegKey regApp(RegKey::HKLM, R"(SOFTWARE)"); + + const RegKey reg(regApp, APP_NAME); + + return reg.value("passwordHash").toString(); +} + void StartupUtil::setRegistryPasswordHash(const QString &passwordHash) { const bool isAdding = !passwordHash.isEmpty(); - RegKey regApp(RegKey::HKLM, R"(SOFTWARE)", + const RegKey regApp(RegKey::HKLM, R"(SOFTWARE)", isAdding ? RegKey::DefaultCreate : RegKey::DefaultReadWrite); RegKey reg(regApp, APP_NAME, RegKey::DefaultCreate); diff --git a/src/ui/util/startuputil.h b/src/ui/util/startuputil.h index 1295c68d..ace7c45d 100644 --- a/src/ui/util/startuputil.h +++ b/src/ui/util/startuputil.h @@ -21,6 +21,7 @@ public: static bool isExplorerIntegrated(); static void setExplorerIntegrated(bool integrate); + static QString registryPasswordHash(); static void setRegistryPasswordHash(const QString &passwordHash); static void setPortable(bool portable);