diff options
author | Andrey Nazarov <skuller@skuller.net> | 2010-07-03 16:01:48 +0000 |
---|---|---|
committer | Andrey Nazarov <skuller@skuller.net> | 2010-07-03 16:01:48 +0000 |
commit | 7a914ef872a436adcdb36d21ceddba6bb24eb993 (patch) | |
tree | dafc86024742e7bbced8ef897754beff5160f1ae /source/cl_parse.c | |
parent | 1acd69e9a128e4f3abf06b5ae97c968c87663864 (diff) |
Yet another huge commit.
Implemented new error reporting framework based on errno and custom error codes.
Converted filesystem code, image and model managers, BSP loader to use the new framework and report errors more accurately.
Replaced fileHandle_t with qhandle_t.
Removed INVALID_LENGTH definition.
Killed USE_LOADBUF code.
Defined FS_FileExists(Ex) macro, implemented FS_EasyOpenFile and FS_WriteFile helper functions.
When testing for free screenshot slots, open the file with O_EXCL flag to avoid race conditions (works only on glibc yet).
Don't allow quake paths with high bits set.
Don't tolerate any fatal errors encountered when searching for files and pass errors back to the caller.
FS_Seek() now fails on files from packs instead of returning an invalid position.
Fixed ‘mvdskip’ command not working properly.
Avoid inefficient usage of MakeColor macro in image loading functions.
Prevent memory leak in JPEG and PNG image functions after calling longjmp() by marking some local variables volatile.
Added support for loading monochrome JPEG images.
Fixed signed integer overflow in GetWavinfo().
Fixed missing return statement in BSP_LoadSurfEdges() causing out of range edge indices to be left uncaught.
Fixed possible access to uninitialized memory in BSP_LoadLeafs() for maps with no leafs.
Properly NUL terminate the buffer in SCR_ScoreDump_f(), also check for being in a level.
Always free latched_string when cvar is set back to current value.
Fixed a crash in ‘mvdplay’ command possible when demo file is invalid.
Diffstat (limited to 'source/cl_parse.c')
-rw-r--r-- | source/cl_parse.c | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/source/cl_parse.c b/source/cl_parse.c index f37872c..0423066 100644 --- a/source/cl_parse.c +++ b/source/cl_parse.c @@ -32,8 +32,9 @@ to start a download from the server. =============== */ qboolean CL_CheckOrDownloadFile( const char *path ) { - fileHandle_t f; + qhandle_t f; size_t len; + ssize_t ret; len = strlen( path ); if( len < 1 || len >= MAX_QPATH @@ -48,7 +49,7 @@ qboolean CL_CheckOrDownloadFile( const char *path ) { return qtrue; } - if( FS_LoadFile( path, NULL ) != INVALID_LENGTH ) { + if( FS_FileExists( path ) ) { // it exists, no need to download return qtrue; } @@ -73,20 +74,19 @@ qboolean CL_CheckOrDownloadFile( const char *path ) { //ZOID // check to see if we already have a tmp for this file, if so, try to resume // open the file if not opened yet - len = FS_FOpenFile( cls.download.temp, &f, FS_MODE_RDWR ); - if( len == INVALID_LENGTH && f ) { - Com_WPrintf( "Couldn't determine size of %s\n", cls.download.temp ); - FS_FCloseFile( f ); - f = 0; - } - if( f ) { // it exists + ret = FS_FOpenFile( cls.download.temp, &f, FS_MODE_RDWR ); + if( ret >= 0 ) { // it exists cls.download.file = f; // give the server an offset to start the download Com_Printf( "Resuming %s\n", cls.download.name ); - CL_ClientCommand( va( "download \"%s\" %"PRIz, cls.download.name, len ) ); - } else { + CL_ClientCommand( va( "download \"%s\" %d", cls.download.name, (int)ret ) ); + } else if( ret == Q_ERR_NOENT ) { // it doesn't exist Com_Printf( "Downloading %s\n", cls.download.name ); CL_ClientCommand( va( "download \"%s\"", cls.download.name ) ); + } else { // error happened + Com_EPrintf( "Couldn't open %s for appending: %s\n", cls.download.temp, + Q_ErrorString( ret ) ); + return qtrue; } return qfalse; @@ -126,8 +126,8 @@ void CL_Download_f( void ) { path = Cmd_Argv( 1 ); - if( FS_LoadFile( path, NULL ) != INVALID_LENGTH ) { - Com_Printf( "File '%s' already exists.\n", path ); + if( FS_FileExists( path ) ) { + Com_Printf( "%s already exists.\n", path ); return; } @@ -143,7 +143,8 @@ A download message has been received from the server ===================== */ static void CL_ParseDownload( void ) { - int size, percent; + int size, percent; + qerror_t ret; if( !cls.download.temp[0] ) { Com_Error( ERR_DROP, "%s: no download requested", __func__ ); @@ -175,11 +176,11 @@ static void CL_ParseDownload( void ) { // open the file if not opened yet if( !cls.download.file ) { - FS_FOpenFile( cls.download.temp, &cls.download.file, FS_MODE_WRITE ); + ret = FS_FOpenFile( cls.download.temp, &cls.download.file, FS_MODE_WRITE ); if( !cls.download.file ) { msg_read.readcount += size; - Com_WPrintf( "Failed to open '%s' for writing\n", - cls.download.temp ); + Com_EPrintf( "Couldn't open %s for writing: %s\n", + cls.download.temp, Q_ErrorString( ret ) ); goto another; } } @@ -197,9 +198,10 @@ static void CL_ParseDownload( void ) { FS_FCloseFile( cls.download.file ); // rename the temp file to it's final name - if( !FS_RenameFile( cls.download.temp, cls.download.name ) ) { - Com_WPrintf( "Failed to rename %s to %s\n", - cls.download.temp, cls.download.name ); + ret = FS_RenameFile( cls.download.temp, cls.download.name ); + if( ret ) { + Com_EPrintf( "Couldn't rename %s to %s: %s\n", + cls.download.temp, cls.download.name, Q_ErrorString( ret ) ); } Com_Printf( "Downloaded successfully.\n" ); |