2003-03-30 20:59:54 +02:00
|
|
|
/*
|
|
|
|
* HOG support routines for PhysicsFS.
|
|
|
|
*
|
|
|
|
* This driver handles Descent I/II HOG archives.
|
|
|
|
*
|
|
|
|
* The format is very simple:
|
|
|
|
*
|
|
|
|
* The file always starts with the 3-byte signature "DHF" (Descent
|
|
|
|
* HOG file). After that the files of a HOG are just attached after
|
|
|
|
* another, divided by a 17 bytes header, which specifies the name
|
|
|
|
* and length (in bytes) of the forthcoming file! So you just read
|
|
|
|
* the header with its information of how big the following file is,
|
|
|
|
* and then skip exact that number of bytes to get to the next file
|
|
|
|
* in that HOG.
|
|
|
|
*
|
|
|
|
* char sig[3] = {'D', 'H', 'F'}; // "DHF"=Descent HOG File
|
|
|
|
*
|
|
|
|
* struct {
|
|
|
|
* char file_name[13]; // Filename, padded to 13 bytes with 0s
|
|
|
|
* int file_size; // filesize in bytes
|
|
|
|
* char data[file_size]; // The file data
|
|
|
|
* } FILE_STRUCT; // Repeated until the end of the file.
|
|
|
|
*
|
|
|
|
* (That info is from http://www.descent2.com/ddn/specs/hog/)
|
|
|
|
*
|
2007-03-11 11:10:28 +01:00
|
|
|
* Please see the file LICENSE.txt in the source's root directory.
|
2003-03-30 20:59:54 +02:00
|
|
|
*
|
|
|
|
* This file written by Bradley Bell.
|
|
|
|
* Based on grp.c by Ryan C. Gordon.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if (defined PHYSFS_SUPPORTS_HOG)
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "physfs.h"
|
|
|
|
|
|
|
|
#define __PHYSICSFS_INTERNAL__
|
|
|
|
#include "physfs_internal.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* One HOGentry is kept for each file in an open HOG archive.
|
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char name[13];
|
|
|
|
PHYSFS_uint32 startPos;
|
|
|
|
PHYSFS_uint32 size;
|
|
|
|
} HOGentry;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* One HOGinfo is kept for each open HOG archive.
|
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
PHYSFS_Io *io;
|
2003-03-30 20:59:54 +02:00
|
|
|
PHYSFS_uint32 entryCount;
|
|
|
|
HOGentry *entries;
|
|
|
|
} HOGinfo;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* One HOGfileinfo is kept for each open file in a HOG archive.
|
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
PHYSFS_Io *io;
|
2003-03-30 20:59:54 +02:00
|
|
|
HOGentry *entry;
|
|
|
|
PHYSFS_uint32 curPos;
|
|
|
|
} HOGfileinfo;
|
|
|
|
|
|
|
|
|
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 HOG_dirClose(dvoid *opaque)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2004-09-26 02:25:04 +02:00
|
|
|
HOGinfo *info = ((HOGinfo *) 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-03-30 20:59:54 +02:00
|
|
|
} /* HOG_dirClose */
|
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static PHYSFS_sint64 HOG_read(PHYSFS_Io *io, void *buffer, PHYSFS_uint64 len)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
HOGfileinfo *finfo = (HOGfileinfo *) io->opaque;
|
2010-08-21 08:47:58 +02:00
|
|
|
const HOGentry *entry = finfo->entry;
|
|
|
|
const PHYSFS_uint64 bytesLeft = (PHYSFS_uint64)(entry->size-finfo->curPos);
|
2003-03-30 20:59:54 +02:00
|
|
|
PHYSFS_sint64 rc;
|
|
|
|
|
2010-08-21 08:47:58 +02:00
|
|
|
if (bytesLeft < len)
|
|
|
|
len = bytesLeft;
|
2003-03-30 20:59:54 +02:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
rc = finfo->io->read(finfo->io, buffer, len);
|
2003-03-30 20:59:54 +02:00
|
|
|
if (rc > 0)
|
2010-08-21 08:47:58 +02:00
|
|
|
finfo->curPos += (PHYSFS_uint32) rc;
|
2003-03-30 20:59:54 +02:00
|
|
|
|
2010-01-28 08:27:45 +01:00
|
|
|
return rc;
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* HOG_read */
|
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static PHYSFS_sint64 HOG_write(PHYSFS_Io *io, const void *b, PHYSFS_uint64 len)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
|
|
|
BAIL_MACRO(ERR_NOT_SUPPORTED, -1);
|
|
|
|
} /* HOG_write */
|
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static PHYSFS_sint64 HOG_tell(PHYSFS_Io *io)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
return ((HOGfileinfo *) io->opaque)->curPos;
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* HOG_tell */
|
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static int HOG_seek(PHYSFS_Io *io, PHYSFS_uint64 offset)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
HOGfileinfo *finfo = (HOGfileinfo *) io->opaque;
|
|
|
|
const HOGentry *entry = finfo->entry;
|
2003-03-30 20:59:54 +02: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-03-30 20:59:54 +02:00
|
|
|
if (rc)
|
|
|
|
finfo->curPos = (PHYSFS_uint32) offset;
|
|
|
|
|
2010-01-28 08:27:45 +01:00
|
|
|
return rc;
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* HOG_seek */
|
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static PHYSFS_sint64 HOG_length(PHYSFS_Io *io)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
const HOGfileinfo *finfo = (HOGfileinfo *) io->opaque;
|
2010-01-28 08:27:45 +01:00
|
|
|
return ((PHYSFS_sint64) finfo->entry->size);
|
2010-08-30 09:01:57 +02:00
|
|
|
} /* HOG_length */
|
2003-03-30 20:59:54 +02:00
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static PHYSFS_Io *HOG_duplicate(PHYSFS_Io *_io)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
HOGfileinfo *origfinfo = (HOGfileinfo *) _io->opaque;
|
|
|
|
PHYSFS_Io *io = NULL;
|
|
|
|
PHYSFS_Io *retval = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io));
|
|
|
|
HOGfileinfo *finfo = (HOGfileinfo *) allocator.Malloc(sizeof (HOGfileinfo));
|
|
|
|
GOTO_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, HOG_duplicate_failed);
|
|
|
|
GOTO_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, HOG_duplicate_failed);
|
|
|
|
|
|
|
|
io = origfinfo->io->duplicate(origfinfo->io);
|
|
|
|
GOTO_IF_MACRO(io == NULL, NULL, HOG_duplicate_failed);
|
|
|
|
finfo->io = io;
|
|
|
|
finfo->entry = origfinfo->entry;
|
|
|
|
finfo->curPos = 0;
|
|
|
|
memcpy(retval, _io, sizeof (PHYSFS_Io));
|
|
|
|
retval->opaque = finfo;
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
HOG_duplicate_failed:
|
|
|
|
if (finfo != NULL) allocator.Free(finfo);
|
|
|
|
if (retval != NULL) allocator.Free(retval);
|
|
|
|
if (io != NULL) io->destroy(io);
|
|
|
|
return NULL;
|
|
|
|
} /* HOG_duplicate */
|
2003-03-30 20:59:54 +02:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static int HOG_flush(PHYSFS_Io *io) { return 1; /* no write support. */ }
|
2003-03-30 20:59:54 +02:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static void HOG_destroy(PHYSFS_Io *io)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
HOGfileinfo *finfo = (HOGfileinfo *) io->opaque;
|
|
|
|
finfo->io->destroy(finfo->io);
|
|
|
|
allocator.Free(finfo);
|
|
|
|
allocator.Free(io);
|
|
|
|
} /* HOG_destroy */
|
2003-03-30 20:59:54 +02:00
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static const PHYSFS_Io HOG_Io =
|
|
|
|
{
|
|
|
|
HOG_read,
|
|
|
|
HOG_write,
|
|
|
|
HOG_seek,
|
|
|
|
HOG_tell,
|
|
|
|
HOG_length,
|
|
|
|
HOG_duplicate,
|
|
|
|
HOG_flush,
|
|
|
|
HOG_destroy,
|
|
|
|
NULL
|
|
|
|
};
|
2003-03-30 20:59:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static int hogEntryCmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2008-02-20 13:24:10 +01:00
|
|
|
if (one != two)
|
|
|
|
{
|
|
|
|
const HOGentry *a = (const HOGentry *) _a;
|
2010-01-28 08:27:45 +01: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
|
|
|
} /* hogEntryCmp */
|
2003-03-30 20:59:54 +02:00
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static void hogEntrySwap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2008-02-20 13:24:10 +01:00
|
|
|
if (one != two)
|
|
|
|
{
|
|
|
|
HOGentry tmp;
|
|
|
|
HOGentry *first = &(((HOGentry *) _a)[one]);
|
|
|
|
HOGentry *second = &(((HOGentry *) _a)[two]);
|
|
|
|
memcpy(&tmp, first, sizeof (HOGentry));
|
|
|
|
memcpy(first, second, sizeof (HOGentry));
|
|
|
|
memcpy(second, &tmp, sizeof (HOGentry));
|
|
|
|
} /* if */
|
2010-08-30 09:01:57 +02:00
|
|
|
} /* hogEntrySwap */
|
2003-03-30 20:59:54 +02:00
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static int hog_load_entries(PHYSFS_Io *io, HOGinfo *info)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
const PHYSFS_uint64 iolen = io->length(io);
|
|
|
|
PHYSFS_uint32 entCount = 0;
|
|
|
|
void *ptr = NULL;
|
|
|
|
HOGentry *entry = NULL;
|
|
|
|
PHYSFS_uint32 size = 0;
|
|
|
|
PHYSFS_uint32 pos = 3;
|
|
|
|
|
|
|
|
while (pos < iolen)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
entCount++;
|
|
|
|
ptr = allocator.Realloc(ptr, sizeof (HOGentry) * entCount);
|
|
|
|
BAIL_IF_MACRO(ptr == NULL, ERR_OUT_OF_MEMORY, 0);
|
|
|
|
info->entries = (HOGentry *) ptr;
|
|
|
|
entry = &info->entries[entCount-1];
|
|
|
|
|
|
|
|
BAIL_IF_MACRO(!readAll(io, &entry->name, 13), NULL, 0);
|
|
|
|
pos += 13;
|
|
|
|
BAIL_IF_MACRO(!readAll(io, &size, 4), NULL, 0);
|
|
|
|
pos += 4;
|
|
|
|
|
|
|
|
entry->size = PHYSFS_swapULE32(size);
|
|
|
|
entry->startPos = pos;
|
|
|
|
pos += size;
|
|
|
|
|
|
|
|
BAIL_IF_MACRO(!io->seek(io, pos), NULL, 0); /* skip over entry */
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* for */
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
info->entryCount = entCount;
|
2003-03-30 20:59:54 +02:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
__PHYSFS_sort(info->entries, entCount, hogEntryCmp, hogEntrySwap);
|
2010-01-28 08:27:45 +01:00
|
|
|
return 1;
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* hog_load_entries */
|
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static void *HOG_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
PHYSFS_uint8 buf[3];
|
|
|
|
HOGinfo *info = NULL;
|
2003-03-30 20:59:54 +02:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
assert(io != NULL); /* shouldn't ever happen. */
|
2003-03-30 20:59:54 +02:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0);
|
2003-03-30 20:59:54 +02:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
BAIL_IF_MACRO(!readAll(io, buf, 3), NULL, 0);
|
|
|
|
if (memcmp(buf, "DHF", 3) != 0)
|
|
|
|
GOTO_MACRO(ERR_NOT_AN_ARCHIVE, HOG_openArchive_failed);
|
|
|
|
|
|
|
|
info = (HOGinfo *) allocator.Malloc(sizeof (HOGinfo));
|
|
|
|
GOTO_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, HOG_openArchive_failed);
|
|
|
|
memset(info, '\0', sizeof (HOGinfo));
|
|
|
|
info->io = io;
|
|
|
|
|
|
|
|
GOTO_IF_MACRO(!hog_load_entries(io, info), NULL, HOG_openArchive_failed);
|
2004-09-26 02:25:04 +02:00
|
|
|
|
2010-01-28 08:27:45 +01:00
|
|
|
return info;
|
2003-03-30 20:59:54 +02:00
|
|
|
|
|
|
|
HOG_openArchive_failed:
|
2004-09-26 02:25:04 +02:00
|
|
|
if (info != NULL)
|
2003-03-30 20:59:54 +02: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-03-30 20:59:54 +02:00
|
|
|
} /* if */
|
|
|
|
|
2010-01-28 08:27:45 +01:00
|
|
|
return NULL;
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* HOG_openArchive */
|
|
|
|
|
|
|
|
|
2004-09-29 08:09:29 +02:00
|
|
|
static void HOG_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-03-30 20:59:54 +02:00
|
|
|
{
|
|
|
|
/* no directories in HOG files. */
|
2007-03-28 19:29:52 +02:00
|
|
|
if (*dname == '\0')
|
2004-09-29 08:09:29 +02:00
|
|
|
{
|
|
|
|
HOGinfo *info = (HOGinfo *) opaque;
|
|
|
|
HOGentry *entry = info->entries;
|
|
|
|
PHYSFS_uint32 max = info->entryCount;
|
|
|
|
PHYSFS_uint32 i;
|
2003-03-30 20:59:54 +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 */
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* HOG_enumerateFiles */
|
|
|
|
|
|
|
|
|
2010-02-15 20:02:36 +01:00
|
|
|
static HOGentry *hog_find_entry(const HOGinfo *info, const char *name)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
|
|
|
char *ptr = strchr(name, '.');
|
|
|
|
HOGentry *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)
|
|
|
|
{
|
|
|
|
middle = lo + ((hi - lo) / 2);
|
2007-03-15 09:16:23 +01:00
|
|
|
rc = __PHYSFS_stricmpASCII(name, a[middle].name);
|
2003-03-30 20:59:54 +02:00
|
|
|
if (rc == 0) /* found it! */
|
2010-01-28 08:27:45 +01:00
|
|
|
return &a[middle];
|
2003-03-30 20:59:54 +02:00
|
|
|
else if (rc > 0)
|
|
|
|
lo = middle + 1;
|
|
|
|
else
|
|
|
|
hi = middle - 1;
|
|
|
|
} /* while */
|
|
|
|
|
|
|
|
BAIL_MACRO(ERR_NO_SUCH_FILE, NULL);
|
|
|
|
} /* hog_find_entry */
|
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static PHYSFS_Io *HOG_openRead(dvoid *opaque, const char *fnm, int *fileExists)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
PHYSFS_Io *retval = NULL;
|
|
|
|
HOGinfo *info = (HOGinfo *) opaque;
|
2003-03-30 20:59:54 +02:00
|
|
|
HOGfileinfo *finfo;
|
|
|
|
HOGentry *entry;
|
|
|
|
|
|
|
|
entry = hog_find_entry(info, fnm);
|
|
|
|
*fileExists = (entry != NULL);
|
2010-08-30 09:01:57 +02:00
|
|
|
GOTO_IF_MACRO(entry == NULL, NULL, HOG_openRead_failed);
|
|
|
|
|
|
|
|
retval = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io));
|
|
|
|
GOTO_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, HOG_openRead_failed);
|
2003-03-30 20:59:54 +02:00
|
|
|
|
2005-03-14 12:49:30 +01:00
|
|
|
finfo = (HOGfileinfo *) allocator.Malloc(sizeof (HOGfileinfo));
|
2010-08-30 09:01:57 +02:00
|
|
|
GOTO_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, HOG_openRead_failed);
|
|
|
|
|
|
|
|
finfo->io = info->io->duplicate(info->io);
|
|
|
|
GOTO_IF_MACRO(finfo->io == NULL, NULL, HOG_openRead_failed);
|
2003-03-30 20:59:54 +02:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
if (!finfo->io->seek(finfo->io, entry->startPos))
|
|
|
|
GOTO_MACRO(NULL, HOG_openRead_failed);
|
|
|
|
|
|
|
|
finfo->curPos = 0;
|
|
|
|
finfo->entry = entry;
|
|
|
|
|
|
|
|
memcpy(retval, &HOG_Io, sizeof (*retval));
|
|
|
|
retval->opaque = finfo;
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
HOG_openRead_failed:
|
|
|
|
if (finfo != NULL)
|
2003-03-30 20:59:54 +02: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-03-30 20:59:54 +02:00
|
|
|
} /* if */
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
if (retval != NULL)
|
|
|
|
allocator.Free(retval);
|
|
|
|
|
|
|
|
return NULL;
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* HOG_openRead */
|
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static PHYSFS_Io *HOG_openWrite(dvoid *opaque, const char *name)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
|
|
|
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
|
|
|
|
} /* HOG_openWrite */
|
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static PHYSFS_Io *HOG_openAppend(dvoid *opaque, const char *name)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
|
|
|
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
|
|
|
|
} /* HOG_openAppend */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static int HOG_remove(dvoid *opaque, const char *name)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
|
|
|
BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
|
|
|
|
} /* HOG_remove */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static int HOG_mkdir(dvoid *opaque, const char *name)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
|
|
|
BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
|
|
|
|
} /* HOG_mkdir */
|
|
|
|
|
2004-09-29 08:18:04 +02:00
|
|
|
|
2010-08-22 06:37:25 +02:00
|
|
|
static int HOG_stat(dvoid *opaque, const char *filename, int *exists,
|
2010-02-15 20:02:36 +01:00
|
|
|
PHYSFS_Stat *stat)
|
|
|
|
{
|
|
|
|
const HOGinfo *info = (const HOGinfo *) opaque;
|
|
|
|
const HOGentry *entry = hog_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
|
|
|
} /* HOG_stat */
|
|
|
|
|
|
|
|
|
2004-09-29 08:18:04 +02:00
|
|
|
const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_HOG =
|
|
|
|
{
|
|
|
|
"HOG",
|
|
|
|
HOG_ARCHIVE_DESCRIPTION,
|
|
|
|
"Bradley Bell <btb@icculus.org>",
|
|
|
|
"http://icculus.org/physfs/",
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const PHYSFS_Archiver __PHYSFS_Archiver_HOG =
|
|
|
|
{
|
|
|
|
&__PHYSFS_ArchiveInfo_HOG,
|
|
|
|
HOG_openArchive, /* openArchive() method */
|
|
|
|
HOG_enumerateFiles, /* enumerateFiles() method */
|
|
|
|
HOG_openRead, /* openRead() method */
|
|
|
|
HOG_openWrite, /* openWrite() method */
|
|
|
|
HOG_openAppend, /* openAppend() method */
|
|
|
|
HOG_remove, /* remove() method */
|
|
|
|
HOG_mkdir, /* mkdir() method */
|
|
|
|
HOG_dirClose, /* dirClose() method */
|
2010-08-30 09:01:57 +02:00
|
|
|
HOG_stat /* stat() method */
|
2004-09-29 08:18:04 +02:00
|
|
|
};
|
|
|
|
|
2003-03-30 20:59:54 +02:00
|
|
|
#endif /* defined PHYSFS_SUPPORTS_HOG */
|
|
|
|
|
|
|
|
/* end of hog.c ... */
|
|
|
|
|