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
|
|
|
|
|
2017-07-16 10:39:14 +02:00
|
|
|
static int mvlLoadEntries(PHYSFS_Io *io, const PHYSFS_uint32 count, void *arc)
|
2010-08-30 09:01:57 +02:00
|
|
|
{
|
2017-07-22 18:47:32 +02:00
|
|
|
PHYSFS_uint32 pos = 8 + (17 * count); /* past sig+metadata. */
|
2017-07-16 10:39:14 +02:00
|
|
|
PHYSFS_uint32 i;
|
2003-03-30 20:59:54 +02:00
|
|
|
|
2017-07-16 10:39:14 +02:00
|
|
|
for (i = 0; i < count; i++)
|
2003-03-30 20:59:54 +02:00
|
|
|
{
|
2017-07-16 10:39:14 +02:00
|
|
|
PHYSFS_uint32 size;
|
|
|
|
char name[13];
|
|
|
|
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, name, 13), 0);
|
|
|
|
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &size, 4), 0);
|
|
|
|
name[12] = '\0'; /* just in case. */
|
|
|
|
size = PHYSFS_swapULE32(size);
|
2017-07-22 18:47:32 +02:00
|
|
|
BAIL_IF_ERRPASS(!UNPK_addEntry(arc, name, 0, -1, -1, pos, size), 0);
|
|
|
|
pos += size;
|
2003-03-30 20:59:54 +02:00
|
|
|
} /* for */
|
|
|
|
|
2017-07-16 10:39:14 +02:00
|
|
|
return 1;
|
2010-09-06 08:50:29 +02:00
|
|
|
} /* 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;
|
2017-07-16 10:39:14 +02:00
|
|
|
void *unpkarc;
|
2003-03-30 20:59:54 +02:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
assert(io != NULL); /* shouldn't ever happen. */
|
2017-07-06 17:51:41 +02:00
|
|
|
BAIL_IF(forWriting, PHYSFS_ERR_READ_ONLY, NULL);
|
|
|
|
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, buf, 4), NULL);
|
|
|
|
BAIL_IF(memcmp(buf, "DMVL", 4) != 0, PHYSFS_ERR_UNSUPPORTED, NULL);
|
|
|
|
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &count, sizeof(count)), NULL);
|
2003-03-30 20:59:54 +02:00
|
|
|
|
2012-03-09 10:50:27 +01:00
|
|
|
count = PHYSFS_swapULE32(count);
|
2017-07-16 10:39:14 +02:00
|
|
|
|
2017-07-21 19:54:42 +02:00
|
|
|
unpkarc = UNPK_openArchive(io);
|
2017-07-16 10:39:14 +02:00
|
|
|
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
|
|
|
|
|
|
|
if (!mvlLoadEntries(io, count, unpkarc))
|
|
|
|
{
|
2017-07-22 01:01:41 +02:00
|
|
|
UNPK_abandonArchive(unpkarc);
|
2017-07-16 10:39:14 +02:00
|
|
|
return NULL;
|
|
|
|
} /* if */
|
|
|
|
|
|
|
|
return unpkarc;
|
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>",
|
2016-02-25 08:51:28 +01:00
|
|
|
"https://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
|
|
|
|