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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define __PHYSICSFS_INTERNAL__
|
|
|
|
#include "physfs_internal.h"
|
|
|
|
|
2012-03-23 05:52:32 +01:00
|
|
|
#if PHYSFS_SUPPORTS_MVL
|
|
|
|
|
2010-09-06 08:50:29 +02:00
|
|
|
static UNPKentry *mvlLoadEntries(PHYSFS_Io *io, PHYSFS_uint32 fileCount)
|
2010-08-30 09:01:57 +02:00
|
|
|
{
|
2003-03-30 20:59:54 +02:00
|
|
|
PHYSFS_uint32 location = 8; /* sizeof sig. */
|
2010-09-06 08:50:29 +02:00
|
|
|
UNPKentry *entries = NULL;
|
|
|
|
UNPKentry *entry = NULL;
|
2003-03-30 20:59:54 +02:00
|
|
|
|
2010-09-06 08:50:29 +02:00
|
|
|
entries = (UNPKentry *) allocator.Malloc(sizeof (UNPKentry) * fileCount);
|
2012-03-20 20:38:12 +01:00
|
|
|
BAIL_IF_MACRO(entries == NULL, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
|
2003-03-30 20:59:54 +02:00
|
|
|
|
|
|
|
location += (17 * fileCount);
|
|
|
|
|
2010-09-06 08:50:29 +02:00
|
|
|
for (entry = entries; fileCount > 0; fileCount--, entry++)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2012-03-20 20:38:12 +01:00
|
|
|
if (!__PHYSFS_readAll(io, &entry->name, 13)) goto failed;
|
|
|
|
if (!__PHYSFS_readAll(io, &entry->size, 4)) goto failed;
|
2003-03-30 20:59:54 +02:00
|
|
|
entry->size = PHYSFS_swapULE32(entry->size);
|
|
|
|
entry->startPos = location;
|
|
|
|
location += entry->size;
|
|
|
|
} /* for */
|
|
|
|
|
2010-09-06 08:50:29 +02:00
|
|
|
return entries;
|
|
|
|
|
2012-03-09 10:50:27 +01:00
|
|
|
failed:
|
2010-09-06 08:50:29 +02:00
|
|
|
allocator.Free(entries);
|
|
|
|
return NULL;
|
|
|
|
} /* mvlLoadEntries */
|
2003-03-30 20:59:54 +02:00
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static void *MVL_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[4];
|
2012-03-09 10:50:27 +01:00
|
|
|
PHYSFS_uint32 count = 0;
|
2010-09-06 08:50:29 +02:00
|
|
|
UNPKentry *entries = NULL;
|
2003-03-30 20:59:54 +02:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
assert(io != NULL); /* shouldn't ever happen. */
|
2012-03-20 20:38:12 +01:00
|
|
|
BAIL_IF_MACRO(forWriting, PHYSFS_ERR_READ_ONLY, NULL);
|
|
|
|
BAIL_IF_MACRO(!__PHYSFS_readAll(io, buf, 4), ERRPASS, NULL);
|
|
|
|
BAIL_IF_MACRO(memcmp(buf, "DMVL", 4) != 0, PHYSFS_ERR_UNSUPPORTED, NULL);
|
|
|
|
BAIL_IF_MACRO(!__PHYSFS_readAll(io, &count, sizeof(count)), ERRPASS, NULL);
|
2003-03-30 20:59:54 +02:00
|
|
|
|
2012-03-09 10:50:27 +01:00
|
|
|
count = PHYSFS_swapULE32(count);
|
|
|
|
entries = mvlLoadEntries(io, count);
|
2012-03-20 20:38:12 +01:00
|
|
|
return (!entries) ? NULL : UNPK_openArchive(io, entries, count);
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* MVL_openArchive */
|
|
|
|
|
|
|
|
|
2004-09-29 08:18:04 +02:00
|
|
|
const PHYSFS_Archiver __PHYSFS_Archiver_MVL =
|
|
|
|
{
|
2012-11-28 07:36:13 +01:00
|
|
|
CURRENT_PHYSFS_ARCHIVER_API_VERSION,
|
2012-03-25 23:17:56 +02:00
|
|
|
{
|
|
|
|
"MVL",
|
|
|
|
"Descent II Movielib format",
|
|
|
|
"Bradley Bell <btb@icculus.org>",
|
|
|
|
"http://icculus.org/physfs/",
|
2012-11-30 06:04:52 +01:00
|
|
|
0, /* supportsSymlinks */
|
2012-03-25 23:17:56 +02:00
|
|
|
},
|
2012-11-30 20:06:21 +01:00
|
|
|
MVL_openArchive,
|
|
|
|
UNPK_enumerateFiles,
|
|
|
|
UNPK_openRead,
|
|
|
|
UNPK_openWrite,
|
|
|
|
UNPK_openAppend,
|
|
|
|
UNPK_remove,
|
|
|
|
UNPK_mkdir,
|
2012-11-30 20:09:56 +01:00
|
|
|
UNPK_stat,
|
|
|
|
UNPK_closeArchive
|
2004-09-29 08:18:04 +02:00
|
|
|
};
|
|
|
|
|
2003-03-30 20:59:54 +02:00
|
|
|
#endif /* defined PHYSFS_SUPPORTS_MVL */
|
|
|
|
|
2012-11-27 06:12:39 +01:00
|
|
|
/* end of archiver_mvl.c ... */
|
2003-03-30 20:59:54 +02:00
|
|
|
|