diff --git a/configure.in b/configure.in index 8a987db..08e5b30 100644 --- a/configure.in +++ b/configure.in @@ -305,6 +305,12 @@ dnl ------------------------ HAVE_MPG123=disabled +dnl --------------------- +dnl Check for zip library +dnl --------------------- + +HAVE_ZIP=disabled + dnl ----------------------- dnl Checks for header files dnl ----------------------- diff --git a/src/files.c b/src/files.c index c98fb4d..05d27c1 100644 --- a/src/files.c +++ b/src/files.c @@ -446,19 +446,25 @@ of the list so they override previous pack files. */ pack_t *FS_LoadPackFile (char *packfile) { - dpackheader_t header; - int i; - packfile_t *newfiles; - int numpackfiles; +#ifdef HAVE_ZIP + dpackheader_t temp; /* header; */ + int numOfItems = 0; /* numOfItems added for .zip */ +#else /* !HAVE_ZIP */ + dpackheader_t header; + int numpackfiles; + unsigned checksum; +#endif /* HAVE_ZIP */ + packfile_t * newfiles = 0; + int i; pack_t *pack; FILE *packhandle; dpackfile_t info[MAX_FILES_IN_PACK]; - unsigned checksum; packhandle = fopen(packfile, "rb"); if (!packhandle) return NULL; +#ifndef HAVE_ZIP fread (&header, 1, sizeof(header), packhandle); if (LittleLong(header.ident) != IDPAKHEADER) Com_Error (ERR_FATAL, "%s is not a packfile", packfile); @@ -475,28 +481,72 @@ pack_t *FS_LoadPackFile (char *packfile) fseek (packhandle, header.dirofs, SEEK_SET); fread (info, 1, header.dirlen, packhandle); -// crc the directory to check for modifications + /* crc the directory to check for modifications */ checksum = Com_BlockChecksum ((void *)info, header.dirlen); +#endif /* !HAVE_ZIP */ #ifdef NO_ADDONS if (checksum != PAK0_CHECKSUM) return NULL; #endif // parse the directory - for (i=0 ; ifilename, packfile); pack->handle = packhandle; +#ifdef HAVE_ZIP + pack->numfiles = numOfItems; +#else pack->numfiles = numpackfiles; +#endif pack->files = newfiles; - Com_Printf ("Added packfile %s (%i files)\n", packfile, numpackfiles); + Com_Printf ("Added packfile %s (%i files)\n", packfile, +#ifdef HAVE_ZIP + numOfItems +#else + numpackfiles +#endif + ); return pack; } diff --git a/src/qfiles.h b/src/qfiles.h index 7679bef..7584a0b 100644 --- a/src/qfiles.h +++ b/src/qfiles.h @@ -24,9 +24,18 @@ #ifndef __QFILES_H__ #define __QFILES_H__ -/* The .pak files are just a linear collapse of a directory tree */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif -#define IDPAKHEADER (('K'<<24)+('C'<<16)+('A'<<8)+'P') +#ifdef HAVE_ZIP +# define ZPAKHEADER (0x504B0304) +# define ZPAKDIRHEADER (0x504B0102) +#else +# define IDPAKHEADER (('K'<<24)+('C'<<16)+('A'<<8)+'P') +#endif + +/* The .pak files are just a linear collapse of a directory tree */ typedef struct { @@ -34,6 +43,26 @@ typedef struct int filepos, filelen; } dpackfile_t; +#ifdef HAVE_ZIP + +# pragma pack(push, 2) +typedef struct { + unsigned long ident; + unsigned short version; + unsigned short flags; + unsigned short compression; + unsigned short modtime; + unsigned short moddate; + unsigned long crc32; + unsigned long compressedSize; + unsigned long uncompressedSize; + unsigned short filenameLength; + unsigned short extraFieldLength; +} dpackheader_t; +# pragma pack (pop) + +#else /* !HAVE_ZIP */ + typedef struct { int ident; // == IDPAKHEADER @@ -41,6 +70,8 @@ typedef struct int dirlen; } dpackheader_t; +#endif /* HAVE_ZIP */ + #define MAX_FILES_IN_PACK 4096