fix: Delete HKEY_LOCAL_MACHINE\SOFTWARE\Deskflow when clearing settings

This commit is contained in:
Nick Bolton
2025-03-03 18:01:32 +00:00
committed by Chris Rizzitello
parent 9de268d293
commit b64942e3a3
18 changed files with 73 additions and 1 deletions

View File

@ -99,6 +99,10 @@ int main(int argc, char **argv)
&ipcServer, &ipc::DaemonIpcServer::stopProcessRequested, &daemon, &DaemonApp::clearWatchdogCommand, //
Qt::DirectConnection
);
QObject::connect(
&ipcServer, &ipc::DaemonIpcServer::clearSettingsRequested, &daemon, &DaemonApp::clearSettings, //
Qt::DirectConnection
);
daemonThread.start();
const auto exitCode = QCoreApplication::exec();

View File

@ -459,6 +459,7 @@ void MainWindow::clearSettings()
}
m_coreProcess.stop();
m_coreProcess.clearSettings();
m_saveOnExit = false;
diagnostic::clearSettings(m_configScopes, true);

View File

@ -46,4 +46,11 @@ public:
*/
virtual void setting(const std::string &valueName, const std::string &valueString) const = 0;
//@}
//! Delete settings
/*!
Deletes all Core settings from the system.
*/
virtual void clearSettings() const = 0;
//@}
};

View File

@ -67,6 +67,11 @@ void ArchSystemUnix::setting(const std::string &, const std::string &) const
{
}
void ArchSystemUnix::clearSettings() const
{
// Not implemented
}
std::string ArchSystemUnix::getLibsUsed(void) const
{
return "not implemented.\nuse lsof on shell";

View File

@ -24,6 +24,7 @@ public:
virtual std::string setting(const std::string &) const;
virtual void setting(const std::string &, const std::string &) const;
virtual std::string getLibsUsed(void) const;
virtual void clearSettings() const;
#ifndef __APPLE__
enum class InhibitScreenServices

View File

@ -165,6 +165,15 @@ void ArchMiscWindows::deleteValue(HKEY key, const TCHAR *name)
RegDeleteValue(key, name);
}
void ArchMiscWindows::deleteKeyTree(HKEY key, const TCHAR *name)
{
assert(key != NULL);
assert(name != NULL);
if (key == NULL || name == NULL)
return;
RegDeleteTree(key, name);
}
bool ArchMiscWindows::hasValue(HKEY key, const TCHAR *name)
{
DWORD type;

View File

@ -99,6 +99,9 @@ public:
//! Delete a value
static void deleteValue(HKEY parent, const TCHAR *name);
//! Delete a tree of keys from the registry
static void deleteKeyTree(HKEY parent, const TCHAR *name);
//! Test if a value exists
static bool hasValue(HKEY key, const TCHAR *name);

View File

@ -9,6 +9,7 @@
#include "arch/win32/ArchMiscWindows.h"
#include "arch/XArch.h"
#include "base/Log.h"
#include "common/constants.h"
#include "tchar.h"
@ -17,7 +18,7 @@
#include <psapi.h>
#include <windows.h>
static const char *s_settingsKeyNames[] = {_T("SOFTWARE"), _T(kAppName), NULL};
static const TCHAR *s_settingsKeyNames[] = {_T("SOFTWARE"), _T(kAppName), NULL};
//
// ArchSystemWindows
@ -86,6 +87,11 @@ void ArchSystemWindows::setting(const std::string &valueName, const std::string
ArchMiscWindows::setValue(key, valueName.c_str(), valueString.c_str());
}
void ArchSystemWindows::clearSettings() const
{
ArchMiscWindows::deleteKeyTree(HKEY_LOCAL_MACHINE, kWindowsRegistryKey);
}
bool ArchSystemWindows::isWOW64() const
{
#if WINVER >= _WIN32_WINNT_WINXP

View File

@ -23,6 +23,7 @@ public:
virtual std::string getPlatformName() const;
virtual std::string setting(const std::string &valueName) const;
virtual void setting(const std::string &valueName, const std::string &valueString) const;
virtual void clearSettings() const;
bool isWOW64() const;
};

View File

@ -15,6 +15,7 @@ const auto kVersionGitSha = "@GIT_SHA_SHORT@";
const auto kDaemonBinName = "@CMAKE_PROJECT_NAME@-daemon";
const auto kDaemonIpcName = "@CMAKE_PROJECT_NAME@-daemon";
const auto kDaemonLogFilename = "@CMAKE_PROJECT_NAME@-daemon.log";
const auto kWindowsRegistryKey = "SOFTWARE\\@CMAKE_PROJECT_PROPER_NAME@";
const auto kCopyright = //
"Copyright @CMAKE_PROJECT_COPYRIGHT@\n"

View File

@ -135,6 +135,12 @@ void DaemonApp::clearWatchdogCommand()
#endif
}
void DaemonApp::clearSettings()
{
LOG_INFO("clearing daemon settings");
ARCH->clearSettings();
}
DaemonApp::InitResult DaemonApp::init(IEventQueue *events, int argc, char **argv) // NOSONAR - CLI args
{
using enum InitResult;

View File

@ -52,6 +52,7 @@ public:
void setCommand(const QString &command);
void applyWatchdogCommand() const;
void clearWatchdogCommand();
void clearSettings();
std::string logFilename();
static DaemonApp &instance()

View File

@ -130,6 +130,10 @@ void DaemonIpcServer::processMessage(QLocalSocket *clientSocket, const QString &
} else if (command == "logPath") {
LOG_DEBUG("ipc server got log path request");
clientSocket->write("logPath=" + m_logFilename.toUtf8());
} else if (command == "clearSettings") {
LOG_DEBUG("ipc server got clear settings message");
Q_EMIT clearSettingsRequested();
clientSocket->write(kAckMessage);
} else {
LOG_WARN("ipc server got unknown message: %s", message.toUtf8().constData());
}

View File

@ -28,6 +28,7 @@ signals:
void commandChanged(const QString &command);
void startProcessRequested();
void stopProcessRequested();
void clearSettingsRequested();
private:
void processMessage(QLocalSocket *clientSocket, const QString &message);

View File

@ -746,4 +746,19 @@ QString CoreProcess::requestDaemonLogPath()
return logPath;
}
void CoreProcess::clearSettings()
{
if (m_appConfig.processMode() == ProcessMode::kDesktop) {
qDebug("no core settings to clear in desktop mode");
return;
}
if (m_appConfig.processMode() != ProcessMode::kService) {
qFatal("invalid process mode");
}
qInfo("clearing core settings through daemon");
m_daemonIpcClient->sendClearSettings();
}
} // namespace deskflow::gui

View File

@ -87,6 +87,7 @@ public:
void restart();
void cleanup();
void applyLogLevel();
void clearSettings();
// getters
Mode mode() const

View File

@ -194,4 +194,9 @@ QString DaemonIpcClient::requestLogPath()
return parts[1];
}
bool DaemonIpcClient::sendClearSettings()
{
return sendMessage("clearSettings");
}
} // namespace deskflow::gui::ipc

View File

@ -24,6 +24,7 @@ public:
bool sendLogLevel(const QString &logLevel);
bool sendStartProcess(const QString &command, ElevateMode elevateMode);
bool sendStopProcess();
bool sendClearSettings();
QString requestLogPath();
bool isConnected() const