engine: filesystem: fixed current directory changing for Windows

This commit is contained in:
SNMetamorph
2021-10-03 12:28:59 +03:00
committed by a1batross
parent ec95948b69
commit e4ad8def0d
4 changed files with 40 additions and 3 deletions
+1
View File
@@ -566,6 +566,7 @@ int FS_FileTime( const char *filename, qboolean gamedironly );
int FS_Print( file_t *file, const char *msg );
qboolean FS_Rename( const char *oldname, const char *newname );
int FS_FileExists( const char *filename, int gamedironly );
int FS_SetCurrentDirectory( const char *path );
qboolean FS_SysFileExists( const char *path, qboolean casesensitive );
qboolean FS_FileCopy( file_t *pOutput, file_t *pInput, int fileSize );
qboolean FS_Delete( const char *path );
+38
View File
@@ -463,6 +463,22 @@ static const char *FS_FixFileCase( const char *path )
return path;
}
#if XASH_WIN32
/*
====================
FS_PathToWideChar
Converts input UTF-8 string to wide char string.
====================
*/
const wchar_t *FS_PathToWideChar( const char *path )
{
static wchar_t pathBuffer[MAX_PATH];
MultiByteToWideChar( CP_UTF8, 0, path, -1, pathBuffer, MAX_PATH );
return pathBuffer;
}
#endif
/*
====================
FS_AddFileToPack
@@ -2240,7 +2256,11 @@ static file_t *FS_SysOpen( const char *filepath, const char *mode )
file->filetime = FS_SysFileTime( filepath );
file->ungetc = EOF;
#if XASH_WIN32
file->handle = _wopen( FS_PathToWideChar(filepath), mod | opt, 0666 );
#else
file->handle = open( filepath, mod|opt, 0666 );
#endif
#if !XASH_WIN32
if( file->handle < 0 )
@@ -2394,6 +2414,24 @@ qboolean FS_SysFileExists( const char *path, qboolean caseinsensitive )
#endif
}
/*
==================
FS_SetCurrentDirectory
Sets current directory, path should be in UTF-8 encoding
==================
*/
int FS_SetCurrentDirectory( const char *path )
{
#if XASH_WIN32
return SetCurrentDirectoryW( FS_PathToWideChar(path) );
#elif XASH_POSIX
return !chdir( path );
#else
#error
#endif
}
/*
==================
FS_SysFolderExists
+1 -1
View File
@@ -980,7 +980,7 @@ void Host_InitCommon( int argc, char **argv, const char *progname, qboolean bCha
if( len && host.rodir[len - 1] == '/' )
host.rodir[len - 1] = 0;
if( !COM_CheckStringEmpty( host.rootdir ) || SetCurrentDirectory( host.rootdir ) != 0 )
if( !COM_CheckStringEmpty( host.rootdir ) || FS_SetCurrentDirectory( host.rootdir ) != 0 )
Con_Reportf( "%s is working directory now\n", host.rootdir );
else
Sys_Error( "Changing working directory to %s failed.\n", host.rootdir );