本文整理汇总了C++中FS_FOpenFile函数的典型用法代码示例。如果您正苦于以下问题:C++ FS_FOpenFile函数的具体用法?C++ FS_FOpenFile怎么用?C++ FS_FOpenFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FS_FOpenFile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WriteCache
static void WriteCache( void ) {
char buffer[MAX_OSPATH];
qhandle_t f;
int i;
char *map, *pov;
demoEntry_t *e;
size_t len;
if( m_demos.list.numItems == m_demos.numDirs ) {
return;
}
len = Q_concat( buffer, sizeof( buffer ), m_demos.browse, "/" COM_DEMOCACHE_NAME, NULL );
if( len >= sizeof( buffer ) ) {
return;
}
FS_FOpenFile( buffer, &f, FS_MODE_WRITE );
if( !f ) {
return;
}
for( i = 0; i < 16; i++ ) {
FS_FPrintf( f, "%02x", m_demos.hash[i] );
}
FS_FPrintf( f, "\\" );
for( i = m_demos.numDirs; i < m_demos.list.numItems; i++ ) {
e = m_demos.list.items[i];
map = UI_GetColumn( e->name, COL_MAP );
pov = UI_GetColumn( e->name, COL_POV );
FS_FPrintf( f, "%s\\%s\\", map, pov );
}
FS_FCloseFile( f );
}
示例2: SV_RunGameFrame
/*
static qboolean SV_RunGameFrame( int msec )
{
int extraTime = 0;
static unsigned int accTime = 0;
accTime += msec;
// move autonomous things around if enough time has passed
if( svs.gametime < sv.nextSnapTime )
{
if( svs.gametime + svc.snapFrameTime < sv.nextSnapTime )
{
if( sv_showclamp->integer )
Com_Printf( "sv lowclamp\n" );
sv.nextSnapTime = svs.gametime + svc.snapFrameTime;
return qfalse;
}
// see if it's time to advance the world
if( accTime >= WORLDFRAMETIME )
{
if( host_speeds->integer )
time_before_game = Sys_Milliseconds();
ge->RunFrame( WORLDFRAMETIME, svs.gametime );
if( host_speeds->integer )
time_after_game = Sys_Milliseconds();
accTime = accTime - WORLDFRAMETIME;
}
if( !SV_SendClientsFragments() )
{
// FIXME: gametime might slower/faster than real time
if( dedicated->integer )
{
socket_t *sockets[] = { &svs.socket_udp, NULL };
NET_Sleep( min( WORLDFRAMETIME - accTime, sv.nextSnapTime - svs.gametime ), sockets );
}
}
return qfalse;
}
if( sv.nextSnapTime <= svs.gametime )
{
extraTime = (int)( svs.gametime - sv.nextSnapTime );
}
if( extraTime >= msec )
extraTime = msec - 1;
sv.nextSnapTime = ( svs.gametime + svc.snapFrameTime ) - extraTime;
// Execute all clients pending move commands
if( accTime )
{
ge->RunFrame( accTime, svs.gametime );
accTime = 0;
}
// update ping based on the last known frame from all clients
SV_CalcPings();
sv.framenum++;
ge->SnapFrame();
return qtrue;
}
*/
static void SV_CheckDefaultMap( void )
{
if( svc.autostarted )
return;
svc.autostarted = qtrue;
if( dedicated->integer )
{
if( sv.state == ss_dead && !strlen( sv.mapname ) )
{
int filehandle;
if( sv_write_defaultmap && sv_write_defaultmap->integer && FS_FOpenFile( "defaultmap", &filehandle, FS_READ ) != -1 )
{
static char buffer[MAX_QPATH];
buffer[0] = '\0';
FS_Read( buffer, MAX_QPATH - 1, filehandle );
FS_FCloseFile( filehandle );
if( buffer[0] )
{
Cbuf_ExecuteText( EXEC_APPEND, va( "map %s\n", buffer ) );
return;
}
}
if( sv_defaultmap && strlen( sv_defaultmap->string ) )
Cbuf_ExecuteText( EXEC_APPEND, va( "map %s\n", sv_defaultmap->string ) );
}
}
}
示例3: Com_DPrintf
// returns static string of md5 contents
const char *MM_PasswordRead( const char *user )
{
static char buffer[MAX_STRING_CHARS];
const char *filename;
int filenum;
size_t bytes;
Com_DPrintf( "MM_PasswordRead %s\n", user );
filename = mm_passwordFilename( user );
if( FS_FOpenFile( filename, &filenum, FS_READ ) == -1 )
{
Com_Printf( "MM_PasswordRead: Couldnt open file %s\n", filename);
return NULL;
}
bytes = FS_Read(buffer, sizeof( buffer ) - 1, filenum );
FS_FCloseFile( filenum );
if( bytes == 0 || bytes >= sizeof(buffer) - 1 )
return NULL;
buffer[bytes] = '\0';
return buffer;
}
示例4: CL_CheckOrDownloadFile
/*
* CL_CheckOrDownloadFile
*
* Returns true if the file exists or couldn't send download request
* Files with .pk3 or .pak extension have to have gamedir attached
* Other files must not have gamedir
*/
qboolean CL_CheckOrDownloadFile( const char *filename )
{
const char *ext;
if( !cl_downloads->integer )
return qtrue;
if( !COM_ValidateRelativeFilename( filename ) )
return qtrue;
ext = COM_FileExtension( filename );
if( !ext || !*ext )
return qtrue;
if( FS_CheckPakExtension( filename ) )
{
if( FS_FOpenBaseFile( filename, NULL, FS_READ ) != -1 )
return qtrue;
}
else
{
if( FS_FOpenFile( filename, NULL, FS_READ ) != -1 )
return qtrue;
}
if( !CL_DownloadRequest( filename, qtrue ) )
return qtrue;
cls.download.requestnext = qtrue; // call CL_RequestNextDownload when done
return qfalse;
}
示例5: wswcurl_write
static size_t wswcurl_write(void *ptr, size_t size, size_t nmemb, void *stream)
{
wswcurl_req *req = (wswcurl_req*)stream;
if (!req->filename) {
// Reallocate buffer
req->rxdata = WREALLOC(req->rxdata, req->rxsize + (size * nmemb) + 1);
// Set remaining data to 0
memset(&(req->rxdata[req->rxsize]), 0, (size * nmemb));
// Copy received data
memcpy(&(req->rxdata[req->rxsize]), ptr, size*nmemb);
// Recalculate size
req->rxsize += size*nmemb;
// Add trailing NULL byte at the end to prevent string overflow
req->rxdata[req->rxsize] = '\0';
} else {
// Receive to the filename.
// TODO: FILE RESUMING??
#ifndef WSWCURL_TEST_MAIN
if ( (req->filenum < 0) && ( FS_FOpenFile( req->filename, &(req->filenum), FS_WRITE ) < 0 ) ) {
return 0; // RETURN ERROR
}
FS_Write(ptr, size * nmemb, req->filenum);
#else
// TODO: IMPLEMENT TEST
#endif
}
// Mark connection as having had activity.
req->activity = 1;
if (req->callback_progress) {
// Execute progress callback
// ??? What to return when expected size is unknown? - currently, return 0.0
req->callback_progress(req, ( req->rx_expsize < 0 ) ? 0.0 : (req->rxsize / req->rx_expsize) * 100.0);
}
return size*nmemb;
}
示例6: FS_LoadFile
/*
* Filename are reletive to the quake search path. A null buffer will just
* return the file length without loading.
*/
int
FS_LoadFile(char *path, void **buffer)
{
byte *buf; /* Buffer. */
int size; /* File size. */
fileHandle_t f; /* File handle. */
buf = NULL;
size = FS_FOpenFile(path, &f, FS_READ);
if (size <= 0)
{
if (buffer)
{
*buffer = NULL;
}
return size;
}
if (buffer == NULL)
{
FS_FCloseFile(f);
return size;
}
buf = Z_Malloc(size);
*buffer = buf;
FS_Read(buf, size, f);
FS_FCloseFile(f);
return size;
}
示例7: SV_ReadLevelFile
void
SV_ReadLevelFile(void)
{
char name[MAX_OSPATH];
fileHandle_t f;
Com_DPrintf("SV_ReadLevelFile()\n");
Com_sprintf(name, sizeof(name), "save/current/%s.sv2", sv.name);
FS_FOpenFile(name, &f, FS_READ);
if (!f)
{
Com_Printf("Failed to open %s\n", name);
return;
}
FS_Read(sv.configstrings, sizeof(sv.configstrings), f);
CM_ReadPortalState(f);
FS_FCloseFile(f);
Com_sprintf(name, sizeof(name), "%s/save/current/%s.sav",
FS_Gamedir(), sv.name);
ge->ReadLevel(name);
}
示例8: FS_LoadFile
/*
============
FS_LoadFile
Filename are reletive to the quake search path
a null buffer will just return the file length without loading
============
*/
int FS_LoadFile(char *path, void **buffer)
{
FILE *h;
byte *buf;
int len;
buf = NULL; // quiet compiler warning
// look for it in the filesystem or pack files
len = FS_FOpenFile(path, &h);
if (!h)
{
if (buffer)
*buffer = NULL;
return -1;
}
if (!buffer)
{
fclose(h);
return len;
}
buf = Z_Malloc(len);
*buffer = buf;
FS_Read(buf, len, h);
fclose(h);
return len;
}
示例9: Prompt_LoadHistory
void Prompt_LoadHistory( commandPrompt_t *prompt, const char *filename ) {
char buffer[MAX_FIELD_TEXT];
qhandle_t f;
int i;
ssize_t len;
FS_FOpenFile( filename, &f, FS_MODE_READ|FS_TYPE_REAL|FS_PATH_BASE );
if( !f ) {
return;
}
for( i = 0; i < HISTORY_SIZE; i++ ) {
if( ( len = FS_ReadLine( f, buffer, sizeof( buffer ) ) ) < 1 ) {
break;
}
if( prompt->history[i] ) {
Z_Free( prompt->history[i] );
}
prompt->history[i] = memcpy( Z_Malloc( len + 1 ), buffer, len + 1 );
}
FS_FCloseFile( f );
prompt->historyLineNum = i;
prompt->inputLineNum = i;
}
示例10: Prompt_SaveHistory
void Prompt_SaveHistory( commandPrompt_t *prompt, const char *filename, int lines ) {
qhandle_t f;
char *s;
int i;
FS_FOpenFile( filename, &f, FS_MODE_WRITE|FS_PATH_BASE );
if( !f ) {
return;
}
if( lines > HISTORY_SIZE ) {
lines = HISTORY_SIZE;
}
i = prompt->inputLineNum - lines;
if( i < 0 ) {
i = 0;
}
for( ; i < prompt->inputLineNum; i++ ) {
s = prompt->history[i & HISTORY_MASK];
if( s ) {
FS_FPrintf( f, "%s\n", s );
}
}
FS_FCloseFile( f );
}
示例11: read_binary_file
static int read_binary_file(const char *name)
{
qhandle_t f;
size_t len;
len = FS_FOpenFile(name, &f, FS_MODE_READ | FS_TYPE_REAL | FS_PATH_GAME);
if (!f)
return -1;
if (len > MAX_MSGLEN)
goto fail;
if (FS_Read(msg_read_buffer, len, f) != len)
goto fail;
SZ_Init(&msg_read, msg_read_buffer, len);
msg_read.cursize = len;
FS_FCloseFile(f);
return 0;
fail:
FS_FCloseFile(f);
return -1;
}
示例12: SNAP_WriteDemoMetaData
/*
* SNAP_WriteDemoMetaData
*/
void SNAP_WriteDemoMetaData( const char *filename, const char *meta_data, size_t meta_data_realsize )
{
unsigned i;
unsigned v;
char tmpn[256];
int filenum, filelen;
msg_t msg;
uint8_t msg_buffer[MAX_MSGLEN];
void *compressed_msg;
MSG_Init( &msg, msg_buffer, sizeof( msg_buffer ) );
// write to a temp file
v = 0;
for( i = 0; filename[i]; i++ ) {
v = ( v + i ) * 37 + tolower( filename[i] ); // case insensitivity
}
Q_snprintfz( tmpn, sizeof( tmpn ), "%u.tmp", v );
if( FS_FOpenFile( tmpn, &filenum, FS_WRITE|SNAP_DEMO_GZ ) == -1 ) {
return;
}
SNAP_DemoMetaDataMessage( &msg, meta_data, meta_data_realsize );
SNAP_RecordDemoMetaDataMessage( filenum, &msg );
// now open the original file in update mode and overwrite metadata
// important note: we need to the load the temp file before closing it
// because in the case of gz compression, closing the file may actually
// write some data we don't want to copy
filelen = FS_LoadFile( tmpn, &compressed_msg, NULL, 0 );
if( compressed_msg ) {
int origfile;
if( FS_FOpenFile( filename, &origfile, FS_READ|FS_UPDATE ) != -1 ) {
FS_Write( compressed_msg, filelen, origfile );
FS_FCloseFile( origfile );
}
FS_FreeFile( compressed_msg );
}
FS_FCloseFile( filenum );
FS_RemoveFile( tmpn );
}
示例13: CL_ReadServerCache
/*
* CL_ReadServerCache
*/
void CL_ReadServerCache( void )
{
int filelen, filehandle;
qbyte *buf = NULL;
char *ptr, *token;
netadr_t adr;
char adrString[64];
qboolean favorite = qfalse;
filelen = FS_FOpenFile( SERVERSFILE, &filehandle, FS_READ );
if( !filehandle || filelen < 1 )
{
FS_FCloseFile( filehandle );
}
else
{
buf = Mem_TempMalloc( filelen + 1 );
filelen = FS_Read( buf, filelen, filehandle );
FS_FCloseFile( filehandle );
}
if( !buf )
return;
ptr = ( char * )buf;
while( ptr )
{
token = COM_ParseExt( &ptr, qtrue );
if( !token[0] )
break;
if( !Q_stricmp( token, "master" ) )
{
favorite = qfalse;
continue;
}
if( !Q_stricmp( token, "favorites" ) )
{
favorite = qtrue;
continue;
}
if( NET_StringToAddress( token, &adr ) )
{
Q_strncpyz( adrString, token, sizeof( adrString ) );
token = COM_ParseExt( &ptr, qfalse );
if( !token[0] )
continue;
if( favorite )
CL_AddServerToList( &favoritesList, adrString, (unsigned int)atoi( token ) );
else
CL_AddServerToList( &masterList, adrString, (unsigned int)atoi( token ) );
}
}
Mem_TempFree( buf );
}
示例14: S_OpenBackgroundTrack
/*
=================
S_OpenBackgroundTrack
=================
*/
static qboolean S_OpenBackgroundTrack (char *name, bgTrack_t *track)
{
OggVorbis_File *vorbisFile;
vorbis_info *vorbisInfo;
ov_callbacks vorbisCallbacks = {ovc_read, ovc_seek, ovc_close, ovc_tell};
#ifdef OGG_DIRECT_FILE
char filename[1024];
char *path = NULL;
#endif
// Com_Printf("Opening background track: %s\n", name);
#ifdef OGG_DIRECT_FILE
do {
path = FS_NextPath( path );
Com_sprintf( filename, sizeof(filename), "%s/%s", path, name );
if ( (track->file = fopen(filename, "rb")) != 0)
break;
} while ( path );
#else
FS_FOpenFile(name, &track->file);
#endif
if (!track->file)
{
Com_Printf("S_OpenBackgroundTrack: couldn't find %s\n", name);
return false;
}
track->vorbisFile = vorbisFile = Z_Malloc(sizeof(OggVorbis_File));
// Com_Printf("Opening callbacks for background track\n");
// bombs out here- ovc_read, FS_Read 0 bytes error
if (ov_open_callbacks(track, vorbisFile, NULL, 0, vorbisCallbacks) < 0)
{
Com_Printf("S_OpenBackgroundTrack: couldn't open OGG stream (%s)\n", name);
return false;
}
// Com_Printf("Getting info for background track\n");
vorbisInfo = ov_info(vorbisFile, -1);
if (vorbisInfo->channels != 1 && vorbisInfo->channels != 2)
{
Com_Printf("S_OpenBackgroundTrack: only mono and stereo OGG files supported (%s)\n", name);
return false;
}
track->start = ov_raw_tell(vorbisFile);
track->rate = vorbisInfo->rate;
track->width = 2;
track->channels = vorbisInfo->channels; // Knightmare added
track->format = (vorbisInfo->channels == 2) ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16;
// Com_Printf("Vorbis info: frequency: %i channels: %i bitrate: %i\n",
// vorbisInfo->rate, vorbisInfo->channels, vorbisInfo->bitrate_nominal);
return true;
}
示例15: SV_BeginDemoserver
/*
==================
SV_BeginDemoServer
==================
*/
void SV_BeginDemoserver(void){
char name[MAX_OSPATH];
Com_sprintf(name, sizeof(name), "demos/%s", sv.name);
FS_FOpenFile(name, &sv.demofile);
if(!sv.demofile)
Com_Error(ERR_DROP, "Couldn't open %s\n", name);
}