From 64716e6b429377942ef3c9d7586a1586525313af Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 9 Jul 2024 08:25:15 +0300 Subject: [PATCH] filesystem: request win32 error string in wide chars and then transform it to UTF-8 using our utflib --- filesystem/filesystem.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/filesystem/filesystem.c b/filesystem/filesystem.c index 870d4325..a363cf04 100644 --- a/filesystem/filesystem.c +++ b/filesystem/filesystem.c @@ -1357,7 +1357,7 @@ static qboolean FS_FindLibrary( const char *dllname, qboolean directpath, fs_dll { // NOTE: gamedll might resolve it's own path using dladdr() and expects absolute path // NOTE: the only allowed case when searchpath is set by absolute path is the RoDir - // rather than figuring out whether path is absolute, just check if it matches + // rather than figuring out whether path is absolute, just check if it matches if( !Q_strnicmp( search->filename, fs_rodir, Q_strlen( fs_rodir ))) { Q_snprintf( dllInfo->fullPath, sizeof( dllInfo->fullPath ), "%s%s", search->filename, dllInfo->shortPath ); @@ -1845,10 +1845,13 @@ int FS_SetCurrentDirectory( const char *path ) #if XASH_WIN32 if( !SetCurrentDirectoryW( FS_PathToWideChar( path ))) { + const DWORD fm_flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK; + DWORD errorcode; + wchar_t wide_buf[1024]; char buf[1024]; - FormatMessageA( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, GetLastError(), MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT ), - buf, sizeof( buf ), NULL ); + + FormatMessageW( fm_flags, NULL, GetLastError(), 0, wide_buf, sizeof( wide_buf ) / sizeof( wide_buf[0] ), NULL ); + Q_UTF16ToUTF8( buf, sizeof( buf ), wide_buf, sizeof( wide_buf ) / sizeof( wide_buf[0] )); Sys_Error( "Changing directory to %s failed: %s\n", path, buf ); return false;