2003-03-30 20:59:54 +02:00
|
|
|
/*
|
|
|
|
* MVL support routines for PhysicsFS.
|
|
|
|
*
|
|
|
|
* This driver handles Descent II Movielib archives.
|
|
|
|
*
|
|
|
|
* The file format of MVL is quite easy...
|
|
|
|
*
|
|
|
|
* //MVL File format - Written by Heiko Herrmann
|
|
|
|
* char sig[4] = {'D','M', 'V', 'L'}; // "DMVL"=Descent MoVie Library
|
|
|
|
*
|
|
|
|
* int num_files; // the number of files in this MVL
|
|
|
|
*
|
|
|
|
* struct {
|
|
|
|
* char file_name[13]; // Filename, padded to 13 bytes with 0s
|
|
|
|
* int file_size; // filesize in bytes
|
|
|
|
* }DIR_STRUCT[num_files];
|
|
|
|
*
|
|
|
|
* struct {
|
|
|
|
* char data[file_size]; // The file data
|
|
|
|
* }FILE_STRUCT[num_files];
|
|
|
|
*
|
|
|
|
* (That info is from http://www.descent2.com/ddn/specs/mvl/)
|
|
|
|
*
|
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_MVL)
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "physfs.h"
|
|
|
|
|
|
|
|
#define __PHYSICSFS_INTERNAL__
|
|
|
|
#include "physfs_internal.h"
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char name[13];
|
|
|
|
PHYSFS_uint32 startPos;
|
|
|
|
PHYSFS_uint32 size;
|
|
|
|
} MVLentry;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char *filename;
|
|
|
|
PHYSFS_sint64 last_mod_time;
|
|
|
|
PHYSFS_uint32 entryCount;
|
|
|
|
MVLentry *entries;
|
|
|
|
} MVLinfo;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
void *handle;
|
|
|
|
MVLentry *entry;
|
|
|
|
PHYSFS_uint32 curPos;
|
|
|
|
} MVLfileinfo;
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static void MVL_dirClose(dvoid *opaque)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2004-09-26 02:25:04 +02:00
|
|
|
MVLinfo *info = ((MVLinfo *) 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
|
|
|
} /* MVL_dirClose */
|
|
|
|
|
|
|
|
|
2010-08-21 08:47:58 +02:00
|
|
|
static PHYSFS_sint64 MVL_read(fvoid *opaque, void *buffer, PHYSFS_uint64 len)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2004-09-26 15:00:59 +02:00
|
|
|
MVLfileinfo *finfo = (MVLfileinfo *) opaque;
|
2010-08-21 08:47:58 +02:00
|
|
|
const MVLentry *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-21 08:47:58 +02:00
|
|
|
rc = __PHYSFS_platformRead(finfo->handle, 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
|
|
|
} /* MVL_read */
|
|
|
|
|
|
|
|
|
2010-08-21 08:47:58 +02:00
|
|
|
static PHYSFS_sint64 MVL_write(fvoid *f, const void *buf, PHYSFS_uint64 len)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
|
|
|
BAIL_MACRO(ERR_NOT_SUPPORTED, -1);
|
|
|
|
} /* MVL_write */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static int MVL_eof(fvoid *opaque)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2004-09-26 15:00:59 +02:00
|
|
|
MVLfileinfo *finfo = (MVLfileinfo *) opaque;
|
2003-03-30 20:59:54 +02:00
|
|
|
MVLentry *entry = finfo->entry;
|
2010-01-28 08:27:45 +01:00
|
|
|
return (finfo->curPos >= entry->size);
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* MVL_eof */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static PHYSFS_sint64 MVL_tell(fvoid *opaque)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2010-01-28 08:27:45 +01:00
|
|
|
return ((MVLfileinfo *) opaque)->curPos;
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* MVL_tell */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static int MVL_seek(fvoid *opaque, PHYSFS_uint64 offset)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2004-09-26 15:00:59 +02:00
|
|
|
MVLfileinfo *finfo = (MVLfileinfo *) opaque;
|
2003-03-30 20:59:54 +02:00
|
|
|
MVLentry *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;
|
|
|
|
|
2010-01-28 08:27:45 +01:00
|
|
|
return rc;
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* MVL_seek */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static PHYSFS_sint64 MVL_fileLength(fvoid *opaque)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2004-09-26 15:00:59 +02:00
|
|
|
MVLfileinfo *finfo = (MVLfileinfo *) opaque;
|
2010-01-28 08:27:45 +01:00
|
|
|
return ((PHYSFS_sint64) finfo->entry->size);
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* MVL_fileLength */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static int MVL_fileClose(fvoid *opaque)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2004-09-26 15:00:59 +02:00
|
|
|
MVLfileinfo *finfo = (MVLfileinfo *) 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);
|
2010-01-28 08:27:45 +01:00
|
|
|
return 1;
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* MVL_fileClose */
|
|
|
|
|
|
|
|
|
|
|
|
static int mvl_open(const char *filename, int forWriting,
|
|
|
|
void **fh, PHYSFS_uint32 *count)
|
|
|
|
{
|
|
|
|
PHYSFS_uint8 buf[4];
|
|
|
|
|
|
|
|
*fh = NULL;
|
|
|
|
BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0);
|
|
|
|
|
|
|
|
*fh = __PHYSFS_platformOpenRead(filename);
|
|
|
|
BAIL_IF_MACRO(*fh == NULL, NULL, 0);
|
|
|
|
|
2010-08-21 08:47:58 +02:00
|
|
|
if (__PHYSFS_platformRead(*fh, buf, 4) != 4)
|
2003-03-30 20:59:54 +02:00
|
|
|
goto openMvl_failed;
|
|
|
|
|
|
|
|
if (memcmp(buf, "DMVL", 4) != 0)
|
|
|
|
{
|
|
|
|
__PHYSFS_setError(ERR_UNSUPPORTED_ARCHIVE);
|
|
|
|
goto openMvl_failed;
|
|
|
|
} /* if */
|
|
|
|
|
2010-08-21 08:47:58 +02:00
|
|
|
if (__PHYSFS_platformRead(*fh, count, 4) != 4)
|
2003-03-30 20:59:54 +02:00
|
|
|
goto openMvl_failed;
|
|
|
|
|
|
|
|
*count = PHYSFS_swapULE32(*count);
|
|
|
|
|
2010-01-28 08:27:45 +01:00
|
|
|
return 1;
|
2003-03-30 20:59:54 +02:00
|
|
|
|
|
|
|
openMvl_failed:
|
|
|
|
if (*fh != NULL)
|
|
|
|
__PHYSFS_platformClose(*fh);
|
|
|
|
|
|
|
|
*count = -1;
|
|
|
|
*fh = NULL;
|
2010-01-28 08:27:45 +01:00
|
|
|
return 0;
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* mvl_open */
|
|
|
|
|
|
|
|
|
|
|
|
static int MVL_isArchive(const char *filename, int forWriting)
|
|
|
|
{
|
|
|
|
void *fh;
|
|
|
|
PHYSFS_uint32 fileCount;
|
|
|
|
int retval = mvl_open(filename, forWriting, &fh, &fileCount);
|
|
|
|
|
|
|
|
if (fh != NULL)
|
|
|
|
__PHYSFS_platformClose(fh);
|
|
|
|
|
2010-01-28 08:27:45 +01:00
|
|
|
return retval;
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* MVL_isArchive */
|
|
|
|
|
|
|
|
|
|
|
|
static int mvl_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
|
|
|
{
|
2008-02-20 13:24:10 +01:00
|
|
|
if (one != two)
|
|
|
|
{
|
|
|
|
const MVLentry *a = (const MVLentry *) _a;
|
2010-01-28 08:27:45 +01:00
|
|
|
return strcmp(a[one].name, a[two].name);
|
2008-02-20 13:24:10 +01:00
|
|
|
} /* if */
|
|
|
|
|
|
|
|
return 0;
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* mvl_entry_cmp */
|
|
|
|
|
|
|
|
|
|
|
|
static void mvl_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
|
|
|
{
|
2008-02-20 13:24:10 +01:00
|
|
|
if (one != two)
|
|
|
|
{
|
|
|
|
MVLentry tmp;
|
|
|
|
MVLentry *first = &(((MVLentry *) _a)[one]);
|
|
|
|
MVLentry *second = &(((MVLentry *) _a)[two]);
|
|
|
|
memcpy(&tmp, first, sizeof (MVLentry));
|
|
|
|
memcpy(first, second, sizeof (MVLentry));
|
|
|
|
memcpy(second, &tmp, sizeof (MVLentry));
|
|
|
|
} /* if */
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* mvl_entry_swap */
|
|
|
|
|
|
|
|
|
|
|
|
static int mvl_load_entries(const char *name, int forWriting, MVLinfo *info)
|
|
|
|
{
|
|
|
|
void *fh = NULL;
|
|
|
|
PHYSFS_uint32 fileCount;
|
|
|
|
PHYSFS_uint32 location = 8; /* sizeof sig. */
|
|
|
|
MVLentry *entry;
|
|
|
|
|
|
|
|
BAIL_IF_MACRO(!mvl_open(name, forWriting, &fh, &fileCount), NULL, 0);
|
|
|
|
info->entryCount = fileCount;
|
2005-03-14 12:49:30 +01:00
|
|
|
info->entries = (MVLentry *) allocator.Malloc(sizeof(MVLentry)*fileCount);
|
2003-03-30 20:59:54 +02:00
|
|
|
if (info->entries == NULL)
|
|
|
|
{
|
|
|
|
__PHYSFS_platformClose(fh);
|
|
|
|
BAIL_MACRO(ERR_OUT_OF_MEMORY, 0);
|
|
|
|
} /* if */
|
|
|
|
|
|
|
|
location += (17 * fileCount);
|
|
|
|
|
|
|
|
for (entry = info->entries; fileCount > 0; fileCount--, entry++)
|
|
|
|
{
|
2010-08-21 08:47:58 +02:00
|
|
|
if (__PHYSFS_platformRead(fh, &entry->name, 13) != 13)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
|
|
|
__PHYSFS_platformClose(fh);
|
2010-01-28 08:27:45 +01:00
|
|
|
return 0;
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* if */
|
|
|
|
|
2010-08-21 08:47:58 +02:00
|
|
|
if (__PHYSFS_platformRead(fh, &entry->size, 4) != 4)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
|
|
|
__PHYSFS_platformClose(fh);
|
2010-01-28 08:27:45 +01:00
|
|
|
return 0;
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* if */
|
|
|
|
|
|
|
|
entry->size = PHYSFS_swapULE32(entry->size);
|
|
|
|
entry->startPos = location;
|
|
|
|
location += entry->size;
|
|
|
|
} /* for */
|
|
|
|
|
|
|
|
__PHYSFS_platformClose(fh);
|
|
|
|
|
|
|
|
__PHYSFS_sort(info->entries, info->entryCount,
|
|
|
|
mvl_entry_cmp, mvl_entry_swap);
|
2010-01-28 08:27:45 +01:00
|
|
|
return 1;
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* mvl_load_entries */
|
|
|
|
|
|
|
|
|
2004-09-26 02:25:04 +02:00
|
|
|
static void *MVL_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
|
|
|
MVLinfo *info = (MVLinfo *) allocator.Malloc(sizeof (MVLinfo));
|
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, NULL);
|
2003-03-30 20:59:54 +02:00
|
|
|
memset(info, '\0', sizeof (MVLinfo));
|
|
|
|
|
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, MVL_openArchive_failed);
|
2003-03-30 20:59:54 +02:00
|
|
|
if (!mvl_load_entries(name, forWriting, info))
|
|
|
|
goto MVL_openArchive_failed;
|
|
|
|
|
|
|
|
strcpy(info->filename, name);
|
|
|
|
info->last_mod_time = modtime;
|
2010-01-28 08:27:45 +01:00
|
|
|
return info;
|
2003-03-30 20:59:54 +02:00
|
|
|
|
|
|
|
MVL_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 */
|
|
|
|
|
2010-01-28 08:27:45 +01:00
|
|
|
return NULL;
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* MVL_openArchive */
|
|
|
|
|
|
|
|
|
2004-09-29 08:09:29 +02:00
|
|
|
static void MVL_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 MVL files. */
|
2007-03-28 19:29:52 +02:00
|
|
|
if (*dname == '\0')
|
2004-09-29 08:09:29 +02:00
|
|
|
{
|
|
|
|
MVLinfo *info = ((MVLinfo *) opaque);
|
|
|
|
MVLentry *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
|
|
|
} /* MVL_enumerateFiles */
|
|
|
|
|
|
|
|
|
2010-02-15 20:02:36 +01:00
|
|
|
static MVLentry *mvl_find_entry(const MVLinfo *info, const char *name)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
|
|
|
char *ptr = strchr(name, '.');
|
|
|
|
MVLentry *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);
|
|
|
|
} /* mvl_find_entry */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static int MVL_exists(dvoid *opaque, const char *name)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2010-01-28 08:27:45 +01:00
|
|
|
return (mvl_find_entry((MVLinfo *) opaque, name) != NULL);
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* MVL_exists */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static int MVL_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 = MVL_exists(opaque, name);
|
2010-01-28 08:27:45 +01:00
|
|
|
return 0; /* never directories in a groupfile. */
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* MVL_isDirectory */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static int MVL_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 = MVL_exists(opaque, name);
|
2010-01-28 08:27:45 +01:00
|
|
|
return 0; /* never symlinks in a groupfile. */
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* MVL_isSymLink */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static PHYSFS_sint64 MVL_getLastModTime(dvoid *opaque,
|
2003-03-30 20:59:54 +02:00
|
|
|
const char *name,
|
|
|
|
int *fileExists)
|
|
|
|
{
|
2004-09-26 02:25:04 +02:00
|
|
|
MVLinfo *info = ((MVLinfo *) opaque);
|
2003-03-30 20:59:54 +02:00
|
|
|
PHYSFS_sint64 retval = -1;
|
|
|
|
|
|
|
|
*fileExists = (mvl_find_entry(info, name) != NULL);
|
|
|
|
if (*fileExists) /* use time of MVL 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
|
|
|
|
2010-01-28 08:27:45 +01:00
|
|
|
return retval;
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* MVL_getLastModTime */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static fvoid *MVL_openRead(dvoid *opaque, const char *fnm, int *fileExists)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2004-09-26 02:25:04 +02:00
|
|
|
MVLinfo *info = ((MVLinfo *) opaque);
|
2003-03-30 20:59:54 +02:00
|
|
|
MVLfileinfo *finfo;
|
|
|
|
MVLentry *entry;
|
|
|
|
|
|
|
|
entry = mvl_find_entry(info, fnm);
|
|
|
|
*fileExists = (entry != NULL);
|
|
|
|
BAIL_IF_MACRO(entry == NULL, NULL, NULL);
|
|
|
|
|
2005-03-14 12:49:30 +01:00
|
|
|
finfo = (MVLfileinfo *) allocator.Malloc(sizeof (MVLfileinfo));
|
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);
|
2010-01-28 08:27:45 +01:00
|
|
|
return NULL;
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* if */
|
|
|
|
|
|
|
|
finfo->curPos = 0;
|
|
|
|
finfo->entry = entry;
|
2010-01-28 08:27:45 +01:00
|
|
|
return finfo;
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* MVL_openRead */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static fvoid *MVL_openWrite(dvoid *opaque, const char *name)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
|
|
|
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
|
|
|
|
} /* MVL_openWrite */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static fvoid *MVL_openAppend(dvoid *opaque, const char *name)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
|
|
|
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
|
|
|
|
} /* MVL_openAppend */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static int MVL_remove(dvoid *opaque, const char *name)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
|
|
|
BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
|
|
|
|
} /* MVL_remove */
|
|
|
|
|
|
|
|
|
2004-09-26 15:00:59 +02:00
|
|
|
static int MVL_mkdir(dvoid *opaque, const char *name)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
|
|
|
BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
|
|
|
|
} /* MVL_mkdir */
|
|
|
|
|
2004-09-29 08:18:04 +02:00
|
|
|
|
2010-02-15 20:02:36 +01:00
|
|
|
static int MVL_stat(fvoid *opaque, const char *filename, int *exists,
|
|
|
|
PHYSFS_Stat *stat)
|
|
|
|
{
|
|
|
|
const MVLinfo *info = (const MVLinfo *) opaque;
|
|
|
|
const MVLentry *entry = mvl_find_entry(info, filename);
|
|
|
|
|
|
|
|
*exists = (entry != 0);
|
|
|
|
if (!entry)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
stat->filesize = entry->size;
|
|
|
|
stat->filetype = PHYSFS_FILETYPE_REGULAR;
|
|
|
|
stat->modtime = info->last_mod_time;
|
|
|
|
stat->createtime = info->last_mod_time;
|
|
|
|
stat->accesstime = 0;
|
|
|
|
stat->readonly = 1;
|
|
|
|
|
2010-08-22 01:10:42 +02:00
|
|
|
return 1;
|
2010-02-15 20:02:36 +01:00
|
|
|
} /* MVL_stat */
|
|
|
|
|
|
|
|
|
2004-09-29 08:18:04 +02:00
|
|
|
const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_MVL =
|
|
|
|
{
|
|
|
|
"MVL",
|
|
|
|
MVL_ARCHIVE_DESCRIPTION,
|
|
|
|
"Bradley Bell <btb@icculus.org>",
|
|
|
|
"http://icculus.org/physfs/",
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const PHYSFS_Archiver __PHYSFS_Archiver_MVL =
|
|
|
|
{
|
|
|
|
&__PHYSFS_ArchiveInfo_MVL,
|
|
|
|
MVL_isArchive, /* isArchive() method */
|
|
|
|
MVL_openArchive, /* openArchive() method */
|
|
|
|
MVL_enumerateFiles, /* enumerateFiles() method */
|
|
|
|
MVL_exists, /* exists() method */
|
|
|
|
MVL_isDirectory, /* isDirectory() method */
|
|
|
|
MVL_isSymLink, /* isSymLink() method */
|
|
|
|
MVL_getLastModTime, /* getLastModTime() method */
|
|
|
|
MVL_openRead, /* openRead() method */
|
|
|
|
MVL_openWrite, /* openWrite() method */
|
|
|
|
MVL_openAppend, /* openAppend() method */
|
|
|
|
MVL_remove, /* remove() method */
|
|
|
|
MVL_mkdir, /* mkdir() method */
|
|
|
|
MVL_dirClose, /* dirClose() method */
|
|
|
|
MVL_read, /* read() method */
|
|
|
|
MVL_write, /* write() method */
|
|
|
|
MVL_eof, /* eof() method */
|
|
|
|
MVL_tell, /* tell() method */
|
|
|
|
MVL_seek, /* seek() method */
|
|
|
|
MVL_fileLength, /* fileLength() method */
|
2010-02-15 20:02:36 +01:00
|
|
|
MVL_fileClose, /* fileClose() method */
|
|
|
|
MVL_stat /* stat() method */
|
2004-09-29 08:18:04 +02:00
|
|
|
};
|
|
|
|
|
2003-03-30 20:59:54 +02:00
|
|
|
#endif /* defined PHYSFS_SUPPORTS_MVL */
|
|
|
|
|
|
|
|
/* end of mvl.c ... */
|
|
|
|
|