From 5a7b68fcc12857dad9f30aa27410467e537cd197 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 2 May 2023 08:52:54 +0300 Subject: [PATCH] filesystem: add new export FS_GetFullDiskPath, similar to FS_GetDiskPath, but generates full path to the file, including searchpath --- engine/common/common.c | 5 +---- filesystem/VFileSystem009.cpp | 2 +- filesystem/VFileSystem009.h | 2 ++ filesystem/filesystem.c | 29 +++++++++++++++++++++++++++++ filesystem/filesystem.h | 8 +++++--- filesystem/filesystem_internal.h | 1 + filesystem/tests/interface.cpp | 2 +- 7 files changed, 40 insertions(+), 9 deletions(-) diff --git a/engine/common/common.c b/engine/common/common.c index 391b4e50..23c97880 100644 --- a/engine/common/common.c +++ b/engine/common/common.c @@ -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; diff --git a/filesystem/VFileSystem009.cpp b/filesystem/VFileSystem009.cpp index 250f494d..1dcde90e 100644 --- a/filesystem/VFileSystem009.cpp +++ b/filesystem/VFileSystem009.cpp @@ -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; diff --git a/filesystem/VFileSystem009.h b/filesystem/VFileSystem009.h index e48f4b7a..60437154 100644 --- a/filesystem/VFileSystem009.h +++ b/filesystem/VFileSystem009.h @@ -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 diff --git a/filesystem/filesystem.c b/filesystem/filesystem.c index 6d4389d4..157cd403 100644 --- a/filesystem/filesystem.c +++ b/filesystem/filesystem.c @@ -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 ) diff --git a/filesystem/filesystem.h b/filesystem/filesystem.h index e245984e..0b46f9af 100644 --- a/filesystem/filesystem.h +++ b/filesystem/filesystem.h @@ -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 diff --git a/filesystem/filesystem_internal.h b/filesystem/filesystem_internal.h index 51748b22..378e0554 100644 --- a/filesystem/filesystem_internal.h +++ b/filesystem/filesystem_internal.h @@ -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 ); diff --git a/filesystem/tests/interface.cpp b/filesystem/tests/interface.cpp index 889c59a2..5bdbe001 100644 --- a/filesystem/tests/interface.cpp +++ b/filesystem/tests/interface.cpp @@ -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;