aboutsummaryrefslogtreecommitdiffstats
path: root/code/qcommon
diff options
context:
space:
mode:
authortma <tma@edf5b092-35ff-0310-97b2-ce42778d08ea>2005-11-16 20:23:37 +0000
committertma <tma@edf5b092-35ff-0310-97b2-ce42778d08ea>2005-11-16 20:23:37 +0000
commite6d6a71599419908afd39c704ccda0cf5e475dea (patch)
treef17969ce5872de83c33998d5002168b3a0b946a8 /code/qcommon
parent8ed1228e0233fd309e944ae2dab9ee272eecf75f (diff)
downloadioquake3-aero-e6d6a71599419908afd39c704ccda0cf5e475dea.tar.gz
ioquake3-aero-e6d6a71599419908afd39c704ccda0cf5e475dea.zip
* Partial implementation of FS_Seek for files in pk3s
* A couple of RIFF decoder tweaks/fixes git-svn-id: svn://svn.icculus.org/quake3/trunk@363 edf5b092-35ff-0310-97b2-ce42778d08ea
Diffstat (limited to 'code/qcommon')
-rw-r--r--code/qcommon/files.c44
1 files changed, 32 insertions, 12 deletions
diff --git a/code/qcommon/files.c b/code/qcommon/files.c
index ecdc885..9baadb7 100644
--- a/code/qcommon/files.c
+++ b/code/qcommon/files.c
@@ -1361,6 +1361,8 @@ void QDECL FS_Printf( fileHandle_t h, const char *fmt, ... ) {
FS_Write(msg, strlen(msg), h);
}
+#define PK3_SEEK_BUFFER_SIZE 65536
+
/*
=================
FS_Seek
@@ -1369,7 +1371,6 @@ FS_Seek
*/
int FS_Seek( fileHandle_t f, long offset, int origin ) {
int _origin;
- char foo[65536];
if ( !fs_searchpaths ) {
Com_Error( ERR_FATAL, "Filesystem call made without initialization\n" );
@@ -1383,19 +1384,38 @@ int FS_Seek( fileHandle_t f, long offset, int origin ) {
}
if (fsh[f].zipFile == qtrue) {
- if (offset == 0 && origin == FS_SEEK_SET) {
- // set the file position in the zip file (also sets the current file info)
- unzSetCurrentFileInfoPosition(fsh[f].handleFiles.file.z, fsh[f].zipFilePos);
- return unzOpenCurrentFile(fsh[f].handleFiles.file.z);
- } else if (offset<65536) {
- // set the file position in the zip file (also sets the current file info)
- unzSetCurrentFileInfoPosition(fsh[f].handleFiles.file.z, fsh[f].zipFilePos);
- unzOpenCurrentFile(fsh[f].handleFiles.file.z);
- return FS_Read(foo, offset, f);
- } else {
- Com_Error( ERR_FATAL, "ZIP FILE FSEEK NOT YET IMPLEMENTED\n" );
+ //FIXME: this is incomplete and really, really
+ //crappy (but better than what was here before)
+ byte buffer[PK3_SEEK_BUFFER_SIZE];
+ int remainder = offset;
+
+ Com_Printf( S_COLOR_YELLOW "%s %d %d\n", fsh[f].name, offset, origin );
+ if( offset < 0 || origin == FS_SEEK_END ) {
+ Com_Error( ERR_FATAL, "Negative offsets and FS_SEEK_END not implemented "
+ "for FS_Seek on pk3 file contents\n" );
return -1;
}
+
+ switch( origin ) {
+ case FS_SEEK_SET:
+ unzSetCurrentFileInfoPosition(fsh[f].handleFiles.file.z, fsh[f].zipFilePos);
+ unzOpenCurrentFile(fsh[f].handleFiles.file.z);
+ //fallthrough
+
+ case FS_SEEK_CUR:
+ while( remainder > PK3_SEEK_BUFFER_SIZE ) {
+ FS_Read( buffer, PK3_SEEK_BUFFER_SIZE, f );
+ remainder -= PK3_SEEK_BUFFER_SIZE;
+ }
+ FS_Read( buffer, remainder, f );
+ return offset;
+ break;
+
+ default:
+ Com_Error( ERR_FATAL, "Bad origin in FS_Seek\n" );
+ return -1;
+ break;
+ }
} else {
FILE *file;
file = FS_FileForHandle(f);