filesystem: add new export FS_GetFullDiskPath, similar to FS_GetDiskPath, but generates full path to the file, including searchpath

This commit is contained in:
Alibek Omarov 2023-05-02 08:52:54 +03:00
parent c33a384975
commit 5a7b68fcc1
7 changed files with 40 additions and 9 deletions

View File

@ -553,7 +553,6 @@ This doesn't search in the pak file.
*/
int GAME_EXPORT COM_ExpandFilename( const char *fileName, char *nameOutBuffer, int nameOutBufferSize )
{
const char *path;
char result[MAX_SYSPATH];
if( !COM_CheckString( fileName ) || !nameOutBuffer || nameOutBufferSize <= 0 )
@ -562,10 +561,8 @@ int GAME_EXPORT COM_ExpandFilename( const char *fileName, char *nameOutBuffer, i
// filename examples:
// media\sierra.avi - D:\Xash3D\valve\media\sierra.avi
// models\barney.mdl - D:\Xash3D\bshift\models\barney.mdl
if(( path = FS_GetDiskPath( fileName, false )) != NULL )
if( g_fsapi.GetFullDiskPath( result, sizeof( result ), fileName, false ))
{
Q_snprintf( result, sizeof( result ), "%s/%s", host.rootdir, path );
// check for enough room
if( Q_strlen( result ) > nameOutBufferSize )
return 0;

View File

@ -511,7 +511,7 @@ public:
extern "C" void EXPORT *CreateInterface( const char *interface, int *retval )
{
if( !Q_strcmp( interface, "VFileSystem009" ))
if( !Q_strcmp( interface, FILESYSTEM_INTERFACE_VERSION ))
{
if( retval )
*retval = 0;

View File

@ -150,4 +150,6 @@ public:
virtual void AddSearchPathNoWrite(const char *, const char *) = 0; /* linkage=_ZN11IFileSystem20AddSearchPathNoWriteEPKcS1_ */
};
#define FILESYSTEM_INTERFACE_VERSION "VFileSystem009" // never change this!
#endif // VFILESYSTEM009_H

View File

@ -2432,6 +2432,30 @@ const char *FS_GetDiskPath( const char *name, qboolean gamedironly )
return NULL;
}
/*
==================
FS_GetFullDiskPath
Build full path for file on disk
return false for file in pack
==================
*/
qboolean FS_GetFullDiskPath( char *buffer, size_t size, const char *name, qboolean gamedironly )
{
searchpath_t *search;
char temp[MAX_SYSPATH];
search = FS_FindFile( name, NULL, temp, sizeof( temp ), gamedironly );
if( search && search->type == SEARCHPATH_PLAIN )
{
Q_snprintf( buffer, size, "%s/%s", search->filename, temp );
return true;
}
return false;
}
/*
==================
FS_FileSize
@ -2773,6 +2797,11 @@ fs_api_t g_api =
FS_Delete,
FS_SysFileExists,
FS_GetDiskPath,
NULL,
NULL,
FS_GetFullDiskPath,
};
int EXPORT GetFSAPI( int version, fs_api_t *api, fs_globals_t **globals, fs_interface_t *engfuncs )

View File

@ -182,9 +182,11 @@ typedef struct fs_api_t
qboolean (*SysFileExists)( const char *path );
const char *(*GetDiskPath)( const char *name, qboolean gamedironly );
// file watcher
void (*WatchFrame)( void ); // engine will read all events and call appropriate callbacks
qboolean (*AddWatch)( const char *path, fs_event_callback_t callback );
// reserved
void (*Unused0)( void );
void (*Unused1)( void );
qboolean (*GetFullDiskPath)( char *buffer, size_t size, const char *name, qboolean gamedironly );
} fs_api_t;
typedef struct fs_interface_t

View File

@ -177,6 +177,7 @@ qboolean FS_Rename( const char *oldname, const char *newname );
qboolean FS_Delete( const char *path );
qboolean FS_SysFileExists( const char *path );
const char *FS_GetDiskPath( const char *name, qboolean gamedironly );
qboolean FS_GetFullDiskPath( char *buffer, size_t size, const char *name, qboolean gamedironly );
void FS_CreatePath( char *path );
qboolean FS_SysFolderExists( const char *path );
qboolean FS_SysFileOrFolderExists( const char *path );

View File

@ -48,7 +48,7 @@ static bool LoadFilesystem()
if( !g_pfnCreateInterface )
return false;
if( !g_pfnCreateInterface( "VFileSystem009", &temp ) || temp != 0 )
if( !g_pfnCreateInterface( FILESYSTEM_INTERFACE_VERSION, &temp ) || temp != 0 )
return false;
temp = -1;