Skip to content

Latest commit

 

History

History
116 lines (93 loc) · 3.2 KB

physfs_archiver_grp.c

File metadata and controls

116 lines (93 loc) · 3.2 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
* GRP support routines for PhysicsFS.
*
* This driver handles BUILD engine archives ("groupfiles"). This format
* (but not this driver) was put together by Ken Silverman.
*
* The format is simple enough. In Ken's words:
*
* What's the .GRP file format?
*
* The ".grp" file format is just a collection of a lot of files stored
* into 1 big one. I tried to make the format as simple as possible: The
* first 12 bytes contains my name, "KenSilverman". The next 4 bytes is
* the number of files that were compacted into the group file. Then for
* each file, there is a 16 byte structure, where the first 12 bytes are
* the filename, and the last 4 bytes are the file's size. The rest of
* the group file is just the raw data packed one after the other in the
* same order as the list of files.
*
* (That info is from http://www.advsys.net/ken/build.htm ...)
*
Mar 11, 2007
Mar 11, 2007
22
* Please see the file LICENSE.txt in the source's root directory.
23
24
25
26
27
28
29
*
* This file written by Ryan C. Gordon.
*/
#define __PHYSICSFS_INTERNAL__
#include "physfs_internal.h"
Mar 23, 2012
Mar 23, 2012
30
31
#if PHYSFS_SUPPORTS_GRP
Jul 16, 2017
Jul 16, 2017
32
static int grpLoadEntries(PHYSFS_Io *io, const PHYSFS_uint32 count, void *arc)
Jul 22, 2017
Jul 22, 2017
34
PHYSFS_uint32 pos = 16 + (16 * count); /* past sig+metadata. */
Jul 16, 2017
Jul 16, 2017
35
PHYSFS_uint32 i;
Jul 23, 2002
Jul 23, 2002
36
Jul 16, 2017
Jul 16, 2017
37
for (i = 0; i < count; i++)
Jul 23, 2002
Jul 23, 2002
38
{
Jul 16, 2017
Jul 16, 2017
39
40
41
42
43
44
45
46
char *ptr;
char name[13];
PHYSFS_uint32 size;
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, name, 12), 0);
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &size, 4), 0);
name[12] = '\0'; /* name isn't null-terminated in file. */
if ((ptr = strchr(name, ' ')) != NULL)
Jul 23, 2002
Jul 23, 2002
47
48
*ptr = '\0'; /* trim extra spaces. */
Jul 16, 2017
Jul 16, 2017
49
size = PHYSFS_swapULE32(size);
Jul 22, 2017
Jul 22, 2017
50
BAIL_IF_ERRPASS(!UNPK_addEntry(arc, name, 0, -1, -1, pos, size), 0);
Jul 23, 2002
Jul 23, 2002
51
Jul 22, 2017
Jul 22, 2017
52
pos += size;
Jul 16, 2017
Jul 16, 2017
53
} /* for */
Sep 6, 2010
Sep 6, 2010
54
Jul 16, 2017
Jul 16, 2017
55
return 1;
Sep 6, 2010
Sep 6, 2010
56
} /* grpLoadEntries */
Jul 23, 2002
Jul 23, 2002
57
58
Aug 14, 2017
Aug 14, 2017
59
60
static void *GRP_openArchive(PHYSFS_Io *io, const char *name,
int forWriting, int *claimed)
Jul 23, 2002
Jul 23, 2002
61
{
Aug 30, 2010
Aug 30, 2010
62
PHYSFS_uint8 buf[12];
Mar 9, 2012
Mar 9, 2012
63
PHYSFS_uint32 count = 0;
Jul 16, 2017
Jul 16, 2017
64
void *unpkarc = NULL;
Aug 30, 2010
Aug 30, 2010
65
66
assert(io != NULL); /* shouldn't ever happen. */
Jul 6, 2017
Jul 6, 2017
68
BAIL_IF(forWriting, PHYSFS_ERR_READ_ONLY, NULL);
Jul 6, 2017
Jul 6, 2017
70
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, buf, sizeof (buf)), NULL);
Aug 30, 2010
Aug 30, 2010
71
if (memcmp(buf, "KenSilverman", sizeof (buf)) != 0)
Jul 6, 2017
Jul 6, 2017
72
BAIL(PHYSFS_ERR_UNSUPPORTED, NULL);
Mar 25, 2002
Mar 25, 2002
73
Aug 14, 2017
Aug 14, 2017
74
75
*claimed = 1;
Jul 6, 2017
Jul 6, 2017
76
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &count, sizeof(count)), NULL);
Mar 9, 2012
Mar 9, 2012
77
count = PHYSFS_swapULE32(count);
Mar 25, 2002
Mar 25, 2002
78
Jul 21, 2017
Jul 21, 2017
79
unpkarc = UNPK_openArchive(io);
Jul 16, 2017
Jul 16, 2017
80
81
82
83
BAIL_IF_ERRPASS(!unpkarc, NULL);
if (!grpLoadEntries(io, count, unpkarc))
{
Jul 21, 2017
Jul 21, 2017
84
UNPK_abandonArchive(unpkarc);
Jul 16, 2017
Jul 16, 2017
85
86
87
88
return NULL;
} /* if */
return unpkarc;
89
90
91
} /* GRP_openArchive */
Sep 29, 2004
Sep 29, 2004
92
93
const PHYSFS_Archiver __PHYSFS_Archiver_GRP =
{
Nov 28, 2012
Nov 28, 2012
94
CURRENT_PHYSFS_ARCHIVER_API_VERSION,
Mar 25, 2012
Mar 25, 2012
95
96
97
98
{
"GRP",
"Build engine Groupfile format",
"Ryan C. Gordon <icculus@icculus.org>",
Feb 25, 2016
Feb 25, 2016
99
"https://icculus.org/physfs/",
Nov 30, 2012
Nov 30, 2012
100
0, /* supportsSymlinks */
Mar 25, 2012
Mar 25, 2012
101
},
Nov 30, 2012
Nov 30, 2012
102
GRP_openArchive,
Aug 12, 2017
Aug 12, 2017
103
UNPK_enumerate,
Nov 30, 2012
Nov 30, 2012
104
105
106
107
108
UNPK_openRead,
UNPK_openWrite,
UNPK_openAppend,
UNPK_remove,
UNPK_mkdir,
Nov 30, 2012
Nov 30, 2012
109
110
UNPK_stat,
UNPK_closeArchive
Sep 29, 2004
Sep 29, 2004
111
112
};
May 10, 2002
May 10, 2002
113
114
#endif /* defined PHYSFS_SUPPORTS_GRP */
Jul 22, 2017
Jul 22, 2017
115
/* end of physfs_archiver_grp.c ... */