Skip to content

Latest commit

 

History

History
108 lines (89 loc) · 3.18 KB

archiver_mvl.c

File metadata and controls

108 lines (89 loc) · 3.18 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
33
34
*
* This file written by Bradley Bell.
* Based on grp.c by Ryan C. Gordon.
*/
#if (defined PHYSFS_SUPPORTS_MVL)
#define __PHYSICSFS_INTERNAL__
#include "physfs_internal.h"
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
42
entries = (UNPKentry *) allocator.Malloc(sizeof (UNPKentry) * fileCount);
BAIL_IF_MACRO(entries == NULL, 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 9, 2012
Mar 9, 2012
48
49
GOTO_IF_MACRO(!__PHYSFS_readAll(io, &entry->name, 13), NULL, failed);
GOTO_IF_MACRO(!__PHYSFS_readAll(io, &entry->size, 4), NULL, 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
70
assert(io != NULL); /* shouldn't ever happen. */
BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0);
Mar 9, 2012
Mar 9, 2012
71
BAIL_IF_MACRO(!__PHYSFS_readAll(io, buf, 4), NULL, NULL);
Sep 6, 2010
Sep 6, 2010
72
BAIL_IF_MACRO(memcmp(buf, "DMVL", 4) != 0, ERR_NOT_AN_ARCHIVE, NULL);
Mar 9, 2012
Mar 9, 2012
73
BAIL_IF_MACRO(!__PHYSFS_readAll(io, &count, sizeof (count)), NULL, NULL);
Mar 9, 2012
Mar 9, 2012
75
76
count = PHYSFS_swapULE32(count);
entries = mvlLoadEntries(io, count);
Sep 6, 2010
Sep 6, 2010
77
BAIL_IF_MACRO(entries == NULL, NULL, NULL);
Mar 9, 2012
Mar 9, 2012
78
return UNPK_openArchive(io, entries, count);
79
80
81
} /* MVL_openArchive */
Sep 29, 2004
Sep 29, 2004
82
83
84
85
86
87
88
89
90
91
92
93
94
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_openArchive, /* openArchive() method */
Sep 6, 2010
Sep 6, 2010
95
96
97
98
99
100
101
102
UNPK_enumerateFiles, /* enumerateFiles() method */
UNPK_openRead, /* openRead() method */
UNPK_openWrite, /* openWrite() method */
UNPK_openAppend, /* openAppend() method */
UNPK_remove, /* remove() method */
UNPK_mkdir, /* mkdir() method */
UNPK_dirClose, /* dirClose() method */
UNPK_stat /* stat() method */
Sep 29, 2004
Sep 29, 2004
103
104
};
105
106
107
#endif /* defined PHYSFS_SUPPORTS_MVL */
/* end of mvl.c ... */