mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 21:20:06 +00:00
Added basic high privilege checks and message box
This commit is contained in:
parent
d81f187d88
commit
71f967d536
4 changed files with 75 additions and 2 deletions
|
|
@ -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/map_provider_page.cpp
|
||||||
source/scwx/qt/ui/setup/setup_wizard.cpp
|
source/scwx/qt/ui/setup/setup_wizard.cpp
|
||||||
source/scwx/qt/ui/setup/welcome_page.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/file.hpp
|
||||||
source/scwx/qt/util/geographic_lib.hpp
|
source/scwx/qt/util/geographic_lib.hpp
|
||||||
source/scwx/qt/util/imgui.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/q_file_input_stream.hpp
|
||||||
source/scwx/qt/util/time.hpp
|
source/scwx/qt/util/time.hpp
|
||||||
source/scwx/qt/util/tooltip.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/file.cpp
|
||||||
source/scwx/qt/util/geographic_lib.cpp
|
source/scwx/qt/util/geographic_lib.cpp
|
||||||
source/scwx/qt/util/imgui.cpp
|
source/scwx/qt/util/imgui.cpp
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
#include <scwx/qt/settings/general_settings.hpp>
|
#include <scwx/qt/settings/general_settings.hpp>
|
||||||
#include <scwx/qt/types/qt_types.hpp>
|
#include <scwx/qt/types/qt_types.hpp>
|
||||||
#include <scwx/qt/ui/setup/setup_wizard.hpp>
|
#include <scwx/qt/ui/setup/setup_wizard.hpp>
|
||||||
|
#include <scwx/qt/util/check_privilege.hpp>
|
||||||
#include <scwx/network/cpr.hpp>
|
#include <scwx/network/cpr.hpp>
|
||||||
#include <scwx/util/environment.hpp>
|
#include <scwx/util/environment.hpp>
|
||||||
#include <scwx/util/logger.hpp>
|
#include <scwx/util/logger.hpp>
|
||||||
|
|
@ -31,6 +32,8 @@
|
||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
|
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
#define QT6CT_LIBRARY
|
#define QT6CT_LIBRARY
|
||||||
#include <qt6ct-common/qt6ct.h>
|
#include <qt6ct-common/qt6ct.h>
|
||||||
#undef QT6CT_LIBRARY
|
#undef QT6CT_LIBRARY
|
||||||
|
|
@ -73,6 +76,20 @@ int main(int argc, char* argv[])
|
||||||
QCoreApplication::installTranslator(&translator);
|
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())
|
if (!scwx::util::GetEnvironment("SCWX_TEST").empty())
|
||||||
{
|
{
|
||||||
QStandardPaths::setTestModeEnabled(true);
|
QStandardPaths::setTestModeEnabled(true);
|
||||||
|
|
|
||||||
43
scwx-qt/source/scwx/qt/util/check_privilege.cpp
Normal file
43
scwx-qt/source/scwx/qt/util/check_privilege.cpp
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
#include "scwx/qt/util/check_privilege.hpp"
|
||||||
|
#include <QtGlobal>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
|
#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
|
||||||
11
scwx-qt/source/scwx/qt/util/check_privilege.hpp
Normal file
11
scwx-qt/source/scwx/qt/util/check_privilege.hpp
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace scwx {
|
||||||
|
namespace qt {
|
||||||
|
namespace util {
|
||||||
|
|
||||||
|
bool is_high_privilege();
|
||||||
|
|
||||||
|
} // namespace util
|
||||||
|
} // namespace qt
|
||||||
|
} // namespace scwx
|
||||||
Loading…
Add table
Add a link
Reference in a new issue