mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-22 15:23:01 +01:00
Display a warning dialog if user runs program elevated (#6063)
This commit is contained in:
committed by
Ted John
parent
4ed970afef
commit
06d1f49d61
@@ -199,6 +199,19 @@ namespace OpenRCT2
|
||||
config_save_default();
|
||||
}
|
||||
|
||||
if (platform_process_is_elevated())
|
||||
{
|
||||
std::string elevationWarning = "It is not recommended to run OpenRCT2 with elevated permissions.";
|
||||
if (gOpenRCT2Headless)
|
||||
{
|
||||
Console::Error::WriteLine(elevationWarning.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
_uiContext->ShowMessageBox(elevationWarning);
|
||||
}
|
||||
}
|
||||
|
||||
if (!rct2_init_directories())
|
||||
{
|
||||
return false;
|
||||
|
||||
@@ -127,6 +127,7 @@ uint16 platform_get_locale_language();
|
||||
uint8 platform_get_locale_measurement_format();
|
||||
uint8 platform_get_locale_temperature_format();
|
||||
uint8 platform_get_locale_date_format();
|
||||
bool platform_process_is_elevated();
|
||||
|
||||
#ifndef NO_TTF
|
||||
bool platform_get_font_path(TTFFontDescriptor *font, utf8 *buffer, size_t size);
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include "../config/Config.h"
|
||||
#include "../localisation/date.h"
|
||||
#include "../localisation/language.h"
|
||||
@@ -836,4 +837,9 @@ utf8* platform_get_username() {
|
||||
}
|
||||
}
|
||||
|
||||
bool platform_process_is_elevated()
|
||||
{
|
||||
return (geteuid() == 0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -816,6 +816,23 @@ utf8* platform_get_username()
|
||||
return username;
|
||||
}
|
||||
|
||||
bool platform_process_is_elevated()
|
||||
{
|
||||
BOOL isElevated = FALSE;
|
||||
HANDLE hToken = NULL;
|
||||
if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) {
|
||||
TOKEN_ELEVATION Elevation;
|
||||
DWORD tokenSize = sizeof(TOKEN_ELEVATION);
|
||||
if (GetTokenInformation(hToken, TokenElevation, &Elevation, sizeof(Elevation), &tokenSize)) {
|
||||
isElevated = Elevation.TokenIsElevated;
|
||||
}
|
||||
}
|
||||
if (hToken) {
|
||||
CloseHandle(hToken);
|
||||
}
|
||||
return isElevated;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// File association setup
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user