mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-11 14:42:05 +08:00
filesystem: introduce new module, based on engine filesystem.
The goal is to share filesystem code between engine and utilities and provide C++ VFileSystem interface in the future
This commit is contained in:
@@ -980,7 +980,7 @@ pfnGetGamesList
|
||||
*/
|
||||
static GAMEINFO ** GAME_EXPORT pfnGetGamesList( int *numGames )
|
||||
{
|
||||
if( numGames ) *numGames = SI.numgames;
|
||||
if( numGames ) *numGames = FI->numgames;
|
||||
return gameui.modsInfo;
|
||||
}
|
||||
|
||||
@@ -1117,6 +1117,30 @@ static char *pfnParseFile( char *buf, char *token )
|
||||
return COM_ParseFile( buf, token, INT_MAX );
|
||||
}
|
||||
|
||||
/*
|
||||
=============
|
||||
pfnFileExists
|
||||
|
||||
legacy wrapper
|
||||
=============
|
||||
*/
|
||||
static int pfnFileExists( const char *path, int gamedironly )
|
||||
{
|
||||
return FS_FileExists( path, gamedironly );
|
||||
}
|
||||
|
||||
/*
|
||||
=============
|
||||
pfnDelete
|
||||
|
||||
legacy wrapper
|
||||
=============
|
||||
*/
|
||||
static int pfnDelete( const char *path )
|
||||
{
|
||||
return FS_Delete( path );
|
||||
}
|
||||
|
||||
// engine callbacks
|
||||
static ui_enginefuncs_t gEngfuncs =
|
||||
{
|
||||
@@ -1163,7 +1187,7 @@ static ui_enginefuncs_t gEngfuncs =
|
||||
pfnRenderScene,
|
||||
pfnAddEntity,
|
||||
Host_Error,
|
||||
FS_FileExists,
|
||||
pfnFileExists,
|
||||
pfnGetGameDir,
|
||||
Cmd_CheckMapsList,
|
||||
CL_Active,
|
||||
@@ -1202,7 +1226,7 @@ static ui_enginefuncs_t gEngfuncs =
|
||||
COM_CompareFileTime,
|
||||
VID_GetModeString,
|
||||
(void*)COM_SaveFile,
|
||||
(void*)FS_Delete
|
||||
pfnDelete
|
||||
};
|
||||
|
||||
static void pfnEnableTextInput( int enable )
|
||||
@@ -1358,13 +1382,13 @@ qboolean UI_LoadProgs( void )
|
||||
Cvar_FullSet( "host_gameuiloaded", "1", FCVAR_READ_ONLY );
|
||||
|
||||
// setup gameinfo
|
||||
for( i = 0; i < SI.numgames; i++ )
|
||||
for( i = 0; i < FI->numgames; i++ )
|
||||
{
|
||||
gameui.modsInfo[i] = Mem_Calloc( gameui.mempool, sizeof( GAMEINFO ));
|
||||
UI_ConvertGameInfo( gameui.modsInfo[i], SI.games[i] );
|
||||
UI_ConvertGameInfo( gameui.modsInfo[i], FI->games[i] );
|
||||
}
|
||||
|
||||
UI_ConvertGameInfo( &gameui.gameInfo, SI.GameInfo ); // current gameinfo
|
||||
UI_ConvertGameInfo( &gameui.gameInfo, FI->GameInfo ); // current gameinfo
|
||||
|
||||
// setup globals
|
||||
gameui.globals->developer = host.allow_console;
|
||||
|
||||
@@ -334,10 +334,6 @@ static ref_api_t gEngfuncs =
|
||||
COM_FreeLibrary,
|
||||
COM_GetProcAddress,
|
||||
|
||||
FS_LoadFile,
|
||||
FS_FileExists,
|
||||
FS_AllowDirectPaths,
|
||||
|
||||
R_Init_Video_,
|
||||
R_Free_Video,
|
||||
|
||||
@@ -383,7 +379,9 @@ static ref_api_t gEngfuncs =
|
||||
|
||||
pfnDrawNormalTriangles,
|
||||
pfnDrawTransparentTriangles,
|
||||
&clgame.drawFuncs
|
||||
&clgame.drawFuncs,
|
||||
|
||||
&g_fsapi,
|
||||
};
|
||||
|
||||
static void R_UnloadProgs( void )
|
||||
|
||||
@@ -585,23 +585,6 @@ void COM_TrimSpace( const char *source, char *dest )
|
||||
dest[length] = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
============
|
||||
COM_FixSlashes
|
||||
|
||||
Changes all '/' characters into '\' characters, in place.
|
||||
============
|
||||
*/
|
||||
void COM_FixSlashes( char *pname )
|
||||
{
|
||||
while( *pname )
|
||||
{
|
||||
if( *pname == '\\' )
|
||||
*pname = '/';
|
||||
pname++;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
==================
|
||||
COM_Nibble
|
||||
|
||||
+15
-127
@@ -76,13 +76,6 @@ XASH SPECIFIC - sort of hack that works only in Xash3D not in GoldSrc
|
||||
|
||||
#define HACKS_RELATED_HLMODS // some HL-mods works differently under Xash and can't be fixed without some hacks at least at current time
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int numfilenames;
|
||||
char **filenames;
|
||||
char *filenamesbuffer;
|
||||
} search_t;
|
||||
|
||||
enum
|
||||
{
|
||||
DEV_NONE = 0,
|
||||
@@ -118,6 +111,8 @@ typedef enum
|
||||
#include "cvar.h"
|
||||
#include "con_nprint.h"
|
||||
#include "crclib.h"
|
||||
#include "ref_api.h"
|
||||
#include "fscallback.h"
|
||||
|
||||
// PERFORMANCE INFO
|
||||
#define MIN_FPS 20.0f // host minimum fps value for maxfps.
|
||||
@@ -147,18 +142,6 @@ typedef enum
|
||||
#define MAX_STATIC_ENTITIES 32 // static entities that moved on the client when level is spawn
|
||||
#endif
|
||||
|
||||
// filesystem flags
|
||||
#define FS_STATIC_PATH ( 1U << 0 ) // FS_ClearSearchPath will be ignore this path
|
||||
#define FS_NOWRITE_PATH ( 1U << 1 ) // default behavior - last added gamedir set as writedir. This flag disables it
|
||||
#define FS_GAMEDIR_PATH ( 1U << 2 ) // just a marker for gamedir path
|
||||
#define FS_CUSTOM_PATH ( 1U << 3 ) // custom directory
|
||||
#define FS_GAMERODIR_PATH ( 1U << 4 ) // caseinsensitive
|
||||
|
||||
#define FS_GAMEDIRONLY_SEARCH_FLAGS ( FS_GAMEDIR_PATH | FS_CUSTOM_PATH | FS_GAMERODIR_PATH )
|
||||
|
||||
#define GI SI.GameInfo
|
||||
#define FS_Gamedir() SI.GameInfo->gamefolder
|
||||
#define FS_Title() SI.GameInfo->title
|
||||
#define GameState (&host.game)
|
||||
|
||||
#define FORCE_DRAW_VERSION_TIME 5.0f // draw version for 5 seconds
|
||||
@@ -199,61 +182,6 @@ GAMEINFO stuff
|
||||
internal shared gameinfo structure (readonly for engine parts)
|
||||
========================================================================
|
||||
*/
|
||||
typedef struct gameinfo_s
|
||||
{
|
||||
// filesystem info
|
||||
char gamefolder[MAX_QPATH]; // used for change game '-game x'
|
||||
char basedir[MAX_QPATH]; // base game directory (like 'id1' for Quake or 'valve' for Half-Life)
|
||||
char falldir[MAX_QPATH]; // used as second basedir
|
||||
char startmap[MAX_QPATH];// map to start singleplayer game
|
||||
char trainmap[MAX_QPATH];// map to start hazard course (if specified)
|
||||
char title[64]; // Game Main Title
|
||||
float version; // game version (optional)
|
||||
|
||||
// .dll pathes
|
||||
char dll_path[MAX_QPATH]; // e.g. "bin" or "cl_dlls"
|
||||
char game_dll[MAX_QPATH]; // custom path for game.dll
|
||||
|
||||
// .ico path
|
||||
char iconpath[MAX_QPATH]; // "game.ico" by default
|
||||
|
||||
// about mod info
|
||||
string game_url; // link to a developer's site
|
||||
string update_url; // link to updates page
|
||||
char type[MAX_QPATH]; // single, toolkit, multiplayer etc
|
||||
char date[MAX_QPATH];
|
||||
size_t size;
|
||||
|
||||
int gamemode;
|
||||
qboolean secure; // prevent to console acess
|
||||
qboolean nomodels; // don't let player to choose model (use player.mdl always)
|
||||
qboolean noskills; // disable skill menu selection
|
||||
qboolean render_picbutton_text; // use font renderer to render WON buttons
|
||||
|
||||
char sp_entity[32]; // e.g. info_player_start
|
||||
char mp_entity[32]; // e.g. info_player_deathmatch
|
||||
char mp_filter[32]; // filtering multiplayer-maps
|
||||
|
||||
char ambientsound[NUM_AMBIENTS][MAX_QPATH]; // quake ambient sounds
|
||||
|
||||
int max_edicts; // min edicts is 600, max edicts is 8196
|
||||
int max_tents; // min temp ents is 300, max is 2048
|
||||
int max_beams; // min beams is 64, max beams is 512
|
||||
int max_particles; // min particles is 4096, max particles is 32768
|
||||
|
||||
char game_dll_linux[64]; // custom path for game.dll
|
||||
char game_dll_osx[64]; // custom path for game.dll
|
||||
|
||||
qboolean added;
|
||||
} gameinfo_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GAME_NORMAL,
|
||||
GAME_SINGLEPLAYER_ONLY,
|
||||
GAME_MULTIPLAYER_ONLY
|
||||
} gametype_t;
|
||||
|
||||
typedef struct sysinfo_s
|
||||
{
|
||||
string exeName; // exe.filename
|
||||
@@ -261,9 +189,6 @@ typedef struct sysinfo_s
|
||||
string basedirName; // name of base directory
|
||||
string gamedll;
|
||||
string clientlib;
|
||||
gameinfo_t *GameInfo; // current GameInfo
|
||||
gameinfo_t *games[MAX_MODS]; // environment games (founded at each engine start)
|
||||
int numgames;
|
||||
} sysinfo_t;
|
||||
|
||||
typedef enum
|
||||
@@ -470,6 +395,14 @@ extern sysinfo_t SI;
|
||||
|
||||
typedef void (*xcommand_t)( void );
|
||||
|
||||
//
|
||||
// filesystem_engine.c
|
||||
//
|
||||
#define FILESYSTEM_STDIO_DLL "filesystem_stdio." OS_LIB_EXT
|
||||
qboolean FS_LoadProgs( const char *name );
|
||||
void FS_Init( void );
|
||||
void FS_Shutdown( void );
|
||||
|
||||
//
|
||||
// cmd.c
|
||||
//
|
||||
@@ -529,56 +462,6 @@ void Mem_PrintStats( void );
|
||||
#define Mem_IsAllocated( mem ) Mem_IsAllocatedExt( NULL, mem )
|
||||
#define Mem_Check() _Mem_Check( __FILE__, __LINE__ )
|
||||
|
||||
//
|
||||
// filesystem.c
|
||||
//
|
||||
void FS_Init( void );
|
||||
void FS_Path( void );
|
||||
void FS_Rescan( void );
|
||||
void FS_Shutdown( void );
|
||||
void FS_ClearSearchPath( void );
|
||||
void FS_AllowDirectPaths( qboolean enable );
|
||||
void FS_AddGameDirectory( const char *dir, uint flags );
|
||||
void FS_AddGameHierarchy( const char *dir, uint flags );
|
||||
void FS_LoadGameInfo( const char *rootfolder );
|
||||
const char *FS_GetDiskPath( const char *name, qboolean gamedironly );
|
||||
byte *W_LoadLump( wfile_t *wad, const char *lumpname, size_t *lumpsizeptr, const char type );
|
||||
void W_Close( wfile_t *wad );
|
||||
byte *FS_LoadFile( const char *path, fs_offset_t *filesizeptr, qboolean gamedironly );
|
||||
qboolean CRC32_File( dword *crcvalue, const char *filename );
|
||||
qboolean MD5_HashFile( byte digest[16], const char *pszFileName, uint seed[4] );
|
||||
byte *FS_LoadDirectFile( const char *path, fs_offset_t *filesizeptr );
|
||||
qboolean FS_WriteFile( const char *filename, const void *data, fs_offset_t len );
|
||||
qboolean COM_ParseVector( char **pfile, float *v, size_t size );
|
||||
void COM_NormalizeAngles( vec3_t angles );
|
||||
int COM_FileSize( const char *filename );
|
||||
void COM_FixSlashes( char *pname );
|
||||
void COM_FreeFile( void *buffer );
|
||||
int COM_CompareFileTime( const char *filename1, const char *filename2, int *iCompare );
|
||||
search_t *FS_Search( const char *pattern, int caseinsensitive, int gamedironly );
|
||||
file_t *FS_Open( const char *filepath, const char *mode, qboolean gamedironly );
|
||||
fs_offset_t FS_Write( file_t *file, const void *data, size_t datasize );
|
||||
fs_offset_t FS_Read( file_t *file, void *buffer, size_t buffersize );
|
||||
int FS_VPrintf( file_t *file, const char *format, va_list ap );
|
||||
int FS_Seek( file_t *file, fs_offset_t offset, int whence );
|
||||
int FS_Gets( file_t *file, byte *string, size_t bufsize );
|
||||
int FS_Printf( file_t *file, const char *format, ... ) _format( 2 );
|
||||
fs_offset_t FS_FileSize( const char *filename, qboolean gamedironly );
|
||||
int FS_FileTime( const char *filename, qboolean gamedironly );
|
||||
int FS_Print( file_t *file, const char *msg );
|
||||
qboolean FS_Rename( const char *oldname, const char *newname );
|
||||
int FS_FileExists( const char *filename, int gamedironly );
|
||||
int FS_SetCurrentDirectory( const char *path );
|
||||
qboolean FS_SysFileExists( const char *path, qboolean casesensitive );
|
||||
qboolean FS_FileCopy( file_t *pOutput, file_t *pInput, int fileSize );
|
||||
qboolean FS_Delete( const char *path );
|
||||
int FS_UnGetc( file_t *file, byte c );
|
||||
fs_offset_t FS_Tell( file_t *file );
|
||||
qboolean FS_Eof( file_t *file );
|
||||
int FS_Close( file_t *file );
|
||||
int FS_Getc( file_t *file );
|
||||
fs_offset_t FS_FileLength( file_t *f );
|
||||
|
||||
//
|
||||
// imagelib
|
||||
//
|
||||
@@ -942,6 +825,11 @@ void UI_SetActiveMenu( qboolean fActive );
|
||||
void UI_ShowConnectionWarning( void );
|
||||
void Cmd_Null_f( void );
|
||||
void Rcon_Print( const char *pMsg );
|
||||
qboolean COM_ParseVector( char **pfile, float *v, size_t size );
|
||||
void COM_NormalizeAngles( vec3_t angles );
|
||||
int COM_FileSize( const char *filename );
|
||||
void COM_FreeFile( void *buffer );
|
||||
int COM_CompareFileTime( const char *filename1, const char *filename2, int *iCompare );
|
||||
|
||||
// soundlib shared exports
|
||||
qboolean S_Init( void );
|
||||
|
||||
@@ -761,10 +761,10 @@ qboolean Cmd_GetGamesList( const char *s, char *completedname, int length )
|
||||
// compare gamelist with current keyword
|
||||
len = Q_strlen( s );
|
||||
|
||||
for( i = 0, numgamedirs = 0; i < SI.numgames; i++ )
|
||||
for( i = 0, numgamedirs = 0; i < FI->numgames; i++ )
|
||||
{
|
||||
if(( *s == '*' ) || !Q_strnicmp( SI.games[i]->gamefolder, s, len))
|
||||
Q_strcpy( gamedirs[numgamedirs++], SI.games[i]->gamefolder );
|
||||
if(( *s == '*' ) || !Q_strnicmp( FI->games[i]->gamefolder, s, len))
|
||||
Q_strcpy( gamedirs[numgamedirs++], FI->games[i]->gamefolder );
|
||||
}
|
||||
|
||||
if( !numgamedirs ) return false;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,200 +0,0 @@
|
||||
/*
|
||||
filesystem.h - engine FS
|
||||
Copyright (C) 2007 Uncle Mike
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef FILESYSTEM_H
|
||||
#define FILESYSTEM_H
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
PAK FILES
|
||||
|
||||
The .pak files are just a linear collapse of a directory tree
|
||||
========================================================================
|
||||
*/
|
||||
// header
|
||||
#define IDPACKV1HEADER (('K'<<24)+('C'<<16)+('A'<<8)+'P') // little-endian "PACK"
|
||||
|
||||
#define MAX_FILES_IN_PACK 65536 // pak
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int ident;
|
||||
int dirofs;
|
||||
int dirlen;
|
||||
} dpackheader_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char name[56]; // total 64 bytes
|
||||
int filepos;
|
||||
int filelen;
|
||||
} dpackfile_t;
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
.WAD archive format (WhereAllData - WAD)
|
||||
|
||||
List of compressed files, that can be identify only by TYPE_*
|
||||
|
||||
<format>
|
||||
header: dwadinfo_t[dwadinfo_t]
|
||||
file_1: byte[dwadinfo_t[num]->disksize]
|
||||
file_2: byte[dwadinfo_t[num]->disksize]
|
||||
file_3: byte[dwadinfo_t[num]->disksize]
|
||||
...
|
||||
file_n: byte[dwadinfo_t[num]->disksize]
|
||||
infotable dlumpinfo_t[dwadinfo_t->numlumps]
|
||||
========================================================================
|
||||
*/
|
||||
#define WAD3_NAMELEN 16
|
||||
#define HINT_NAMELEN 5 // e.g. _mask, _norm
|
||||
#define MAX_FILES_IN_WAD 65535 // real limit as above <2Gb size not a lumpcount
|
||||
|
||||
#include "const.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int ident; // should be WAD3
|
||||
int numlumps; // num files
|
||||
int infotableofs; // LUT offset
|
||||
} dwadinfo_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int filepos; // file offset in WAD
|
||||
int disksize; // compressed or uncompressed
|
||||
int size; // uncompressed
|
||||
signed char type; // TYP_*
|
||||
signed char attribs; // file attribs
|
||||
signed char pad0;
|
||||
signed char pad1;
|
||||
char name[WAD3_NAMELEN]; // must be null terminated
|
||||
} dlumpinfo_t;
|
||||
|
||||
#include "custom.h"
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
.HPK archive format (Hash PAK - HPK)
|
||||
|
||||
List of compressed files, that can be identify only by TYPE_*
|
||||
|
||||
<format>
|
||||
header: dwadinfo_t[dwadinfo_t]
|
||||
file_1: byte[dwadinfo_t[num]->disksize]
|
||||
file_2: byte[dwadinfo_t[num]->disksize]
|
||||
file_3: byte[dwadinfo_t[num]->disksize]
|
||||
...
|
||||
file_n: byte[dwadinfo_t[num]->disksize]
|
||||
infotable dlumpinfo_t[dwadinfo_t->numlumps]
|
||||
========================================================================
|
||||
*/
|
||||
|
||||
#define IDHPAKHEADER (('K'<<24)+('A'<<16)+('P'<<8)+'H') // little-endian "HPAK"
|
||||
#define IDHPAK_VERSION 1
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int ident; // should be equal HPAK
|
||||
int version;
|
||||
int infotableofs;
|
||||
} hpak_header_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
resource_t resource;
|
||||
int filepos;
|
||||
int disksize;
|
||||
} hpak_lump_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int count;
|
||||
hpak_lump_t *entries; // variable sized.
|
||||
} hpak_info_t;
|
||||
|
||||
#define ZIP_HEADER_LF (('K'<<8)+('P')+(0x03<<16)+(0x04<<24))
|
||||
#define ZIP_HEADER_SPANNED ((0x08<<24)+(0x07<<16)+('K'<<8)+'P')
|
||||
|
||||
#define ZIP_HEADER_CDF ((0x02<<24)+(0x01<<16)+('K'<<8)+'P')
|
||||
#define ZIP_HEADER_EOCD ((0x06<<24)+(0x05<<16)+('K'<<8)+'P')
|
||||
|
||||
#define ZIP_COMPRESSION_NO_COMPRESSION 0
|
||||
#define ZIP_COMPRESSION_DEFLATED 8
|
||||
|
||||
#define ZIP_ZIP64 0xffffffff
|
||||
|
||||
#pragma pack( push, 1 )
|
||||
typedef struct zip_header_s
|
||||
{
|
||||
unsigned int signature; // little endian ZIP_HEADER
|
||||
unsigned short version; // version of pkzip need to unpack
|
||||
unsigned short flags; // flags (16 bits == 16 flags)
|
||||
unsigned short compression_flags; // compression flags (bits)
|
||||
unsigned int dos_date; // file modification time and file modification date
|
||||
unsigned int crc32; //crc32
|
||||
unsigned int compressed_size;
|
||||
unsigned int uncompressed_size;
|
||||
unsigned short filename_len;
|
||||
unsigned short extrafield_len;
|
||||
} zip_header_t;
|
||||
|
||||
/*
|
||||
in zip64 comp and uncompr size == 0xffffffff remeber this
|
||||
compressed and uncompress filesize stored in extra field
|
||||
*/
|
||||
|
||||
typedef struct zip_header_extra_s
|
||||
{
|
||||
unsigned int signature; // ZIP_HEADER_SPANNED
|
||||
unsigned int crc32;
|
||||
unsigned int compressed_size;
|
||||
unsigned int uncompressed_size;
|
||||
} zip_header_extra_t;
|
||||
|
||||
typedef struct zip_cdf_header_s
|
||||
{
|
||||
unsigned int signature;
|
||||
unsigned short version;
|
||||
unsigned short version_need;
|
||||
unsigned short generalPurposeBitFlag;
|
||||
unsigned short flags;
|
||||
unsigned short modification_time;
|
||||
unsigned short modification_date;
|
||||
unsigned int crc32;
|
||||
unsigned int compressed_size;
|
||||
unsigned int uncompressed_size;
|
||||
unsigned short filename_len;
|
||||
unsigned short extrafield_len;
|
||||
unsigned short file_commentary_len;
|
||||
unsigned short disk_start;
|
||||
unsigned short internal_attr;
|
||||
unsigned int external_attr;
|
||||
unsigned int local_header_offset;
|
||||
} zip_cdf_header_t;
|
||||
|
||||
typedef struct zip_header_eocd_s
|
||||
{
|
||||
unsigned short disk_number;
|
||||
unsigned short start_disk_number;
|
||||
unsigned short number_central_directory_record;
|
||||
unsigned short total_central_directory_record;
|
||||
unsigned int size_of_central_directory;
|
||||
unsigned int central_directory_offset;
|
||||
unsigned short commentary_len;
|
||||
} zip_header_eocd_t;
|
||||
#pragma pack( pop )
|
||||
|
||||
#endif//FILESYSTEM_H
|
||||
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
filesystem.c - game filesystem based on DP fs
|
||||
Copyright (C) 2007 Uncle Mike
|
||||
|
||||
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 "common.h"
|
||||
#include "library.h"
|
||||
|
||||
fs_api_t g_fsapi;
|
||||
fs_globals_t *FI;
|
||||
|
||||
static HINSTANCE fs_hInstance;
|
||||
|
||||
static void FS_Rescan_f( void )
|
||||
{
|
||||
FS_Rescan();
|
||||
}
|
||||
|
||||
static void FS_ClearPaths_f( void )
|
||||
{
|
||||
FS_ClearSearchPath();
|
||||
}
|
||||
|
||||
static void FS_Path_f_( void )
|
||||
{
|
||||
FS_Path_f();
|
||||
}
|
||||
|
||||
static fs_interface_t fs_memfuncs =
|
||||
{
|
||||
Con_Printf,
|
||||
Con_DPrintf,
|
||||
Con_Reportf,
|
||||
Sys_Error,
|
||||
|
||||
_Mem_AllocPool,
|
||||
_Mem_FreePool,
|
||||
_Mem_Alloc,
|
||||
_Mem_Realloc,
|
||||
_Mem_Free,
|
||||
};
|
||||
|
||||
static void FS_UnloadProgs( void )
|
||||
{
|
||||
COM_FreeLibrary( fs_hInstance );
|
||||
fs_hInstance = 0;
|
||||
}
|
||||
|
||||
qboolean FS_LoadProgs( const char *name )
|
||||
{
|
||||
FSAPI GetFSAPI;
|
||||
|
||||
fs_hInstance = COM_LoadLibrary( name, false, true );
|
||||
|
||||
if( !fs_hInstance )
|
||||
{
|
||||
Host_Error( "FS_LoadProgs: can't load filesystem library %s: %s\n", name, COM_GetLibraryError() );
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !( GetFSAPI = (FSAPI)COM_GetProcAddress( fs_hInstance, GET_FS_API )))
|
||||
{
|
||||
FS_UnloadProgs();
|
||||
Host_Error( "FS_LoadProgs: can't find GetFSAPI entry point in %s\n", name );
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !GetFSAPI( FS_API_VERSION, &g_fsapi, &FI, &fs_memfuncs ))
|
||||
{
|
||||
FS_UnloadProgs();
|
||||
Host_Error( "FS_LoadProgs: can't initialize filesystem API: wrong version\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
Con_DPrintf( "FS_LoadProgs: filesystem_stdio successfully loaded\n" );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
FS_Init
|
||||
================
|
||||
*/
|
||||
void FS_Init( void )
|
||||
{
|
||||
qboolean hasBaseDir = false;
|
||||
qboolean hasGameDir = false;
|
||||
qboolean caseinsensitive = true;
|
||||
int i;
|
||||
string gamedir;
|
||||
|
||||
Cmd_AddRestrictedCommand( "fs_rescan", FS_Rescan_f, "rescan filesystem search pathes" );
|
||||
Cmd_AddRestrictedCommand( "fs_path", FS_Path_f_, "show filesystem search pathes" );
|
||||
Cmd_AddRestrictedCommand( "fs_clearpaths", FS_ClearPaths_f, "clear filesystem search pathes" );
|
||||
|
||||
#if !XASH_WIN32
|
||||
if( Sys_CheckParm( "-casesensitive" ) )
|
||||
caseinsensitive = false;
|
||||
#endif
|
||||
|
||||
if( !Sys_GetParmFromCmdLine( "-game", gamedir ))
|
||||
Q_strncpy( gamedir, SI.basedirName, sizeof( gamedir )); // gamedir == basedir
|
||||
|
||||
if( !FS_InitStdio( caseinsensitive, host.rootdir, SI.basedirName, gamedir, host.rodir ))
|
||||
{
|
||||
Host_Error( "Can't init filesystem_stdio!\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
if( !Sys_GetParmFromCmdLine( "-dll", SI.gamedll ))
|
||||
SI.gamedll[0] = 0;
|
||||
|
||||
if( !Sys_GetParmFromCmdLine( "-clientlib", SI.clientlib ))
|
||||
SI.clientlib[0] = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
FS_Shutdown
|
||||
================
|
||||
*/
|
||||
void FS_Shutdown( void )
|
||||
{
|
||||
int i;
|
||||
|
||||
FS_ShutdownStdio();
|
||||
|
||||
memset( &SI, 0, sizeof( sysinfo_t ));
|
||||
|
||||
FS_UnloadProgs();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
+23
-6
@@ -328,13 +328,13 @@ void Host_ChangeGame_f( void )
|
||||
}
|
||||
|
||||
// validate gamedir
|
||||
for( i = 0; i < SI.numgames; i++ )
|
||||
for( i = 0; i < FI->numgames; i++ )
|
||||
{
|
||||
if( !Q_stricmp( SI.games[i]->gamefolder, Cmd_Argv( 1 )))
|
||||
if( !Q_stricmp( FI->games[i]->gamefolder, Cmd_Argv( 1 )))
|
||||
break;
|
||||
}
|
||||
|
||||
if( i == SI.numgames )
|
||||
if( i == FI->numgames )
|
||||
{
|
||||
Con_Printf( "%s not exist\n", Cmd_Argv( 1 ));
|
||||
}
|
||||
@@ -345,7 +345,7 @@ void Host_ChangeGame_f( void )
|
||||
else
|
||||
{
|
||||
const char *arg1 = va( "%s%s", (host.type == HOST_NORMAL) ? "" : "#", Cmd_Argv( 1 ));
|
||||
const char *arg2 = va( "change game to '%s'", SI.games[i]->title );
|
||||
const char *arg2 = va( "change game to '%s'", FI->games[i]->title );
|
||||
|
||||
Host_NewInstance( arg1, arg2 );
|
||||
}
|
||||
@@ -1027,18 +1027,27 @@ void Host_InitCommon( int argc, char **argv, const char *progname, qboolean bCha
|
||||
if( len && host.rodir[len - 1] == '/' )
|
||||
host.rodir[len - 1] = 0;
|
||||
|
||||
if( !COM_CheckStringEmpty( host.rootdir ) || FS_SetCurrentDirectory( host.rootdir ) != 0 )
|
||||
if( !COM_CheckStringEmpty( host.rootdir ))
|
||||
{
|
||||
Sys_Error( "Changing working directory failed (empty working directory)\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
FS_LoadProgs( FILESYSTEM_STDIO_DLL );
|
||||
|
||||
if( FS_SetCurrentDirectory( host.rootdir ) != 0 )
|
||||
Con_Reportf( "%s is working directory now\n", host.rootdir );
|
||||
else
|
||||
Sys_Error( "Changing working directory to %s failed.\n", host.rootdir );
|
||||
|
||||
FS_Init();
|
||||
|
||||
Sys_InitLog();
|
||||
|
||||
Cmd_AddCommand( "exec", Host_Exec_f, "execute a script file" );
|
||||
Cmd_AddCommand( "memlist", Host_MemStats_f, "prints memory pool information" );
|
||||
Cmd_AddRestrictedCommand( "userconfigd", Host_Userconfigd_f, "execute all scripts from userconfig.d" );
|
||||
|
||||
FS_Init();
|
||||
Image_Init();
|
||||
Sound_Init();
|
||||
|
||||
@@ -1048,8 +1057,16 @@ void Host_InitCommon( int argc, char **argv, const char *progname, qboolean bCha
|
||||
#endif
|
||||
|
||||
FS_LoadGameInfo( NULL );
|
||||
|
||||
if( FS_FileExists( va( "%s.rc", SI.basedirName ), false ))
|
||||
Q_strncpy( SI.rcName, SI.basedirName, sizeof( SI.rcName )); // e.g. valve.rc
|
||||
else Q_strncpy( SI.rcName, SI.exeName, sizeof( SI.rcName )); // e.g. quake.rc
|
||||
|
||||
Q_strncpy( host.gamefolder, GI->gamefolder, sizeof( host.gamefolder ));
|
||||
|
||||
Image_CheckPaletteQ1 ();
|
||||
Host_InitDecals (); // reload decals
|
||||
|
||||
// DEPRECATED: by FWGS fork
|
||||
#if 0
|
||||
if( GI->secure )
|
||||
|
||||
@@ -14,7 +14,7 @@ GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include "filesystem.h"
|
||||
#include "hpak.h"
|
||||
|
||||
#define HPAK_MAX_ENTRIES 0x8000
|
||||
#define HPAK_MIN_SIZE (1 * 1024)
|
||||
@@ -402,7 +402,7 @@ static qboolean HPAK_Validate( const char *filename, qboolean quiet )
|
||||
FS_Seek( f, hdr.infotableofs, SEEK_SET );
|
||||
FS_Read( f, &num_lumps, sizeof( num_lumps ));
|
||||
|
||||
if( num_lumps < 1 || num_lumps > MAX_FILES_IN_WAD )
|
||||
if( num_lumps < 1 || num_lumps > HPAK_MAX_ENTRIES )
|
||||
{
|
||||
Con_DPrintf( S_ERROR "HPAK_ValidatePak: %s has too many lumps %u.\n", pakname, num_lumps );
|
||||
FS_Close( f );
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
hpak.c - custom user package to send other clients
|
||||
Copyright (C) 2010 Uncle Mike
|
||||
|
||||
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.
|
||||
*/
|
||||
#ifndef HPAK_H
|
||||
#define HPAK_H
|
||||
|
||||
#include "custom.h"
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
.HPK archive format (Hash PAK - HPK)
|
||||
|
||||
List of compressed files, that can be identify only by TYPE_*
|
||||
|
||||
<format>
|
||||
header: dwadinfo_t[dwadinfo_t]
|
||||
file_1: byte[dwadinfo_t[num]->disksize]
|
||||
file_2: byte[dwadinfo_t[num]->disksize]
|
||||
file_3: byte[dwadinfo_t[num]->disksize]
|
||||
...
|
||||
file_n: byte[dwadinfo_t[num]->disksize]
|
||||
infotable dlumpinfo_t[dwadinfo_t->numlumps]
|
||||
========================================================================
|
||||
*/
|
||||
|
||||
#define IDHPAKHEADER (('K'<<24)+('A'<<16)+('P'<<8)+'H') // little-endian "HPAK"
|
||||
#define IDHPAK_VERSION 1
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int ident; // should be equal HPAK
|
||||
int version;
|
||||
int infotableofs;
|
||||
} hpak_header_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
resource_t resource;
|
||||
int filepos;
|
||||
int disksize;
|
||||
} hpak_lump_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int count;
|
||||
hpak_lump_t *entries; // variable sized.
|
||||
} hpak_info_t;
|
||||
|
||||
#endif // HPAK_H
|
||||
@@ -13,7 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#define MINIZ_HEADER_FILE_ONLY
|
||||
#include "miniz.h"
|
||||
#include "imagelib.h"
|
||||
#include "xash3d_mathlib.h"
|
||||
|
||||
@@ -86,6 +86,31 @@ const char *COM_OffsetNameForFunction( void *function )
|
||||
return sname;
|
||||
}
|
||||
|
||||
dll_user_t *FS_FindLibrary( const char *dllname, qboolean directpath )
|
||||
{
|
||||
dll_user_t *p;
|
||||
fs_dllinfo_t dllInfo;
|
||||
|
||||
// no fs loaded, can't search
|
||||
if( !g_fsapi.FindLibrary )
|
||||
return NULL;
|
||||
|
||||
// fs can't find library
|
||||
if( !g_fsapi.FindLibrary( dllname, directpath, &dllInfo ))
|
||||
return NULL;
|
||||
|
||||
// NOTE: for libraries we not fail even if search is NULL
|
||||
// let the OS find library himself
|
||||
p = Mem_Calloc( host.mempool, sizeof( dll_user_t ));
|
||||
Q_strncpy( p->shortPath, dllInfo.shortPath, sizeof( p->shortPath ));
|
||||
Q_strncpy( p->fullPath, dllInfo.fullPath, sizeof( p->fullPath ));
|
||||
Q_strncpy( p->dllName, dllname, sizeof( p->dllName ));
|
||||
p->custom_loader = dllInfo.custom_loader;
|
||||
p->encrypted = dllInfo.encrypted;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
=============================================================================
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -391,7 +391,7 @@ qboolean COM_CheckLibraryDirectDependency( const char *name, const char *depname
|
||||
dll_user_t *hInst;
|
||||
qboolean ret = FALSE;
|
||||
|
||||
hInst = FS_FindLibrary( name, directpath );
|
||||
hInst = COM_FindLibrary( name, directpath );
|
||||
if ( !hInst ) return FALSE;
|
||||
|
||||
data = FS_LoadFile( name, NULL, false );
|
||||
@@ -439,7 +439,7 @@ void *COM_LoadLibrary( const char *dllname, int build_ordinals_table, qboolean d
|
||||
|
||||
COM_ResetLibraryError();
|
||||
|
||||
hInst = FS_FindLibrary( dllname, directpath );
|
||||
hInst = COM_FindLibrary( dllname, directpath );
|
||||
if( !hInst )
|
||||
{
|
||||
COM_PushLibraryError( va( "Failed to find library %s", dllname ) );
|
||||
|
||||
+8
-8
@@ -27,8 +27,12 @@ GNU General Public License for more details.
|
||||
#include "studio.h"
|
||||
#include "r_efx.h"
|
||||
#include "com_image.h"
|
||||
#include "filesystem.h"
|
||||
|
||||
#define REF_API_VERSION 1
|
||||
// RefAPI changelog:
|
||||
// 1. Initial release
|
||||
// 2. FS functions are removed, instead we have full fs_api_t
|
||||
#define REF_API_VERSION 2
|
||||
|
||||
|
||||
#define TF_SKY (TF_SKYSIDE|TF_NOMIPMAP)
|
||||
@@ -367,13 +371,6 @@ typedef struct ref_api_s
|
||||
void (*COM_FreeLibrary)( void *handle );
|
||||
void *(*COM_GetProcAddress)( void *handle, const char *name );
|
||||
|
||||
// filesystem
|
||||
byte* (*COM_LoadFile)( const char *path, fs_offset_t *pLength, qboolean gamedironly );
|
||||
// use Mem_Free instead
|
||||
// void (*COM_FreeFile)( void *buffer );
|
||||
int (*FS_FileExists)( const char *filename, int gamedironly );
|
||||
void (*FS_AllowDirectPaths)( qboolean enable );
|
||||
|
||||
// video init
|
||||
// try to create window
|
||||
// will call GL_SetupAttributes in case of REF_GL
|
||||
@@ -430,6 +427,9 @@ typedef struct ref_api_s
|
||||
void (*pfnDrawNormalTriangles)( void );
|
||||
void (*pfnDrawTransparentTriangles)( void );
|
||||
render_interface_t *drawFuncs;
|
||||
|
||||
// filesystem exports
|
||||
fs_api_t *fsapi;
|
||||
} ref_api_t;
|
||||
|
||||
struct mip_s;
|
||||
|
||||
+1
-1
@@ -166,7 +166,7 @@ def build(bld):
|
||||
'client/vgui/*.c',
|
||||
'client/avi/*.c'])
|
||||
|
||||
includes = ['common', 'server', 'client', 'client/vgui', 'tests', '.', '../public', '../common', '../pm_shared' ]
|
||||
includes = ['common', 'server', 'client', 'client/vgui', 'tests', '.', '../public', '../common', '../filesystem', '../pm_shared' ]
|
||||
|
||||
if bld.env.SINGLE_BINARY:
|
||||
install_path = bld.env.BINDIR
|
||||
|
||||
Reference in New Issue
Block a user