Browse Source

filesystem: verbose error printing in FS_SetCurrentDirectory, move error reporting from engine

pull/2/head
Alibek Omarov 1 year ago
parent
commit
f13c285287
  1. 7
      engine/common/host.c
  2. 25
      filesystem/filesystem.c
  3. 2
      filesystem/tests/no-init.c

7
engine/common/host.c

@ -1077,10 +1077,9 @@ void Host_InitCommon( int argc, char **argv, const char *progname, qboolean bCha @@ -1077,10 +1077,9 @@ void Host_InitCommon( int argc, char **argv, const char *progname, qboolean bCha
FS_LoadProgs();
if( 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 );
// TODO: this function will cause engine to stop in case of fail
// when it will have an option to return string error, restore Sys_Error
FS_SetCurrentDirectory( host.rootdir );
FS_Init();

25
filesystem/filesystem.c

@ -1703,17 +1703,36 @@ qboolean FS_SysFileOrFolderExists( const char *path ) @@ -1703,17 +1703,36 @@ qboolean FS_SysFileOrFolderExists( const char *path )
FS_SetCurrentDirectory
Sets current directory, path should be in UTF-8 encoding
TODO: make this non-fatal
==================
*/
int FS_SetCurrentDirectory( const char *path )
{
#if XASH_WIN32
return SetCurrentDirectoryW( FS_PathToWideChar( path ));
if( !SetCurrentDirectoryW( FS_PathToWideChar( path )))
{
char buf[1024];
FormatMessageA( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, GetLastError(), MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT ),
buf, sizeof( buf ), NULL );
Sys_Error( "Changing directory to %s failed: %s\n", path, buf )
return false;
}
#elif XASH_POSIX
return !chdir( path );
if( chdir( path ) < 0 )
{
Sys_Error( "Changing directory to %s failed: %s\n", path, strerror( errno ));
return false;
}
#else
#error
// it may be fine for some systems to skip chdir
Con_Printf( "FS_SetCurrentDirectory: not implemented, ignoring...\n" );
return true;
#endif
Con_Printf( "%s is working directory now\n", path );
return true;
}
/*

2
filesystem/tests/no-init.c

@ -48,7 +48,7 @@ static int TestNoInit( void ) @@ -48,7 +48,7 @@ static int TestNoInit( void )
g_fs.AllowDirectPaths( false );
if( g_fs.Search( "asfjkajk", 0, 0 ) != 0 )
return 0;
g_fs.SetCurrentDirectory( "asdasdasdasd" );
g_fs.SetCurrentDirectory( "." ); // must succeed!
g_fs.FindLibrary( "kek", true, &dllinfo );
if( g_fs.Open( "afbvasvwerf", "w+", true ) != 0 )
return 0;

Loading…
Cancel
Save