diff --git a/Quake/common.c b/Quake/common.c index 7b371545..c745f39b 100644 --- a/Quake/common.c +++ b/Quake/common.c @@ -2095,7 +2095,7 @@ static int COM_FindFile (const char *filename, int *handle, FILE **file, if (f) { fseek (f, pak->files[i].filepos, SEEK_SET); - f = FSZIP_Deflate(f, pak->files[i].deflatedsize, pak->files[i].filelen); + f = FSZIP_Deflate(f, pak->files[i].deflatedsize, pak->files[i].filelen, pak->files[i].name); if (f) *handle = Sys_FileOpenStdio(f); else @@ -2124,7 +2124,7 @@ static int COM_FindFile (const char *filename, int *handle, FILE **file, { fseek (*file, pak->files[i].filepos, SEEK_SET); if (pak->files[i].deflatedsize) - *file = FSZIP_Deflate(*file, pak->files[i].deflatedsize, pak->files[i].filelen); + *file = FSZIP_Deflate(*file, pak->files[i].deflatedsize, pak->files[i].filelen, pak->files[i].name); } return com_filesize; } diff --git a/Quake/common.h b/Quake/common.h index 30ad72c9..2344e8d5 100644 --- a/Quake/common.h +++ b/Quake/common.h @@ -352,7 +352,7 @@ const char *COM_GetGameNames(qboolean full); qboolean COM_GameDirMatches(const char *tdirs); pack_t *FSZIP_LoadArchive (const char *packfile); -FILE *FSZIP_Deflate(FILE *src, qofs_t srcsize, qofs_t outsize); +FILE *FSZIP_Deflate(FILE *src, qofs_t srcsize, qofs_t outsize, const char *entryname); void COM_WriteFile (const char *filename, const void *data, int len); int COM_OpenFile (const char *filename, int *handle, unsigned int *path_id); diff --git a/Quake/fs_zip.c b/Quake/fs_zip.c index 0b4f1ff6..bbd00bdf 100644 --- a/Quake/fs_zip.c +++ b/Quake/fs_zip.c @@ -744,7 +744,7 @@ pack_t *FSZIP_LoadArchive (const char *packfile) return pack; } -FILE *FSZIP_Deflate(FILE *src, qofs_t srcsize, qofs_t outsize) +FILE *FSZIP_Deflate(FILE *src, qofs_t srcsize, qofs_t outsize, const char *entryname) { #ifdef USE_ZLIB byte inbuffer[65536]; @@ -773,6 +773,7 @@ FILE *FSZIP_Deflate(FILE *src, qofs_t srcsize, qofs_t outsize) memset(&strm, 0, sizeof(strm)); strm.data_type = Z_UNKNOWN; + strm.next_out = outbuffer; inflateInit2(&strm, -MAX_WBITS); while ((ret=inflate(&strm, Z_SYNC_FLUSH)) != Z_STREAM_END) { @@ -787,9 +788,8 @@ FILE *FSZIP_Deflate(FILE *src, qofs_t srcsize, qofs_t outsize) } if (strm.avail_out == 0) { + fwrite(outbuffer, 1, strm.next_out - outbuffer, of); strm.next_out = outbuffer; - fwrite(outbuffer, 1, strm.total_out, of); - strm.total_out = 0; strm.avail_out = sizeof(outbuffer); } continue; @@ -801,7 +801,7 @@ FILE *FSZIP_Deflate(FILE *src, qofs_t srcsize, qofs_t outsize) inflateEnd(&strm); fclose(src); fclose(of); - Con_Printf("Couldn't decompress file, corrupt?\n"); + Con_Printf("Couldn't decompress file \"%s\", corrupt?\n", entryname); return NULL; } } @@ -811,7 +811,7 @@ FILE *FSZIP_Deflate(FILE *src, qofs_t srcsize, qofs_t outsize) if (strm.total_out != outsize) { - Con_Printf("Decompressed %u bytes, expected %u\n", (unsigned int)strm.total_out, (unsigned int)outsize); + Con_Printf("%s: Decompressed %u bytes, expected %u\n", entryname, (unsigned int)strm.total_out, (unsigned int)outsize); fclose(of); return NULL; }