2006-07-07 18:41:05 +00:00
|
|
|
#include "compat.h"
|
|
|
|
#include "baselayer.h"
|
|
|
|
|
|
|
|
#include "scriptfile.h"
|
|
|
|
#include "cache1d.h"
|
|
|
|
#include "crc32.h"
|
|
|
|
|
2006-07-22 05:20:25 +00:00
|
|
|
#include "duke3d.h"
|
|
|
|
#include "grpscan.h"
|
2006-07-07 18:41:05 +00:00
|
|
|
|
2006-11-15 01:16:55 +00:00
|
|
|
struct grpfile grpfiles[numgrpfiles] =
|
2007-08-25 01:05:00 +00:00
|
|
|
{
|
|
|
|
{ "Duke Nukem 3D", 0xBBC9CE44, 26524524, GAMEDUKE, NULL },
|
|
|
|
{ "Duke Nukem 3D: Atomic Edition", 0xF514A6AC, 44348015, GAMEDUKE, NULL },
|
|
|
|
{ "Duke Nukem 3D: Atomic Edition", 0xFD3DCFF1, 44356548, GAMEDUKE, NULL },
|
|
|
|
{ "Duke Nukem 3D Shareware", 0x983AD923, 11035779, GAMEDUKE, NULL },
|
|
|
|
{ "Duke Nukem 3D Mac Shareware", 0xC5F71561, 10444391, GAMEDUKE, NULL },
|
2008-07-22 09:05:34 +00:00
|
|
|
// { "Duke Nukem 3D Mac", 0x00000000, 0, GAMEDUKE, NULL },
|
2007-08-25 01:05:00 +00:00
|
|
|
{ "NAM", 0x75C1F07B, 43448927, GAMENAM, NULL },
|
|
|
|
{ "Napalm", 0x3DE1589A, 44365728, GAMENAM, NULL },
|
|
|
|
{ "WW2GI", 0x907B82BF, 77939508, GAMEWW2, NULL },
|
|
|
|
};
|
2006-07-07 18:41:05 +00:00
|
|
|
struct grpfile *foundgrps = NULL;
|
|
|
|
|
|
|
|
#define GRPCACHEFILE "grpfiles.cache"
|
2006-11-15 01:16:55 +00:00
|
|
|
static struct grpcache
|
|
|
|
{
|
2006-07-07 18:41:05 +00:00
|
|
|
struct grpcache *next;
|
|
|
|
char name[BMAX_PATH+1];
|
|
|
|
int size;
|
|
|
|
int mtime;
|
|
|
|
int crcval;
|
2006-11-15 01:16:55 +00:00
|
|
|
}
|
|
|
|
*grpcache = NULL, *usedgrpcache = NULL;
|
2006-07-07 18:41:05 +00:00
|
|
|
|
|
|
|
static int LoadGroupsCache(void)
|
|
|
|
{
|
|
|
|
struct grpcache *fg;
|
|
|
|
|
|
|
|
int fsize, fmtime, fcrcval;
|
|
|
|
char *fname;
|
|
|
|
|
|
|
|
scriptfile *script;
|
|
|
|
|
|
|
|
script = scriptfile_fromfile(GRPCACHEFILE);
|
|
|
|
if (!script) return -1;
|
|
|
|
|
2006-11-15 01:16:55 +00:00
|
|
|
while (!scriptfile_eof(script))
|
|
|
|
{
|
2006-07-07 18:41:05 +00:00
|
|
|
if (scriptfile_getstring(script, &fname)) break; // filename
|
|
|
|
if (scriptfile_getnumber(script, &fsize)) break; // filesize
|
|
|
|
if (scriptfile_getnumber(script, &fmtime)) break; // modification time
|
|
|
|
if (scriptfile_getnumber(script, &fcrcval)) break; // crc checksum
|
|
|
|
|
2008-06-29 10:40:37 +00:00
|
|
|
fg = Bcalloc(1, sizeof(struct grpcache));
|
2006-07-07 18:41:05 +00:00
|
|
|
fg->next = grpcache;
|
|
|
|
grpcache = fg;
|
|
|
|
|
|
|
|
strncpy(fg->name, fname, BMAX_PATH);
|
|
|
|
fg->size = fsize;
|
|
|
|
fg->mtime = fmtime;
|
|
|
|
fg->crcval = fcrcval;
|
|
|
|
}
|
|
|
|
|
|
|
|
scriptfile_close(script);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void FreeGroupsCache(void)
|
|
|
|
{
|
|
|
|
struct grpcache *fg;
|
|
|
|
|
2006-11-15 01:16:55 +00:00
|
|
|
while (grpcache)
|
|
|
|
{
|
2006-07-07 18:41:05 +00:00
|
|
|
fg = grpcache->next;
|
|
|
|
free(grpcache);
|
|
|
|
grpcache = fg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int ScanGroups(void)
|
|
|
|
{
|
|
|
|
CACHE1D_FIND_REC *srch, *sidx;
|
|
|
|
struct grpcache *fg, *fgg;
|
|
|
|
struct grpfile *grp;
|
|
|
|
char *fn;
|
|
|
|
struct Bstat st;
|
|
|
|
|
|
|
|
initprintf("Scanning for GRP files...\n");
|
|
|
|
|
|
|
|
LoadGroupsCache();
|
|
|
|
|
|
|
|
srch = klistpath("/", "*.grp", CACHE1D_FIND_FILE);
|
|
|
|
|
2006-11-15 01:16:55 +00:00
|
|
|
for (sidx = srch; sidx; sidx = sidx->next)
|
|
|
|
{
|
|
|
|
for (fg = grpcache; fg; fg = fg->next)
|
|
|
|
{
|
2006-07-07 18:41:05 +00:00
|
|
|
if (!Bstrcmp(fg->name, sidx->name)) break;
|
|
|
|
}
|
|
|
|
|
2006-11-15 01:16:55 +00:00
|
|
|
if (fg)
|
|
|
|
{
|
2006-07-07 18:41:05 +00:00
|
|
|
if (findfrompath(sidx->name, &fn)) continue; // failed to resolve the filename
|
2006-11-15 01:16:55 +00:00
|
|
|
if (Bstat(fn, &st))
|
|
|
|
{
|
|
|
|
free(fn);
|
|
|
|
continue;
|
|
|
|
} // failed to stat the file
|
2006-07-07 18:41:05 +00:00
|
|
|
free(fn);
|
2006-11-15 01:16:55 +00:00
|
|
|
if (fg->size == st.st_size && fg->mtime == st.st_mtime)
|
|
|
|
{
|
2008-06-29 10:40:37 +00:00
|
|
|
grp = (struct grpfile *)Bcalloc(1, sizeof(struct grpfile));
|
2006-07-07 18:41:05 +00:00
|
|
|
grp->name = strdup(sidx->name);
|
|
|
|
grp->crcval = fg->crcval;
|
|
|
|
grp->size = fg->size;
|
|
|
|
grp->next = foundgrps;
|
|
|
|
foundgrps = grp;
|
|
|
|
|
2008-06-29 10:40:37 +00:00
|
|
|
fgg = (struct grpcache *)Bcalloc(1, sizeof(struct grpcache));
|
2006-07-07 18:41:05 +00:00
|
|
|
strcpy(fgg->name, fg->name);
|
|
|
|
fgg->size = fg->size;
|
|
|
|
fgg->mtime = fg->mtime;
|
|
|
|
fgg->crcval = fg->crcval;
|
|
|
|
fgg->next = usedgrpcache;
|
|
|
|
usedgrpcache = fgg;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
int b, fh;
|
|
|
|
int crcval;
|
|
|
|
char buf[16*512];
|
|
|
|
|
|
|
|
fh = openfrompath(sidx->name, BO_RDONLY|BO_BINARY, BS_IREAD);
|
|
|
|
if (fh < 0) continue;
|
|
|
|
if (fstat(fh, &st)) continue;
|
|
|
|
|
|
|
|
initprintf(" Checksumming %s...", sidx->name);
|
2007-12-12 17:42:14 +00:00
|
|
|
crc32init((unsigned int *)&crcval);
|
2006-11-15 01:16:55 +00:00
|
|
|
do
|
|
|
|
{
|
2006-07-07 18:41:05 +00:00
|
|
|
b = read(fh, buf, sizeof(buf));
|
2007-12-12 17:42:14 +00:00
|
|
|
if (b > 0) crc32block((unsigned int *)&crcval, (unsigned char *)buf, b);
|
2006-11-15 01:16:55 +00:00
|
|
|
}
|
|
|
|
while (b == sizeof(buf));
|
2007-12-12 17:42:14 +00:00
|
|
|
crc32finish((unsigned int *)&crcval);
|
2006-07-07 18:41:05 +00:00
|
|
|
close(fh);
|
|
|
|
initprintf(" Done\n");
|
|
|
|
|
2008-06-29 10:40:37 +00:00
|
|
|
grp = (struct grpfile *)Bcalloc(1, sizeof(struct grpfile));
|
2006-07-07 18:41:05 +00:00
|
|
|
grp->name = strdup(sidx->name);
|
|
|
|
grp->crcval = crcval;
|
|
|
|
grp->size = st.st_size;
|
|
|
|
grp->next = foundgrps;
|
|
|
|
foundgrps = grp;
|
|
|
|
|
2008-06-29 10:40:37 +00:00
|
|
|
fgg = (struct grpcache *)Bcalloc(1, sizeof(struct grpcache));
|
2006-07-07 18:41:05 +00:00
|
|
|
strncpy(fgg->name, sidx->name, BMAX_PATH);
|
|
|
|
fgg->size = st.st_size;
|
|
|
|
fgg->mtime = st.st_mtime;
|
|
|
|
fgg->crcval = crcval;
|
|
|
|
fgg->next = usedgrpcache;
|
|
|
|
usedgrpcache = fgg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
klistfree(srch);
|
|
|
|
FreeGroupsCache();
|
|
|
|
|
2006-11-15 01:16:55 +00:00
|
|
|
if (usedgrpcache)
|
|
|
|
{
|
2006-07-07 18:41:05 +00:00
|
|
|
FILE *fp;
|
|
|
|
fp = fopen(GRPCACHEFILE, "wt");
|
2006-11-15 01:16:55 +00:00
|
|
|
if (fp)
|
|
|
|
{
|
|
|
|
for (fg = usedgrpcache; fg; fg=fgg)
|
|
|
|
{
|
2006-07-07 18:41:05 +00:00
|
|
|
fgg = fg->next;
|
|
|
|
fprintf(fp, "\"%s\" %d %d %d\n", fg->name, fg->size, fg->mtime, fg->crcval);
|
|
|
|
free(fg);
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FreeGroups(void)
|
|
|
|
{
|
|
|
|
struct grpfile *fg;
|
|
|
|
|
2006-11-15 01:16:55 +00:00
|
|
|
while (foundgrps)
|
|
|
|
{
|
2006-07-07 18:41:05 +00:00
|
|
|
fg = foundgrps->next;
|
|
|
|
free((char*)foundgrps->name);
|
|
|
|
free(foundgrps);
|
|
|
|
foundgrps = fg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|