author | Ryan C. Gordon <icculus@icculus.org> |
Sun, 05 Sep 2010 02:41:13 -0400 | |
changeset 1125 | bcff76dbd9fd |
parent 1118 | 2e09fc635fdd |
child 1128 | 067d8e76261e |
permissions | -rw-r--r-- |
609 | 1 |
/* |
2 |
* WAD support routines for PhysicsFS. |
|
3 |
* |
|
4 |
* This driver handles DOOM engine archives ("wads"). |
|
5 |
* This format (but not this driver) was designed by id Software for use |
|
6 |
* with the DOOM engine. |
|
7 |
* The specs of the format are from the unofficial doom specs v1.666 |
|
8 |
* found here: http://www.gamers.org/dhs/helpdocs/dmsp1666.html |
|
9 |
* The format of the archive: (from the specs) |
|
10 |
* |
|
11 |
* A WAD file has three parts: |
|
12 |
* (1) a twelve-byte header |
|
13 |
* (2) one or more "lumps" |
|
14 |
* (3) a directory or "info table" that contains the names, offsets, and |
|
15 |
* sizes of all the lumps in the WAD |
|
16 |
* |
|
17 |
* The header consists of three four-byte parts: |
|
18 |
* (a) an ASCII string which must be either "IWAD" or "PWAD" |
|
19 |
* (b) a 4-byte (long) integer which is the number of lumps in the wad |
|
20 |
* (c) a long integer which is the file offset to the start of |
|
21 |
* the directory |
|
22 |
* |
|
23 |
* The directory has one 16-byte entry for every lump. Each entry consists |
|
24 |
* of three parts: |
|
25 |
* |
|
26 |
* (a) a long integer, the file offset to the start of the lump |
|
27 |
* (b) a long integer, the size of the lump in bytes |
|
28 |
* (c) an 8-byte ASCII string, the name of the lump, padded with zeros. |
|
29 |
* For example, the "DEMO1" entry in hexadecimal would be |
|
30 |
* (44 45 4D 4F 31 00 00 00) |
|
31 |
* |
|
32 |
* Note that there is no way to tell if an opened WAD archive is a |
|
33 |
* IWAD or PWAD with this archiver. |
|
34 |
* I couldn't think of a way to provide that information, without being too |
|
35 |
* hacky. |
|
36 |
* I don't think it's really that important though. |
|
37 |
* |
|
38 |
* |
|
809
116b8fe30371
Renamed LICENSE to LICENSE.txt
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
39 |
* Please see the file LICENSE.txt in the source's root directory. |
609 | 40 |
* |
41 |
* This file written by Travis Wells, based on the GRP archiver by |
|
42 |
* Ryan C. Gordon. |
|
43 |
*/ |
|
44 |
||
45 |
#if (defined PHYSFS_SUPPORTS_WAD) |
|
46 |
||
47 |
#include <stdio.h> |
|
48 |
#include <stdlib.h> |
|
49 |
#include <string.h> |
|
50 |
#include "physfs.h" |
|
51 |
||
52 |
#define __PHYSICSFS_INTERNAL__ |
|
53 |
#include "physfs_internal.h" |
|
54 |
||
55 |
typedef struct |
|
56 |
{ |
|
610 | 57 |
char name[18]; |
609 | 58 |
PHYSFS_uint32 startPos; |
59 |
PHYSFS_uint32 size; |
|
60 |
} WADentry; |
|
61 |
||
62 |
typedef struct |
|
63 |
{ |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
64 |
PHYSFS_Io *io; |
609 | 65 |
PHYSFS_uint32 entryCount; |
66 |
WADentry *entries; |
|
67 |
} WADinfo; |
|
68 |
||
69 |
typedef struct |
|
70 |
{ |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
71 |
PHYSFS_Io *io; |
609 | 72 |
WADentry *entry; |
73 |
PHYSFS_uint32 curPos; |
|
74 |
} WADfileinfo; |
|
75 |
||
76 |
||
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
77 |
static inline int readAll(PHYSFS_Io *io, void *buf, const PHYSFS_uint64 len) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
78 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
79 |
return (io->read(io, buf, len) == len); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
80 |
} /* readAll */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
81 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
82 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
83 |
static void WAD_dirClose(dvoid *opaque) |
609 | 84 |
{ |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
622
diff
changeset
|
85 |
WADinfo *info = ((WADinfo *) opaque); |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
86 |
info->io->destroy(info->io); |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
678
diff
changeset
|
87 |
allocator.Free(info->entries); |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
678
diff
changeset
|
88 |
allocator.Free(info); |
609 | 89 |
} /* WAD_dirClose */ |
90 |
||
91 |
||
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
92 |
static PHYSFS_sint64 WAD_read(PHYSFS_Io *io, void *buffer, PHYSFS_uint64 len) |
609 | 93 |
{ |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
94 |
WADfileinfo *finfo = (WADfileinfo *) io->opaque; |
1098
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
95 |
const WADentry *entry = finfo->entry; |
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
96 |
const PHYSFS_uint64 bytesLeft = (PHYSFS_uint64)(entry->size-finfo->curPos); |
609 | 97 |
PHYSFS_sint64 rc; |
98 |
||
1098
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
99 |
if (bytesLeft < len) |
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
100 |
len = bytesLeft; |
609 | 101 |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
102 |
rc = finfo->io->read(finfo->io, buffer, len); |
609 | 103 |
if (rc > 0) |
1098
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
104 |
finfo->curPos += (PHYSFS_uint32) rc; |
609 | 105 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
972
diff
changeset
|
106 |
return rc; |
609 | 107 |
} /* WAD_read */ |
108 |
||
109 |
||
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
110 |
static PHYSFS_sint64 WAD_write(PHYSFS_Io *io, const void *b, PHYSFS_uint64 len) |
609 | 111 |
{ |
112 |
BAIL_MACRO(ERR_NOT_SUPPORTED, -1); |
|
113 |
} /* WAD_write */ |
|
114 |
||
115 |
||
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
116 |
static PHYSFS_sint64 WAD_tell(PHYSFS_Io *io) |
609 | 117 |
{ |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
118 |
return ((WADfileinfo *) io->opaque)->curPos; |
609 | 119 |
} /* WAD_tell */ |
120 |
||
121 |
||
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
122 |
static int WAD_seek(PHYSFS_Io *io, PHYSFS_uint64 offset) |
609 | 123 |
{ |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
124 |
WADfileinfo *finfo = (WADfileinfo *) io->opaque; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
125 |
const WADentry *entry = finfo->entry; |
609 | 126 |
int rc; |
127 |
||
128 |
BAIL_IF_MACRO(offset >= entry->size, ERR_PAST_EOF, 0); |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
129 |
rc = finfo->io->seek(finfo->io, entry->startPos + offset); |
609 | 130 |
if (rc) |
131 |
finfo->curPos = (PHYSFS_uint32) offset; |
|
132 |
||
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
972
diff
changeset
|
133 |
return rc; |
609 | 134 |
} /* WAD_seek */ |
135 |
||
136 |
||
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
137 |
static PHYSFS_sint64 WAD_length(PHYSFS_Io *io) |
609 | 138 |
{ |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
139 |
const WADfileinfo *finfo = (WADfileinfo *) io->opaque; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
140 |
return ((PHYSFS_sint64) finfo->entry->size); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
141 |
} /* WAD_length */ |
1098
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
142 |
|
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
143 |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
144 |
static PHYSFS_Io *WAD_duplicate(PHYSFS_Io *_io) |
609 | 145 |
{ |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
146 |
WADfileinfo *origfinfo = (WADfileinfo *) _io->opaque; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
147 |
PHYSFS_Io *io = NULL; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
148 |
PHYSFS_Io *retval = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io)); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
149 |
WADfileinfo *finfo = (WADfileinfo *) allocator.Malloc(sizeof (WADfileinfo)); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
150 |
GOTO_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, WAD_duplicate_failed); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
151 |
GOTO_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, WAD_duplicate_failed); |
609 | 152 |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
153 |
io = origfinfo->io->duplicate(origfinfo->io); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
154 |
GOTO_IF_MACRO(io == NULL, NULL, WAD_duplicate_failed); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
155 |
finfo->io = io; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
156 |
finfo->entry = origfinfo->entry; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
157 |
finfo->curPos = 0; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
158 |
memcpy(retval, _io, sizeof (PHYSFS_Io)); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
159 |
retval->opaque = finfo; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
160 |
return retval; |
609 | 161 |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
162 |
WAD_duplicate_failed: |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
163 |
if (finfo != NULL) allocator.Free(finfo); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
164 |
if (retval != NULL) allocator.Free(retval); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
165 |
if (io != NULL) io->destroy(io); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
166 |
return NULL; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
167 |
} /* WAD_duplicate */ |
609 | 168 |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
169 |
static int WAD_flush(PHYSFS_Io *io) { return 1; /* no write support. */ } |
609 | 170 |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
171 |
static void WAD_destroy(PHYSFS_Io *io) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
172 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
173 |
WADfileinfo *finfo = (WADfileinfo *) io->opaque; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
174 |
finfo->io->destroy(finfo->io); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
175 |
allocator.Free(finfo); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
176 |
allocator.Free(io); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
177 |
} /* WAD_destroy */ |
609 | 178 |
|
179 |
||
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
180 |
static const PHYSFS_Io WAD_Io = |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
181 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
182 |
WAD_read, |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
183 |
WAD_write, |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
184 |
WAD_seek, |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
185 |
WAD_tell, |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
186 |
WAD_length, |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
187 |
WAD_duplicate, |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
188 |
WAD_flush, |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
189 |
WAD_destroy, |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
190 |
NULL |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
191 |
}; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
192 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
193 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
194 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
195 |
static int wadEntryCmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) |
609 | 196 |
{ |
928
0e37b8163248
Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
197 |
if (one != two) |
0e37b8163248
Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
198 |
{ |
0e37b8163248
Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
199 |
const WADentry *a = (const WADentry *) _a; |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
200 |
return __PHYSFS_stricmpASCII(a[one].name, a[two].name); |
928
0e37b8163248
Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
201 |
} /* if */ |
0e37b8163248
Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
202 |
|
0e37b8163248
Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
203 |
return 0; |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
204 |
} /* wadEntryCmp */ |
609 | 205 |
|
206 |
||
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
207 |
static void wadEntrySwap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) |
609 | 208 |
{ |
928
0e37b8163248
Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
209 |
if (one != two) |
0e37b8163248
Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
210 |
{ |
0e37b8163248
Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
211 |
WADentry tmp; |
0e37b8163248
Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
212 |
WADentry *first = &(((WADentry *) _a)[one]); |
0e37b8163248
Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
213 |
WADentry *second = &(((WADentry *) _a)[two]); |
0e37b8163248
Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
214 |
memcpy(&tmp, first, sizeof (WADentry)); |
0e37b8163248
Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
215 |
memcpy(first, second, sizeof (WADentry)); |
0e37b8163248
Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
216 |
memcpy(second, &tmp, sizeof (WADentry)); |
0e37b8163248
Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
217 |
} /* if */ |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
218 |
} /* wadEntrySwap */ |
609 | 219 |
|
220 |
||
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
221 |
static int wad_load_entries(PHYSFS_Io *io, WADinfo *info) |
609 | 222 |
{ |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
223 |
PHYSFS_uint32 fileCount = info->entryCount; |
609 | 224 |
PHYSFS_uint32 directoryOffset; |
225 |
WADentry *entry; |
|
610 | 226 |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
227 |
BAIL_IF_MACRO(!readAll(io, &directoryOffset, 4), NULL, 0); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
228 |
directoryOffset = PHYSFS_swapULE32(directoryOffset); |
609 | 229 |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
678
diff
changeset
|
230 |
info->entries = (WADentry *) allocator.Malloc(sizeof(WADentry)*fileCount); |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
231 |
BAIL_IF_MACRO(info->entries == NULL, ERR_OUT_OF_MEMORY, 0); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
232 |
BAIL_IF_MACRO(!io->seek(io, directoryOffset), NULL, 0); |
609 | 233 |
|
234 |
for (entry = info->entries; fileCount > 0; fileCount--, entry++) |
|
235 |
{ |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
236 |
BAIL_IF_MACRO(!readAll(io, &entry->startPos, 4), NULL, 0); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
237 |
BAIL_IF_MACRO(!readAll(io, &entry->size, 4), NULL, 0); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
238 |
BAIL_IF_MACRO(!readAll(io, &entry->name, 8), NULL, 0); |
609 | 239 |
|
240 |
entry->name[8] = '\0'; /* name might not be null-terminated in file. */ |
|
241 |
entry->size = PHYSFS_swapULE32(entry->size); |
|
242 |
entry->startPos = PHYSFS_swapULE32(entry->startPos); |
|
243 |
} /* for */ |
|
244 |
||
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
245 |
__PHYSFS_sort(info->entries, info->entryCount, wadEntryCmp, wadEntrySwap); |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
972
diff
changeset
|
246 |
return 1; |
609 | 247 |
} /* wad_load_entries */ |
248 |
||
249 |
||
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
250 |
static void *WAD_openArchive(PHYSFS_Io *io, const char *name, int forWriting) |
609 | 251 |
{ |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
252 |
PHYSFS_uint8 buf[4]; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
253 |
WADinfo *info = NULL; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
254 |
PHYSFS_uint32 val = 0; |
609 | 255 |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
256 |
assert(io != NULL); /* shouldn't ever happen. */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
257 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
258 |
BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0); |
609 | 259 |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
260 |
BAIL_IF_MACRO(!readAll(io, buf, sizeof (buf)), NULL, NULL); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
261 |
if ((memcmp(buf, "IWAD", 4) != 0) && (memcmp(buf, "PWAD", 4) != 0)) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
262 |
GOTO_MACRO(ERR_NOT_AN_ARCHIVE, WAD_openArchive_failed); |
609 | 263 |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
264 |
info = (WADinfo *) allocator.Malloc(sizeof (WADinfo)); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
265 |
GOTO_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, WAD_openArchive_failed); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
266 |
memset(info, '\0', sizeof (WADinfo)); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
267 |
info->io = io; |
609 | 268 |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
269 |
GOTO_IF_MACRO(!readAll(io,&val,sizeof(val)), NULL, WAD_openArchive_failed); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
270 |
info->entryCount = PHYSFS_swapULE32(val); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
271 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
272 |
GOTO_IF_MACRO(!wad_load_entries(io, info), NULL, WAD_openArchive_failed); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
273 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
972
diff
changeset
|
274 |
return info; |
609 | 275 |
|
276 |
WAD_openArchive_failed: |
|
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
622
diff
changeset
|
277 |
if (info != NULL) |
609 | 278 |
{ |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
622
diff
changeset
|
279 |
if (info->entries != NULL) |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
678
diff
changeset
|
280 |
allocator.Free(info->entries); |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
678
diff
changeset
|
281 |
allocator.Free(info); |
609 | 282 |
} /* if */ |
283 |
||
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
972
diff
changeset
|
284 |
return NULL; |
609 | 285 |
} /* WAD_openArchive */ |
286 |
||
287 |
||
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
650
diff
changeset
|
288 |
static void WAD_enumerateFiles(dvoid *opaque, const char *dname, |
754
e7cd7411eadf
API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents:
694
diff
changeset
|
289 |
int omitSymLinks, PHYSFS_EnumFilesCallback cb, |
e7cd7411eadf
API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents:
694
diff
changeset
|
290 |
const char *origdir, void *callbackdata) |
609 | 291 |
{ |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
292 |
/* no directories in WAD files. */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
293 |
if (*dname == '\0') |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
294 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
295 |
WADinfo *info = (WADinfo *) opaque; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
296 |
WADentry *entry = info->entries; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
297 |
PHYSFS_uint32 max = info->entryCount; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
298 |
PHYSFS_uint32 i; |
609 | 299 |
|
610 | 300 |
for (i = 0; i < max; i++, entry++) |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
301 |
cb(callbackdata, origdir, entry->name); |
610 | 302 |
} /* if */ |
609 | 303 |
} /* WAD_enumerateFiles */ |
304 |
||
305 |
||
1054
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
306 |
static WADentry *wad_find_entry(const WADinfo *info, const char *name) |
609 | 307 |
{ |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
308 |
char *ptr = strchr(name, '.'); |
609 | 309 |
WADentry *a = info->entries; |
310 |
PHYSFS_sint32 lo = 0; |
|
311 |
PHYSFS_sint32 hi = (PHYSFS_sint32) (info->entryCount - 1); |
|
312 |
PHYSFS_sint32 middle; |
|
313 |
int rc; |
|
314 |
||
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
315 |
/* |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
316 |
* Rule out filenames to avoid unneeded processing...no dirs, |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
317 |
* big filenames, or extensions. |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
318 |
*/ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
319 |
BAIL_IF_MACRO(ptr != NULL, ERR_NO_SUCH_FILE, NULL); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
320 |
BAIL_IF_MACRO(strlen(name) > 8, ERR_NO_SUCH_FILE, NULL); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
321 |
BAIL_IF_MACRO(strchr(name, '/') != NULL, ERR_NO_SUCH_FILE, NULL); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
322 |
|
609 | 323 |
while (lo <= hi) |
324 |
{ |
|
325 |
middle = lo + ((hi - lo) / 2); |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
326 |
rc = __PHYSFS_stricmpASCII(name, a[middle].name); |
609 | 327 |
if (rc == 0) /* found it! */ |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
972
diff
changeset
|
328 |
return &a[middle]; |
609 | 329 |
else if (rc > 0) |
330 |
lo = middle + 1; |
|
331 |
else |
|
332 |
hi = middle - 1; |
|
333 |
} /* while */ |
|
334 |
||
335 |
BAIL_MACRO(ERR_NO_SUCH_FILE, NULL); |
|
336 |
} /* wad_find_entry */ |
|
337 |
||
338 |
||
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
339 |
static PHYSFS_Io *WAD_openRead(dvoid *opaque, const char *fnm, int *fileExists) |
609 | 340 |
{ |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
341 |
PHYSFS_Io *retval = NULL; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
342 |
WADinfo *info = (WADinfo *) opaque; |
609 | 343 |
WADfileinfo *finfo; |
344 |
WADentry *entry; |
|
345 |
||
346 |
entry = wad_find_entry(info, fnm); |
|
347 |
*fileExists = (entry != NULL); |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
348 |
GOTO_IF_MACRO(entry == NULL, NULL, WAD_openRead_failed); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
349 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
350 |
retval = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io)); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
351 |
GOTO_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, WAD_openRead_failed); |
609 | 352 |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
678
diff
changeset
|
353 |
finfo = (WADfileinfo *) allocator.Malloc(sizeof (WADfileinfo)); |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
354 |
GOTO_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, WAD_openRead_failed); |
609 | 355 |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
356 |
finfo->io = info->io->duplicate(info->io); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
357 |
GOTO_IF_MACRO(finfo->io == NULL, NULL, WAD_openRead_failed); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
358 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
359 |
if (!finfo->io->seek(finfo->io, entry->startPos)) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
360 |
GOTO_MACRO(NULL, WAD_openRead_failed); |
609 | 361 |
|
362 |
finfo->curPos = 0; |
|
363 |
finfo->entry = entry; |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
364 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
365 |
memcpy(retval, &WAD_Io, sizeof (*retval)); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
366 |
retval->opaque = finfo; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
367 |
return retval; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
368 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
369 |
WAD_openRead_failed: |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
370 |
if (finfo != NULL) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
371 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
372 |
if (finfo->io != NULL) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
373 |
finfo->io->destroy(finfo->io); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
374 |
allocator.Free(finfo); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
375 |
} /* if */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
376 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
377 |
if (retval != NULL) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
378 |
allocator.Free(retval); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
379 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
380 |
return NULL; |
609 | 381 |
} /* WAD_openRead */ |
382 |
||
383 |
||
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
384 |
static PHYSFS_Io *WAD_openWrite(dvoid *opaque, const char *name) |
609 | 385 |
{ |
386 |
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL); |
|
387 |
} /* WAD_openWrite */ |
|
388 |
||
389 |
||
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
390 |
static PHYSFS_Io *WAD_openAppend(dvoid *opaque, const char *name) |
609 | 391 |
{ |
392 |
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL); |
|
393 |
} /* WAD_openAppend */ |
|
394 |
||
395 |
||
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
396 |
static int WAD_remove(dvoid *opaque, const char *name) |
609 | 397 |
{ |
398 |
BAIL_MACRO(ERR_NOT_SUPPORTED, 0); |
|
399 |
} /* WAD_remove */ |
|
400 |
||
401 |
||
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
402 |
static int WAD_mkdir(dvoid *opaque, const char *name) |
609 | 403 |
{ |
404 |
BAIL_MACRO(ERR_NOT_SUPPORTED, 0); |
|
405 |
} /* WAD_mkdir */ |
|
406 |
||
658
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
407 |
|
1108
b63e39d5be04
Fixed details of PHYSFS_Archiver's stat method.
Ryan C. Gordon <icculus@icculus.org>
parents:
1106
diff
changeset
|
408 |
static int WAD_stat(dvoid *opaque, const char *filename, int *exists, |
1054
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
409 |
PHYSFS_Stat *stat) |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
410 |
{ |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
411 |
const WADinfo *info = (const WADinfo *) opaque; |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
412 |
const WADentry *entry = wad_find_entry(info, filename); |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
413 |
|
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
414 |
*exists = (entry != 0); |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
415 |
if (!entry) |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
416 |
return 0; |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
417 |
|
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
418 |
stat->filesize = entry->size; |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
419 |
stat->filetype = PHYSFS_FILETYPE_REGULAR; |
1115
bc7257f4f8da
Removed __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
420 |
stat->modtime = -1; |
bc7257f4f8da
Removed __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
421 |
stat->createtime = -1; |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
422 |
stat->accesstime = -1; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
423 |
stat->readonly = 1; |
1054
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
424 |
|
1106
94c3669d0311
Fixed PHYSFS_stat()'s return value to match rest of PhysicsFS API.
Ryan C. Gordon <icculus@icculus.org>
parents:
1098
diff
changeset
|
425 |
return 1; |
1054
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
426 |
} /* WAD_stat */ |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
427 |
|
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
428 |
|
658
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
429 |
const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_WAD = |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
430 |
{ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
431 |
"WAD", |
694
80bc8858b4ab
Added translation for WAD file type.
Ryan C. Gordon <icculus@icculus.org>
parents:
691
diff
changeset
|
432 |
WAD_ARCHIVE_DESCRIPTION, |
658
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
433 |
"Travis Wells <traviswells@mchsi.com>", |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
434 |
"http://www.3dmm2.com/doom/", |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
435 |
}; |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
436 |
|
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
437 |
|
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
438 |
const PHYSFS_Archiver __PHYSFS_Archiver_WAD = |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
439 |
{ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
440 |
&__PHYSFS_ArchiveInfo_WAD, |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
441 |
WAD_openArchive, /* openArchive() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
442 |
WAD_enumerateFiles, /* enumerateFiles() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
443 |
WAD_openRead, /* openRead() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
444 |
WAD_openWrite, /* openWrite() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
445 |
WAD_openAppend, /* openAppend() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
446 |
WAD_remove, /* remove() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
447 |
WAD_mkdir, /* mkdir() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
448 |
WAD_dirClose, /* dirClose() method */ |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
449 |
WAD_stat /* stat() method */ |
658
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
450 |
}; |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
451 |
|
609 | 452 |
#endif /* defined PHYSFS_SUPPORTS_WAD */ |
453 |
||
454 |
/* end of wad.c ... */ |
|
455 |