2001-07-09 02:49:41 +02:00
|
|
|
/*
|
|
|
|
* GRP support routines for PhysicsFS.
|
|
|
|
*
|
|
|
|
* This driver handles BUILD engine archives ("groupfiles"). This format
|
|
|
|
* (but not this driver) was put together by Ken Silverman.
|
|
|
|
*
|
|
|
|
* The format is simple enough. In Ken's words:
|
|
|
|
*
|
|
|
|
* What's the .GRP file format?
|
|
|
|
*
|
|
|
|
* The ".grp" file format is just a collection of a lot of files stored
|
|
|
|
* into 1 big one. I tried to make the format as simple as possible: The
|
|
|
|
* first 12 bytes contains my name, "KenSilverman". The next 4 bytes is
|
|
|
|
* the number of files that were compacted into the group file. Then for
|
|
|
|
* each file, there is a 16 byte structure, where the first 12 bytes are
|
|
|
|
* the filename, and the last 4 bytes are the file's size. The rest of
|
|
|
|
* the group file is just the raw data packed one after the other in the
|
|
|
|
* same order as the list of files.
|
|
|
|
*
|
|
|
|
* (That info is from http://www.advsys.net/ken/build.htm ...)
|
|
|
|
*
|
2007-03-11 11:10:28 +01:00
|
|
|
* Please see the file LICENSE.txt in the source's root directory.
|
2001-07-09 02:49:41 +02:00
|
|
|
*
|
|
|
|
* This file written by Ryan C. Gordon.
|
|
|
|
*/
|
|
|
|
|
2002-05-10 11:25:25 +02:00
|
|
|
#if (defined PHYSFS_SUPPORTS_GRP)
|
|
|
|
|
2001-07-09 02:49:41 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "physfs.h"
|
|
|
|
|
|
|
|
#define __PHYSICSFS_INTERNAL__
|
|
|
|
#include "physfs_internal.h"
|
|
|
|
|
2002-07-23 09:48:43 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char name[13];
|
2002-08-28 10:58:39 +02:00
|
|
|
PHYSFS_uint32 startPos;
|
|
|
|
PHYSFS_uint32 size;
|
2002-07-23 09:48:43 +02:00
|
|
|
} GRPentry;
|
|
|
|
|
2001-07-09 02:49:41 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
PHYSFS_Io *io;
|
2002-07-23 09:48:43 +02:00
|
|
|
PHYSFS_uint32 entryCount;
|
|
|
|
GRPentry *entries;
|
2001-07-09 02:49:41 +02:00
|
|
|
} GRPinfo;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
PHYSFS_Io *io;
|
2002-07-23 09:48:43 +02:00
|
|
|
GRPentry *entry;
|
2002-08-28 10:58:39 +02:00
|
|
|
PHYSFS_uint32 curPos;
|
2001-07-09 02:49:41 +02:00
|
|
|
} GRPfileinfo;
|
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static inline int readAll(PHYSFS_Io *io, void *buf, const PHYSFS_uint64 len)
|
2010-08-21 08:47:58 +02:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
return (io->read(io, buf, len) == len);
|
2010-08-21 08:47:58 +02:00
|
|
|
} /* readAll */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static void GRP_dirClose(dvoid *opaque)
|
2001-09-02 06:55:25 +02:00
|
|
|
{
|
2004-09-26 02:25:04 +02:00
|
|
|
GRPinfo *info = ((GRPinfo *) 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);
|
2001-09-02 06:55:25 +02:00
|
|
|
} /* GRP_dirClose */
|
2001-07-09 02:49:41 +02:00
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static PHYSFS_sint64 GRP_read(PHYSFS_Io *io, void *buffer, PHYSFS_uint64 len)
|
2001-07-09 02:49:41 +02:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
GRPfileinfo *finfo = (GRPfileinfo *) io->opaque;
|
2010-08-21 08:47:58 +02:00
|
|
|
const GRPentry *entry = finfo->entry;
|
|
|
|
const PHYSFS_uint64 bytesLeft = (PHYSFS_uint64)(entry->size-finfo->curPos);
|
2002-07-23 09:48:43 +02:00
|
|
|
PHYSFS_sint64 rc;
|
2001-07-09 02:49:41 +02:00
|
|
|
|
2010-08-21 08:47:58 +02:00
|
|
|
if (bytesLeft < len)
|
|
|
|
len = bytesLeft;
|
2001-07-09 02:49:41 +02:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
rc = finfo->io->read(finfo->io, buffer, len);
|
2002-07-23 09:48:43 +02:00
|
|
|
if (rc > 0)
|
2010-08-21 08:47:58 +02:00
|
|
|
finfo->curPos += (PHYSFS_uint32) rc;
|
2002-07-23 09:48:43 +02:00
|
|
|
|
2010-01-28 08:27:45 +01:00
|
|
|
return rc;
|
2001-07-09 02:49:41 +02:00
|
|
|
} /* GRP_read */
|
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static PHYSFS_sint64 GRP_write(PHYSFS_Io *io, const void *b, PHYSFS_uint64 len)
|
2002-08-21 04:59:15 +02:00
|
|
|
{
|
|
|
|
BAIL_MACRO(ERR_NOT_SUPPORTED, -1);
|
|
|
|
} /* GRP_write */
|
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static PHYSFS_sint64 GRP_tell(PHYSFS_Io *io)
|
2001-07-09 02:49:41 +02:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
return ((GRPfileinfo *) io->opaque)->curPos;
|
2001-07-09 02:49:41 +02:00
|
|
|
} /* GRP_tell */
|
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static int GRP_seek(PHYSFS_Io *io, PHYSFS_uint64 offset)
|
2001-07-09 02:49:41 +02:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
GRPfileinfo *finfo = (GRPfileinfo *) io->opaque;
|
|
|
|
const GRPentry *entry = finfo->entry;
|
2002-07-23 09:48:43 +02:00
|
|
|
int rc;
|
2001-07-09 02:49:41 +02:00
|
|
|
|
2002-08-28 10:58:39 +02:00
|
|
|
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);
|
2002-07-23 09:48:43 +02:00
|
|
|
if (rc)
|
2002-08-28 10:58:39 +02:00
|
|
|
finfo->curPos = (PHYSFS_uint32) offset;
|
2002-07-23 09:48:43 +02:00
|
|
|
|
2010-01-28 08:27:45 +01:00
|
|
|
return rc;
|
2001-07-09 02:49:41 +02:00
|
|
|
} /* GRP_seek */
|
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static PHYSFS_sint64 GRP_length(PHYSFS_Io *io)
|
2001-07-09 06:15:35 +02:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
const GRPfileinfo *finfo = (GRPfileinfo *) io->opaque;
|
2010-01-28 08:27:45 +01:00
|
|
|
return ((PHYSFS_sint64) finfo->entry->size);
|
2010-08-30 09:01:57 +02:00
|
|
|
} /* GRP_length */
|
2001-07-09 06:15:35 +02:00
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static PHYSFS_Io *GRP_duplicate(PHYSFS_Io *_io)
|
2001-07-09 02:49:41 +02:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
GRPfileinfo *origfinfo = (GRPfileinfo *) _io->opaque;
|
|
|
|
PHYSFS_Io *io = NULL;
|
|
|
|
PHYSFS_Io *retval = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io));
|
|
|
|
GRPfileinfo *finfo = (GRPfileinfo *) allocator.Malloc(sizeof (GRPfileinfo));
|
|
|
|
GOTO_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, GRP_duplicate_failed);
|
|
|
|
GOTO_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, GRP_duplicate_failed);
|
|
|
|
|
|
|
|
io = origfinfo->io->duplicate(origfinfo->io);
|
|
|
|
GOTO_IF_MACRO(io == NULL, NULL, GRP_duplicate_failed);
|
|
|
|
finfo->io = io;
|
|
|
|
finfo->entry = origfinfo->entry;
|
|
|
|
finfo->curPos = 0;
|
|
|
|
memcpy(retval, _io, sizeof (PHYSFS_Io));
|
|
|
|
retval->opaque = finfo;
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
GRP_duplicate_failed:
|
|
|
|
if (finfo != NULL) allocator.Free(finfo);
|
|
|
|
if (retval != NULL) allocator.Free(retval);
|
|
|
|
if (io != NULL) io->destroy(io);
|
|
|
|
return NULL;
|
|
|
|
} /* GRP_duplicate */
|
2001-07-09 02:49:41 +02:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static int GRP_flush(PHYSFS_Io *io) { return 1; /* no write support. */ }
|
2001-07-09 02:49:41 +02:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static void GRP_destroy(PHYSFS_Io *io)
|
2001-07-09 02:49:41 +02:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
GRPfileinfo *finfo = (GRPfileinfo *) io->opaque;
|
|
|
|
finfo->io->destroy(finfo->io);
|
|
|
|
allocator.Free(finfo);
|
|
|
|
allocator.Free(io);
|
|
|
|
} /* GRP_destroy */
|
2001-07-09 02:49:41 +02:00
|
|
|
|
2002-04-05 20:05:50 +02:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static const PHYSFS_Io GRP_Io =
|
|
|
|
{
|
|
|
|
GRP_read,
|
|
|
|
GRP_write,
|
|
|
|
GRP_seek,
|
|
|
|
GRP_tell,
|
|
|
|
GRP_length,
|
|
|
|
GRP_duplicate,
|
|
|
|
GRP_flush,
|
|
|
|
GRP_destroy,
|
|
|
|
NULL
|
|
|
|
};
|
2002-03-25 09:13:06 +01:00
|
|
|
|
|
|
|
|
2001-07-09 02:49:41 +02:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static int grpEntryCmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
2002-07-23 09:48:43 +02:00
|
|
|
{
|
2008-02-20 13:24:10 +01:00
|
|
|
if (one != two)
|
|
|
|
{
|
|
|
|
const GRPentry *a = (const GRPentry *) _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
|
|
|
} /* grpEntryCmp */
|
2002-07-23 09:48:43 +02:00
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static void grpEntrySwap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
2002-07-23 09:48:43 +02:00
|
|
|
{
|
2008-02-20 13:24:10 +01:00
|
|
|
if (one != two)
|
|
|
|
{
|
|
|
|
GRPentry tmp;
|
|
|
|
GRPentry *first = &(((GRPentry *) _a)[one]);
|
|
|
|
GRPentry *second = &(((GRPentry *) _a)[two]);
|
|
|
|
memcpy(&tmp, first, sizeof (GRPentry));
|
|
|
|
memcpy(first, second, sizeof (GRPentry));
|
|
|
|
memcpy(second, &tmp, sizeof (GRPentry));
|
|
|
|
} /* if */
|
2010-08-30 09:01:57 +02:00
|
|
|
} /* grpEntrySwap */
|
2002-07-23 09:48:43 +02:00
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static int grp_load_entries(PHYSFS_Io *io, GRPinfo *info)
|
2001-07-09 02:49:41 +02:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
PHYSFS_uint32 fileCount = info->entryCount;
|
2002-07-23 20:11:12 +02:00
|
|
|
PHYSFS_uint32 location = 16; /* sizeof sig. */
|
2002-07-23 09:48:43 +02:00
|
|
|
GRPentry *entry;
|
|
|
|
char *ptr;
|
|
|
|
|
2005-03-14 12:49:30 +01:00
|
|
|
info->entries = (GRPentry *) allocator.Malloc(sizeof(GRPentry)*fileCount);
|
2010-08-30 09:01:57 +02:00
|
|
|
BAIL_IF_MACRO(info->entries == NULL, ERR_OUT_OF_MEMORY, 0);
|
2002-07-23 09:48:43 +02:00
|
|
|
|
2002-07-23 20:11:12 +02:00
|
|
|
location += (16 * fileCount);
|
|
|
|
|
2002-07-23 09:48:43 +02:00
|
|
|
for (entry = info->entries; fileCount > 0; fileCount--, entry++)
|
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
BAIL_IF_MACRO(!readAll(io, &entry->name, 12), NULL, 0);
|
|
|
|
BAIL_IF_MACRO(!readAll(io, &entry->size, 4), NULL, 0);
|
2002-07-23 09:48:43 +02:00
|
|
|
entry->name[12] = '\0'; /* name isn't null-terminated in file. */
|
|
|
|
if ((ptr = strchr(entry->name, ' ')) != NULL)
|
|
|
|
*ptr = '\0'; /* trim extra spaces. */
|
|
|
|
|
|
|
|
entry->size = PHYSFS_swapULE32(entry->size);
|
|
|
|
entry->startPos = location;
|
2002-07-23 20:11:12 +02:00
|
|
|
location += entry->size;
|
2002-07-23 09:48:43 +02:00
|
|
|
} /* for */
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
__PHYSFS_sort(info->entries, info->entryCount, grpEntryCmp, grpEntrySwap);
|
2010-01-28 08:27:45 +01:00
|
|
|
return 1;
|
2002-07-23 09:48:43 +02:00
|
|
|
} /* grp_load_entries */
|
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static void *GRP_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
|
2002-07-23 09:48:43 +02:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
PHYSFS_uint8 buf[12];
|
|
|
|
GRPinfo *info = NULL;
|
|
|
|
PHYSFS_uint32 val = 0;
|
|
|
|
|
|
|
|
assert(io != NULL); /* shouldn't ever happen. */
|
2001-07-09 02:49:41 +02:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0);
|
2001-07-09 02:49:41 +02:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
BAIL_IF_MACRO(!readAll(io, buf, sizeof (buf)), NULL, NULL);
|
|
|
|
if (memcmp(buf, "KenSilverman", sizeof (buf)) != 0)
|
|
|
|
GOTO_MACRO(ERR_NOT_AN_ARCHIVE, GRP_openArchive_failed);
|
|
|
|
|
|
|
|
info = (GRPinfo *) allocator.Malloc(sizeof (GRPinfo));
|
|
|
|
GOTO_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, GRP_openArchive_failed);
|
2002-07-23 09:48:43 +02:00
|
|
|
memset(info, '\0', sizeof (GRPinfo));
|
2010-08-30 09:01:57 +02:00
|
|
|
info->io = io;
|
2001-07-09 02:49:41 +02:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
GOTO_IF_MACRO(!readAll(io,&val,sizeof(val)), NULL, GRP_openArchive_failed);
|
|
|
|
info->entryCount = PHYSFS_swapULE32(val);
|
2002-03-25 09:13:06 +01:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
GOTO_IF_MACRO(!grp_load_entries(io, info), NULL, GRP_openArchive_failed);
|
2004-09-26 02:25:04 +02:00
|
|
|
|
2010-01-28 08:27:45 +01:00
|
|
|
return info;
|
2002-03-25 09:13:06 +01:00
|
|
|
|
|
|
|
GRP_openArchive_failed:
|
2004-09-26 02:25:04 +02:00
|
|
|
if (info != NULL)
|
2002-03-25 09:13:06 +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);
|
2002-03-25 09:13:06 +01:00
|
|
|
} /* if */
|
|
|
|
|
2010-01-28 08:27:45 +01:00
|
|
|
return NULL;
|
2001-07-09 02:49:41 +02:00
|
|
|
} /* GRP_openArchive */
|
|
|
|
|
|
|
|
|
2004-09-29 08:09:29 +02:00
|
|
|
static void GRP_enumerateFiles(dvoid *opaque, const char *dname,
|
2005-09-18 23:44:42 +02:00
|
|
|
int omitSymLinks, PHYSFS_EnumFilesCallback cb,
|
|
|
|
const char *origdir, void *callbackdata)
|
2001-07-09 02:49:41 +02:00
|
|
|
{
|
2002-07-23 09:48:43 +02:00
|
|
|
/* no directories in GRP files. */
|
2007-03-28 19:29:52 +02:00
|
|
|
if (*dname == '\0')
|
2004-09-29 08:09:29 +02:00
|
|
|
{
|
|
|
|
GRPinfo *info = (GRPinfo *) opaque;
|
|
|
|
GRPentry *entry = info->entries;
|
|
|
|
PHYSFS_uint32 max = info->entryCount;
|
|
|
|
PHYSFS_uint32 i;
|
2001-07-09 02:49:41 +02:00
|
|
|
|
2004-09-29 08:09:29 +02:00
|
|
|
for (i = 0; i < max; i++, entry++)
|
2005-09-18 23:44:42 +02:00
|
|
|
cb(callbackdata, origdir, entry->name);
|
2004-09-29 08:09:29 +02:00
|
|
|
} /* if */
|
2001-07-09 02:49:41 +02:00
|
|
|
} /* GRP_enumerateFiles */
|
|
|
|
|
|
|
|
|
2010-02-15 20:02:36 +01:00
|
|
|
static GRPentry *grp_find_entry(const GRPinfo *info, const char *name)
|
2001-07-09 02:49:41 +02:00
|
|
|
{
|
2002-07-23 09:48:43 +02:00
|
|
|
char *ptr = strchr(name, '.');
|
|
|
|
GRPentry *a = info->entries;
|
|
|
|
PHYSFS_sint32 lo = 0;
|
|
|
|
PHYSFS_sint32 hi = (PHYSFS_sint32) (info->entryCount - 1);
|
|
|
|
PHYSFS_sint32 middle;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Rule out filenames to avoid unneeded processing...no dirs,
|
|
|
|
* big filenames, or extensions > 3 chars.
|
|
|
|
*/
|
|
|
|
BAIL_IF_MACRO((ptr) && (strlen(ptr) > 4), ERR_NO_SUCH_FILE, NULL);
|
|
|
|
BAIL_IF_MACRO(strlen(name) > 12, ERR_NO_SUCH_FILE, NULL);
|
|
|
|
BAIL_IF_MACRO(strchr(name, '/') != NULL, ERR_NO_SUCH_FILE, NULL);
|
|
|
|
|
|
|
|
while (lo <= hi)
|
2001-07-09 02:49:41 +02:00
|
|
|
{
|
2002-07-23 09:48:43 +02:00
|
|
|
middle = lo + ((hi - lo) / 2);
|
2010-08-30 09:01:57 +02:00
|
|
|
rc = __PHYSFS_stricmpASCII(name, a[middle].name);
|
2002-07-23 09:48:43 +02:00
|
|
|
if (rc == 0) /* found it! */
|
2010-01-28 08:27:45 +01:00
|
|
|
return &a[middle];
|
2002-07-23 09:48:43 +02:00
|
|
|
else if (rc > 0)
|
|
|
|
lo = middle + 1;
|
|
|
|
else
|
|
|
|
hi = middle - 1;
|
|
|
|
} /* while */
|
2001-07-09 02:49:41 +02:00
|
|
|
|
2002-07-23 09:48:43 +02:00
|
|
|
BAIL_MACRO(ERR_NO_SUCH_FILE, NULL);
|
|
|
|
} /* grp_find_entry */
|
2001-07-09 02:49:41 +02:00
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static PHYSFS_Io *GRP_openRead(dvoid *opaque, const char *fnm, int *fileExists)
|
2001-07-09 02:49:41 +02:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
PHYSFS_Io *retval = NULL;
|
2004-09-26 15:00:59 +02:00
|
|
|
GRPinfo *info = (GRPinfo *) opaque;
|
2001-07-09 02:49:41 +02:00
|
|
|
GRPfileinfo *finfo;
|
2002-07-23 09:48:43 +02:00
|
|
|
GRPentry *entry;
|
2001-07-09 02:49:41 +02:00
|
|
|
|
2002-08-21 04:59:15 +02:00
|
|
|
entry = grp_find_entry(info, fnm);
|
|
|
|
*fileExists = (entry != NULL);
|
2010-08-30 09:01:57 +02:00
|
|
|
GOTO_IF_MACRO(entry == NULL, NULL, GRP_openRead_failed);
|
|
|
|
|
|
|
|
retval = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io));
|
|
|
|
GOTO_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, GRP_openRead_failed);
|
2001-07-09 02:49:41 +02:00
|
|
|
|
2005-03-14 12:49:30 +01:00
|
|
|
finfo = (GRPfileinfo *) allocator.Malloc(sizeof (GRPfileinfo));
|
2010-08-30 09:01:57 +02:00
|
|
|
GOTO_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, GRP_openRead_failed);
|
2001-07-09 02:49:41 +02:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
finfo->io = info->io->duplicate(info->io);
|
|
|
|
GOTO_IF_MACRO(finfo->io == NULL, NULL, GRP_openRead_failed);
|
|
|
|
|
|
|
|
if (!finfo->io->seek(finfo->io, entry->startPos))
|
|
|
|
GOTO_MACRO(NULL, GRP_openRead_failed);
|
|
|
|
|
|
|
|
finfo->curPos = 0;
|
|
|
|
finfo->entry = entry;
|
|
|
|
|
|
|
|
memcpy(retval, &GRP_Io, sizeof (*retval));
|
|
|
|
retval->opaque = finfo;
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
GRP_openRead_failed:
|
|
|
|
if (finfo != NULL)
|
2002-03-25 09:13:06 +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);
|
2002-03-25 09:13:06 +01:00
|
|
|
} /* if */
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
if (retval != NULL)
|
|
|
|
allocator.Free(retval);
|
|
|
|
|
|
|
|
return NULL;
|
2001-07-09 02:49:41 +02:00
|
|
|
} /* GRP_openRead */
|
|
|
|
|
2002-08-21 04:59:15 +02:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static PHYSFS_Io *GRP_openWrite(dvoid *opaque, const char *name)
|
2002-08-21 04:59:15 +02:00
|
|
|
{
|
|
|
|
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
|
|
|
|
} /* GRP_openWrite */
|
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static PHYSFS_Io *GRP_openAppend(dvoid *opaque, const char *name)
|
2002-08-21 04:59:15 +02:00
|
|
|
{
|
|
|
|
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
|
|
|
|
} /* GRP_openAppend */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static int GRP_remove(dvoid *opaque, const char *name)
|
2002-08-21 04:59:15 +02:00
|
|
|
{
|
|
|
|
BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
|
|
|
|
} /* GRP_remove */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static int GRP_mkdir(dvoid *opaque, const char *name)
|
2002-08-21 04:59:15 +02:00
|
|
|
{
|
|
|
|
BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
|
|
|
|
} /* GRP_mkdir */
|
|
|
|
|
2004-09-29 08:18:04 +02:00
|
|
|
|
2010-08-22 06:37:25 +02:00
|
|
|
static int GRP_stat(dvoid *opaque, const char *filename, int *exists,
|
2010-02-15 20:02:36 +01:00
|
|
|
PHYSFS_Stat *stat)
|
|
|
|
{
|
|
|
|
const GRPinfo *info = (const GRPinfo *) opaque;
|
|
|
|
const GRPentry *entry = grp_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-02-15 20:02:36 +01:00
|
|
|
stat->accesstime = -1;
|
|
|
|
stat->readonly = 1;
|
|
|
|
|
2010-08-22 01:10:42 +02:00
|
|
|
return 1;
|
2010-02-15 20:02:36 +01:00
|
|
|
} /* GRP_stat */
|
|
|
|
|
|
|
|
|
2004-09-29 08:18:04 +02:00
|
|
|
const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_GRP =
|
|
|
|
{
|
|
|
|
"GRP",
|
|
|
|
GRP_ARCHIVE_DESCRIPTION,
|
2006-01-01 13:33:19 +01:00
|
|
|
"Ryan C. Gordon <icculus@icculus.org>",
|
2004-09-29 08:18:04 +02:00
|
|
|
"http://icculus.org/physfs/",
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const PHYSFS_Archiver __PHYSFS_Archiver_GRP =
|
|
|
|
{
|
|
|
|
&__PHYSFS_ArchiveInfo_GRP,
|
|
|
|
GRP_openArchive, /* openArchive() method */
|
|
|
|
GRP_enumerateFiles, /* enumerateFiles() method */
|
|
|
|
GRP_openRead, /* openRead() method */
|
|
|
|
GRP_openWrite, /* openWrite() method */
|
|
|
|
GRP_openAppend, /* openAppend() method */
|
|
|
|
GRP_remove, /* remove() method */
|
|
|
|
GRP_mkdir, /* mkdir() method */
|
|
|
|
GRP_dirClose, /* dirClose() method */
|
2010-08-30 09:01:57 +02:00
|
|
|
GRP_stat /* stat() method */
|
2004-09-29 08:18:04 +02:00
|
|
|
};
|
|
|
|
|
2002-05-10 11:25:25 +02:00
|
|
|
#endif /* defined PHYSFS_SUPPORTS_GRP */
|
|
|
|
|
2001-07-09 02:49:41 +02:00
|
|
|
/* end of grp.c ... */
|
|
|
|
|