From 4798cd6d1e90e4e83717ad186430044ea479ac56 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sat, 30 Nov 2024 09:27:12 +0300 Subject: [PATCH] filesystem: add new export to get fs_rootdir path --- filesystem/VFileSystem009.cpp | 4 +--- filesystem/filesystem.c | 20 ++++++++++++++++++++ filesystem/filesystem.h | 3 +++ filesystem/filesystem_internal.h | 1 + 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/filesystem/VFileSystem009.cpp b/filesystem/VFileSystem009.cpp index 3b748ad8..c00b882d 100644 --- a/filesystem/VFileSystem009.cpp +++ b/filesystem/VFileSystem009.cpp @@ -435,9 +435,7 @@ public: bool GetCurrentDirectory( char *p, int size ) override { - Q_strncpy( p, fs_rootdir, size ); - - return true; + return FS_GetRootDirectory( p, size ); } void PrintOpenedFiles() override diff --git a/filesystem/filesystem.c b/filesystem/filesystem.c index 2911ef7d..b79df970 100644 --- a/filesystem/filesystem.c +++ b/filesystem/filesystem.c @@ -1905,6 +1905,24 @@ int FS_SetCurrentDirectory( const char *path ) return true; } +/* +================== +FS_GetRootDirectory + +Returns writable root directory path +================== +*/ +qboolean FS_GetRootDirectory( char *path, size_t size ) +{ + size_t dirlen = Q_strlen( fs_rootdir ); + + if( dirlen >= size ) // check for possible overflow + return false; + + Q_strncpy( path, fs_rootdir, size ); + return true; +} + /* ==================== FS_FindFile @@ -3139,6 +3157,8 @@ const fs_api_t g_api = FS_FindFileInArchive, FS_OpenFileFromArchive, FS_LoadFileFromArchive, + + FS_GetRootDirectory, }; 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 9614c288..874d7bcb 100644 --- a/filesystem/filesystem.h +++ b/filesystem/filesystem.h @@ -223,6 +223,9 @@ typedef struct fs_api_t // NOTE: for speed reasons, path is case-sensitive here! // Use FindFileInArchive to retrieve real path from caseinsensitive FS emulation! byte *(*LoadFileFromArchive)( searchpath_t *sp, const char *path, int pack_ind, fs_offset_t *filesizeptr, const qboolean sys_malloc ); + + // gets current root directory, set by InitStdio + qboolean (*GetRootDirectory)( char *path, size_t size ); } fs_api_t; typedef struct fs_interface_t diff --git a/filesystem/filesystem_internal.h b/filesystem/filesystem_internal.h index 4a8d5132..68080435 100644 --- a/filesystem/filesystem_internal.h +++ b/filesystem/filesystem_internal.h @@ -162,6 +162,7 @@ void FS_AddGameHierarchy( const char *dir, uint flags ); search_t *FS_Search( const char *pattern, int caseinsensitive, int gamedironly ) MALLOC_LIKE( _Mem_Free, 1 ) WARN_UNUSED_RESULT; int FS_SetCurrentDirectory( const char *path ); +qboolean FS_GetRootDirectory( char *path, size_t size ); void FS_Path_f( void ); // gameinfo utils