better zip file handling. (less crashy...)
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@274 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
37a8fd5056
commit
cc8b34639b
1 changed files with 9 additions and 12 deletions
|
@ -2051,8 +2051,7 @@ typedef struct zipfile_s
|
||||||
} zipfile_t;
|
} zipfile_t;
|
||||||
|
|
||||||
static packfile_t *Com_FileInZip(zipfile_t *zip, char *filename);
|
static packfile_t *Com_FileInZip(zipfile_t *zip, char *filename);
|
||||||
char *Com_ReadFileInZip(zipfile_t *zip, char *buffer);
|
char *Com_ReadFileInZip(zipfile_t *zip, int index, char *buffer);
|
||||||
int com_filenum;
|
|
||||||
void *com_pathforfile; //fread and stuff is preferable if null.
|
void *com_pathforfile; //fread and stuff is preferable if null.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -2691,7 +2690,7 @@ int FS_FLocateFile(char *filename, FSLF_ReturnType_e returntype, flocation_t *lo
|
||||||
loc->offset = pf->filepos;
|
loc->offset = pf->filepos;
|
||||||
loc->len = pf->filelen;
|
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);
|
loc->offset = unzGetCurrentFileUncompressedPos(zip->handle);
|
||||||
if (loc->offset<0)
|
if (loc->offset<0)
|
||||||
{ //file not found...
|
{ //file not found...
|
||||||
|
@ -2785,8 +2784,7 @@ int COM_FOpenLocationFILE(flocation_t *loc, FILE **file)
|
||||||
char *buf;
|
char *buf;
|
||||||
FILE *f = tmpfile();
|
FILE *f = tmpfile();
|
||||||
buf = BZ_Malloc(loc->len);
|
buf = BZ_Malloc(loc->len);
|
||||||
com_filenum = loc->index;
|
Com_ReadFileInZip(loc->search->u.zip, loc->index, buf);
|
||||||
Com_ReadFileInZip(loc->search->u.zip, buf);
|
|
||||||
fwrite(buf, 1, loc->len, f);
|
fwrite(buf, 1, loc->len, f);
|
||||||
BZ_Free(buf);
|
BZ_Free(buf);
|
||||||
fseek(f, 0, SEEK_SET);
|
fseek(f, 0, SEEK_SET);
|
||||||
|
@ -2911,8 +2909,7 @@ qbyte *COM_LoadFile (char *path, int usehunk)
|
||||||
{
|
{
|
||||||
#ifdef ZLIB
|
#ifdef ZLIB
|
||||||
case SPT_ZIP:
|
case SPT_ZIP:
|
||||||
com_filenum = loc.index;
|
Com_ReadFileInZip(loc.search->u.zip, loc.index, buf);
|
||||||
Com_ReadFileInZip(loc.search->u.zip, buf);
|
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
|
@ -3591,19 +3588,19 @@ packfile_t *Com_FileInZip(zipfile_t *zip, char *filename)
|
||||||
#endif
|
#endif
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
char *Com_ReadFileInZip(zipfile_t *zip, char *buffer)
|
char *Com_ReadFileInZip(zipfile_t *zip, int index, char *buffer)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
unzLocateFileMy (zip->handle, com_filenum, zip->files[com_filenum].filepos);
|
unzLocateFileMy (zip->handle, index, zip->files[index].filepos);
|
||||||
|
|
||||||
unzOpenCurrentFile (zip->handle);
|
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);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue