2022-07-11 02:58:59 +02:00
|
|
|
/*
|
|
|
|
VFileSystem009.h - C++ interface for filesystem_stdio
|
2023-04-15 01:28:04 +02:00
|
|
|
Copyright (C) 2022-2023 Xash3D FWGS contributors
|
2022-07-11 02:58:59 +02:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include ALLOCA_H
|
|
|
|
#include "crtlib.h"
|
|
|
|
#include "filesystem.h"
|
|
|
|
#include "filesystem_internal.h"
|
|
|
|
#include "VFileSystem009.h"
|
2023-04-18 03:50:47 +02:00
|
|
|
#include "common/com_strings.h"
|
2022-07-11 02:58:59 +02:00
|
|
|
|
|
|
|
#if __cplusplus < 201103L
|
|
|
|
#define override
|
2023-04-18 03:50:47 +02:00
|
|
|
#define nullptr NULL
|
2022-07-11 02:58:59 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// GoldSrc Directories and ID
|
|
|
|
// GAME gamedir
|
|
|
|
// GAMECONFIG gamedir (rodir integration?)
|
|
|
|
// GAMEDOWNLOAD gamedir_downloads (gamedir/downloads for us)
|
|
|
|
// GAME_FALLBACK liblist.gam's fallback_dir
|
|
|
|
// ROOT and BASE rootdir
|
|
|
|
// PLATFORM platform
|
|
|
|
// CONFIG platform/config
|
|
|
|
|
2023-04-24 01:18:40 +02:00
|
|
|
// This is a macro because pointers returned by alloca
|
|
|
|
// shouldn't leave current scope
|
2023-04-18 03:50:47 +02:00
|
|
|
#define FixupPath( var, str ) \
|
2023-04-24 01:18:40 +02:00
|
|
|
const size_t var ## _size = Q_strlen(( str )) + 1; \
|
|
|
|
char * const var = static_cast<char *>( alloca( var ## _size )); \
|
|
|
|
CopyAndFixSlashes( var, ( str ), var ## _size )
|
2023-04-18 03:50:47 +02:00
|
|
|
|
|
|
|
static inline bool IsIdGamedir( const char *id )
|
2022-07-11 02:58:59 +02:00
|
|
|
{
|
|
|
|
return !Q_strcmp( id, "GAME" ) ||
|
|
|
|
!Q_strcmp( id, "GAMECONFIG" ) ||
|
|
|
|
!Q_strcmp( id, "GAMEDOWNLOAD" );
|
|
|
|
}
|
|
|
|
|
2022-12-18 21:18:40 +01:00
|
|
|
static inline const char *IdToDir( char *dir, size_t size, const char *id )
|
2022-07-11 02:58:59 +02:00
|
|
|
{
|
|
|
|
if( !Q_strcmp( id, "GAME" ))
|
|
|
|
return GI->gamefolder;
|
2023-04-18 03:50:47 +02:00
|
|
|
|
|
|
|
if( !Q_strcmp( id, "GAMEDOWNLOAD" ))
|
2022-12-18 21:18:40 +01:00
|
|
|
{
|
|
|
|
Q_snprintf( dir, size, "%s/downloaded", GI->gamefolder );
|
|
|
|
return dir;
|
|
|
|
}
|
2023-04-18 03:50:47 +02:00
|
|
|
|
|
|
|
if( !Q_strcmp( id, "GAMECONFIG" ))
|
2022-12-26 12:39:51 +01:00
|
|
|
return fs_writepath->filename; // full path here so it's totally our write allowed directory
|
2023-04-18 03:50:47 +02:00
|
|
|
|
|
|
|
if( !Q_strcmp( id, "PLATFORM" ))
|
2022-07-11 02:58:59 +02:00
|
|
|
return "platform"; // stub
|
2023-04-18 03:50:47 +02:00
|
|
|
|
|
|
|
if( !Q_strcmp( id, "CONFIG" ))
|
2022-07-11 02:58:59 +02:00
|
|
|
return "platform/config"; // stub
|
2023-04-18 03:50:47 +02:00
|
|
|
|
|
|
|
// ROOT || BASE
|
|
|
|
return fs_rootdir; // give at least root directory
|
2022-07-11 02:58:59 +02:00
|
|
|
}
|
|
|
|
|
2023-04-24 01:18:40 +02:00
|
|
|
static inline void CopyAndFixSlashes( char *p, const char *in, size_t size )
|
2022-07-11 02:58:59 +02:00
|
|
|
{
|
2023-04-24 01:18:40 +02:00
|
|
|
Q_strncpy( p, in, size );
|
2022-07-11 02:58:59 +02:00
|
|
|
COM_FixSlashes( p );
|
|
|
|
}
|
|
|
|
|
|
|
|
class CXashFS : public IVFileSystem009
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
class CSearchState
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CSearchState( CSearchState **head, search_t *search ) :
|
2023-04-18 03:50:47 +02:00
|
|
|
next( *head ),
|
|
|
|
search( search ),
|
|
|
|
index( 0 ),
|
|
|
|
handle( *head ? ( *head )->handle + 1 : 0 )
|
2022-07-11 02:58:59 +02:00
|
|
|
{
|
|
|
|
*head = this;
|
|
|
|
}
|
|
|
|
~CSearchState()
|
|
|
|
{
|
|
|
|
Mem_Free( search );
|
|
|
|
}
|
|
|
|
|
|
|
|
CSearchState *next;
|
|
|
|
search_t *search;
|
|
|
|
int index;
|
|
|
|
FileFindHandle_t handle;
|
|
|
|
};
|
|
|
|
|
|
|
|
CSearchState *searchHead;
|
|
|
|
|
|
|
|
CSearchState *GetSearchStateByHandle( FileFindHandle_t handle )
|
|
|
|
{
|
|
|
|
for( CSearchState *state = searchHead; state; state = state->next )
|
|
|
|
{
|
|
|
|
if( state->handle == handle )
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
Con_DPrintf( "Can't find search state by handle %d\n", handle );
|
2023-04-18 03:50:47 +02:00
|
|
|
return nullptr;
|
2022-07-11 02:58:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2023-04-18 03:50:47 +02:00
|
|
|
CXashFS() : searchHead( nullptr )
|
2022-07-11 02:58:59 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveAllSearchPaths() override
|
|
|
|
{
|
|
|
|
FS_ClearSearchPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddSearchPath( const char *path, const char *id ) override
|
|
|
|
{
|
2023-04-18 03:50:47 +02:00
|
|
|
FixupPath( p, path );
|
2022-07-11 02:58:59 +02:00
|
|
|
FS_AddGameDirectory( p, FS_CUSTOM_PATH );
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddSearchPathNoWrite( const char *path, const char *id ) override
|
|
|
|
{
|
2023-04-18 03:50:47 +02:00
|
|
|
FixupPath( p, path );
|
2022-07-11 02:58:59 +02:00
|
|
|
FS_AddGameDirectory( p, FS_NOWRITE_PATH | FS_CUSTOM_PATH );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RemoveSearchPath( const char *id ) override
|
|
|
|
{
|
|
|
|
// TODO:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveFile( const char *path, const char *id ) override
|
|
|
|
{
|
|
|
|
FS_Delete( path ); // FS_Delete is aware of slashes
|
|
|
|
}
|
|
|
|
|
|
|
|
void CreateDirHierarchy( const char *path, const char *id ) override
|
|
|
|
{
|
2022-12-18 21:18:40 +01:00
|
|
|
char dir[MAX_VA_STRING], fullpath[MAX_VA_STRING];
|
|
|
|
|
|
|
|
Q_snprintf( fullpath, sizeof( fullpath ), "%s/%s", IdToDir( dir, sizeof( dir ), id ), path );
|
|
|
|
FS_CreatePath( fullpath ); // FS_CreatePath is aware of slashes
|
2022-07-11 02:58:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FileExists( const char *path ) override
|
|
|
|
{
|
2023-04-18 03:50:47 +02:00
|
|
|
FixupPath( p, path );
|
2022-07-11 02:58:59 +02:00
|
|
|
return FS_FileExists( p, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsDirectory( const char *path ) override
|
|
|
|
{
|
2023-04-18 03:50:47 +02:00
|
|
|
FixupPath( p, path );
|
2022-07-11 02:58:59 +02:00
|
|
|
return FS_SysFolderExists( p );
|
|
|
|
}
|
|
|
|
|
|
|
|
FileHandle_t Open( const char *path, const char *mode, const char *id ) override
|
|
|
|
{
|
2023-04-18 03:50:47 +02:00
|
|
|
file_t *fd;
|
2022-07-11 02:58:59 +02:00
|
|
|
|
2023-04-18 03:50:47 +02:00
|
|
|
FixupPath( p, path );
|
|
|
|
fd = FS_Open( p, mode, IsIdGamedir( id ));
|
2022-07-11 02:58:59 +02:00
|
|
|
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Close( FileHandle_t handle ) override
|
|
|
|
{
|
2023-04-18 03:50:47 +02:00
|
|
|
FS_Close( static_cast<file_t *>( handle ));
|
2022-07-11 02:58:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Seek( FileHandle_t handle, int offset, FileSystemSeek_t whence ) override
|
|
|
|
{
|
|
|
|
int whence_ = SEEK_SET;
|
2023-04-18 03:50:47 +02:00
|
|
|
|
2022-07-11 02:58:59 +02:00
|
|
|
switch( whence )
|
|
|
|
{
|
2023-04-18 03:50:47 +02:00
|
|
|
case FILESYSTEM_SEEK_HEAD:
|
|
|
|
whence_ = SEEK_SET;
|
|
|
|
break;
|
|
|
|
case FILESYSTEM_SEEK_CURRENT:
|
|
|
|
whence_ = SEEK_CUR;
|
|
|
|
break;
|
|
|
|
case FILESYSTEM_SEEK_TAIL:
|
|
|
|
whence_ = SEEK_END;
|
|
|
|
break;
|
2022-07-11 02:58:59 +02:00
|
|
|
}
|
|
|
|
|
2023-04-18 03:50:47 +02:00
|
|
|
FS_Seek( static_cast<file_t *>( handle ), offset, whence_ );
|
2022-07-11 02:58:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int Tell( FileHandle_t handle ) override
|
|
|
|
{
|
2023-04-18 03:50:47 +02:00
|
|
|
return FS_Tell( static_cast<file_t *>( handle ));
|
2022-07-11 02:58:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int Size( FileHandle_t handle ) override
|
|
|
|
{
|
2023-04-18 03:50:47 +02:00
|
|
|
return static_cast<file_t *>( handle )->real_length;
|
2022-07-11 02:58:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int Size( const char *path ) override
|
|
|
|
{
|
2023-04-18 03:50:47 +02:00
|
|
|
FixupPath( p, path );
|
2022-07-11 02:58:59 +02:00
|
|
|
return FS_FileSize( p, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
long int GetFileTime( const char *path ) override
|
|
|
|
{
|
2023-04-18 03:50:47 +02:00
|
|
|
FixupPath( p, path );
|
2022-07-11 02:58:59 +02:00
|
|
|
return FS_FileTime( p, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileTimeToString( char *p, int size, long int time ) override
|
|
|
|
{
|
2023-04-18 03:50:47 +02:00
|
|
|
const time_t curtime = time;
|
2022-08-01 02:12:35 +02:00
|
|
|
char *buf = ctime( &curtime );
|
2023-04-18 03:50:47 +02:00
|
|
|
|
2022-07-11 02:58:59 +02:00
|
|
|
Q_strncpy( p, buf, size );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsOk( FileHandle_t handle ) override
|
|
|
|
{
|
2023-04-18 03:50:47 +02:00
|
|
|
return !FS_Eof( static_cast<file_t *>( handle ));
|
2022-07-11 02:58:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Flush( FileHandle_t handle ) override
|
|
|
|
{
|
2023-04-18 03:50:47 +02:00
|
|
|
FS_Flush( static_cast<file_t *>( handle ));
|
2022-07-11 02:58:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool EndOfFile( FileHandle_t handle ) override
|
|
|
|
{
|
2023-04-18 03:50:47 +02:00
|
|
|
return FS_Eof( static_cast<file_t *>( handle ));
|
2022-07-11 02:58:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int Read( void *buf, int size, FileHandle_t handle ) override
|
|
|
|
{
|
2023-04-18 03:50:47 +02:00
|
|
|
return FS_Read( static_cast<file_t *>( handle ), buf, size );
|
2022-07-11 02:58:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int Write( const void *buf, int size, FileHandle_t handle ) override
|
|
|
|
{
|
2023-04-18 03:50:47 +02:00
|
|
|
return FS_Write( static_cast<file_t *>( handle ), buf, size );
|
2022-07-11 02:58:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
char *ReadLine( char *buf, int size, FileHandle_t handle ) override
|
|
|
|
{
|
2023-04-18 03:50:47 +02:00
|
|
|
const int c = FS_Gets( static_cast<file_t *>( handle ), buf, size );
|
2022-07-11 02:58:59 +02:00
|
|
|
|
2023-04-18 03:50:47 +02:00
|
|
|
return c >= 0 ? buf : nullptr;
|
2022-07-11 02:58:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int FPrintf( FileHandle_t handle, char *fmt, ... ) override
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
va_start( ap, fmt );
|
2023-04-18 03:50:47 +02:00
|
|
|
ret = FS_VPrintf( static_cast<file_t *>( handle ), fmt, ap );
|
2022-07-11 02:58:59 +02:00
|
|
|
va_end( ap );
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-04-18 03:50:47 +02:00
|
|
|
void *GetReadBuffer( FileHandle_t, int *size, bool ) override
|
2022-07-11 02:58:59 +02:00
|
|
|
{
|
|
|
|
// deprecated by Valve
|
|
|
|
*size = 0;
|
2023-04-18 03:50:47 +02:00
|
|
|
return nullptr;
|
2022-07-11 02:58:59 +02:00
|
|
|
}
|
|
|
|
|
2023-04-18 03:50:47 +02:00
|
|
|
void ReleaseReadBuffer( FileHandle_t, void * ) override
|
2022-07-11 02:58:59 +02:00
|
|
|
{
|
|
|
|
// deprecated by Valve
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-04-18 03:50:47 +02:00
|
|
|
const char *FindFirst( const char *pattern, FileFindHandle_t *handle, const char *id ) override
|
2022-07-11 02:58:59 +02:00
|
|
|
{
|
2023-04-18 03:50:47 +02:00
|
|
|
CSearchState *state;
|
|
|
|
search_t *search;
|
|
|
|
|
2022-07-11 02:58:59 +02:00
|
|
|
if( !handle || !pattern )
|
2023-04-18 03:50:47 +02:00
|
|
|
return nullptr;
|
2022-07-11 02:58:59 +02:00
|
|
|
|
2023-04-18 03:50:47 +02:00
|
|
|
FixupPath( p, pattern );
|
|
|
|
search = FS_Search( p, true, IsIdGamedir( id ));
|
2022-07-11 02:58:59 +02:00
|
|
|
|
|
|
|
if( !search )
|
2023-04-18 03:50:47 +02:00
|
|
|
return nullptr;
|
2022-07-11 02:58:59 +02:00
|
|
|
|
2023-04-18 03:50:47 +02:00
|
|
|
state = new CSearchState( &searchHead, search );
|
2022-07-11 02:58:59 +02:00
|
|
|
*handle = state->handle;
|
|
|
|
return state->search->filenames[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *FindNext( FileFindHandle_t handle ) override
|
|
|
|
{
|
|
|
|
CSearchState *state = GetSearchStateByHandle( handle );
|
|
|
|
|
2023-04-18 03:50:47 +02:00
|
|
|
if( !state )
|
|
|
|
return nullptr;
|
2022-07-11 02:58:59 +02:00
|
|
|
|
|
|
|
if( state->index + 1 >= state->search->numfilenames )
|
2023-04-18 03:50:47 +02:00
|
|
|
return nullptr;
|
2022-07-11 02:58:59 +02:00
|
|
|
|
|
|
|
return state->search->filenames[++state->index];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FindIsDirectory( FileFindHandle_t handle ) override
|
|
|
|
{
|
|
|
|
CSearchState *state = GetSearchStateByHandle( handle );
|
|
|
|
|
|
|
|
if( !state )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( state->index >= state->search->numfilenames )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return IsDirectory( state->search->filenames[state->index] );
|
|
|
|
}
|
|
|
|
|
|
|
|
void FindClose( FileFindHandle_t handle ) override
|
|
|
|
{
|
2023-04-18 03:50:47 +02:00
|
|
|
CSearchState *prev;
|
|
|
|
CSearchState *i;
|
2022-07-11 02:58:59 +02:00
|
|
|
|
2023-04-18 03:50:47 +02:00
|
|
|
for( prev = nullptr, i = searchHead;
|
|
|
|
i != nullptr && i->handle != handle;
|
|
|
|
prev = i, i = i->next );
|
2022-07-11 02:58:59 +02:00
|
|
|
|
2023-04-18 03:50:47 +02:00
|
|
|
if( i == nullptr )
|
|
|
|
{
|
|
|
|
Con_DPrintf( "FindClose: Can't find search state by handle %d\n", handle );
|
|
|
|
return;
|
2022-07-11 02:58:59 +02:00
|
|
|
}
|
|
|
|
|
2023-04-18 03:50:47 +02:00
|
|
|
if( prev != nullptr )
|
|
|
|
prev->next = i->next;
|
|
|
|
else
|
|
|
|
searchHead = i->next;
|
|
|
|
|
|
|
|
delete i;
|
2022-07-11 02:58:59 +02:00
|
|
|
}
|
|
|
|
|
2023-04-18 03:50:47 +02:00
|
|
|
const char *GetLocalPath( const char *name, char *buf, int size ) override
|
2022-07-11 02:58:59 +02:00
|
|
|
{
|
2023-04-18 03:50:47 +02:00
|
|
|
const char *fullpath;
|
|
|
|
|
|
|
|
if( !name )
|
|
|
|
return nullptr;
|
2022-07-11 02:58:59 +02:00
|
|
|
|
2023-04-18 03:50:47 +02:00
|
|
|
FixupPath( p, name );
|
2022-07-11 02:58:59 +02:00
|
|
|
|
|
|
|
#if !XASH_WIN32
|
|
|
|
if( p[0] == '/' )
|
|
|
|
#else
|
|
|
|
if( Q_strchr( p, ':' ))
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
Q_strncpy( buf, p, size );
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2023-04-18 03:50:47 +02:00
|
|
|
fullpath = FS_GetDiskPath( p, false );
|
2022-07-11 02:58:59 +02:00
|
|
|
if( !fullpath )
|
2023-04-18 03:50:47 +02:00
|
|
|
return nullptr;
|
2022-07-11 02:58:59 +02:00
|
|
|
|
|
|
|
Q_strncpy( buf, fullpath, size );
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *ParseFile( char *buf, char *token, bool *quoted ) override
|
|
|
|
{
|
|
|
|
qboolean qquoted;
|
2023-04-18 03:50:47 +02:00
|
|
|
char *p;
|
2022-07-11 02:58:59 +02:00
|
|
|
|
2023-04-18 03:50:47 +02:00
|
|
|
p = COM_ParseFileSafe( buf, token, PFILE_FS_TOKEN_MAX_LENGTH, 0, nullptr, &qquoted );
|
|
|
|
|
|
|
|
if( quoted )
|
|
|
|
*quoted = qquoted;
|
2022-07-11 02:58:59 +02:00
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FullPathToRelativePath( const char *path, char *out ) override
|
|
|
|
{
|
2023-04-18 03:50:47 +02:00
|
|
|
searchpath_t *sp;
|
|
|
|
|
2022-07-11 02:58:59 +02:00
|
|
|
if( !COM_CheckString( path ))
|
|
|
|
{
|
|
|
|
*out = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-04-18 03:50:47 +02:00
|
|
|
FixupPath( p, path );
|
2022-07-11 02:58:59 +02:00
|
|
|
|
|
|
|
for( sp = fs_searchpaths; sp; sp = sp->next )
|
|
|
|
{
|
|
|
|
size_t splen = Q_strlen( sp->filename );
|
|
|
|
|
|
|
|
if( !Q_strnicmp( sp->filename, p, splen ))
|
|
|
|
{
|
2023-04-24 01:18:40 +02:00
|
|
|
Q_strncpy( out, p + splen + 1, 512 );
|
2022-07-11 02:58:59 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-24 01:18:40 +02:00
|
|
|
Q_strncpy( out, p, 512 );
|
2022-07-11 02:58:59 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetCurrentDirectory( char *p, int size ) override
|
|
|
|
{
|
|
|
|
Q_strncpy( p, fs_rootdir, size );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrintOpenedFiles() override
|
|
|
|
{
|
|
|
|
// we don't track this yet
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-04-18 03:50:47 +02:00
|
|
|
void SetWarningFunc( void (*)( const char *, ... )) override
|
2022-07-11 02:58:59 +02:00
|
|
|
{
|
|
|
|
// TODO:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-04-18 03:50:47 +02:00
|
|
|
void SetWarningLevel( FileWarningLevel_t ) override
|
2022-07-11 02:58:59 +02:00
|
|
|
{
|
|
|
|
// TODO:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SetVBuf( FileHandle_t handle, char *buf, int mode, long int size ) override
|
|
|
|
{
|
|
|
|
// TODO:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-04-18 03:50:47 +02:00
|
|
|
void GetInterfaceVersion( char *p, int size ) override
|
2022-07-11 02:58:59 +02:00
|
|
|
{
|
|
|
|
Q_strncpy( p, "Stdio", size );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AddPackFile( const char *path, const char *id ) override
|
|
|
|
{
|
2022-12-18 21:18:40 +01:00
|
|
|
char dir[MAX_VA_STRING], fullpath[MAX_VA_STRING];
|
|
|
|
|
|
|
|
Q_snprintf( fullpath, sizeof( fullpath ), "%s/%s", IdToDir( dir, sizeof( dir ), id ), path );
|
2023-04-24 01:18:40 +02:00
|
|
|
CopyAndFixSlashes( fullpath, path, sizeof( fullpath ));
|
2022-07-11 02:58:59 +02:00
|
|
|
|
2023-04-18 03:50:47 +02:00
|
|
|
return !!FS_AddPak_Fullpath( fullpath, nullptr, FS_CUSTOM_PATH );
|
2022-07-11 02:58:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
FileHandle_t OpenFromCacheForRead( const char *path , const char *mode, const char *id ) override
|
|
|
|
{
|
2023-04-18 03:50:47 +02:00
|
|
|
FixupPath( p, path );
|
2022-07-11 02:58:59 +02:00
|
|
|
|
|
|
|
return FS_OpenReadFile( p, mode, IsIdGamedir( id ));
|
|
|
|
}
|
|
|
|
|
|
|
|
// stubs
|
|
|
|
void Mount() override {}
|
|
|
|
void Unmount() override {}
|
2023-04-18 03:50:47 +02:00
|
|
|
void GetLocalCopy( const char * ) override {}
|
|
|
|
void LogLevelLoadStarted( const char * ) override {}
|
|
|
|
void LogLevelLoadFinished( const char * ) override {}
|
|
|
|
void CancelWaitForResources( WaitForResourcesHandle_t ) override {}
|
|
|
|
int HintResourceNeed( const char *, int ) override { return 0; }
|
|
|
|
WaitForResourcesHandle_t WaitForResources( const char * ) override { return 0; }
|
2022-07-11 02:58:59 +02:00
|
|
|
int PauseResourcePreloading() override { return 0; }
|
|
|
|
int ResumeResourcePreloading() override { return 0; }
|
2023-04-18 03:50:47 +02:00
|
|
|
bool IsAppReadyForOfflinePlay( int ) override { return true; }
|
|
|
|
bool IsFileImmediatelyAvailable( const char * ) override { return true; }
|
|
|
|
bool GetWaitForResourcesProgress( WaitForResourcesHandle_t, float *pProgress, bool *pOverride ) override
|
2022-07-11 02:58:59 +02:00
|
|
|
{
|
2023-04-18 03:50:47 +02:00
|
|
|
if( pProgress )
|
|
|
|
*pProgress = 0;
|
|
|
|
|
|
|
|
if( pOverride )
|
|
|
|
*pOverride = true;
|
|
|
|
|
2022-07-11 02:58:59 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} g_VFileSystem009;
|
|
|
|
|
|
|
|
extern "C" void EXPORT *CreateInterface( const char *interface, int *retval )
|
|
|
|
{
|
|
|
|
if( !Q_strcmp( interface, "VFileSystem009" ))
|
|
|
|
{
|
2023-04-18 03:50:47 +02:00
|
|
|
if( retval )
|
|
|
|
*retval = 0;
|
|
|
|
|
2022-07-11 02:58:59 +02:00
|
|
|
return &g_VFileSystem009;
|
|
|
|
}
|
|
|
|
|
2022-08-25 19:33:16 +02:00
|
|
|
if( !Q_strcmp( interface, FS_API_CREATEINTERFACE_TAG ))
|
|
|
|
{
|
2023-04-18 03:50:47 +02:00
|
|
|
static fs_api_t copy = { 0 }; // return a copy, to disallow overriding
|
2022-08-25 19:33:16 +02:00
|
|
|
|
|
|
|
if( !copy.InitStdio )
|
|
|
|
memcpy( ©, &g_api, sizeof( copy ));
|
|
|
|
|
2023-04-18 03:50:47 +02:00
|
|
|
if( retval )
|
|
|
|
*retval = 0;
|
|
|
|
|
2022-08-25 19:33:16 +02:00
|
|
|
return ©
|
|
|
|
}
|
|
|
|
|
2023-04-18 03:50:47 +02:00
|
|
|
if( retval )
|
|
|
|
*retval = 1;
|
|
|
|
|
|
|
|
return nullptr;
|
2022-07-11 02:58:59 +02:00
|
|
|
}
|