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
|
|
|
|
{
|
|
|
|
char *filename;
|
|
|
|
PHYSFS_sint64 last_mod_time;
|
|
|
|
PHYSFS_uint32 entryCount;
|
|
|
|
HOGentry *entries;
|
|
|
|
} HOGinfo;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* One HOGfileinfo is kept for each open file in a HOG archive.
|
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
void *handle;
|
|
|
|
HOGentry *entry;
|
|
|
|
PHYSFS_uint32 curPos;
|
|
|
|
} HOGfileinfo;
|
|
|
|
|
|
|
|
|
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);
|
2005-03-14 12:49:30 +01:00
|
|
|
allocator.Free(info->filename);
|
|
|
|
allocator.Free(info->entries);
|
|
|
|
allocator.Free(info);
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* HOG_dirClose */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static PHYSFS_sint64 HOG_read(fvoid *opaque, void *buffer,
|
2003-03-30 20:59:54 +02:00
|
|
|
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
|
|
|
|
{
|
2004-09-26 15:00:59 +02:00
|
|
|
HOGfileinfo *finfo = (HOGfileinfo *) opaque;
|
2003-03-30 20:59:54 +02:00
|
|
|
HOGentry *entry = finfo->entry;
|
|
|
|
PHYSFS_uint32 bytesLeft = entry->size - finfo->curPos;
|
|
|
|
PHYSFS_uint32 objsLeft = (bytesLeft / objSize);
|
|
|
|
PHYSFS_sint64 rc;
|
|
|
|
|
|
|
|
if (objsLeft < objCount)
|
|
|
|
objCount = objsLeft;
|
|
|
|
|
|
|
|
rc = __PHYSFS_platformRead(finfo->handle, buffer, objSize, objCount);
|
|
|
|
if (rc > 0)
|
|
|
|
finfo->curPos += (PHYSFS_uint32) (rc * objSize);
|
|
|
|
|
|
|
|
return(rc);
|
|
|
|
} /* HOG_read */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static PHYSFS_sint64 HOG_write(fvoid *opaque, const void *buffer,
|
2003-03-30 20:59:54 +02:00
|
|
|
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
|
|
|
|
{
|
|
|
|
BAIL_MACRO(ERR_NOT_SUPPORTED, -1);
|
|
|
|
} /* HOG_write */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static int HOG_eof(fvoid *opaque)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2004-09-26 15:00:59 +02:00
|
|
|
HOGfileinfo *finfo = (HOGfileinfo *) opaque;
|
2003-03-30 20:59:54 +02:00
|
|
|
HOGentry *entry = finfo->entry;
|
|
|
|
return(finfo->curPos >= entry->size);
|
|
|
|
} /* HOG_eof */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static PHYSFS_sint64 HOG_tell(fvoid *opaque)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2004-09-26 15:00:59 +02:00
|
|
|
return(((HOGfileinfo *) opaque)->curPos);
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* HOG_tell */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static int HOG_seek(fvoid *opaque, PHYSFS_uint64 offset)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2004-09-26 15:00:59 +02:00
|
|
|
HOGfileinfo *finfo = (HOGfileinfo *) opaque;
|
2003-03-30 20:59:54 +02:00
|
|
|
HOGentry *entry = finfo->entry;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
BAIL_IF_MACRO(offset < 0, ERR_INVALID_ARGUMENT, 0);
|
|
|
|
BAIL_IF_MACRO(offset >= entry->size, ERR_PAST_EOF, 0);
|
|
|
|
rc = __PHYSFS_platformSeek(finfo->handle, entry->startPos + offset);
|
|
|
|
if (rc)
|
|
|
|
finfo->curPos = (PHYSFS_uint32) offset;
|
|
|
|
|
|
|
|
return(rc);
|
|
|
|
} /* HOG_seek */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static PHYSFS_sint64 HOG_fileLength(fvoid *opaque)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2004-09-26 15:00:59 +02:00
|
|
|
HOGfileinfo *finfo = (HOGfileinfo *) opaque;
|
2003-03-30 20:59:54 +02:00
|
|
|
return((PHYSFS_sint64) finfo->entry->size);
|
|
|
|
} /* HOG_fileLength */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static int HOG_fileClose(fvoid *opaque)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2004-09-26 15:00:59 +02:00
|
|
|
HOGfileinfo *finfo = (HOGfileinfo *) opaque;
|
2003-03-30 20:59:54 +02:00
|
|
|
BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0);
|
2005-03-14 12:49:30 +01:00
|
|
|
allocator.Free(finfo);
|
2003-03-30 20:59:54 +02:00
|
|
|
return(1);
|
|
|
|
} /* HOG_fileClose */
|
|
|
|
|
|
|
|
|
|
|
|
static int hog_open(const char *filename, int forWriting,
|
|
|
|
void **fh, PHYSFS_uint32 *count)
|
|
|
|
{
|
|
|
|
PHYSFS_uint8 buf[13];
|
|
|
|
PHYSFS_uint32 size;
|
|
|
|
PHYSFS_sint64 pos;
|
|
|
|
|
|
|
|
*count = 0;
|
|
|
|
|
|
|
|
*fh = NULL;
|
|
|
|
BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0);
|
|
|
|
|
|
|
|
*fh = __PHYSFS_platformOpenRead(filename);
|
|
|
|
BAIL_IF_MACRO(*fh == NULL, NULL, 0);
|
|
|
|
|
|
|
|
if (__PHYSFS_platformRead(*fh, buf, 3, 1) != 1)
|
|
|
|
goto openHog_failed;
|
|
|
|
|
|
|
|
if (memcmp(buf, "DHF", 3) != 0)
|
|
|
|
{
|
|
|
|
__PHYSFS_setError(ERR_UNSUPPORTED_ARCHIVE);
|
|
|
|
goto openHog_failed;
|
|
|
|
} /* if */
|
|
|
|
|
2003-12-29 09:50:21 +01:00
|
|
|
while (1)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
|
|
|
if (__PHYSFS_platformRead(*fh, buf, 13, 1) != 1)
|
2003-12-29 09:50:21 +01:00
|
|
|
break; /* eof here is ok */
|
2003-03-30 20:59:54 +02:00
|
|
|
|
|
|
|
if (__PHYSFS_platformRead(*fh, &size, 4, 1) != 1)
|
|
|
|
goto openHog_failed;
|
|
|
|
|
|
|
|
size = PHYSFS_swapULE32(size);
|
|
|
|
|
|
|
|
(*count)++;
|
|
|
|
|
2003-12-29 09:50:21 +01:00
|
|
|
/* Skip over entry... */
|
2003-03-30 20:59:54 +02:00
|
|
|
pos = __PHYSFS_platformTell(*fh);
|
|
|
|
if (pos == -1)
|
|
|
|
goto openHog_failed;
|
|
|
|
if (!__PHYSFS_platformSeek(*fh, pos + size))
|
|
|
|
goto openHog_failed;
|
2003-12-29 09:50:21 +01:00
|
|
|
} /* while */
|
2003-03-30 20:59:54 +02:00
|
|
|
|
2003-12-29 09:50:21 +01:00
|
|
|
/* Rewind to start of entries... */
|
2003-03-30 20:59:54 +02:00
|
|
|
if (!__PHYSFS_platformSeek(*fh, 3))
|
|
|
|
goto openHog_failed;
|
|
|
|
|
|
|
|
return(1);
|
|
|
|
|
|
|
|
openHog_failed:
|
|
|
|
if (*fh != NULL)
|
|
|
|
__PHYSFS_platformClose(*fh);
|
|
|
|
|
|
|
|
*count = -1;
|
|
|
|
*fh = NULL;
|
|
|
|
return(0);
|
|
|
|
} /* hog_open */
|
|
|
|
|
|
|
|
|
|
|
|
static int HOG_isArchive(const char *filename, int forWriting)
|
|
|
|
{
|
|
|
|
void *fh;
|
|
|
|
PHYSFS_uint32 fileCount;
|
|
|
|
int retval = hog_open(filename, forWriting, &fh, &fileCount);
|
|
|
|
|
|
|
|
if (fh != NULL)
|
|
|
|
__PHYSFS_platformClose(fh);
|
|
|
|
|
|
|
|
return(retval);
|
|
|
|
} /* HOG_isArchive */
|
|
|
|
|
|
|
|
|
|
|
|
static int hog_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
|
|
|
{
|
2008-02-20 13:24:10 +01:00
|
|
|
if (one != two)
|
|
|
|
{
|
|
|
|
const HOGentry *a = (const HOGentry *) _a;
|
|
|
|
return(__PHYSFS_stricmpASCII(a[one].name, a[two].name));
|
|
|
|
} /* if */
|
|
|
|
|
|
|
|
return 0;
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* hog_entry_cmp */
|
|
|
|
|
|
|
|
|
|
|
|
static void hog_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
|
|
|
{
|
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 */
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* hog_entry_swap */
|
|
|
|
|
|
|
|
|
|
|
|
static int hog_load_entries(const char *name, int forWriting, HOGinfo *info)
|
|
|
|
{
|
|
|
|
void *fh = NULL;
|
|
|
|
PHYSFS_uint32 fileCount;
|
|
|
|
HOGentry *entry;
|
|
|
|
|
|
|
|
BAIL_IF_MACRO(!hog_open(name, forWriting, &fh, &fileCount), NULL, 0);
|
|
|
|
info->entryCount = fileCount;
|
2005-03-14 12:49:30 +01:00
|
|
|
info->entries = (HOGentry *) allocator.Malloc(sizeof(HOGentry)*fileCount);
|
2003-03-30 20:59:54 +02:00
|
|
|
if (info->entries == NULL)
|
|
|
|
{
|
|
|
|
__PHYSFS_platformClose(fh);
|
|
|
|
BAIL_MACRO(ERR_OUT_OF_MEMORY, 0);
|
|
|
|
} /* if */
|
|
|
|
|
|
|
|
for (entry = info->entries; fileCount > 0; fileCount--, entry++)
|
|
|
|
{
|
|
|
|
if (__PHYSFS_platformRead(fh, &entry->name, 13, 1) != 1)
|
|
|
|
{
|
|
|
|
__PHYSFS_platformClose(fh);
|
|
|
|
return(0);
|
|
|
|
} /* if */
|
|
|
|
|
|
|
|
if (__PHYSFS_platformRead(fh, &entry->size, 4, 1) != 1)
|
|
|
|
{
|
|
|
|
__PHYSFS_platformClose(fh);
|
|
|
|
return(0);
|
|
|
|
} /* if */
|
|
|
|
|
|
|
|
entry->size = PHYSFS_swapULE32(entry->size);
|
2003-08-09 17:07:08 +02:00
|
|
|
entry->startPos = (unsigned int) __PHYSFS_platformTell(fh);
|
2003-03-30 20:59:54 +02:00
|
|
|
if (entry->startPos == -1)
|
|
|
|
{
|
|
|
|
__PHYSFS_platformClose(fh);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2003-12-29 09:50:21 +01:00
|
|
|
/* Skip over entry */
|
2003-03-30 20:59:54 +02:00
|
|
|
if (!__PHYSFS_platformSeek(fh, entry->startPos + entry->size))
|
|
|
|
{
|
|
|
|
__PHYSFS_platformClose(fh);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
} /* for */
|
|
|
|
|
|
|
|
__PHYSFS_platformClose(fh);
|
|
|
|
|
|
|
|
__PHYSFS_sort(info->entries, info->entryCount,
|
|
|
|
hog_entry_cmp, hog_entry_swap);
|
|
|
|
return(1);
|
|
|
|
} /* hog_load_entries */
|
|
|
|
|
|
|
|
|
2004-09-26 02:25:04 +02:00
|
|
|
static void *HOG_openArchive(const char *name, int forWriting)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
|
|
|
PHYSFS_sint64 modtime = __PHYSFS_platformGetLastModTime(name);
|
2005-03-14 12:49:30 +01:00
|
|
|
HOGinfo *info = (HOGinfo *) allocator.Malloc(sizeof (HOGinfo));
|
2003-03-30 20:59:54 +02:00
|
|
|
|
2004-09-26 02:25:04 +02:00
|
|
|
BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, 0);
|
2003-03-30 20:59:54 +02:00
|
|
|
memset(info, '\0', sizeof (HOGinfo));
|
2005-03-14 12:49:30 +01:00
|
|
|
info->filename = (char *) allocator.Malloc(strlen(name) + 1);
|
2005-03-13 04:33:11 +01:00
|
|
|
GOTO_IF_MACRO(!info->filename, ERR_OUT_OF_MEMORY, HOG_openArchive_failed);
|
2003-03-30 20:59:54 +02:00
|
|
|
|
|
|
|
if (!hog_load_entries(name, forWriting, info))
|
|
|
|
goto HOG_openArchive_failed;
|
|
|
|
|
|
|
|
strcpy(info->filename, name);
|
|
|
|
info->last_mod_time = modtime;
|
2004-09-26 02:25:04 +02: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->filename != NULL)
|
2005-03-14 12:49:30 +01:00
|
|
|
allocator.Free(info->filename);
|
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 */
|
|
|
|
|
|
|
|
return(NULL);
|
|
|
|
} /* 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 */
|
|
|
|
|
|
|
|
|
|
|
|
static HOGentry *hog_find_entry(HOGinfo *info, const char *name)
|
|
|
|
{
|
|
|
|
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! */
|
|
|
|
return(&a[middle]);
|
|
|
|
else if (rc > 0)
|
|
|
|
lo = middle + 1;
|
|
|
|
else
|
|
|
|
hi = middle - 1;
|
|
|
|
} /* while */
|
|
|
|
|
|
|
|
BAIL_MACRO(ERR_NO_SUCH_FILE, NULL);
|
|
|
|
} /* hog_find_entry */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static int HOG_exists(dvoid *opaque, const char *name)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2004-09-26 02:25:04 +02:00
|
|
|
return(hog_find_entry(((HOGinfo *) opaque), name) != NULL);
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* HOG_exists */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static int HOG_isDirectory(dvoid *opaque, const char *name, int *fileExists)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2004-09-26 02:25:04 +02:00
|
|
|
*fileExists = HOG_exists(opaque, name);
|
2003-03-30 20:59:54 +02:00
|
|
|
return(0); /* never directories in a groupfile. */
|
|
|
|
} /* HOG_isDirectory */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static int HOG_isSymLink(dvoid *opaque, const char *name, int *fileExists)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2004-09-26 02:25:04 +02:00
|
|
|
*fileExists = HOG_exists(opaque, name);
|
2003-03-30 20:59:54 +02:00
|
|
|
return(0); /* never symlinks in a groupfile. */
|
|
|
|
} /* HOG_isSymLink */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static PHYSFS_sint64 HOG_getLastModTime(dvoid *opaque,
|
2003-03-30 20:59:54 +02:00
|
|
|
const char *name,
|
|
|
|
int *fileExists)
|
|
|
|
{
|
2004-09-26 02:25:04 +02:00
|
|
|
HOGinfo *info = ((HOGinfo *) opaque);
|
2003-03-30 20:59:54 +02:00
|
|
|
PHYSFS_sint64 retval = -1;
|
|
|
|
|
|
|
|
*fileExists = (hog_find_entry(info, name) != NULL);
|
|
|
|
if (*fileExists) /* use time of HOG itself in the physical filesystem. */
|
2004-09-26 02:25:04 +02:00
|
|
|
retval = info->last_mod_time;
|
2003-03-30 20:59:54 +02:00
|
|
|
|
|
|
|
return(retval);
|
|
|
|
} /* HOG_getLastModTime */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static fvoid *HOG_openRead(dvoid *opaque, const char *fnm, int *fileExists)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2004-09-26 02:25:04 +02:00
|
|
|
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);
|
|
|
|
BAIL_IF_MACRO(entry == NULL, NULL, NULL);
|
|
|
|
|
2005-03-14 12:49:30 +01:00
|
|
|
finfo = (HOGfileinfo *) allocator.Malloc(sizeof (HOGfileinfo));
|
2004-09-26 15:00:59 +02:00
|
|
|
BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL);
|
2003-03-30 20:59:54 +02:00
|
|
|
|
|
|
|
finfo->handle = __PHYSFS_platformOpenRead(info->filename);
|
|
|
|
if ( (finfo->handle == NULL) ||
|
|
|
|
(!__PHYSFS_platformSeek(finfo->handle, entry->startPos)) )
|
|
|
|
{
|
2005-03-14 12:49:30 +01:00
|
|
|
allocator.Free(finfo);
|
2003-03-30 20:59:54 +02:00
|
|
|
return(NULL);
|
|
|
|
} /* if */
|
|
|
|
|
|
|
|
finfo->curPos = 0;
|
|
|
|
finfo->entry = entry;
|
2004-09-26 15:00:59 +02:00
|
|
|
return(finfo);
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* HOG_openRead */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static fvoid *HOG_openWrite(dvoid *opaque, const char *name)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
|
|
|
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
|
|
|
|
} /* HOG_openWrite */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static fvoid *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
|
|
|
|
|
|
|
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_isArchive, /* isArchive() method */
|
|
|
|
HOG_openArchive, /* openArchive() method */
|
|
|
|
HOG_enumerateFiles, /* enumerateFiles() method */
|
|
|
|
HOG_exists, /* exists() method */
|
|
|
|
HOG_isDirectory, /* isDirectory() method */
|
|
|
|
HOG_isSymLink, /* isSymLink() method */
|
|
|
|
HOG_getLastModTime, /* getLastModTime() 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 */
|
|
|
|
HOG_read, /* read() method */
|
|
|
|
HOG_write, /* write() method */
|
|
|
|
HOG_eof, /* eof() method */
|
|
|
|
HOG_tell, /* tell() method */
|
|
|
|
HOG_seek, /* seek() method */
|
|
|
|
HOG_fileLength, /* fileLength() method */
|
|
|
|
HOG_fileClose /* fileClose() method */
|
|
|
|
};
|
|
|
|
|
2003-03-30 20:59:54 +02:00
|
|
|
#endif /* defined PHYSFS_SUPPORTS_HOG */
|
|
|
|
|
|
|
|
/* end of hog.c ... */
|
|
|
|
|