Browse Source

engine: filesystem: fixed current directory changing for Windows

pull/2/head
SNMetamorph 3 years ago committed by a1batross
parent
commit
e4ad8def0d
  1. 2
      common/port.h
  2. 1
      engine/common/common.h
  3. 38
      engine/common/filesystem.c
  4. 2
      engine/common/host.c

2
common/port.h

@ -61,7 +61,6 @@ GNU General Public License for more details. @@ -61,7 +61,6 @@ GNU General Public License for more details.
#define _mkdir( x ) mkdir( x, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH )
#define LoadLibrary( x ) dlopen( x, RTLD_NOW )
#define GetProcAddress( x, y ) dlsym( x, y )
#define SetCurrentDirectory( x ) (!chdir( x ))
#define FreeLibrary( x ) dlclose( x )
#define tell( a ) lseek(a, 0, SEEK_CUR)
#define HAVE_DUP
@ -72,7 +71,6 @@ GNU General Public License for more details. @@ -72,7 +71,6 @@ GNU General Public License for more details.
#define LoadLibrary( x ) (0)
#define GetProcAddress( x, y ) (0)
#define FreeLibrary( x ) (0)
#define SetCurrentDirectory( x ) (!chdir( x ))
#endif
//#define MAKEWORD( a, b ) ((short int)(((unsigned char)(a))|(((short int)((unsigned char)(b)))<<8)))
#define max( a, b ) (((a) > (b)) ? (a) : (b))

1
engine/common/common.h

@ -566,6 +566,7 @@ int FS_FileTime( const char *filename, qboolean gamedironly ); @@ -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
engine/common/filesystem.c

@ -463,6 +463,22 @@ static const char *FS_FixFileCase( const char *path ) @@ -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 ) @@ -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 ) @@ -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

2
engine/common/host.c

@ -980,7 +980,7 @@ void Host_InitCommon( int argc, char **argv, const char *progname, qboolean bCha @@ -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 );

Loading…
Cancel
Save