Skip to content

Latest commit

 

History

History
103 lines (86 loc) · 3.08 KB

archiver_mvl.c

File metadata and controls

103 lines (86 loc) · 3.08 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
* 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/)
*
Mar 11, 2007
Mar 11, 2007
24
* Please see the file LICENSE.txt in the source's root directory.
25
26
27
28
29
30
31
32
*
* This file written by Bradley Bell.
* Based on grp.c by Ryan C. Gordon.
*/
#define __PHYSICSFS_INTERNAL__
#include "physfs_internal.h"
Mar 23, 2012
Mar 23, 2012
33
34
#if PHYSFS_SUPPORTS_MVL
Sep 6, 2010
Sep 6, 2010
35
static UNPKentry *mvlLoadEntries(PHYSFS_Io *io, PHYSFS_uint32 fileCount)
Aug 30, 2010
Aug 30, 2010
36
{
37
PHYSFS_uint32 location = 8; /* sizeof sig. */
Sep 6, 2010
Sep 6, 2010
38
39
UNPKentry *entries = NULL;
UNPKentry *entry = NULL;
Sep 6, 2010
Sep 6, 2010
41
entries = (UNPKentry *) allocator.Malloc(sizeof (UNPKentry) * fileCount);
Mar 20, 2012
Mar 20, 2012
42
BAIL_IF_MACRO(entries == NULL, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
43
44
45
location += (17 * fileCount);
Sep 6, 2010
Sep 6, 2010
46
for (entry = entries; fileCount > 0; fileCount--, entry++)
Mar 20, 2012
Mar 20, 2012
48
49
if (!__PHYSFS_readAll(io, &entry->name, 13)) goto failed;
if (!__PHYSFS_readAll(io, &entry->size, 4)) goto failed;
50
51
52
53
54
entry->size = PHYSFS_swapULE32(entry->size);
entry->startPos = location;
location += entry->size;
} /* for */
Sep 6, 2010
Sep 6, 2010
55
56
return entries;
Mar 9, 2012
Mar 9, 2012
57
failed:
Sep 6, 2010
Sep 6, 2010
58
59
60
allocator.Free(entries);
return NULL;
} /* mvlLoadEntries */
Aug 30, 2010
Aug 30, 2010
63
static void *MVL_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
Aug 30, 2010
Aug 30, 2010
65
PHYSFS_uint8 buf[4];
Mar 9, 2012
Mar 9, 2012
66
PHYSFS_uint32 count = 0;
Sep 6, 2010
Sep 6, 2010
67
UNPKentry *entries = NULL;
Aug 30, 2010
Aug 30, 2010
69
assert(io != NULL); /* shouldn't ever happen. */
Mar 20, 2012
Mar 20, 2012
70
71
72
73
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);
Mar 9, 2012
Mar 9, 2012
75
76
count = PHYSFS_swapULE32(count);
entries = mvlLoadEntries(io, count);
Mar 20, 2012
Mar 20, 2012
77
return (!entries) ? NULL : UNPK_openArchive(io, entries, count);
78
79
80
} /* MVL_openArchive */
Sep 29, 2004
Sep 29, 2004
81
82
const PHYSFS_Archiver __PHYSFS_Archiver_MVL =
{
Mar 25, 2012
Mar 25, 2012
83
84
85
86
87
88
{
"MVL",
"Descent II Movielib format",
"Bradley Bell <btb@icculus.org>",
"http://icculus.org/physfs/",
},
Sep 29, 2004
Sep 29, 2004
89
MVL_openArchive, /* openArchive() method */
Sep 6, 2010
Sep 6, 2010
90
91
92
93
94
95
UNPK_enumerateFiles, /* enumerateFiles() method */
UNPK_openRead, /* openRead() method */
UNPK_openWrite, /* openWrite() method */
UNPK_openAppend, /* openAppend() method */
UNPK_remove, /* remove() method */
UNPK_mkdir, /* mkdir() method */
Mar 24, 2012
Mar 24, 2012
96
UNPK_closeArchive, /* closeArchive() method */
Sep 6, 2010
Sep 6, 2010
97
UNPK_stat /* stat() method */
Sep 29, 2004
Sep 29, 2004
98
99
};
100
101
102
#endif /* defined PHYSFS_SUPPORTS_MVL */
/* end of mvl.c ... */