author | Wuzzy <Wuzzy2@mail.ru> |
Sat, 10 Feb 2018 06:07:24 +0100 | |
changeset 12948 | f85a040d0350 |
parent 12213 | bb5522e88ab2 |
permissions | -rw-r--r-- |
7768 | 1 |
/* |
2 |
* GRP support routines for PhysicsFS. |
|
3 |
* |
|
4 |
* This driver handles BUILD engine archives ("groupfiles"). This format |
|
5 |
* (but not this driver) was put together by Ken Silverman. |
|
6 |
* |
|
7 |
* The format is simple enough. In Ken's words: |
|
8 |
* |
|
9 |
* What's the .GRP file format? |
|
10 |
* |
|
11 |
* The ".grp" file format is just a collection of a lot of files stored |
|
12 |
* into 1 big one. I tried to make the format as simple as possible: The |
|
13 |
* first 12 bytes contains my name, "KenSilverman". The next 4 bytes is |
|
14 |
* the number of files that were compacted into the group file. Then for |
|
15 |
* each file, there is a 16 byte structure, where the first 12 bytes are |
|
16 |
* the filename, and the last 4 bytes are the file's size. The rest of |
|
17 |
* the group file is just the raw data packed one after the other in the |
|
18 |
* same order as the list of files. |
|
19 |
* |
|
20 |
* (That info is from http://www.advsys.net/ken/build.htm ...) |
|
21 |
* |
|
22 |
* Please see the file LICENSE.txt in the source's root directory. |
|
23 |
* |
|
24 |
* This file written by Ryan C. Gordon. |
|
25 |
*/ |
|
26 |
||
27 |
#define __PHYSICSFS_INTERNAL__ |
|
28 |
#include "physfs_internal.h" |
|
29 |
||
30 |
#if PHYSFS_SUPPORTS_GRP |
|
31 |
||
32 |
static UNPKentry *grpLoadEntries(PHYSFS_Io *io, PHYSFS_uint32 fileCount) |
|
33 |
{ |
|
34 |
PHYSFS_uint32 location = 16; /* sizeof sig. */ |
|
35 |
UNPKentry *entries = NULL; |
|
36 |
UNPKentry *entry = NULL; |
|
37 |
char *ptr = NULL; |
|
38 |
||
39 |
entries = (UNPKentry *) allocator.Malloc(sizeof (UNPKentry) * fileCount); |
|
40 |
BAIL_IF_MACRO(entries == NULL, PHYSFS_ERR_OUT_OF_MEMORY, NULL); |
|
41 |
||
42 |
location += (16 * fileCount); |
|
43 |
||
44 |
for (entry = entries; fileCount > 0; fileCount--, entry++) |
|
45 |
{ |
|
46 |
GOTO_IF_MACRO(!__PHYSFS_readAll(io, &entry->name, 12), ERRPASS, failed); |
|
47 |
GOTO_IF_MACRO(!__PHYSFS_readAll(io, &entry->size, 4), ERRPASS, failed); |
|
48 |
entry->name[12] = '\0'; /* name isn't null-terminated in file. */ |
|
49 |
if ((ptr = strchr(entry->name, ' ')) != NULL) |
|
50 |
*ptr = '\0'; /* trim extra spaces. */ |
|
51 |
||
52 |
entry->size = PHYSFS_swapULE32(entry->size); |
|
53 |
entry->startPos = location; |
|
54 |
location += entry->size; |
|
55 |
} /* for */ |
|
56 |
||
57 |
return entries; |
|
58 |
||
59 |
failed: |
|
60 |
allocator.Free(entries); |
|
61 |
return NULL; |
|
62 |
} /* grpLoadEntries */ |
|
63 |
||
64 |
||
65 |
static void *GRP_openArchive(PHYSFS_Io *io, const char *name, int forWriting) |
|
66 |
{ |
|
67 |
PHYSFS_uint8 buf[12]; |
|
68 |
PHYSFS_uint32 count = 0; |
|
69 |
UNPKentry *entries = NULL; |
|
70 |
||
71 |
assert(io != NULL); /* shouldn't ever happen. */ |
|
72 |
||
73 |
BAIL_IF_MACRO(forWriting, PHYSFS_ERR_READ_ONLY, NULL); |
|
74 |
||
75 |
BAIL_IF_MACRO(!__PHYSFS_readAll(io, buf, sizeof (buf)), ERRPASS, NULL); |
|
76 |
if (memcmp(buf, "KenSilverman", sizeof (buf)) != 0) |
|
77 |
BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, NULL); |
|
78 |
||
79 |
BAIL_IF_MACRO(!__PHYSFS_readAll(io, &count, sizeof(count)), ERRPASS, NULL); |
|
80 |
count = PHYSFS_swapULE32(count); |
|
81 |
||
82 |
entries = grpLoadEntries(io, count); |
|
83 |
BAIL_IF_MACRO(!entries, ERRPASS, NULL); |
|
84 |
return UNPK_openArchive(io, entries, count); |
|
85 |
} /* GRP_openArchive */ |
|
86 |
||
87 |
||
88 |
const PHYSFS_Archiver __PHYSFS_Archiver_GRP = |
|
89 |
{ |
|
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
90 |
CURRENT_PHYSFS_ARCHIVER_API_VERSION, |
7768 | 91 |
{ |
92 |
"GRP", |
|
93 |
"Build engine Groupfile format", |
|
94 |
"Ryan C. Gordon <icculus@icculus.org>", |
|
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
95 |
"https://icculus.org/physfs/", |
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
96 |
0, /* supportsSymlinks */ |
7768 | 97 |
}, |
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
98 |
GRP_openArchive, |
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
99 |
UNPK_enumerateFiles, |
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
100 |
UNPK_openRead, |
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
101 |
UNPK_openWrite, |
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
102 |
UNPK_openAppend, |
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
103 |
UNPK_remove, |
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
104 |
UNPK_mkdir, |
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
105 |
UNPK_stat, |
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
106 |
UNPK_closeArchive |
7768 | 107 |
}; |
108 |
||
109 |
#endif /* defined PHYSFS_SUPPORTS_GRP */ |
|
110 |
||
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
111 |
/* end of archiver_grp.c ... */ |
7768 | 112 |