engine: system: convert Windows username to utf8

This commit is contained in:
Alibek Omarov
2025-04-21 19:56:49 +03:00
parent fa47ca0d2d
commit 6ecaea3102

View File

@@ -128,11 +128,17 @@ const char *Sys_GetCurrentUser( void )
{
// TODO: move to platform
#if XASH_WIN32
static string s_userName;
unsigned long size = sizeof( s_userName );
static wchar_t sw_userName[MAX_STRING];
DWORD size = ARRAYSIZE( sw_userName );
if( GetUserName( s_userName, &size ))
if( GetUserNameW( sw_userName, &size ) && sw_userName[0] != 0 )
{
static char s_userName[MAX_STRING * 4];
// set length to -1, so it will null terminate
WideCharToMultiByte( CP_UTF8, 0, sw_userName, -1, s_userName, sizeof( s_userName ), NULL, NULL );
return s_userName;
}
#elif XASH_PSVITA
static string username;
sceAppUtilSystemParamGetString( SCE_SYSTEM_PARAM_ID_USERNAME, username, sizeof( username ) - 1 );