Made fixes to quakefs.c, unzip.c, and unzip.h; compiles for me, and should for you too. Unzip.c was surprisingly broken; quakefs.c was mildy broken but now fixed (GENERATIONS code). Also an "interface" change, no longer searches for .pk3 files but rather .qz (quake pack) as per Knghtbrd's suggestion.

This commit is contained in:
Eric Windisch 2000-03-04 01:55:01 +00:00
parent 3e6df0a25e
commit 45ccae6ba7
3 changed files with 45 additions and 46 deletions

View file

@ -61,21 +61,16 @@ QUAKE FILESYSTEM
============================================================================= =============================================================================
*/ */
/* Begin Generations */ #ifdef GENERATIONS
#if defined(_EXPERIMENTAL_) && defined(GENERATIONS) #include <unzip.h>
#include "unzip.h"
#endif
typedef unsigned char byte_t; typedef unsigned char byte_t;
char gamedirfile[MAX_OSPATH]; char gamedirfile[MAX_OSPATH];
#if 0
#ifndef _AIX #ifndef _AIX
typedef unsigned int uint_t; typedef unsigned int uint_t;
typedef unsigned short ushort_t; typedef unsigned short ushort_t;
#endif #endif
#endif #endif
/* End Generations */
int com_filesize; int com_filesize;
@ -540,7 +535,7 @@ pack_t *COM_LoadPackFile (char *packfile)
return pack; return pack;
} }
#if defined(_EXPERIMENTAL_) && defined(GENERATIONS) #ifdef GENERATIONS
int int
COM_pakzip_checkfile(unzFile *pak, const char *path) COM_pakzip_checkfile(unzFile *pak, const char *path)
{ {
@ -564,14 +559,10 @@ COM_pakzip_close(unzFile *pak)
unzCloseCurrentFile(pak); unzCloseCurrentFile(pak);
} }
int int
COM_pakzip_read(unzFile *pak, void *buf, uint_t size, uint_t nmemb) COM_pakzip_read(unzFile *pak, void *buf, uint_t size, uint_t nmemb)
{ {
int len; int len = unzReadCurrentFile(pak, buf, size * nmemb);
len = unzReadCurrentFile(pak, buf, size * nmemb);
return len / size; return len / size;
} }
@ -613,20 +604,19 @@ COM_pakzip_readfile(unzFile *pak, const char *path, uint_t bufsize, byte_t *buf)
return len; return len;
} }
#endif
#if defined _EXPERIMENTAL_ && GENERATIONS
pack_t *COM_LoadPackZipFile (char *packfile) pack_t *COM_LoadPackZipFile (char *packfile)
{ {
int i=0;
int i;
packfile_t *newfiles; packfile_t *newfiles;
float numpackfiles; float numpackfiles;
unzFile *pak; unzFile *pak;
pack_t *pack_old; pack_t *pack_old;
int status; int status;
dpackfile_t info[MAX_FILES_IN_PACK];
char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; // This following variable info is unused ATM.
// dpackfile_t info[MAX_FILES_IN_PACK];
char szCurrentFileName[256];
pak = unzOpen(packfile); pak = unzOpen(packfile);
@ -641,7 +631,7 @@ pack_t *COM_LoadPackZipFile (char *packfile)
status=unzGoToFirstFile(pak); status=unzGoToFirstFile(pak);
while(status == UNZ_OK) { while(status == UNZ_OK) {
unzGetCurrentFileInfo(pak,NULL,&szCurrentFileName,64,NULL,0,NULL,0); // unzGetCurrentFileInfo(pak,NULL,&szCurrentFileName,64,NULL,0,NULL,0);
if(strcmp(newfiles[i].name, szCurrentFileName)==0) if(strcmp(newfiles[i].name, szCurrentFileName)==0)
break; break;
@ -671,7 +661,7 @@ pack_t *COM_LoadPackZipFile (char *packfile)
COM_pakzip_close(pak); COM_pakzip_close(pak);
return pack_old; return pack_old;
} }
#endif #endif
void void
COM_LoadGameDirectory(char *dir) COM_LoadGameDirectory(char *dir)
@ -697,9 +687,9 @@ COM_LoadGameDirectory(char *dir)
} }
} }
#if defined _EXPERIMENTAL_ && GENERATIONS #ifdef GENERATIONS
for (done=false, i=0 ; !done ; i++ ) { // Load all Pak3 files. for (done=false, i=0 ; !done ; i++ ) { // Load all Pak3 files.
snprintf(pakfile, sizeof(pakfile), "%s/pak%i.pk3", dir, i); snprintf(pakfile, sizeof(pakfile), "%s/pak%i.qz", dir, i);
pak = COM_LoadPackZipFile(pakfile); pak = COM_LoadPackZipFile(pakfile);

View file

@ -35,6 +35,15 @@
#define CASESENSITIVITYDEFAULT_NO #define CASESENSITIVITYDEFAULT_NO
#endif #endif
#ifndef UNZ_BUFSIZE
#define UNZ_BUFSIZE (16384)
#endif
#ifndef UNZ_MAXFILENAMEINZIP
#define UNZ_MAXFILENAMEINZIP (256)
#endif
#ifndef ALLOC #ifndef ALLOC
# define ALLOC(size) (malloc(size)) # define ALLOC(size) (malloc(size))
#endif #endif
@ -88,7 +97,7 @@ typedef struct
uLong crc32_wait; /* crc32 we must obtain after decompress all */ uLong crc32_wait; /* crc32 we must obtain after decompress all */
uLong rest_read_compressed; /* number of byte to be decompressed */ uLong rest_read_compressed; /* number of byte to be decompressed */
uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/ uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/
QFile* file; /* io structore of the zipfile */ FILE* file; /* io structore of the zipfile */
uLong compression_method; /* compression method (0==store) */ uLong compression_method; /* compression method (0==store) */
uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
} file_in_zip_read_info_s; } file_in_zip_read_info_s;
@ -98,7 +107,7 @@ typedef struct
*/ */
typedef struct typedef struct
{ {
QFile* file; /* io structore of the zipfile */ FILE* file; /* io structore of the zipfile */
unz_global_info gi; /* public global information */ unz_global_info gi; /* public global information */
uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
uLong num_file; /* number of the current file in the zipfile*/ uLong num_file; /* number of the current file in the zipfile*/
@ -125,7 +134,7 @@ typedef struct
local int unzlocal_getByte(fin,pi) local int unzlocal_getByte(fin,pi)
QFile *fin; FILE *fin;
int *pi; int *pi;
{ {
unsigned char c; unsigned char c;
@ -149,7 +158,7 @@ local int unzlocal_getByte(fin,pi)
Reads a long in LSB order from the given gz_stream. Sets Reads a long in LSB order from the given gz_stream. Sets
*/ */
local int unzlocal_getShort (fin,pX) local int unzlocal_getShort (fin,pX)
QFile* fin; FILE* fin;
uLong *pX; uLong *pX;
{ {
uLong x ; uLong x ;
@ -171,7 +180,7 @@ local int unzlocal_getShort (fin,pX)
} }
local int unzlocal_getLong (fin,pX) local int unzlocal_getLong (fin,pX)
QFile* fin; FILE* fin;
uLong *pX; uLong *pX;
{ {
uLong x ; uLong x ;
@ -266,7 +275,7 @@ extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivit
the global comment) the global comment)
*/ */
local uLong unzlocal_SearchCentralDir(fin) local uLong unzlocal_SearchCentralDir(fin)
QFile *fin; FILE *fin;
{ {
unsigned char* buf; unsigned char* buf;
uLong uSizeFile; uLong uSizeFile;
@ -336,7 +345,7 @@ extern unzFile ZEXPORT unzOpen (path)
unz_s us; unz_s us;
unz_s *s; unz_s *s;
uLong central_pos,uL; uLong central_pos,uL;
QFile * fin ; FILE * fin ;
uLong number_disk; /* number of the current dist, used for uLong number_disk; /* number of the current dist, used for
spaning ZIP, unsupported, always 0*/ spaning ZIP, unsupported, always 0*/
@ -527,10 +536,12 @@ local int unzlocal_GetCurrentFileInfoInternal (file,
/* we check the magic */ /* we check the magic */
if (err==UNZ_OK) if (err==UNZ_OK)
{
if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK) if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK)
err=UNZ_ERRNO; err=UNZ_ERRNO;
else if (uMagic!=0x02014b50) else if (uMagic!=0x02014b50)
err=UNZ_BADZIPFILE; err=UNZ_BADZIPFILE;
}
if (unzlocal_getShort(s->file,&file_info.version) != UNZ_OK) if (unzlocal_getShort(s->file,&file_info.version) != UNZ_OK)
err=UNZ_ERRNO; err=UNZ_ERRNO;
@ -607,10 +618,12 @@ local int unzlocal_GetCurrentFileInfoInternal (file,
uSizeRead = extraFieldBufferSize; uSizeRead = extraFieldBufferSize;
if (lSeek!=0) if (lSeek!=0)
{
if (fseek(s->file,lSeek,SEEK_CUR)==0) if (fseek(s->file,lSeek,SEEK_CUR)==0)
lSeek=0; lSeek=0;
else else
err=UNZ_ERRNO; err=UNZ_ERRNO;
}
if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
if (fread(extraField,(uInt)uSizeRead,1,s->file)!=1) if (fread(extraField,(uInt)uSizeRead,1,s->file)!=1)
err=UNZ_ERRNO; err=UNZ_ERRNO;
@ -631,11 +644,13 @@ local int unzlocal_GetCurrentFileInfoInternal (file,
else else
uSizeRead = commentBufferSize; uSizeRead = commentBufferSize;
if (lSeek!=0) if (lSeek!=0)
{
if (fseek(s->file,lSeek,SEEK_CUR)==0) if (fseek(s->file,lSeek,SEEK_CUR)==0)
lSeek=0; lSeek=0;
else else
err=UNZ_ERRNO; err=UNZ_ERRNO;
}
if ((file_info.size_file_comment>0) && (commentBufferSize>0)) if ((file_info.size_file_comment>0) && (commentBufferSize>0))
if (fread(szComment,(uInt)uSizeRead,1,s->file)!=1) if (fread(szComment,(uInt)uSizeRead,1,s->file)!=1)
err=UNZ_ERRNO; err=UNZ_ERRNO;
@ -815,14 +830,17 @@ local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar,
return UNZ_ERRNO; return UNZ_ERRNO;
if (err==UNZ_OK) if (err==UNZ_OK) {
if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK) if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK) {
err=UNZ_ERRNO; err=UNZ_ERRNO;
else if (uMagic!=0x04034b50) } else if (uMagic!=0x04034b50) {
err=UNZ_BADZIPFILE; err=UNZ_BADZIPFILE;
}
}
if (unzlocal_getShort(s->file,&uData) != UNZ_OK) if (unzlocal_getShort(s->file,&uData) != UNZ_OK) {
err=UNZ_ERRNO; err=UNZ_ERRNO;
}
/* /*
else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion)) else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
err=UNZ_BADZIPFILE; err=UNZ_BADZIPFILE;
@ -1258,7 +1276,7 @@ extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf)
char *szComment; char *szComment;
uLong uSizeBuf; uLong uSizeBuf;
{ {
int err=UNZ_OK; // int err=UNZ_OK;
unz_s* s; unz_s* s;
uLong uReadThis ; uLong uReadThis ;
if (file==NULL) if (file==NULL)

View file

@ -46,18 +46,9 @@ extern "C" {
#endif #endif
#ifndef _ZLIB_H #ifndef _ZLIB_H
#include "zlib.h" #include <zlib.h>
#endif #endif
#ifndef UNZ_BUFSIZE
#define UNZ_BUFSIZE (16384)
#endif
#ifndef UNZ_MAXFILENAMEINZIP
#define UNZ_MAXFILENAMEINZIP (256)
#endif
#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
/* like the STRICT of WIN32, we define a pointer that cannot be converted /* like the STRICT of WIN32, we define a pointer that cannot be converted
from (void*) without cast */ from (void*) without cast */