mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
error checking in LoadLump and handle muptiple wad files better (ie,
properly:P)
This commit is contained in:
parent
04a1ff51b1
commit
1a250f0ef7
1 changed files with 26 additions and 5 deletions
|
@ -294,11 +294,11 @@ typedef struct {
|
||||||
|
|
||||||
typedef struct wadlist_s {
|
typedef struct wadlist_s {
|
||||||
struct wadlist_s *next;
|
struct wadlist_s *next;
|
||||||
|
const char *path;
|
||||||
wadinfo_t wadinfo;
|
wadinfo_t wadinfo;
|
||||||
lumpinfo_t *lumpinfo;
|
lumpinfo_t *lumpinfo;
|
||||||
} wadlist_t;
|
} wadlist_t;
|
||||||
|
|
||||||
QFile *texfile;
|
|
||||||
wadlist_t *wadlist;
|
wadlist_t *wadlist;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -322,17 +322,19 @@ TEX_InitFromWad (char *path)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
wadlist_t *wl;
|
wadlist_t *wl;
|
||||||
|
QFile *texfile;
|
||||||
|
|
||||||
texfile = Qopen (path, "rbz");
|
texfile = Qopen (path, "rbz");
|
||||||
#ifdef HAVE_ZLIB
|
#ifdef HAVE_ZLIB
|
||||||
if (!texfile)
|
if (!texfile)
|
||||||
texfile = Qopen (va ("%s.gz", path), "rbz");
|
texfile = Qopen (path = va ("%s.gz", path), "rbz");
|
||||||
#endif
|
#endif
|
||||||
if (!texfile)
|
if (!texfile)
|
||||||
return -1;
|
return -1;
|
||||||
printf ("wadfile: %s\n", path);
|
printf ("wadfile: %s\n", path);
|
||||||
|
|
||||||
wl = calloc (1, sizeof (wadlist_t));
|
wl = calloc (1, sizeof (wadlist_t));
|
||||||
|
wl->path = strdup (path);
|
||||||
|
|
||||||
Qread (texfile, &wl->wadinfo, sizeof (wadinfo_t));
|
Qread (texfile, &wl->wadinfo, sizeof (wadinfo_t));
|
||||||
if (strncmp (wl->wadinfo.identification, "WAD2", 4))
|
if (strncmp (wl->wadinfo.identification, "WAD2", 4))
|
||||||
|
@ -342,6 +344,7 @@ TEX_InitFromWad (char *path)
|
||||||
Qseek (texfile, wl->wadinfo.infotableofs, SEEK_SET);
|
Qseek (texfile, wl->wadinfo.infotableofs, SEEK_SET);
|
||||||
wl->lumpinfo = malloc (wl->wadinfo.numlumps * sizeof (lumpinfo_t));
|
wl->lumpinfo = malloc (wl->wadinfo.numlumps * sizeof (lumpinfo_t));
|
||||||
Qread (texfile, wl->lumpinfo, wl->wadinfo.numlumps * sizeof (lumpinfo_t));
|
Qread (texfile, wl->lumpinfo, wl->wadinfo.numlumps * sizeof (lumpinfo_t));
|
||||||
|
Qclose (texfile);
|
||||||
|
|
||||||
for (i = 0; i < wl->wadinfo.numlumps; i++) {
|
for (i = 0; i < wl->wadinfo.numlumps; i++) {
|
||||||
CleanupName (wl->lumpinfo[i].name, wl->lumpinfo[i].name);
|
CleanupName (wl->lumpinfo[i].name, wl->lumpinfo[i].name);
|
||||||
|
@ -357,9 +360,10 @@ static int
|
||||||
LoadLump (char *name, dstring_t *dest)
|
LoadLump (char *name, dstring_t *dest)
|
||||||
{
|
{
|
||||||
char cname[16]; //FIXME: overflow
|
char cname[16]; //FIXME: overflow
|
||||||
int i;
|
int i, r;
|
||||||
int ofs = dest->size;
|
int ofs = dest->size;
|
||||||
wadlist_t *wl;
|
wadlist_t *wl;
|
||||||
|
QFile *texfile;
|
||||||
|
|
||||||
CleanupName (name, cname);
|
CleanupName (name, cname);
|
||||||
|
|
||||||
|
@ -368,8 +372,25 @@ LoadLump (char *name, dstring_t *dest)
|
||||||
if (!strcmp (cname, wl->lumpinfo[i].name)) {
|
if (!strcmp (cname, wl->lumpinfo[i].name)) {
|
||||||
dest->size += wl->lumpinfo[i].disksize;
|
dest->size += wl->lumpinfo[i].disksize;
|
||||||
dstring_adjust (dest);
|
dstring_adjust (dest);
|
||||||
Qseek (texfile, wl->lumpinfo[i].filepos, SEEK_SET);
|
texfile = Qopen (wl->path, "rbz");
|
||||||
Qread (texfile, dest->str + ofs, wl->lumpinfo[i].disksize);
|
if (!texfile) {
|
||||||
|
printf ("couldn't open %s\n", wl->path);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
r = Qseek (texfile, wl->lumpinfo[i].filepos, SEEK_SET);
|
||||||
|
if (r == -1) {
|
||||||
|
printf ("seek error: %s:%s %d\n", wl->path,
|
||||||
|
wl->lumpinfo[i].name, wl->lumpinfo[i].filepos);
|
||||||
|
Qclose (texfile);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
r = Qread (texfile, dest->str + ofs, wl->lumpinfo[i].disksize);
|
||||||
|
Qclose (texfile);
|
||||||
|
if (r != wl->lumpinfo[i].disksize) {
|
||||||
|
printf ("seek error: %s:%s %d\n", wl->path,
|
||||||
|
wl->lumpinfo[i].name, wl->lumpinfo[i].disksize);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
return wl->lumpinfo[i].disksize;
|
return wl->lumpinfo[i].disksize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue