2003-12-15 05:01:18 +01:00
|
|
|
/*
|
|
|
|
* WAD support routines for PhysicsFS.
|
|
|
|
*
|
|
|
|
* This driver handles DOOM engine archives ("wads").
|
|
|
|
* This format (but not this driver) was designed by id Software for use
|
|
|
|
* with the DOOM engine.
|
|
|
|
* The specs of the format are from the unofficial doom specs v1.666
|
|
|
|
* found here: http://www.gamers.org/dhs/helpdocs/dmsp1666.html
|
|
|
|
* The format of the archive: (from the specs)
|
|
|
|
*
|
|
|
|
* A WAD file has three parts:
|
|
|
|
* (1) a twelve-byte header
|
|
|
|
* (2) one or more "lumps"
|
|
|
|
* (3) a directory or "info table" that contains the names, offsets, and
|
|
|
|
* sizes of all the lumps in the WAD
|
|
|
|
*
|
|
|
|
* The header consists of three four-byte parts:
|
|
|
|
* (a) an ASCII string which must be either "IWAD" or "PWAD"
|
|
|
|
* (b) a 4-byte (long) integer which is the number of lumps in the wad
|
|
|
|
* (c) a long integer which is the file offset to the start of
|
|
|
|
* the directory
|
|
|
|
*
|
|
|
|
* The directory has one 16-byte entry for every lump. Each entry consists
|
|
|
|
* of three parts:
|
|
|
|
*
|
|
|
|
* (a) a long integer, the file offset to the start of the lump
|
|
|
|
* (b) a long integer, the size of the lump in bytes
|
|
|
|
* (c) an 8-byte ASCII string, the name of the lump, padded with zeros.
|
|
|
|
* For example, the "DEMO1" entry in hexadecimal would be
|
|
|
|
* (44 45 4D 4F 31 00 00 00)
|
|
|
|
*
|
|
|
|
* Note that there is no way to tell if an opened WAD archive is a
|
|
|
|
* IWAD or PWAD with this archiver.
|
|
|
|
* I couldn't think of a way to provide that information, without being too
|
|
|
|
* hacky.
|
|
|
|
* I don't think it's really that important though.
|
|
|
|
*
|
|
|
|
*
|
2007-03-11 11:10:28 +01:00
|
|
|
* Please see the file LICENSE.txt in the source's root directory.
|
2003-12-15 05:01:18 +01:00
|
|
|
*
|
|
|
|
* This file written by Travis Wells, based on the GRP archiver by
|
|
|
|
* Ryan C. Gordon.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if (defined PHYSFS_SUPPORTS_WAD)
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "physfs.h"
|
|
|
|
|
|
|
|
#define __PHYSICSFS_INTERNAL__
|
|
|
|
#include "physfs_internal.h"
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2003-12-18 20:53:20 +01:00
|
|
|
char name[18];
|
2003-12-15 05:01:18 +01:00
|
|
|
PHYSFS_uint32 startPos;
|
|
|
|
PHYSFS_uint32 size;
|
|
|
|
} WADentry;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
PHYSFS_Io *io;
|
2003-12-15 05:01:18 +01:00
|
|
|
PHYSFS_uint32 entryCount;
|
|
|
|
WADentry *entries;
|
|
|
|
} WADinfo;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
PHYSFS_Io *io;
|
2003-12-15 05:01:18 +01:00
|
|
|
WADentry *entry;
|
|
|
|
PHYSFS_uint32 curPos;
|
|
|
|
} WADfileinfo;
|
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static inline int readAll(PHYSFS_Io *io, void *buf, const PHYSFS_uint64 len)
|
|
|
|
{
|
|
|
|
return (io->read(io, buf, len) == len);
|
|
|
|
} /* readAll */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static void WAD_dirClose(dvoid *opaque)
|
2003-12-15 05:01:18 +01:00
|
|
|
{
|
2004-09-26 02:25:04 +02:00
|
|
|
WADinfo *info = ((WADinfo *) opaque);
|
2010-08-30 09:01:57 +02:00
|
|
|
info->io->destroy(info->io);
|
2005-03-14 12:49:30 +01:00
|
|
|
allocator.Free(info->entries);
|
|
|
|
allocator.Free(info);
|
2003-12-15 05:01:18 +01:00
|
|
|
} /* WAD_dirClose */
|
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static PHYSFS_sint64 WAD_read(PHYSFS_Io *io, void *buffer, PHYSFS_uint64 len)
|
2003-12-15 05:01:18 +01:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
WADfileinfo *finfo = (WADfileinfo *) io->opaque;
|
2010-08-21 08:47:58 +02:00
|
|
|
const WADentry *entry = finfo->entry;
|
|
|
|
const PHYSFS_uint64 bytesLeft = (PHYSFS_uint64)(entry->size-finfo->curPos);
|
2003-12-15 05:01:18 +01:00
|
|
|
PHYSFS_sint64 rc;
|
|
|
|
|
2010-08-21 08:47:58 +02:00
|
|
|
if (bytesLeft < len)
|
|
|
|
len = bytesLeft;
|
2003-12-15 05:01:18 +01:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
rc = finfo->io->read(finfo->io, buffer, len);
|
2003-12-15 05:01:18 +01:00
|
|
|
if (rc > 0)
|
2010-08-21 08:47:58 +02:00
|
|
|
finfo->curPos += (PHYSFS_uint32) rc;
|
2003-12-15 05:01:18 +01:00
|
|
|
|
2010-01-28 08:27:45 +01:00
|
|
|
return rc;
|
2003-12-15 05:01:18 +01:00
|
|
|
} /* WAD_read */
|
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static PHYSFS_sint64 WAD_write(PHYSFS_Io *io, const void *b, PHYSFS_uint64 len)
|
2003-12-15 05:01:18 +01:00
|
|
|
{
|
|
|
|
BAIL_MACRO(ERR_NOT_SUPPORTED, -1);
|
|
|
|
} /* WAD_write */
|
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static PHYSFS_sint64 WAD_tell(PHYSFS_Io *io)
|
2003-12-15 05:01:18 +01:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
return ((WADfileinfo *) io->opaque)->curPos;
|
2003-12-15 05:01:18 +01:00
|
|
|
} /* WAD_tell */
|
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static int WAD_seek(PHYSFS_Io *io, PHYSFS_uint64 offset)
|
2003-12-15 05:01:18 +01:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
WADfileinfo *finfo = (WADfileinfo *) io->opaque;
|
|
|
|
const WADentry *entry = finfo->entry;
|
2003-12-15 05:01:18 +01:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
BAIL_IF_MACRO(offset >= entry->size, ERR_PAST_EOF, 0);
|
2010-08-30 09:01:57 +02:00
|
|
|
rc = finfo->io->seek(finfo->io, entry->startPos + offset);
|
2003-12-15 05:01:18 +01:00
|
|
|
if (rc)
|
|
|
|
finfo->curPos = (PHYSFS_uint32) offset;
|
|
|
|
|
2010-01-28 08:27:45 +01:00
|
|
|
return rc;
|
2003-12-15 05:01:18 +01:00
|
|
|
} /* WAD_seek */
|
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static PHYSFS_sint64 WAD_length(PHYSFS_Io *io)
|
2003-12-15 05:01:18 +01:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
const WADfileinfo *finfo = (WADfileinfo *) io->opaque;
|
2010-01-28 08:27:45 +01:00
|
|
|
return ((PHYSFS_sint64) finfo->entry->size);
|
2010-08-30 09:01:57 +02:00
|
|
|
} /* WAD_length */
|
2003-12-15 05:01:18 +01:00
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static PHYSFS_Io *WAD_duplicate(PHYSFS_Io *_io)
|
2003-12-15 05:01:18 +01:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
WADfileinfo *origfinfo = (WADfileinfo *) _io->opaque;
|
|
|
|
PHYSFS_Io *io = NULL;
|
|
|
|
PHYSFS_Io *retval = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io));
|
|
|
|
WADfileinfo *finfo = (WADfileinfo *) allocator.Malloc(sizeof (WADfileinfo));
|
|
|
|
GOTO_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, WAD_duplicate_failed);
|
|
|
|
GOTO_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, WAD_duplicate_failed);
|
|
|
|
|
|
|
|
io = origfinfo->io->duplicate(origfinfo->io);
|
|
|
|
GOTO_IF_MACRO(io == NULL, NULL, WAD_duplicate_failed);
|
|
|
|
finfo->io = io;
|
|
|
|
finfo->entry = origfinfo->entry;
|
|
|
|
finfo->curPos = 0;
|
|
|
|
memcpy(retval, _io, sizeof (PHYSFS_Io));
|
|
|
|
retval->opaque = finfo;
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
WAD_duplicate_failed:
|
|
|
|
if (finfo != NULL) allocator.Free(finfo);
|
|
|
|
if (retval != NULL) allocator.Free(retval);
|
|
|
|
if (io != NULL) io->destroy(io);
|
|
|
|
return NULL;
|
|
|
|
} /* WAD_duplicate */
|
2003-12-15 05:01:18 +01:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static int WAD_flush(PHYSFS_Io *io) { return 1; /* no write support. */ }
|
2003-12-15 05:01:18 +01:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static void WAD_destroy(PHYSFS_Io *io)
|
2010-08-21 08:47:58 +02:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
WADfileinfo *finfo = (WADfileinfo *) io->opaque;
|
|
|
|
finfo->io->destroy(finfo->io);
|
|
|
|
allocator.Free(finfo);
|
|
|
|
allocator.Free(io);
|
|
|
|
} /* WAD_destroy */
|
2010-08-21 08:47:58 +02:00
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static const PHYSFS_Io WAD_Io =
|
2003-12-15 05:01:18 +01:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
WAD_read,
|
|
|
|
WAD_write,
|
|
|
|
WAD_seek,
|
|
|
|
WAD_tell,
|
|
|
|
WAD_length,
|
|
|
|
WAD_duplicate,
|
|
|
|
WAD_flush,
|
|
|
|
WAD_destroy,
|
|
|
|
NULL
|
|
|
|
};
|
2003-12-15 05:01:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static int wadEntryCmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
2003-12-15 05:01:18 +01:00
|
|
|
{
|
2008-02-20 13:24:10 +01:00
|
|
|
if (one != two)
|
|
|
|
{
|
|
|
|
const WADentry *a = (const WADentry *) _a;
|
2010-08-30 09:01:57 +02:00
|
|
|
return __PHYSFS_stricmpASCII(a[one].name, a[two].name);
|
2008-02-20 13:24:10 +01:00
|
|
|
} /* if */
|
|
|
|
|
|
|
|
return 0;
|
2010-08-30 09:01:57 +02:00
|
|
|
} /* wadEntryCmp */
|
2003-12-15 05:01:18 +01:00
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static void wadEntrySwap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
2003-12-15 05:01:18 +01:00
|
|
|
{
|
2008-02-20 13:24:10 +01:00
|
|
|
if (one != two)
|
|
|
|
{
|
|
|
|
WADentry tmp;
|
|
|
|
WADentry *first = &(((WADentry *) _a)[one]);
|
|
|
|
WADentry *second = &(((WADentry *) _a)[two]);
|
|
|
|
memcpy(&tmp, first, sizeof (WADentry));
|
|
|
|
memcpy(first, second, sizeof (WADentry));
|
|
|
|
memcpy(second, &tmp, sizeof (WADentry));
|
|
|
|
} /* if */
|
2010-08-30 09:01:57 +02:00
|
|
|
} /* wadEntrySwap */
|
2003-12-15 05:01:18 +01:00
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static int wad_load_entries(PHYSFS_Io *io, WADinfo *info)
|
2003-12-15 05:01:18 +01:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
PHYSFS_uint32 fileCount = info->entryCount;
|
2003-12-15 05:01:18 +01:00
|
|
|
PHYSFS_uint32 directoryOffset;
|
|
|
|
WADentry *entry;
|
2003-12-18 20:53:20 +01:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
BAIL_IF_MACRO(!readAll(io, &directoryOffset, 4), NULL, 0);
|
|
|
|
directoryOffset = PHYSFS_swapULE32(directoryOffset);
|
2003-12-15 05:01:18 +01:00
|
|
|
|
2005-03-14 12:49:30 +01:00
|
|
|
info->entries = (WADentry *) allocator.Malloc(sizeof(WADentry)*fileCount);
|
2010-08-30 09:01:57 +02:00
|
|
|
BAIL_IF_MACRO(info->entries == NULL, ERR_OUT_OF_MEMORY, 0);
|
|
|
|
BAIL_IF_MACRO(!io->seek(io, directoryOffset), NULL, 0);
|
2003-12-15 05:01:18 +01:00
|
|
|
|
|
|
|
for (entry = info->entries; fileCount > 0; fileCount--, entry++)
|
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
BAIL_IF_MACRO(!readAll(io, &entry->startPos, 4), NULL, 0);
|
|
|
|
BAIL_IF_MACRO(!readAll(io, &entry->size, 4), NULL, 0);
|
|
|
|
BAIL_IF_MACRO(!readAll(io, &entry->name, 8), NULL, 0);
|
2003-12-15 05:01:18 +01:00
|
|
|
|
|
|
|
entry->name[8] = '\0'; /* name might not be null-terminated in file. */
|
|
|
|
entry->size = PHYSFS_swapULE32(entry->size);
|
|
|
|
entry->startPos = PHYSFS_swapULE32(entry->startPos);
|
|
|
|
} /* for */
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
__PHYSFS_sort(info->entries, info->entryCount, wadEntryCmp, wadEntrySwap);
|
2010-01-28 08:27:45 +01:00
|
|
|
return 1;
|
2003-12-15 05:01:18 +01:00
|
|
|
} /* wad_load_entries */
|
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static void *WAD_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
|
2003-12-15 05:01:18 +01:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
PHYSFS_uint8 buf[4];
|
|
|
|
WADinfo *info = NULL;
|
|
|
|
PHYSFS_uint32 val = 0;
|
2003-12-15 05:01:18 +01:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
assert(io != NULL); /* shouldn't ever happen. */
|
|
|
|
|
|
|
|
BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0);
|
|
|
|
|
|
|
|
BAIL_IF_MACRO(!readAll(io, buf, sizeof (buf)), NULL, NULL);
|
|
|
|
if ((memcmp(buf, "IWAD", 4) != 0) && (memcmp(buf, "PWAD", 4) != 0))
|
|
|
|
GOTO_MACRO(ERR_NOT_AN_ARCHIVE, WAD_openArchive_failed);
|
|
|
|
|
|
|
|
info = (WADinfo *) allocator.Malloc(sizeof (WADinfo));
|
|
|
|
GOTO_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, WAD_openArchive_failed);
|
2003-12-15 05:01:18 +01:00
|
|
|
memset(info, '\0', sizeof (WADinfo));
|
2010-08-30 09:01:57 +02:00
|
|
|
info->io = io;
|
2003-12-15 05:01:18 +01:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
GOTO_IF_MACRO(!readAll(io,&val,sizeof(val)), NULL, WAD_openArchive_failed);
|
|
|
|
info->entryCount = PHYSFS_swapULE32(val);
|
2003-12-15 05:01:18 +01:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
GOTO_IF_MACRO(!wad_load_entries(io, info), NULL, WAD_openArchive_failed);
|
2003-12-15 05:01:18 +01:00
|
|
|
|
2010-01-28 08:27:45 +01:00
|
|
|
return info;
|
2003-12-15 05:01:18 +01:00
|
|
|
|
|
|
|
WAD_openArchive_failed:
|
2004-09-26 02:25:04 +02:00
|
|
|
if (info != NULL)
|
2003-12-15 05:01:18 +01:00
|
|
|
{
|
2004-09-26 02:25:04 +02:00
|
|
|
if (info->entries != NULL)
|
2005-03-14 12:49:30 +01:00
|
|
|
allocator.Free(info->entries);
|
|
|
|
allocator.Free(info);
|
2003-12-15 05:01:18 +01:00
|
|
|
} /* if */
|
|
|
|
|
2010-01-28 08:27:45 +01:00
|
|
|
return NULL;
|
2003-12-15 05:01:18 +01:00
|
|
|
} /* WAD_openArchive */
|
|
|
|
|
|
|
|
|
2004-09-29 08:09:29 +02:00
|
|
|
static void WAD_enumerateFiles(dvoid *opaque, const char *dname,
|
2005-09-18 23:44:42 +02:00
|
|
|
int omitSymLinks, PHYSFS_EnumFilesCallback cb,
|
|
|
|
const char *origdir, void *callbackdata)
|
2003-12-15 05:01:18 +01:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
/* no directories in WAD files. */
|
|
|
|
if (*dname == '\0')
|
2003-12-18 20:53:20 +01:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
WADinfo *info = (WADinfo *) opaque;
|
|
|
|
WADentry *entry = info->entries;
|
|
|
|
PHYSFS_uint32 max = info->entryCount;
|
|
|
|
PHYSFS_uint32 i;
|
|
|
|
|
2003-12-18 20:53:20 +01:00
|
|
|
for (i = 0; i < max; i++, entry++)
|
2010-08-30 09:01:57 +02:00
|
|
|
cb(callbackdata, origdir, entry->name);
|
2003-12-18 20:53:20 +01:00
|
|
|
} /* if */
|
2003-12-15 05:01:18 +01:00
|
|
|
} /* WAD_enumerateFiles */
|
|
|
|
|
|
|
|
|
2010-02-15 20:02:36 +01:00
|
|
|
static WADentry *wad_find_entry(const WADinfo *info, const char *name)
|
2003-12-15 05:01:18 +01:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
char *ptr = strchr(name, '.');
|
2003-12-15 05:01:18 +01:00
|
|
|
WADentry *a = info->entries;
|
|
|
|
PHYSFS_sint32 lo = 0;
|
|
|
|
PHYSFS_sint32 hi = (PHYSFS_sint32) (info->entryCount - 1);
|
|
|
|
PHYSFS_sint32 middle;
|
|
|
|
int rc;
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
/*
|
|
|
|
* Rule out filenames to avoid unneeded processing...no dirs,
|
|
|
|
* big filenames, or extensions.
|
|
|
|
*/
|
|
|
|
BAIL_IF_MACRO(ptr != NULL, ERR_NO_SUCH_FILE, NULL);
|
|
|
|
BAIL_IF_MACRO(strlen(name) > 8, ERR_NO_SUCH_FILE, NULL);
|
|
|
|
BAIL_IF_MACRO(strchr(name, '/') != NULL, ERR_NO_SUCH_FILE, NULL);
|
|
|
|
|
2003-12-15 05:01:18 +01:00
|
|
|
while (lo <= hi)
|
|
|
|
{
|
|
|
|
middle = lo + ((hi - lo) / 2);
|
2010-08-30 09:01:57 +02:00
|
|
|
rc = __PHYSFS_stricmpASCII(name, a[middle].name);
|
2003-12-15 05:01:18 +01:00
|
|
|
if (rc == 0) /* found it! */
|
2010-01-28 08:27:45 +01:00
|
|
|
return &a[middle];
|
2003-12-15 05:01:18 +01:00
|
|
|
else if (rc > 0)
|
|
|
|
lo = middle + 1;
|
|
|
|
else
|
|
|
|
hi = middle - 1;
|
|
|
|
} /* while */
|
|
|
|
|
|
|
|
BAIL_MACRO(ERR_NO_SUCH_FILE, NULL);
|
|
|
|
} /* wad_find_entry */
|
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static PHYSFS_Io *WAD_openRead(dvoid *opaque, const char *fnm, int *fileExists)
|
2003-12-15 05:01:18 +01:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
PHYSFS_Io *retval = NULL;
|
|
|
|
WADinfo *info = (WADinfo *) opaque;
|
2003-12-15 05:01:18 +01:00
|
|
|
WADfileinfo *finfo;
|
|
|
|
WADentry *entry;
|
|
|
|
|
|
|
|
entry = wad_find_entry(info, fnm);
|
|
|
|
*fileExists = (entry != NULL);
|
2010-08-30 09:01:57 +02:00
|
|
|
GOTO_IF_MACRO(entry == NULL, NULL, WAD_openRead_failed);
|
|
|
|
|
|
|
|
retval = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io));
|
|
|
|
GOTO_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, WAD_openRead_failed);
|
2003-12-15 05:01:18 +01:00
|
|
|
|
2005-03-14 12:49:30 +01:00
|
|
|
finfo = (WADfileinfo *) allocator.Malloc(sizeof (WADfileinfo));
|
2010-08-30 09:01:57 +02:00
|
|
|
GOTO_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, WAD_openRead_failed);
|
2003-12-15 05:01:18 +01:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
finfo->io = info->io->duplicate(info->io);
|
|
|
|
GOTO_IF_MACRO(finfo->io == NULL, NULL, WAD_openRead_failed);
|
|
|
|
|
|
|
|
if (!finfo->io->seek(finfo->io, entry->startPos))
|
|
|
|
GOTO_MACRO(NULL, WAD_openRead_failed);
|
|
|
|
|
|
|
|
finfo->curPos = 0;
|
|
|
|
finfo->entry = entry;
|
|
|
|
|
|
|
|
memcpy(retval, &WAD_Io, sizeof (*retval));
|
|
|
|
retval->opaque = finfo;
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
WAD_openRead_failed:
|
|
|
|
if (finfo != NULL)
|
2003-12-15 05:01:18 +01:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
if (finfo->io != NULL)
|
|
|
|
finfo->io->destroy(finfo->io);
|
2005-03-14 12:49:30 +01:00
|
|
|
allocator.Free(finfo);
|
2003-12-15 05:01:18 +01:00
|
|
|
} /* if */
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
if (retval != NULL)
|
|
|
|
allocator.Free(retval);
|
|
|
|
|
|
|
|
return NULL;
|
2003-12-15 05:01:18 +01:00
|
|
|
} /* WAD_openRead */
|
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static PHYSFS_Io *WAD_openWrite(dvoid *opaque, const char *name)
|
2003-12-15 05:01:18 +01:00
|
|
|
{
|
|
|
|
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
|
|
|
|
} /* WAD_openWrite */
|
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static PHYSFS_Io *WAD_openAppend(dvoid *opaque, const char *name)
|
2003-12-15 05:01:18 +01:00
|
|
|
{
|
|
|
|
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
|
|
|
|
} /* WAD_openAppend */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static int WAD_remove(dvoid *opaque, const char *name)
|
2003-12-15 05:01:18 +01:00
|
|
|
{
|
|
|
|
BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
|
|
|
|
} /* WAD_remove */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static int WAD_mkdir(dvoid *opaque, const char *name)
|
2003-12-15 05:01:18 +01:00
|
|
|
{
|
|
|
|
BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
|
|
|
|
} /* WAD_mkdir */
|
|
|
|
|
2004-09-29 08:18:04 +02:00
|
|
|
|
2010-08-22 06:37:25 +02:00
|
|
|
static int WAD_stat(dvoid *opaque, const char *filename, int *exists,
|
2010-02-15 20:02:36 +01:00
|
|
|
PHYSFS_Stat *stat)
|
|
|
|
{
|
|
|
|
const WADinfo *info = (const WADinfo *) opaque;
|
|
|
|
const WADentry *entry = wad_find_entry(info, filename);
|
|
|
|
|
|
|
|
*exists = (entry != 0);
|
|
|
|
if (!entry)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
stat->filesize = entry->size;
|
|
|
|
stat->filetype = PHYSFS_FILETYPE_REGULAR;
|
2010-08-25 07:28:28 +02:00
|
|
|
stat->modtime = -1;
|
|
|
|
stat->createtime = -1;
|
2010-08-30 09:01:57 +02:00
|
|
|
stat->accesstime = -1;
|
|
|
|
stat->readonly = 1;
|
2010-02-15 20:02:36 +01:00
|
|
|
|
2010-08-22 01:10:42 +02:00
|
|
|
return 1;
|
2010-02-15 20:02:36 +01:00
|
|
|
} /* WAD_stat */
|
|
|
|
|
|
|
|
|
2004-09-29 08:18:04 +02:00
|
|
|
const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_WAD =
|
|
|
|
{
|
|
|
|
"WAD",
|
2005-03-16 12:27:31 +01:00
|
|
|
WAD_ARCHIVE_DESCRIPTION,
|
2004-09-29 08:18:04 +02:00
|
|
|
"Travis Wells <traviswells@mchsi.com>",
|
|
|
|
"http://www.3dmm2.com/doom/",
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const PHYSFS_Archiver __PHYSFS_Archiver_WAD =
|
|
|
|
{
|
|
|
|
&__PHYSFS_ArchiveInfo_WAD,
|
|
|
|
WAD_openArchive, /* openArchive() method */
|
|
|
|
WAD_enumerateFiles, /* enumerateFiles() method */
|
|
|
|
WAD_openRead, /* openRead() method */
|
|
|
|
WAD_openWrite, /* openWrite() method */
|
|
|
|
WAD_openAppend, /* openAppend() method */
|
|
|
|
WAD_remove, /* remove() method */
|
|
|
|
WAD_mkdir, /* mkdir() method */
|
|
|
|
WAD_dirClose, /* dirClose() method */
|
2010-08-30 09:01:57 +02:00
|
|
|
WAD_stat /* stat() method */
|
2004-09-29 08:18:04 +02:00
|
|
|
};
|
|
|
|
|
2003-12-15 05:01:18 +01:00
|
|
|
#endif /* defined PHYSFS_SUPPORTS_WAD */
|
|
|
|
|
|
|
|
/* end of wad.c ... */
|
|
|
|
|