From 71f967d53657fdc2b87f582abfc092b475870db5 Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Thu, 19 Dec 2024 14:31:12 -0500 Subject: [PATCH 01/11] Added basic high privilege checks and message box --- scwx-qt/scwx-qt.cmake | 6 ++- scwx-qt/source/scwx/qt/main/main.cpp | 17 ++++++++ .../source/scwx/qt/util/check_privilege.cpp | 43 +++++++++++++++++++ .../source/scwx/qt/util/check_privilege.hpp | 11 +++++ 4 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 scwx-qt/source/scwx/qt/util/check_privilege.cpp create mode 100644 scwx-qt/source/scwx/qt/util/check_privilege.hpp diff --git a/scwx-qt/scwx-qt.cmake b/scwx-qt/scwx-qt.cmake index 92ca70a4..087c61e5 100644 --- a/scwx-qt/scwx-qt.cmake +++ b/scwx-qt/scwx-qt.cmake @@ -353,7 +353,8 @@ set(SRC_UI_SETUP source/scwx/qt/ui/setup/audio_codec_page.cpp source/scwx/qt/ui/setup/map_provider_page.cpp source/scwx/qt/ui/setup/setup_wizard.cpp source/scwx/qt/ui/setup/welcome_page.cpp) -set(HDR_UTIL source/scwx/qt/util/color.hpp +set(HDR_UTIL source/scwx/qt/util/check_privilege.hpp + source/scwx/qt/util/color.hpp source/scwx/qt/util/file.hpp source/scwx/qt/util/geographic_lib.hpp source/scwx/qt/util/imgui.hpp @@ -367,7 +368,8 @@ set(HDR_UTIL source/scwx/qt/util/color.hpp source/scwx/qt/util/q_file_input_stream.hpp source/scwx/qt/util/time.hpp source/scwx/qt/util/tooltip.hpp) -set(SRC_UTIL source/scwx/qt/util/color.cpp +set(SRC_UTIL source/scwx/qt/util/check_privilege.cpp + source/scwx/qt/util/color.cpp source/scwx/qt/util/file.cpp source/scwx/qt/util/geographic_lib.cpp source/scwx/qt/util/imgui.cpp diff --git a/scwx-qt/source/scwx/qt/main/main.cpp b/scwx-qt/source/scwx/qt/main/main.cpp index 7d66c80d..e8a833b4 100644 --- a/scwx-qt/source/scwx/qt/main/main.cpp +++ b/scwx-qt/source/scwx/qt/main/main.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -31,6 +32,8 @@ #include #include +#include + #define QT6CT_LIBRARY #include #undef QT6CT_LIBRARY @@ -73,6 +76,20 @@ int main(int argc, char* argv[]) QCoreApplication::installTranslator(&translator); } + // Test to see if scwx was run with high privilege + if (scwx::qt::util::is_high_privilege()) + { + QMessageBox::StandardButton pressed = QMessageBox::warning( + nullptr, + "Warning: Running with High Privileges", + "Although Supercell-Wx can be run with high privileges, " + "it is not recommended", + QMessageBox::Ok | QMessageBox::Close); + if (pressed & QMessageBox::Ok) { + return 0; + } + } + if (!scwx::util::GetEnvironment("SCWX_TEST").empty()) { QStandardPaths::setTestModeEnabled(true); diff --git a/scwx-qt/source/scwx/qt/util/check_privilege.cpp b/scwx-qt/source/scwx/qt/util/check_privilege.cpp new file mode 100644 index 00000000..c33f87b4 --- /dev/null +++ b/scwx-qt/source/scwx/qt/util/check_privilege.cpp @@ -0,0 +1,43 @@ +#include "scwx/qt/util/check_privilege.hpp" +#include + +#ifdef _WIN32 +#include +#else +#include +#endif + +namespace scwx { +namespace qt { +namespace util { + +bool is_high_privilege() +{ +#if defined(_WIN32) + bool isAdmin = false; + HANDLE token = NULL; + TOKEN_ELEVATION elevation; + DWORD elevationSize = sizeof(TOKEN_ELEVATION); + + if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token)) + { + return false; + } + if (!GetTokenInformation( + token, TokenElevation, &elevation, elevationSize, &elevationSize)) + { + CloseHandle(token); + return false; + } + isAdmin = elevation.TokenIsElevated; + CloseHandle(token); + return isAdmin; +#elif defined(Q_OS_UNIX) + // On UNIX root is always uid 0. On Linux this is enforced by the kernal. + return geteuid() == 0; +#endif +} + +} // namespace util +} // namespace qt +} // namespace scwx diff --git a/scwx-qt/source/scwx/qt/util/check_privilege.hpp b/scwx-qt/source/scwx/qt/util/check_privilege.hpp new file mode 100644 index 00000000..1234f0ef --- /dev/null +++ b/scwx-qt/source/scwx/qt/util/check_privilege.hpp @@ -0,0 +1,11 @@ +#pragma once + +namespace scwx { +namespace qt { +namespace util { + +bool is_high_privilege(); + +} // namespace util +} // namespace qt +} // namespace scwx From 923dad4e2ec93750697586171607e8f4ee7148de Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Thu, 19 Dec 2024 17:08:46 -0500 Subject: [PATCH 02/11] Add specific dialog and setting for high privilege warning --- scwx-qt/scwx-qt.cmake | 3 + scwx-qt/source/scwx/qt/main/main.cpp | 85 ++++++++++++--- .../scwx/qt/settings/general_settings.cpp | 15 ++- .../scwx/qt/settings/general_settings.hpp | 1 + .../scwx/qt/ui/high_privilege_dialog.cpp | 47 ++++++++ .../scwx/qt/ui/high_privilege_dialog.hpp | 40 +++++++ .../scwx/qt/ui/high_privilege_dialog.ui | 101 ++++++++++++++++++ 7 files changed, 274 insertions(+), 18 deletions(-) create mode 100644 scwx-qt/source/scwx/qt/ui/high_privilege_dialog.cpp create mode 100644 scwx-qt/source/scwx/qt/ui/high_privilege_dialog.hpp create mode 100644 scwx-qt/source/scwx/qt/ui/high_privilege_dialog.ui diff --git a/scwx-qt/scwx-qt.cmake b/scwx-qt/scwx-qt.cmake index 087c61e5..a386d8b9 100644 --- a/scwx-qt/scwx-qt.cmake +++ b/scwx-qt/scwx-qt.cmake @@ -260,6 +260,7 @@ set(HDR_UI source/scwx/qt/ui/about_dialog.hpp source/scwx/qt/ui/edit_marker_dialog.hpp source/scwx/qt/ui/flow_layout.hpp source/scwx/qt/ui/gps_info_dialog.hpp + source/scwx/qt/ui/high_privilege_dialog.hpp source/scwx/qt/ui/hotkey_edit.hpp source/scwx/qt/ui/imgui_debug_dialog.hpp source/scwx/qt/ui/imgui_debug_widget.hpp @@ -291,6 +292,7 @@ set(SRC_UI source/scwx/qt/ui/about_dialog.cpp source/scwx/qt/ui/edit_marker_dialog.cpp source/scwx/qt/ui/flow_layout.cpp source/scwx/qt/ui/gps_info_dialog.cpp + source/scwx/qt/ui/high_privilege_dialog.cpp source/scwx/qt/ui/hotkey_edit.cpp source/scwx/qt/ui/imgui_debug_dialog.cpp source/scwx/qt/ui/imgui_debug_widget.cpp @@ -320,6 +322,7 @@ set(UI_UI source/scwx/qt/ui/about_dialog.ui source/scwx/qt/ui/edit_line_dialog.ui source/scwx/qt/ui/edit_marker_dialog.ui source/scwx/qt/ui/gps_info_dialog.ui + source/scwx/qt/ui/high_privilege_dialog.ui source/scwx/qt/ui/imgui_debug_dialog.ui source/scwx/qt/ui/layer_dialog.ui source/scwx/qt/ui/open_url_dialog.ui diff --git a/scwx-qt/source/scwx/qt/main/main.cpp b/scwx-qt/source/scwx/qt/main/main.cpp index e8a833b4..4a6445d0 100644 --- a/scwx-qt/source/scwx/qt/main/main.cpp +++ b/scwx-qt/source/scwx/qt/main/main.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -21,6 +22,7 @@ #include #include +#include #include #include @@ -32,8 +34,6 @@ #include #include -#include - #define QT6CT_LIBRARY #include #undef QT6CT_LIBRARY @@ -46,6 +46,9 @@ static void OverrideDefaultStyle(const std::vector& args); int main(int argc, char* argv[]) { + bool disableHighPrivilegeWarning = false; + bool highPrivilegeChecked = false; + // Store arguments std::vector args {}; for (int i = 0; i < argc; ++i) @@ -76,25 +79,35 @@ int main(int argc, char* argv[]) QCoreApplication::installTranslator(&translator); } - // Test to see if scwx was run with high privilege - if (scwx::qt::util::is_high_privilege()) - { - QMessageBox::StandardButton pressed = QMessageBox::warning( - nullptr, - "Warning: Running with High Privileges", - "Although Supercell-Wx can be run with high privileges, " - "it is not recommended", - QMessageBox::Ok | QMessageBox::Close); - if (pressed & QMessageBox::Ok) { - return 0; - } - } - if (!scwx::util::GetEnvironment("SCWX_TEST").empty()) { QStandardPaths::setTestModeEnabled(true); } + // Test to see if scwx was run with high privilege + std::string appDataPath { + QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + .toStdString()}; + + // Check if high privilege before writing settings, assuming no settings + // have been written + if (!std::filesystem::exists(appDataPath) && + scwx::qt::util::is_high_privilege()) + { + auto dialog = + scwx::qt::ui::HighPrivilegeDialog(); // TODO does this need cleaned up? + const int result = dialog.exec(); + + disableHighPrivilegeWarning = dialog.disable_high_privilege_message(); + highPrivilegeChecked = true; + + if (result == QDialog::Rejected) + { + // TODO any other cleanup needed here? + return 0; + } + } + // Start the io_context main loop boost::asio::io_context& ioContext = scwx::util::io_context(); auto work = boost::asio::make_work_guard(ioContext); @@ -133,6 +146,46 @@ int main(int argc, char* argv[]) // Check process modules for compatibility scwx::qt::main::CheckProcessModules(); + auto& generalSettings = scwx::qt::settings::GeneralSettings::Instance(); + + if (!highPrivilegeChecked && + generalSettings.high_privilege_warning_enabled().GetValue() && + scwx::qt::util::is_high_privilege()) + { + auto dialog = + scwx::qt::ui::HighPrivilegeDialog(); // TODO does this need cleaned up? + const int result = dialog.exec(); + + disableHighPrivilegeWarning = dialog.disable_high_privilege_message(); + + if (result == QDialog::Rejected) + { + // Deinitialize application + scwx::qt::manager::RadarProductManager::Cleanup(); + + // Stop Qt Threads + scwx::qt::manager::ThreadManager::Instance().StopThreads(); + + // Gracefully stop the io_context main loop + work.reset(); + threadPool.join(); + + // Shutdown application + scwx::qt::manager::ResourceManager::Shutdown(); + scwx::qt::manager::SettingsManager::Instance().Shutdown(); + + // Shutdown AWS SDK + Aws::ShutdownAPI(awsSdkOptions); + return 0; + } + } + + // Save high privilege settings + if (disableHighPrivilegeWarning) + { + generalSettings.high_privilege_warning_enabled().SetValue(false); + scwx::qt::manager::SettingsManager::Instance().SaveSettings(); + } // Run initial setup if required if (scwx::qt::ui::setup::SetupWizard::IsSetupRequired()) diff --git a/scwx-qt/source/scwx/qt/settings/general_settings.cpp b/scwx-qt/source/scwx/qt/settings/general_settings.cpp index 77ca764e..0abb45e9 100644 --- a/scwx-qt/source/scwx/qt/settings/general_settings.cpp +++ b/scwx-qt/source/scwx/qt/settings/general_settings.cpp @@ -80,6 +80,7 @@ public: warningsProvider_.SetDefault(defaultWarningsProviderValue); cursorIconAlwaysOn_.SetDefault(false); radarSiteThreshold_.SetDefault(0.0); + highPrivilegeWarningEnabled_.SetDefault(true); fontSizes_.SetElementMinimum(1); fontSizes_.SetElementMaximum(72); @@ -175,6 +176,8 @@ public: SettingsVariable warningsProvider_ {"warnings_provider"}; SettingsVariable cursorIconAlwaysOn_ {"cursor_icon_always_on"}; SettingsVariable radarSiteThreshold_ {"radar_site_threshold"}; + SettingsVariable highPrivilegeWarningEnabled_ { + "high_privilege_warning_enabled"}; }; GeneralSettings::GeneralSettings() : @@ -210,7 +213,8 @@ GeneralSettings::GeneralSettings() : &p->updateNotificationsEnabled_, &p->warningsProvider_, &p->cursorIconAlwaysOn_, - &p->radarSiteThreshold_}); + &p->radarSiteThreshold_, + &p->highPrivilegeWarningEnabled_}); SetDefaults(); } GeneralSettings::~GeneralSettings() = default; @@ -375,6 +379,11 @@ SettingsVariable& GeneralSettings::radar_site_threshold() const return p->radarSiteThreshold_; } +SettingsVariable& GeneralSettings::high_privilege_warning_enabled() const +{ + return p->highPrivilegeWarningEnabled_; +} + bool GeneralSettings::Shutdown() { bool dataChanged = false; @@ -429,7 +438,9 @@ bool operator==(const GeneralSettings& lhs, const GeneralSettings& rhs) rhs.p->updateNotificationsEnabled_ && lhs.p->warningsProvider_ == rhs.p->warningsProvider_ && lhs.p->cursorIconAlwaysOn_ == rhs.p->cursorIconAlwaysOn_ && - lhs.p->radarSiteThreshold_ == rhs.p->radarSiteThreshold_); + lhs.p->radarSiteThreshold_ == rhs.p->radarSiteThreshold_ && + lhs.p->highPrivilegeWarningEnabled_ == + rhs.p->highPrivilegeWarningEnabled_); } } // namespace settings diff --git a/scwx-qt/source/scwx/qt/settings/general_settings.hpp b/scwx-qt/source/scwx/qt/settings/general_settings.hpp index 6a49566b..074b956e 100644 --- a/scwx-qt/source/scwx/qt/settings/general_settings.hpp +++ b/scwx-qt/source/scwx/qt/settings/general_settings.hpp @@ -56,6 +56,7 @@ public: SettingsVariable& warnings_provider() const; SettingsVariable& cursor_icon_always_on() const; SettingsVariable& radar_site_threshold() const; + SettingsVariable& high_privilege_warning_enabled() const; static GeneralSettings& Instance(); diff --git a/scwx-qt/source/scwx/qt/ui/high_privilege_dialog.cpp b/scwx-qt/source/scwx/qt/ui/high_privilege_dialog.cpp new file mode 100644 index 00000000..0c60052a --- /dev/null +++ b/scwx-qt/source/scwx/qt/ui/high_privilege_dialog.cpp @@ -0,0 +1,47 @@ +#include "high_privilege_dialog.hpp" +#include "ui_high_privilege_dialog.h" + +#include +#include + +namespace scwx +{ +namespace qt +{ +namespace ui +{ + +static const std::string logPrefix_ = "scwx::qt::ui::high_privilege_dialog"; +static const auto logger_ = scwx::util::Logger::Create(logPrefix_); + +class HighPrivilegeDialogImpl +{ +public: + explicit HighPrivilegeDialogImpl(HighPrivilegeDialog* self) : + self_ {self} {}; + ~HighPrivilegeDialogImpl() = default; + + HighPrivilegeDialog* self_; +}; + +HighPrivilegeDialog::HighPrivilegeDialog(QWidget* parent) : + QDialog(parent), + p {std::make_unique(this)}, + ui(new Ui::HighPrivilegeDialog) +{ + ui->setupUi(this); +} + +bool HighPrivilegeDialog::disable_high_privilege_message() { + return ui->highPrivilegeCheckBox->isChecked(); +} + +HighPrivilegeDialog::~HighPrivilegeDialog() +{ + delete ui; +} + +} // namespace ui +} // namespace qt +} // namespace scwx + diff --git a/scwx-qt/source/scwx/qt/ui/high_privilege_dialog.hpp b/scwx-qt/source/scwx/qt/ui/high_privilege_dialog.hpp new file mode 100644 index 00000000..5271d245 --- /dev/null +++ b/scwx-qt/source/scwx/qt/ui/high_privilege_dialog.hpp @@ -0,0 +1,40 @@ +#pragma once + +#include + +namespace Ui +{ +class HighPrivilegeDialog; +} + +namespace scwx +{ +namespace qt +{ +namespace ui +{ + +class HighPrivilegeDialogImpl; + +class HighPrivilegeDialog : public QDialog +{ + Q_OBJECT + +private: + Q_DISABLE_COPY(HighPrivilegeDialog) + +public: + explicit HighPrivilegeDialog(QWidget* parent = nullptr); + ~HighPrivilegeDialog(); + + bool disable_high_privilege_message(); + +private: + friend HighPrivilegeDialogImpl; + std::unique_ptr p; + Ui::HighPrivilegeDialog* ui; +}; + +} // namespace ui +} // namespace qt +} // namespace scwx diff --git a/scwx-qt/source/scwx/qt/ui/high_privilege_dialog.ui b/scwx-qt/source/scwx/qt/ui/high_privilege_dialog.ui new file mode 100644 index 00000000..4d6f5075 --- /dev/null +++ b/scwx-qt/source/scwx/qt/ui/high_privilege_dialog.ui @@ -0,0 +1,101 @@ + + + HighPrivilegeDialog + + + + 0 + 0 + 301 + 269 + + + + + 0 + 0 + + + + Warning: High Privilege + + + + + + + 0 + 0 + + + + <html><head/><body><h1 align="center" style=" margin-top:18px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:xx-large; font-weight:700; color:#ff0000;">Warning: Run Supercell Wx with Low Privileges.</span></h1><p align="center">Please run Supercell Wx without admin or root permissions. Supercell Wx should not need such permissions to run. If you do not want to run Supercell Wx with high privilege, click &quot;Close&quot;, and relaunch with lower permissions. Otherwise, click &quot;Ignore&quot;. You may disable this warning with the checkbox below.</p></body></html> + + + Qt::TextFormat::RichText + + + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop + + + true + + + + + + + Disable High Privilege Warning + + + + + + + Qt::Orientation::Horizontal + + + QDialogButtonBox::StandardButton::Close|QDialogButtonBox::StandardButton::Ignore + + + + + + + + + + + buttonBox + accepted() + HighPrivilegeDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + HighPrivilegeDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + From 6408e1b876a1c162f428621a9dc6941897e97203 Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Thu, 19 Dec 2024 17:24:36 -0500 Subject: [PATCH 03/11] Fix formatting for high_privilege_warning --- scwx-qt/source/scwx/qt/main/main.cpp | 4 ++-- .../scwx/qt/ui/high_privilege_dialog.cpp | 6 +++--- .../scwx/qt/ui/high_privilege_dialog.hpp | 2 +- .../source/scwx/qt/util/check_privilege.cpp | 19 +++++++++++-------- .../source/scwx/qt/util/check_privilege.hpp | 9 ++++++--- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/scwx-qt/source/scwx/qt/main/main.cpp b/scwx-qt/source/scwx/qt/main/main.cpp index 4a6445d0..468aa1e6 100644 --- a/scwx-qt/source/scwx/qt/main/main.cpp +++ b/scwx-qt/source/scwx/qt/main/main.cpp @@ -85,7 +85,7 @@ int main(int argc, char* argv[]) } // Test to see if scwx was run with high privilege - std::string appDataPath { + const std::string appDataPath { QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) .toStdString()}; @@ -99,7 +99,7 @@ int main(int argc, char* argv[]) const int result = dialog.exec(); disableHighPrivilegeWarning = dialog.disable_high_privilege_message(); - highPrivilegeChecked = true; + highPrivilegeChecked = true; if (result == QDialog::Rejected) { diff --git a/scwx-qt/source/scwx/qt/ui/high_privilege_dialog.cpp b/scwx-qt/source/scwx/qt/ui/high_privilege_dialog.cpp index 0c60052a..c057e6a4 100644 --- a/scwx-qt/source/scwx/qt/ui/high_privilege_dialog.cpp +++ b/scwx-qt/source/scwx/qt/ui/high_privilege_dialog.cpp @@ -19,7 +19,7 @@ class HighPrivilegeDialogImpl public: explicit HighPrivilegeDialogImpl(HighPrivilegeDialog* self) : self_ {self} {}; - ~HighPrivilegeDialogImpl() = default; + ~HighPrivilegeDialogImpl() = default; HighPrivilegeDialog* self_; }; @@ -32,7 +32,8 @@ HighPrivilegeDialog::HighPrivilegeDialog(QWidget* parent) : ui->setupUi(this); } -bool HighPrivilegeDialog::disable_high_privilege_message() { +bool HighPrivilegeDialog::disable_high_privilege_message() +{ return ui->highPrivilegeCheckBox->isChecked(); } @@ -44,4 +45,3 @@ HighPrivilegeDialog::~HighPrivilegeDialog() } // namespace ui } // namespace qt } // namespace scwx - diff --git a/scwx-qt/source/scwx/qt/ui/high_privilege_dialog.hpp b/scwx-qt/source/scwx/qt/ui/high_privilege_dialog.hpp index 5271d245..b5d79ada 100644 --- a/scwx-qt/source/scwx/qt/ui/high_privilege_dialog.hpp +++ b/scwx-qt/source/scwx/qt/ui/high_privilege_dialog.hpp @@ -25,7 +25,7 @@ private: public: explicit HighPrivilegeDialog(QWidget* parent = nullptr); - ~HighPrivilegeDialog(); + ~HighPrivilegeDialog() override; bool disable_high_privilege_message(); diff --git a/scwx-qt/source/scwx/qt/util/check_privilege.cpp b/scwx-qt/source/scwx/qt/util/check_privilege.cpp index c33f87b4..2d7d1227 100644 --- a/scwx-qt/source/scwx/qt/util/check_privilege.cpp +++ b/scwx-qt/source/scwx/qt/util/check_privilege.cpp @@ -2,20 +2,23 @@ #include #ifdef _WIN32 -#include +# include #else -#include +# include #endif -namespace scwx { -namespace qt { -namespace util { +namespace scwx +{ +namespace qt +{ +namespace util +{ bool is_high_privilege() { #if defined(_WIN32) - bool isAdmin = false; - HANDLE token = NULL; + bool isAdmin = false; + HANDLE token = NULL; TOKEN_ELEVATION elevation; DWORD elevationSize = sizeof(TOKEN_ELEVATION); @@ -33,7 +36,7 @@ bool is_high_privilege() CloseHandle(token); return isAdmin; #elif defined(Q_OS_UNIX) - // On UNIX root is always uid 0. On Linux this is enforced by the kernal. + // On UNIX root is always uid 0. On Linux this is enforced by the kernel. return geteuid() == 0; #endif } diff --git a/scwx-qt/source/scwx/qt/util/check_privilege.hpp b/scwx-qt/source/scwx/qt/util/check_privilege.hpp index 1234f0ef..7a44a070 100644 --- a/scwx-qt/source/scwx/qt/util/check_privilege.hpp +++ b/scwx-qt/source/scwx/qt/util/check_privilege.hpp @@ -1,8 +1,11 @@ #pragma once -namespace scwx { -namespace qt { -namespace util { +namespace scwx +{ +namespace qt +{ +namespace util +{ bool is_high_privilege(); From 4a4075b50fea82a6cb73aa75a109727493eb7c88 Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Sat, 11 Jan 2025 13:36:32 -0500 Subject: [PATCH 04/11] Move dialog logic into check_privilege --- scwx-qt/source/scwx/qt/main/main.cpp | 93 ++++------------ .../scwx/qt/settings/general_settings.cpp | 1 + .../source/scwx/qt/util/check_privilege.cpp | 104 ++++++++++++++++-- .../source/scwx/qt/util/check_privilege.hpp | 27 +++-- 4 files changed, 136 insertions(+), 89 deletions(-) diff --git a/scwx-qt/source/scwx/qt/main/main.cpp b/scwx-qt/source/scwx/qt/main/main.cpp index 468aa1e6..4212050e 100644 --- a/scwx-qt/source/scwx/qt/main/main.cpp +++ b/scwx-qt/source/scwx/qt/main/main.cpp @@ -46,9 +46,6 @@ static void OverrideDefaultStyle(const std::vector& args); int main(int argc, char* argv[]) { - bool disableHighPrivilegeWarning = false; - bool highPrivilegeChecked = false; - // Store arguments std::vector args {}; for (int i = 0; i < argc; ++i) @@ -85,27 +82,10 @@ int main(int argc, char* argv[]) } // Test to see if scwx was run with high privilege - const std::string appDataPath { - QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) - .toStdString()}; - - // Check if high privilege before writing settings, assuming no settings - // have been written - if (!std::filesystem::exists(appDataPath) && - scwx::qt::util::is_high_privilege()) + scwx::qt::util::PrivilegeChecker privilegeChecker; + if (privilegeChecker.first_check()) { - auto dialog = - scwx::qt::ui::HighPrivilegeDialog(); // TODO does this need cleaned up? - const int result = dialog.exec(); - - disableHighPrivilegeWarning = dialog.disable_high_privilege_message(); - highPrivilegeChecked = true; - - if (result == QDialog::Rejected) - { - // TODO any other cleanup needed here? - return 0; - } + return 0; } // Start the io_context main loop @@ -146,61 +126,28 @@ int main(int argc, char* argv[]) // Check process modules for compatibility scwx::qt::main::CheckProcessModules(); - auto& generalSettings = scwx::qt::settings::GeneralSettings::Instance(); - if (!highPrivilegeChecked && - generalSettings.high_privilege_warning_enabled().GetValue() && - scwx::qt::util::is_high_privilege()) + int result = 0; + if (privilegeChecker.second_check()) { - auto dialog = - scwx::qt::ui::HighPrivilegeDialog(); // TODO does this need cleaned up? - const int result = dialog.exec(); - - disableHighPrivilegeWarning = dialog.disable_high_privilege_message(); - - if (result == QDialog::Rejected) + result = 1; + } + else + { + // Run initial setup if required + if (scwx::qt::ui::setup::SetupWizard::IsSetupRequired()) { - // Deinitialize application - scwx::qt::manager::RadarProductManager::Cleanup(); - - // Stop Qt Threads - scwx::qt::manager::ThreadManager::Instance().StopThreads(); - - // Gracefully stop the io_context main loop - work.reset(); - threadPool.join(); - - // Shutdown application - scwx::qt::manager::ResourceManager::Shutdown(); - scwx::qt::manager::SettingsManager::Instance().Shutdown(); - - // Shutdown AWS SDK - Aws::ShutdownAPI(awsSdkOptions); - return 0; + scwx::qt::ui::setup::SetupWizard w; + w.show(); + a.exec(); } - } - // Save high privilege settings - if (disableHighPrivilegeWarning) - { - generalSettings.high_privilege_warning_enabled().SetValue(false); - scwx::qt::manager::SettingsManager::Instance().SaveSettings(); - } - - // Run initial setup if required - if (scwx::qt::ui::setup::SetupWizard::IsSetupRequired()) - { - scwx::qt::ui::setup::SetupWizard w; - w.show(); - a.exec(); - } - - // Run Qt main loop - int result; - { - scwx::qt::main::MainWindow w; - w.show(); - result = a.exec(); + // Run Qt main loop + { + scwx::qt::main::MainWindow w; + w.show(); + result = a.exec(); + } } // Deinitialize application diff --git a/scwx-qt/source/scwx/qt/settings/general_settings.cpp b/scwx-qt/source/scwx/qt/settings/general_settings.cpp index 0abb45e9..6f254c6b 100644 --- a/scwx-qt/source/scwx/qt/settings/general_settings.cpp +++ b/scwx-qt/source/scwx/qt/settings/general_settings.cpp @@ -394,6 +394,7 @@ bool GeneralSettings::Shutdown() dataChanged |= p->loopTime_.Commit(); dataChanged |= p->processModuleWarningsEnabled_.Commit(); dataChanged |= p->trackLocation_.Commit(); + dataChanged |= p->highPrivilegeWarningEnabled_.Commit(); return dataChanged; } diff --git a/scwx-qt/source/scwx/qt/util/check_privilege.cpp b/scwx-qt/source/scwx/qt/util/check_privilege.cpp index 2d7d1227..62a4c4d0 100644 --- a/scwx-qt/source/scwx/qt/util/check_privilege.cpp +++ b/scwx-qt/source/scwx/qt/util/check_privilege.cpp @@ -1,5 +1,11 @@ +#include "scwx/qt/settings/general_settings.hpp" #include "scwx/qt/util/check_privilege.hpp" #include +#include +#include +#include +#include +#include #ifdef _WIN32 # include @@ -7,11 +13,7 @@ # include #endif -namespace scwx -{ -namespace qt -{ -namespace util +namespace scwx::qt::util { bool is_high_privilege() @@ -38,9 +40,95 @@ bool is_high_privilege() #elif defined(Q_OS_UNIX) // On UNIX root is always uid 0. On Linux this is enforced by the kernel. return geteuid() == 0; +#else + return false; #endif } -} // namespace util -} // namespace qt -} // namespace scwx +#if defined(_WIN32) +static const QString message = QObject::tr( + "Supercell Wx has been run with administrator permissions. It is " + "recommended to run it without administrator permissions Do you wish to " + "continue?"); +#elif defined(Q_OS_UNIX) +static const QString message = QObject::tr( + "Supercell Wx has been run as root. It is recommended to run it as a normal " + "user. Do you wish to continue?"); +#else +static const QString message = QObject::tr(""); +#endif + +static const QString title = QObject::tr("Supercell Wx"); +static const QString checkBoxText = + QObject::tr("Do not show this warning again."); + +class PrivilegeChecker::Impl +{ +public: + explicit Impl() : + highPrivilege_ {is_high_privilege()}, + dialog_ {QMessageBox::Icon::Warning, title, message}, + checkBox_(new QCheckBox(checkBoxText, &dialog_)) + { + const std::string appDataPath { + QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + .toStdString()}; + hasAppData_ = std::filesystem::exists(appDataPath); + + dialog_.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + dialog_.setCheckBox(checkBox_); + }; + + bool hasAppData_; + bool firstCheckCheckBoxState_ {true}; + bool highPrivilege_; + + QMessageBox dialog_; + QCheckBox* checkBox_; +}; + +PrivilegeChecker::PrivilegeChecker() : p(std::make_unique()) +{ +} + +PrivilegeChecker::~PrivilegeChecker() = default; + +bool PrivilegeChecker::first_check() +{ + if (p->hasAppData_ || !p->highPrivilege_) + { + return false; + } + + int result = p->dialog_.exec(); + p->firstCheckCheckBoxState_ = p->checkBox_->isChecked(); + + return result != QMessageBox::Yes; +} + +bool PrivilegeChecker::second_check() +{ + auto& highPrivilegeWarningEnabled = + settings::GeneralSettings::Instance().high_privilege_warning_enabled(); + if (!highPrivilegeWarningEnabled.GetValue() || !p->highPrivilege_) + { + return false; + } + else if (!p->hasAppData_) + { + highPrivilegeWarningEnabled.StageValue(!p->firstCheckCheckBoxState_); + return false; + } + + switch (p->dialog_.exec()) + { + case QMessageBox::Yes: + highPrivilegeWarningEnabled.StageValue(!p->checkBox_->isChecked()); + return false; + case QMessageBox::No: + default: + return true; + } +} + +} // namespace scwx::qt::util diff --git a/scwx-qt/source/scwx/qt/util/check_privilege.hpp b/scwx-qt/source/scwx/qt/util/check_privilege.hpp index 7a44a070..7935e54a 100644 --- a/scwx-qt/source/scwx/qt/util/check_privilege.hpp +++ b/scwx-qt/source/scwx/qt/util/check_privilege.hpp @@ -1,14 +1,25 @@ #pragma once -namespace scwx -{ -namespace qt -{ -namespace util +#include + +namespace scwx::qt::util { bool is_high_privilege(); -} // namespace util -} // namespace qt -} // namespace scwx +class PrivilegeChecker +{ +public: + explicit PrivilegeChecker(); + ~PrivilegeChecker(); + + // returning true means check failed. + bool first_check(); + bool second_check(); + +private: + class Impl; + std::unique_ptr p; +}; + +} // namespace scwx::qt::util From 2f9908b54e3f10926707962f2bbfd10122e4aa15 Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Sat, 11 Jan 2025 13:46:32 -0500 Subject: [PATCH 05/11] move check_privilege.* to main --- scwx-qt/scwx-qt.cmake | 8 ++++---- scwx-qt/source/scwx/qt/{util => main}/check_privilege.cpp | 7 ++++--- scwx-qt/source/scwx/qt/{util => main}/check_privilege.hpp | 4 ++-- scwx-qt/source/scwx/qt/main/main.cpp | 5 ++--- 4 files changed, 12 insertions(+), 12 deletions(-) rename scwx-qt/source/scwx/qt/{util => main}/check_privilege.cpp (95%) rename scwx-qt/source/scwx/qt/{util => main}/check_privilege.hpp (84%) diff --git a/scwx-qt/scwx-qt.cmake b/scwx-qt/scwx-qt.cmake index a386d8b9..dece221d 100644 --- a/scwx-qt/scwx-qt.cmake +++ b/scwx-qt/scwx-qt.cmake @@ -51,9 +51,11 @@ find_package(Qt${QT_VERSION_MAJOR} set(SRC_EXE_MAIN source/scwx/qt/main/main.cpp) set(HDR_MAIN source/scwx/qt/main/application.hpp + source/scwx/qt/main/check_privilege.hpp source/scwx/qt/main/main_window.hpp source/scwx/qt/main/process_validation.hpp) set(SRC_MAIN source/scwx/qt/main/application.cpp + source/scwx/qt/main/check_privilege.cpp source/scwx/qt/main/main_window.cpp source/scwx/qt/main/process_validation.cpp) set(UI_MAIN source/scwx/qt/main/main_window.ui) @@ -356,8 +358,7 @@ set(SRC_UI_SETUP source/scwx/qt/ui/setup/audio_codec_page.cpp source/scwx/qt/ui/setup/map_provider_page.cpp source/scwx/qt/ui/setup/setup_wizard.cpp source/scwx/qt/ui/setup/welcome_page.cpp) -set(HDR_UTIL source/scwx/qt/util/check_privilege.hpp - source/scwx/qt/util/color.hpp +set(HDR_UTIL source/scwx/qt/util/color.hpp source/scwx/qt/util/file.hpp source/scwx/qt/util/geographic_lib.hpp source/scwx/qt/util/imgui.hpp @@ -371,8 +372,7 @@ set(HDR_UTIL source/scwx/qt/util/check_privilege.hpp source/scwx/qt/util/q_file_input_stream.hpp source/scwx/qt/util/time.hpp source/scwx/qt/util/tooltip.hpp) -set(SRC_UTIL source/scwx/qt/util/check_privilege.cpp - source/scwx/qt/util/color.cpp +set(SRC_UTIL source/scwx/qt/util/color.cpp source/scwx/qt/util/file.cpp source/scwx/qt/util/geographic_lib.cpp source/scwx/qt/util/imgui.cpp diff --git a/scwx-qt/source/scwx/qt/util/check_privilege.cpp b/scwx-qt/source/scwx/qt/main/check_privilege.cpp similarity index 95% rename from scwx-qt/source/scwx/qt/util/check_privilege.cpp rename to scwx-qt/source/scwx/qt/main/check_privilege.cpp index 62a4c4d0..25f29f22 100644 --- a/scwx-qt/source/scwx/qt/util/check_privilege.cpp +++ b/scwx-qt/source/scwx/qt/main/check_privilege.cpp @@ -1,5 +1,5 @@ #include "scwx/qt/settings/general_settings.hpp" -#include "scwx/qt/util/check_privilege.hpp" +#include "scwx/qt/main/check_privilege.hpp" #include #include #include @@ -13,7 +13,7 @@ # include #endif -namespace scwx::qt::util +namespace scwx::qt::main { bool is_high_privilege() @@ -76,6 +76,7 @@ public: hasAppData_ = std::filesystem::exists(appDataPath); dialog_.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + dialog_.setDefaultButton(QMessageBox::No); dialog_.setCheckBox(checkBox_); }; @@ -131,4 +132,4 @@ bool PrivilegeChecker::second_check() } } -} // namespace scwx::qt::util +} // namespace scwx::qt::main diff --git a/scwx-qt/source/scwx/qt/util/check_privilege.hpp b/scwx-qt/source/scwx/qt/main/check_privilege.hpp similarity index 84% rename from scwx-qt/source/scwx/qt/util/check_privilege.hpp rename to scwx-qt/source/scwx/qt/main/check_privilege.hpp index 7935e54a..34da5bfc 100644 --- a/scwx-qt/source/scwx/qt/util/check_privilege.hpp +++ b/scwx-qt/source/scwx/qt/main/check_privilege.hpp @@ -2,7 +2,7 @@ #include -namespace scwx::qt::util +namespace scwx::qt::main { bool is_high_privilege(); @@ -22,4 +22,4 @@ private: std::unique_ptr p; }; -} // namespace scwx::qt::util +} // namespace scwx::qt::main diff --git a/scwx-qt/source/scwx/qt/main/main.cpp b/scwx-qt/source/scwx/qt/main/main.cpp index 4212050e..dde35cbb 100644 --- a/scwx-qt/source/scwx/qt/main/main.cpp +++ b/scwx-qt/source/scwx/qt/main/main.cpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include #include @@ -22,7 +22,6 @@ #include #include -#include #include #include @@ -82,7 +81,7 @@ int main(int argc, char* argv[]) } // Test to see if scwx was run with high privilege - scwx::qt::util::PrivilegeChecker privilegeChecker; + scwx::qt::main::PrivilegeChecker privilegeChecker; if (privilegeChecker.first_check()) { return 0; From 87e43a528e71556f128b8977a6dfa0255f5a725a Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Sat, 11 Jan 2025 13:50:49 -0500 Subject: [PATCH 06/11] use for descriptive names for when checks are made --- scwx-qt/source/scwx/qt/main/check_privilege.cpp | 4 ++-- scwx-qt/source/scwx/qt/main/check_privilege.hpp | 4 ++-- scwx-qt/source/scwx/qt/main/main.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/scwx-qt/source/scwx/qt/main/check_privilege.cpp b/scwx-qt/source/scwx/qt/main/check_privilege.cpp index 25f29f22..0d1d8cba 100644 --- a/scwx-qt/source/scwx/qt/main/check_privilege.cpp +++ b/scwx-qt/source/scwx/qt/main/check_privilege.cpp @@ -94,7 +94,7 @@ PrivilegeChecker::PrivilegeChecker() : p(std::make_uniquehasAppData_ || !p->highPrivilege_) { @@ -107,7 +107,7 @@ bool PrivilegeChecker::first_check() return result != QMessageBox::Yes; } -bool PrivilegeChecker::second_check() +bool PrivilegeChecker::post_settings_check() { auto& highPrivilegeWarningEnabled = settings::GeneralSettings::Instance().high_privilege_warning_enabled(); diff --git a/scwx-qt/source/scwx/qt/main/check_privilege.hpp b/scwx-qt/source/scwx/qt/main/check_privilege.hpp index 34da5bfc..f9fcadd9 100644 --- a/scwx-qt/source/scwx/qt/main/check_privilege.hpp +++ b/scwx-qt/source/scwx/qt/main/check_privilege.hpp @@ -14,8 +14,8 @@ public: ~PrivilegeChecker(); // returning true means check failed. - bool first_check(); - bool second_check(); + bool pre_settings_check(); + bool post_settings_check(); private: class Impl; diff --git a/scwx-qt/source/scwx/qt/main/main.cpp b/scwx-qt/source/scwx/qt/main/main.cpp index dde35cbb..c1a7c891 100644 --- a/scwx-qt/source/scwx/qt/main/main.cpp +++ b/scwx-qt/source/scwx/qt/main/main.cpp @@ -82,7 +82,7 @@ int main(int argc, char* argv[]) // Test to see if scwx was run with high privilege scwx::qt::main::PrivilegeChecker privilegeChecker; - if (privilegeChecker.first_check()) + if (privilegeChecker.pre_settings_check()) { return 0; } @@ -127,7 +127,7 @@ int main(int argc, char* argv[]) scwx::qt::main::CheckProcessModules(); int result = 0; - if (privilegeChecker.second_check()) + if (privilegeChecker.post_settings_check()) { result = 1; } From eb3b76dcf4fb02d107f9cbe7951244edd7139bf5 Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Sat, 11 Jan 2025 14:22:19 -0500 Subject: [PATCH 07/11] get rid of old high_privilege_dialog build --- scwx-qt/scwx-qt.cmake | 3 - .../source/scwx/qt/main/check_privilege.cpp | 7 +- scwx-qt/source/scwx/qt/main/main.cpp | 1 - .../scwx/qt/ui/high_privilege_dialog.cpp | 47 -------- .../scwx/qt/ui/high_privilege_dialog.hpp | 40 ------- .../scwx/qt/ui/high_privilege_dialog.ui | 101 ------------------ 6 files changed, 4 insertions(+), 195 deletions(-) delete mode 100644 scwx-qt/source/scwx/qt/ui/high_privilege_dialog.cpp delete mode 100644 scwx-qt/source/scwx/qt/ui/high_privilege_dialog.hpp delete mode 100644 scwx-qt/source/scwx/qt/ui/high_privilege_dialog.ui diff --git a/scwx-qt/scwx-qt.cmake b/scwx-qt/scwx-qt.cmake index dece221d..09ea6fe3 100644 --- a/scwx-qt/scwx-qt.cmake +++ b/scwx-qt/scwx-qt.cmake @@ -262,7 +262,6 @@ set(HDR_UI source/scwx/qt/ui/about_dialog.hpp source/scwx/qt/ui/edit_marker_dialog.hpp source/scwx/qt/ui/flow_layout.hpp source/scwx/qt/ui/gps_info_dialog.hpp - source/scwx/qt/ui/high_privilege_dialog.hpp source/scwx/qt/ui/hotkey_edit.hpp source/scwx/qt/ui/imgui_debug_dialog.hpp source/scwx/qt/ui/imgui_debug_widget.hpp @@ -294,7 +293,6 @@ set(SRC_UI source/scwx/qt/ui/about_dialog.cpp source/scwx/qt/ui/edit_marker_dialog.cpp source/scwx/qt/ui/flow_layout.cpp source/scwx/qt/ui/gps_info_dialog.cpp - source/scwx/qt/ui/high_privilege_dialog.cpp source/scwx/qt/ui/hotkey_edit.cpp source/scwx/qt/ui/imgui_debug_dialog.cpp source/scwx/qt/ui/imgui_debug_widget.cpp @@ -324,7 +322,6 @@ set(UI_UI source/scwx/qt/ui/about_dialog.ui source/scwx/qt/ui/edit_line_dialog.ui source/scwx/qt/ui/edit_marker_dialog.ui source/scwx/qt/ui/gps_info_dialog.ui - source/scwx/qt/ui/high_privilege_dialog.ui source/scwx/qt/ui/imgui_debug_dialog.ui source/scwx/qt/ui/layer_dialog.ui source/scwx/qt/ui/open_url_dialog.ui diff --git a/scwx-qt/source/scwx/qt/main/check_privilege.cpp b/scwx-qt/source/scwx/qt/main/check_privilege.cpp index 0d1d8cba..965df9f8 100644 --- a/scwx-qt/source/scwx/qt/main/check_privilege.cpp +++ b/scwx-qt/source/scwx/qt/main/check_privilege.cpp @@ -58,7 +58,7 @@ static const QString message = QObject::tr( static const QString message = QObject::tr(""); #endif -static const QString title = QObject::tr("Supercell Wx"); +static const QString title = QObject::tr("Supercell Wx"); static const QString checkBoxText = QObject::tr("Do not show this warning again."); @@ -88,7 +88,8 @@ public: QCheckBox* checkBox_; }; -PrivilegeChecker::PrivilegeChecker() : p(std::make_unique()) +PrivilegeChecker::PrivilegeChecker() : + p(std::make_unique()) { } @@ -101,7 +102,7 @@ bool PrivilegeChecker::pre_settings_check() return false; } - int result = p->dialog_.exec(); + int result = p->dialog_.exec(); p->firstCheckCheckBoxState_ = p->checkBox_->isChecked(); return result != QMessageBox::Yes; diff --git a/scwx-qt/source/scwx/qt/main/main.cpp b/scwx-qt/source/scwx/qt/main/main.cpp index c1a7c891..65d7e998 100644 --- a/scwx-qt/source/scwx/qt/main/main.cpp +++ b/scwx-qt/source/scwx/qt/main/main.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include diff --git a/scwx-qt/source/scwx/qt/ui/high_privilege_dialog.cpp b/scwx-qt/source/scwx/qt/ui/high_privilege_dialog.cpp deleted file mode 100644 index c057e6a4..00000000 --- a/scwx-qt/source/scwx/qt/ui/high_privilege_dialog.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include "high_privilege_dialog.hpp" -#include "ui_high_privilege_dialog.h" - -#include -#include - -namespace scwx -{ -namespace qt -{ -namespace ui -{ - -static const std::string logPrefix_ = "scwx::qt::ui::high_privilege_dialog"; -static const auto logger_ = scwx::util::Logger::Create(logPrefix_); - -class HighPrivilegeDialogImpl -{ -public: - explicit HighPrivilegeDialogImpl(HighPrivilegeDialog* self) : - self_ {self} {}; - ~HighPrivilegeDialogImpl() = default; - - HighPrivilegeDialog* self_; -}; - -HighPrivilegeDialog::HighPrivilegeDialog(QWidget* parent) : - QDialog(parent), - p {std::make_unique(this)}, - ui(new Ui::HighPrivilegeDialog) -{ - ui->setupUi(this); -} - -bool HighPrivilegeDialog::disable_high_privilege_message() -{ - return ui->highPrivilegeCheckBox->isChecked(); -} - -HighPrivilegeDialog::~HighPrivilegeDialog() -{ - delete ui; -} - -} // namespace ui -} // namespace qt -} // namespace scwx diff --git a/scwx-qt/source/scwx/qt/ui/high_privilege_dialog.hpp b/scwx-qt/source/scwx/qt/ui/high_privilege_dialog.hpp deleted file mode 100644 index b5d79ada..00000000 --- a/scwx-qt/source/scwx/qt/ui/high_privilege_dialog.hpp +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include - -namespace Ui -{ -class HighPrivilegeDialog; -} - -namespace scwx -{ -namespace qt -{ -namespace ui -{ - -class HighPrivilegeDialogImpl; - -class HighPrivilegeDialog : public QDialog -{ - Q_OBJECT - -private: - Q_DISABLE_COPY(HighPrivilegeDialog) - -public: - explicit HighPrivilegeDialog(QWidget* parent = nullptr); - ~HighPrivilegeDialog() override; - - bool disable_high_privilege_message(); - -private: - friend HighPrivilegeDialogImpl; - std::unique_ptr p; - Ui::HighPrivilegeDialog* ui; -}; - -} // namespace ui -} // namespace qt -} // namespace scwx diff --git a/scwx-qt/source/scwx/qt/ui/high_privilege_dialog.ui b/scwx-qt/source/scwx/qt/ui/high_privilege_dialog.ui deleted file mode 100644 index 4d6f5075..00000000 --- a/scwx-qt/source/scwx/qt/ui/high_privilege_dialog.ui +++ /dev/null @@ -1,101 +0,0 @@ - - - HighPrivilegeDialog - - - - 0 - 0 - 301 - 269 - - - - - 0 - 0 - - - - Warning: High Privilege - - - - - - - 0 - 0 - - - - <html><head/><body><h1 align="center" style=" margin-top:18px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:xx-large; font-weight:700; color:#ff0000;">Warning: Run Supercell Wx with Low Privileges.</span></h1><p align="center">Please run Supercell Wx without admin or root permissions. Supercell Wx should not need such permissions to run. If you do not want to run Supercell Wx with high privilege, click &quot;Close&quot;, and relaunch with lower permissions. Otherwise, click &quot;Ignore&quot;. You may disable this warning with the checkbox below.</p></body></html> - - - Qt::TextFormat::RichText - - - Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop - - - true - - - - - - - Disable High Privilege Warning - - - - - - - Qt::Orientation::Horizontal - - - QDialogButtonBox::StandardButton::Close|QDialogButtonBox::StandardButton::Ignore - - - - - - - - - - - buttonBox - accepted() - HighPrivilegeDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - HighPrivilegeDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - From 3ea37ba10468611d7e66bcc62a466a63b0393886 Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Sat, 11 Jan 2025 14:27:54 -0500 Subject: [PATCH 08/11] privilege check clang-tidy fix --- scwx-qt/source/scwx/qt/main/check_privilege.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scwx-qt/source/scwx/qt/main/check_privilege.cpp b/scwx-qt/source/scwx/qt/main/check_privilege.cpp index 965df9f8..710f70be 100644 --- a/scwx-qt/source/scwx/qt/main/check_privilege.cpp +++ b/scwx-qt/source/scwx/qt/main/check_privilege.cpp @@ -102,7 +102,7 @@ bool PrivilegeChecker::pre_settings_check() return false; } - int result = p->dialog_.exec(); + const int result = p->dialog_.exec(); p->firstCheckCheckBoxState_ = p->checkBox_->isChecked(); return result != QMessageBox::Yes; From be8237da721e9f5be5984674fa0d59fff08f2e26 Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Sun, 12 Jan 2025 09:24:48 -0500 Subject: [PATCH 09/11] Added fixes from GitHub comments for high_privilege_warning --- scwx-qt/source/scwx/qt/main/check_privilege.cpp | 4 ++-- scwx-qt/source/scwx/qt/main/check_privilege.hpp | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/scwx-qt/source/scwx/qt/main/check_privilege.cpp b/scwx-qt/source/scwx/qt/main/check_privilege.cpp index 710f70be..e6402af5 100644 --- a/scwx-qt/source/scwx/qt/main/check_privilege.cpp +++ b/scwx-qt/source/scwx/qt/main/check_privilege.cpp @@ -1,5 +1,5 @@ -#include "scwx/qt/settings/general_settings.hpp" -#include "scwx/qt/main/check_privilege.hpp" +#include +#include #include #include #include diff --git a/scwx-qt/source/scwx/qt/main/check_privilege.hpp b/scwx-qt/source/scwx/qt/main/check_privilege.hpp index f9fcadd9..7fe33eb3 100644 --- a/scwx-qt/source/scwx/qt/main/check_privilege.hpp +++ b/scwx-qt/source/scwx/qt/main/check_privilege.hpp @@ -13,6 +13,11 @@ public: explicit PrivilegeChecker(); ~PrivilegeChecker(); + PrivilegeChecker(const PrivilegeChecker&) = delete; + PrivilegeChecker& operator=(const PrivilegeChecker&) = delete; + PrivilegeChecker(const PrivilegeChecker&&) = delete; + PrivilegeChecker& operator=(const PrivilegeChecker&&) = delete; + // returning true means check failed. bool pre_settings_check(); bool post_settings_check(); From f7d2346924ffed5e6b72101616b6e5ba43c713e9 Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Sun, 12 Jan 2025 09:35:59 -0500 Subject: [PATCH 10/11] update test/data for high_privilege_warning --- test/data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/data b/test/data index 24ececcd..1f3e1259 160000 --- a/test/data +++ b/test/data @@ -1 +1 @@ -Subproject commit 24ececcd183d3b8961e5638da89f0eb36309cd6b +Subproject commit 1f3e1259130a5eb4a6df37d721fe6c8301213e7e From 0a749c1245247fc8a4eeb45584a9fd05b8a7f135 Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Sun, 12 Jan 2025 09:39:12 -0500 Subject: [PATCH 11/11] clang-format fixes for high_privilege_warning --- scwx-qt/source/scwx/qt/main/check_privilege.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scwx-qt/source/scwx/qt/main/check_privilege.hpp b/scwx-qt/source/scwx/qt/main/check_privilege.hpp index 7fe33eb3..8ec3f8e2 100644 --- a/scwx-qt/source/scwx/qt/main/check_privilege.hpp +++ b/scwx-qt/source/scwx/qt/main/check_privilege.hpp @@ -13,9 +13,9 @@ public: explicit PrivilegeChecker(); ~PrivilegeChecker(); - PrivilegeChecker(const PrivilegeChecker&) = delete; - PrivilegeChecker& operator=(const PrivilegeChecker&) = delete; - PrivilegeChecker(const PrivilegeChecker&&) = delete; + PrivilegeChecker(const PrivilegeChecker&) = delete; + PrivilegeChecker& operator=(const PrivilegeChecker&) = delete; + PrivilegeChecker(const PrivilegeChecker&&) = delete; PrivilegeChecker& operator=(const PrivilegeChecker&&) = delete; // returning true means check failed.