Browse Source

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

pull/2/head
Alibek Omarov 2 years ago
parent
commit
5a7b68fcc1
  1. 5
      engine/common/common.c
  2. 2
      filesystem/VFileSystem009.cpp
  3. 2
      filesystem/VFileSystem009.h
  4. 29
      filesystem/filesystem.c
  5. 8
      filesystem/filesystem.h
  6. 1
      filesystem/filesystem_internal.h
  7. 2
      filesystem/tests/interface.cpp

5
engine/common/common.c

@ -553,7 +553,6 @@ This doesn't search in the pak 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 @@ -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;

2
filesystem/VFileSystem009.cpp

@ -511,7 +511,7 @@ public: @@ -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;

2
filesystem/VFileSystem009.h

@ -150,4 +150,6 @@ public: @@ -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

29
filesystem/filesystem.c

@ -2432,6 +2432,30 @@ const char *FS_GetDiskPath( const char *name, qboolean gamedironly ) @@ -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 = @@ -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 )

8
filesystem/filesystem.h

@ -182,9 +182,11 @@ typedef struct fs_api_t @@ -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

1
filesystem/filesystem_internal.h

@ -177,6 +177,7 @@ qboolean FS_Rename( const char *oldname, const char *newname ); @@ -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 );

2
filesystem/tests/interface.cpp

@ -48,7 +48,7 @@ static bool LoadFilesystem() @@ -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;

Loading…
Cancel
Save