Skip to content

Latest commit

 

History

History
110 lines (92 loc) · 2.78 KB

physfs_archiver_mvl.c

File metadata and controls

110 lines (92 loc) · 2.78 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
Jul 16, 2017
Jul 16, 2017
35
static int mvlLoadEntries(PHYSFS_Io *io, const PHYSFS_uint32 count, void *arc)
Aug 30, 2010
Aug 30, 2010
36
{
Jul 22, 2017
Jul 22, 2017
37
PHYSFS_uint32 pos = 8 + (17 * count); /* past sig+metadata. */
Jul 16, 2017
Jul 16, 2017
38
PHYSFS_uint32 i;
Jul 16, 2017
Jul 16, 2017
40
for (i = 0; i < count; i++)
Jul 16, 2017
Jul 16, 2017
42
43
44
45
46
47
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);
Jul 22, 2017
Jul 22, 2017
48
49
BAIL_IF_ERRPASS(!UNPK_addEntry(arc, name, 0, -1, -1, pos, size), 0);
pos += size;
Jul 16, 2017
Jul 16, 2017
52
return 1;
Sep 6, 2010
Sep 6, 2010
53
} /* mvlLoadEntries */
Aug 14, 2017
Aug 14, 2017
56
57
static void *MVL_openArchive(PHYSFS_Io *io, const char *name,
int forWriting, int *claimed)
Aug 30, 2010
Aug 30, 2010
59
PHYSFS_uint8 buf[4];
Mar 9, 2012
Mar 9, 2012
60
PHYSFS_uint32 count = 0;
Jul 16, 2017
Jul 16, 2017
61
void *unpkarc;
Aug 30, 2010
Aug 30, 2010
63
assert(io != NULL); /* shouldn't ever happen. */
Jul 6, 2017
Jul 6, 2017
64
65
66
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);
Aug 14, 2017
Aug 14, 2017
68
69
70
*claimed = 1;
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &count, sizeof(count)), NULL);
Mar 9, 2012
Mar 9, 2012
71
count = PHYSFS_swapULE32(count);
Jul 16, 2017
Jul 16, 2017
72
Jul 21, 2017
Jul 21, 2017
73
unpkarc = UNPK_openArchive(io);
Jul 16, 2017
Jul 16, 2017
74
75
76
77
BAIL_IF_ERRPASS(!unpkarc, NULL);
if (!mvlLoadEntries(io, count, unpkarc))
{
Jul 21, 2017
Jul 21, 2017
78
UNPK_abandonArchive(unpkarc);
Jul 16, 2017
Jul 16, 2017
79
80
81
82
return NULL;
} /* if */
return unpkarc;
83
84
85
} /* MVL_openArchive */
Sep 29, 2004
Sep 29, 2004
86
87
const PHYSFS_Archiver __PHYSFS_Archiver_MVL =
{
Nov 28, 2012
Nov 28, 2012
88
CURRENT_PHYSFS_ARCHIVER_API_VERSION,
Mar 25, 2012
Mar 25, 2012
89
90
91
92
{
"MVL",
"Descent II Movielib format",
"Bradley Bell <btb@icculus.org>",
Feb 25, 2016
Feb 25, 2016
93
"https://icculus.org/physfs/",
Nov 30, 2012
Nov 30, 2012
94
0, /* supportsSymlinks */
Mar 25, 2012
Mar 25, 2012
95
},
Nov 30, 2012
Nov 30, 2012
96
MVL_openArchive,
Aug 12, 2017
Aug 12, 2017
97
UNPK_enumerate,
Nov 30, 2012
Nov 30, 2012
98
99
100
101
102
UNPK_openRead,
UNPK_openWrite,
UNPK_openAppend,
UNPK_remove,
UNPK_mkdir,
Nov 30, 2012
Nov 30, 2012
103
104
UNPK_stat,
UNPK_closeArchive
Sep 29, 2004
Sep 29, 2004
105
106
};
107
108
#endif /* defined PHYSFS_SUPPORTS_MVL */
Jul 22, 2017
Jul 22, 2017
109
/* end of physfs_archiver_mvl.c ... */