zlib support (gzipped pack contents). if you have a probelm with gzgets, you

have 3 choices: remove /usr/X11R6/lib/libz.a, --diable-zlib, or fix configure.
I do intend on fixing it myself.
This commit is contained in:
Bill Currie 2000-09-27 19:44:26 +00:00
parent 7c12c9b4c7
commit 86f87122c0
39 changed files with 537 additions and 328 deletions

View file

@ -124,7 +124,7 @@ typedef struct
typedef struct pack_s
{
char filename[MAX_OSPATH];
FILE *handle;
QFile *handle;
int numfiles;
packfile_t *files;
} pack_t;
@ -189,15 +189,15 @@ COM_FileBase (char *in, char *out)
COM_filelength
*/
int
COM_filelength (FILE *f)
COM_filelength (QFile *f)
{
int pos;
int end;
pos = ftell (f);
fseek (f, 0, SEEK_END);
end = ftell (f);
fseek (f, pos, SEEK_SET);
pos = Qtell (f);
Qseek (f, 0, SEEK_END);
end = Qtell (f);
Qseek (f, pos, SEEK_SET);
return end;
}
@ -206,11 +206,11 @@ COM_filelength (FILE *f)
COM_FileOpenRead
*/
int
COM_FileOpenRead (char *path, FILE **hndl)
COM_FileOpenRead (char *path, QFile **hndl)
{
FILE *f;
QFile *f;
f = fopen(path, "rb");
f = Qopen(path, "rbz");
if (!f)
{
*hndl = NULL;
@ -288,22 +288,22 @@ COM_Maplist_f ( void )
void
COM_WriteFile ( char *filename, void *data, int len )
{
FILE *f;
QFile *f;
char name[MAX_OSPATH];
snprintf(name, sizeof(name), "%s/%s", com_gamedir, filename);
f = fopen (name, "wb");
f = Qopen (name, "wb");
if (!f) {
Sys_mkdir(com_gamedir);
f = fopen (name, "wb");
f = Qopen (name, "wb");
if (!f)
Sys_Error ("Error opening %s", filename);
}
Sys_Printf ("COM_WriteFile: %s\n", name);
fwrite (data, 1, len, f);
fclose (f);
Qwrite (f, data, len);
Qclose (f);
}
@ -341,13 +341,13 @@ COM_CreatePath ( char *path )
void
COM_CopyFile (char *netpath, char *cachepath)
{
FILE *in, *out;
QFile *in, *out;
int remaining, count;
char buf[4096];
remaining = COM_FileOpenRead (netpath, &in);
COM_CreatePath (cachepath); // create directories up to the cache file
out = fopen(cachepath, "wb");
out = Qopen(cachepath, "wb");
if (!out)
Sys_Error ("Error opening %s", cachepath);
@ -357,19 +357,19 @@ COM_CopyFile (char *netpath, char *cachepath)
count = remaining;
else
count = sizeof(buf);
fread (buf, 1, count, in);
fwrite (buf, 1, count, out);
Qread (in, buf, count);
Qwrite (out, buf, count);
remaining -= count;
}
fclose (in);
fclose (out);
Qclose (in);
Qclose (out);
}
/*
COM_OpenRead
*/
FILE *
QFile *
COM_OpenRead (const char *path, int offs, int len)
{
int fd=open(path,O_RDONLY);
@ -385,6 +385,7 @@ COM_OpenRead (const char *path, int offs, int len)
len=lseek(fd,0,SEEK_END);
lseek(fd,0,SEEK_SET);
}
lseek(fd,offs,SEEK_SET);
read(fd,id,2);
if (id[0]==0x1f && id[1]==0x8b) {
lseek(fd,offs+len-4,SEEK_SET);
@ -400,7 +401,7 @@ COM_OpenRead (const char *path, int offs, int len)
#ifdef WIN32
setmode(fd,O_BINARY);
#endif
return fdopen(fd,"rb");
return Qdopen(fd,"rbz");
return 0;
}
@ -413,13 +414,21 @@ int file_from_pak; // global indicating file came from pack file ZOID
Sets com_filesize and one of handle or file
*/
int
COM_FOpenFile (char *filename, FILE **gzfile)
COM_FOpenFile (char *filename, QFile **gzfile)
{
searchpath_t *search;
char netpath[MAX_OSPATH];
pack_t *pak;
int i;
int findtime;
#ifdef HAS_ZLIB
char gzfilename[MAX_OSPATH];
int filenamelen;;
filenamelen = strlen(filename);
strncpy(gzfilename,filename,sizeof(gzfilename));
strncat(gzfilename,".gz",sizeof(gzfilename));
#endif
file_from_pak = 0;
@ -435,11 +444,20 @@ COM_FOpenFile (char *filename, FILE **gzfile)
pak = search->pack;
for (i=0 ; i<pak->numfiles ; i++) {
char *fn=0;
#ifdef HAS_ZLIB
if (!strncmp(pak->files[i].name, filename, filenamelen)) {
if (!pak->files[i].name[filenamelen])
fn=filename;
else if (!strcmp (pak->files[i].name, gzfilename))
fn=gzfilename;
}
#else
if (!strcmp (pak->files[i].name, filename))
fn=filename;
#endif
if (fn)
{ // found it!
if (developer->value)
if (developer->int_val)
Sys_Printf ("PackFile: %s : %s\n",pak->filename, fn);
// open a new file on the pakfile
*gzfile=COM_OpenRead(pak->filename,pak->files[i].filepos,
@ -457,10 +475,16 @@ COM_FOpenFile (char *filename, FILE **gzfile)
findtime = Sys_FileTime (netpath);
if (findtime == -1) {
#ifdef HAS_ZLIB
snprintf(netpath, sizeof(netpath), "%s/%s",search->filename,
gzfilename);
findtime = Sys_FileTime (netpath);
if (findtime == -1)
#endif
continue;
}
if(developer->value)
if(developer->int_val)
Sys_Printf ("FindFile: %s\n",netpath);
*gzfile=COM_OpenRead(netpath,-1,-1);
@ -489,7 +513,7 @@ int loadsize;
byte *
COM_LoadFile (char *path, int usehunk)
{
FILE *h;
QFile *h;
byte *buf;
char base[32];
int len;
@ -529,8 +553,8 @@ COM_LoadFile (char *path, int usehunk)
if (!is_server) {
Draw_BeginDisc();
}
fread (buf, 1, len, h);
fclose (h);
Qread (h, buf, len);
Qclose (h);
if (!is_server) {
Draw_EndDisc();
}
@ -586,13 +610,13 @@ COM_LoadPackFile (char *packfile)
packfile_t *newfiles;
int numpackfiles;
pack_t *pack;
FILE *packhandle;
QFile *packhandle;
dpackfile_t info[MAX_FILES_IN_PACK];
if (COM_FileOpenRead (packfile, &packhandle) == -1)
return NULL;
fread (&header, 1, sizeof(header), packhandle);
Qread (packhandle, &header, sizeof(header));
if (header.id[0] != 'P' || header.id[1] != 'A'
|| header.id[2] != 'C' || header.id[3] != 'K')
Sys_Error ("%s is not a packfile", packfile);
@ -606,8 +630,8 @@ COM_LoadPackFile (char *packfile)
newfiles = calloc (1, numpackfiles * sizeof(packfile_t));
fseek (packhandle, header.dirofs, SEEK_SET);
fread (info, 1, header.dirlen, packhandle);
Qseek (packhandle, header.dirofs, SEEK_SET);
Qread (packhandle, info, header.dirlen);
// parse the directory
@ -819,7 +843,7 @@ COM_Gamedir (char *dir)
{
if (com_searchpaths->pack)
{
fclose (com_searchpaths->pack->handle);
Qclose (com_searchpaths->pack->handle);
free (com_searchpaths->pack->files);
free (com_searchpaths->pack);
}