mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-21 05:53:02 +01:00
Upgrade platform_get_username()
This commit is contained in:
@@ -388,7 +388,7 @@ namespace Config
|
||||
auto playerName = reader->GetString("player_name", "");
|
||||
if (playerName.empty())
|
||||
{
|
||||
playerName = platform_get_username();
|
||||
playerName = Platform::GetUsername();
|
||||
if (playerName.empty())
|
||||
{
|
||||
playerName = "Player";
|
||||
|
||||
@@ -253,6 +253,17 @@ namespace Platform
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string GetUsername()
|
||||
{
|
||||
std::string result;
|
||||
auto pw = getpwuid(getuid());
|
||||
if (pw != nullptr)
|
||||
{
|
||||
result = std::string(pw->pw_name);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
} // namespace Platform
|
||||
|
||||
#endif
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
# include "../Version.h"
|
||||
|
||||
# include <datetimeapi.h>
|
||||
# include <lmcons.h>
|
||||
# include <memory>
|
||||
# include <shlobj.h>
|
||||
# undef GetEnvironmentVariable
|
||||
@@ -613,6 +614,18 @@ namespace Platform
|
||||
// using the same window in an unaccelerated and accelerated context is unsupported by SDL2
|
||||
return openGL;
|
||||
}
|
||||
|
||||
std::string GetUsername()
|
||||
{
|
||||
std::string result;
|
||||
wchar_t usernameW[UNLEN + 1]{};
|
||||
DWORD usernameLength = UNLEN + 1;
|
||||
if (GetUserNameW(usernameW, &usernameLength))
|
||||
{
|
||||
result = String::ToUtf8(usernameW);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
} // namespace Platform
|
||||
|
||||
#endif
|
||||
|
||||
@@ -48,6 +48,8 @@ namespace Platform
|
||||
|
||||
bool OriginalGameDataExists(std::string_view path);
|
||||
|
||||
std::string GetUsername();
|
||||
|
||||
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD__)
|
||||
std::string GetEnvironmentPath(const char* name);
|
||||
std::string GetHomePath();
|
||||
|
||||
@@ -337,17 +337,6 @@ datetime64 platform_get_datetime_now_utc()
|
||||
return utcNow;
|
||||
}
|
||||
|
||||
std::string platform_get_username()
|
||||
{
|
||||
std::string result;
|
||||
auto pw = getpwuid(getuid());
|
||||
if (pw != nullptr)
|
||||
{
|
||||
result = std::string(pw->pw_name);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool platform_process_is_elevated()
|
||||
{
|
||||
# ifndef __EMSCRIPTEN__
|
||||
|
||||
@@ -460,18 +460,6 @@ datetime64 platform_get_datetime_now_utc()
|
||||
return utcNow;
|
||||
}
|
||||
|
||||
std::string platform_get_username()
|
||||
{
|
||||
std::string result;
|
||||
wchar_t usernameW[UNLEN + 1]{};
|
||||
DWORD usernameLength = UNLEN + 1;
|
||||
if (GetUserNameW(usernameW, &usernameLength))
|
||||
{
|
||||
result = String::ToUtf8(usernameW);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool platform_process_is_elevated()
|
||||
{
|
||||
BOOL isElevated = FALSE;
|
||||
|
||||
@@ -105,7 +105,6 @@ bool platform_file_delete(const utf8* path);
|
||||
uint32_t platform_get_ticks();
|
||||
void platform_sleep(uint32_t ms);
|
||||
void platform_get_user_directory(utf8* outPath, const utf8* subDirectory, size_t outSize);
|
||||
std::string platform_get_username();
|
||||
bool platform_open_common_file_dialog(utf8* outFilename, file_dialog_desc* desc, size_t outSize);
|
||||
utf8* platform_open_directory_browser(const utf8* title);
|
||||
CurrencyType platform_get_locale_currency();
|
||||
|
||||
Reference in New Issue
Block a user