From cc8b34639b7d6174e93e6fd819182a8014c917d8 Mon Sep 17 00:00:00 2001 From: Spoike Date: Thu, 30 Sep 2004 22:50:03 +0000 Subject: [PATCH] better zip file handling. (less crashy...) git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@274 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/common/common.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/engine/common/common.c b/engine/common/common.c index ec2a1515e..b03c162e2 100644 --- a/engine/common/common.c +++ b/engine/common/common.c @@ -2051,8 +2051,7 @@ typedef struct zipfile_s } zipfile_t; static packfile_t *Com_FileInZip(zipfile_t *zip, char *filename); -char *Com_ReadFileInZip(zipfile_t *zip, char *buffer); -int com_filenum; +char *Com_ReadFileInZip(zipfile_t *zip, int index, char *buffer); void *com_pathforfile; //fread and stuff is preferable if null. #endif @@ -2691,7 +2690,7 @@ int FS_FLocateFile(char *filename, FSLF_ReturnType_e returntype, flocation_t *lo loc->offset = pf->filepos; loc->len = pf->filelen; - unzLocateFileMy (zip->handle, com_filenum, zip->files[com_filenum].filepos); + unzLocateFileMy (zip->handle, loc->index, zip->files[loc->index].filepos); loc->offset = unzGetCurrentFileUncompressedPos(zip->handle); if (loc->offset<0) { //file not found... @@ -2785,8 +2784,7 @@ int COM_FOpenLocationFILE(flocation_t *loc, FILE **file) char *buf; FILE *f = tmpfile(); buf = BZ_Malloc(loc->len); - com_filenum = loc->index; - Com_ReadFileInZip(loc->search->u.zip, buf); + Com_ReadFileInZip(loc->search->u.zip, loc->index, buf); fwrite(buf, 1, loc->len, f); BZ_Free(buf); fseek(f, 0, SEEK_SET); @@ -2911,8 +2909,7 @@ qbyte *COM_LoadFile (char *path, int usehunk) { #ifdef ZLIB case SPT_ZIP: - com_filenum = loc.index; - Com_ReadFileInZip(loc.search->u.zip, buf); + Com_ReadFileInZip(loc.search->u.zip, loc.index, buf); break; #endif default: @@ -3591,19 +3588,19 @@ packfile_t *Com_FileInZip(zipfile_t *zip, char *filename) #endif return NULL; } -char *Com_ReadFileInZip(zipfile_t *zip, char *buffer) +char *Com_ReadFileInZip(zipfile_t *zip, int index, char *buffer) { int err; - unzLocateFileMy (zip->handle, com_filenum, zip->files[com_filenum].filepos); + unzLocateFileMy (zip->handle, index, zip->files[index].filepos); unzOpenCurrentFile (zip->handle); - err = unzReadCurrentFile (zip->handle, buffer, zip->files[com_filenum].filelen); + err = unzReadCurrentFile (zip->handle, buffer, zip->files[index].filelen); unzCloseCurrentFile (zip->handle); - if (err!=zip->files[com_filenum].filelen) + if (err!=zip->files[index].filelen) { - printf ("Can't extract file \"%s:%s\"", zip->filename, zip->files[com_filenum].name); + printf ("Can't extract file \"%s:%s\"", zip->filename, zip->files[index].name); return 0; }