author | Ryan C. Gordon <icculus@icculus.org> |
Thu, 08 Jan 2004 05:53:28 +0000 | |
changeset 625 | 60b5f566a258 |
parent 622 | c8e67ca63ad6 |
child 648 | 5c993684b8f2 |
child 698 | 227bdc7957ca |
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 |
* |
|
39 |
* Please see the file LICENSE in the source's root directory. |
|
40 |
* |
|
41 |
* This file written by Travis Wells, based on the GRP archiver by |
|
42 |
* Ryan C. Gordon. |
|
43 |
*/ |
|
44 |
||
45 |
#if HAVE_CONFIG_H |
|
46 |
# include <config.h> |
|
47 |
#endif |
|
48 |
||
49 |
#if (defined PHYSFS_SUPPORTS_WAD) |
|
50 |
||
51 |
#include <stdio.h> |
|
52 |
#include <stdlib.h> |
|
53 |
#include <string.h> |
|
54 |
#include "physfs.h" |
|
55 |
||
56 |
#define __PHYSICSFS_INTERNAL__ |
|
57 |
#include "physfs_internal.h" |
|
58 |
||
59 |
typedef struct |
|
60 |
{ |
|
610 | 61 |
char name[18]; |
609 | 62 |
PHYSFS_uint32 startPos; |
63 |
PHYSFS_uint32 size; |
|
64 |
} WADentry; |
|
65 |
||
66 |
typedef struct |
|
67 |
{ |
|
68 |
char *filename; |
|
69 |
PHYSFS_sint64 last_mod_time; |
|
70 |
PHYSFS_uint32 entryCount; |
|
71 |
PHYSFS_uint32 entryOffset; |
|
72 |
WADentry *entries; |
|
73 |
} WADinfo; |
|
74 |
||
75 |
typedef struct |
|
76 |
{ |
|
77 |
void *handle; |
|
78 |
WADentry *entry; |
|
79 |
PHYSFS_uint32 curPos; |
|
80 |
} WADfileinfo; |
|
81 |
||
82 |
||
83 |
static void WAD_dirClose(DirHandle *h); |
|
84 |
static PHYSFS_sint64 WAD_read(FileHandle *handle, void *buffer, |
|
85 |
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount); |
|
86 |
static PHYSFS_sint64 WAD_write(FileHandle *handle, const void *buffer, |
|
87 |
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount); |
|
88 |
static int WAD_eof(FileHandle *handle); |
|
89 |
static PHYSFS_sint64 WAD_tell(FileHandle *handle); |
|
90 |
static int WAD_seek(FileHandle *handle, PHYSFS_uint64 offset); |
|
91 |
static PHYSFS_sint64 WAD_fileLength(FileHandle *handle); |
|
92 |
static int WAD_fileClose(FileHandle *handle); |
|
93 |
static int WAD_isArchive(const char *filename, int forWriting); |
|
94 |
static DirHandle *WAD_openArchive(const char *name, int forWriting); |
|
95 |
static LinkedStringList *WAD_enumerateFiles(DirHandle *h, |
|
96 |
const char *dirname, |
|
97 |
int omitSymLinks); |
|
98 |
static int WAD_exists(DirHandle *h, const char *name); |
|
99 |
static int WAD_isDirectory(DirHandle *h, const char *name, int *fileExists); |
|
100 |
static int WAD_isSymLink(DirHandle *h, const char *name, int *fileExists); |
|
101 |
static PHYSFS_sint64 WAD_getLastModTime(DirHandle *h, const char *n, int *e); |
|
102 |
static FileHandle *WAD_openRead(DirHandle *h, const char *name, int *exist); |
|
103 |
static FileHandle *WAD_openWrite(DirHandle *h, const char *name); |
|
104 |
static FileHandle *WAD_openAppend(DirHandle *h, const char *name); |
|
105 |
static int WAD_remove(DirHandle *h, const char *name); |
|
106 |
static int WAD_mkdir(DirHandle *h, const char *name); |
|
107 |
||
108 |
const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_WAD = |
|
109 |
{ |
|
110 |
"WAD", |
|
111 |
/* !!! FIXME WAD_ARCHIVE_DESCRIPTION, */ "DOOM engine format", |
|
112 |
"Travis Wells <traviswells@mchsi.com>", |
|
113 |
"http://www.3dmm2.com/doom/", |
|
114 |
}; |
|
115 |
||
116 |
||
117 |
static const FileFunctions __PHYSFS_FileFunctions_WAD = |
|
118 |
{ |
|
119 |
WAD_read, /* read() method */ |
|
120 |
WAD_write, /* write() method */ |
|
121 |
WAD_eof, /* eof() method */ |
|
122 |
WAD_tell, /* tell() method */ |
|
123 |
WAD_seek, /* seek() method */ |
|
124 |
WAD_fileLength, /* fileLength() method */ |
|
125 |
WAD_fileClose /* fileClose() method */ |
|
126 |
}; |
|
127 |
||
128 |
||
129 |
const DirFunctions __PHYSFS_DirFunctions_WAD = |
|
130 |
{ |
|
131 |
&__PHYSFS_ArchiveInfo_WAD, |
|
132 |
WAD_isArchive, /* isArchive() method */ |
|
133 |
WAD_openArchive, /* openArchive() method */ |
|
134 |
WAD_enumerateFiles, /* enumerateFiles() method */ |
|
135 |
WAD_exists, /* exists() method */ |
|
136 |
WAD_isDirectory, /* isDirectory() method */ |
|
137 |
WAD_isSymLink, /* isSymLink() method */ |
|
138 |
WAD_getLastModTime, /* getLastModTime() method */ |
|
139 |
WAD_openRead, /* openRead() method */ |
|
140 |
WAD_openWrite, /* openWrite() method */ |
|
141 |
WAD_openAppend, /* openAppend() method */ |
|
142 |
WAD_remove, /* remove() method */ |
|
143 |
WAD_mkdir, /* mkdir() method */ |
|
144 |
WAD_dirClose /* dirClose() method */ |
|
145 |
}; |
|
146 |
||
147 |
||
148 |
||
149 |
static void WAD_dirClose(DirHandle *h) |
|
150 |
{ |
|
151 |
WADinfo *info = ((WADinfo *) h->opaque); |
|
152 |
free(info->filename); |
|
153 |
free(info->entries); |
|
154 |
free(info); |
|
155 |
free(h); |
|
156 |
} /* WAD_dirClose */ |
|
157 |
||
158 |
||
159 |
static PHYSFS_sint64 WAD_read(FileHandle *handle, void *buffer, |
|
160 |
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount) |
|
161 |
{ |
|
162 |
WADfileinfo *finfo = (WADfileinfo *) (handle->opaque); |
|
163 |
WADentry *entry = finfo->entry; |
|
164 |
PHYSFS_uint32 bytesLeft = entry->size - finfo->curPos; |
|
165 |
PHYSFS_uint32 objsLeft = (bytesLeft / objSize); |
|
166 |
PHYSFS_sint64 rc; |
|
167 |
||
168 |
if (objsLeft < objCount) |
|
169 |
objCount = objsLeft; |
|
170 |
||
171 |
rc = __PHYSFS_platformRead(finfo->handle, buffer, objSize, objCount); |
|
172 |
if (rc > 0) |
|
173 |
finfo->curPos += (PHYSFS_uint32) (rc * objSize); |
|
174 |
||
175 |
return(rc); |
|
176 |
} /* WAD_read */ |
|
177 |
||
178 |
||
179 |
static PHYSFS_sint64 WAD_write(FileHandle *handle, const void *buffer, |
|
180 |
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount) |
|
181 |
{ |
|
182 |
BAIL_MACRO(ERR_NOT_SUPPORTED, -1); |
|
183 |
} /* WAD_write */ |
|
184 |
||
185 |
||
186 |
static int WAD_eof(FileHandle *handle) |
|
187 |
{ |
|
188 |
WADfileinfo *finfo = (WADfileinfo *) (handle->opaque); |
|
189 |
WADentry *entry = finfo->entry; |
|
190 |
return(finfo->curPos >= entry->size); |
|
191 |
} /* WAD_eof */ |
|
192 |
||
193 |
||
194 |
static PHYSFS_sint64 WAD_tell(FileHandle *handle) |
|
195 |
{ |
|
196 |
return(((WADfileinfo *) (handle->opaque))->curPos); |
|
197 |
} /* WAD_tell */ |
|
198 |
||
199 |
||
200 |
static int WAD_seek(FileHandle *handle, PHYSFS_uint64 offset) |
|
201 |
{ |
|
202 |
WADfileinfo *finfo = (WADfileinfo *) (handle->opaque); |
|
203 |
WADentry *entry = finfo->entry; |
|
204 |
int rc; |
|
205 |
||
206 |
BAIL_IF_MACRO(offset < 0, ERR_INVALID_ARGUMENT, 0); |
|
207 |
BAIL_IF_MACRO(offset >= entry->size, ERR_PAST_EOF, 0); |
|
208 |
rc = __PHYSFS_platformSeek(finfo->handle, entry->startPos + offset); |
|
209 |
if (rc) |
|
210 |
finfo->curPos = (PHYSFS_uint32) offset; |
|
211 |
||
212 |
return(rc); |
|
213 |
} /* WAD_seek */ |
|
214 |
||
215 |
||
216 |
static PHYSFS_sint64 WAD_fileLength(FileHandle *handle) |
|
217 |
{ |
|
218 |
WADfileinfo *finfo = ((WADfileinfo *) handle->opaque); |
|
219 |
return((PHYSFS_sint64) finfo->entry->size); |
|
220 |
} /* WAD_fileLength */ |
|
221 |
||
222 |
||
223 |
static int WAD_fileClose(FileHandle *handle) |
|
224 |
{ |
|
225 |
WADfileinfo *finfo = ((WADfileinfo *) handle->opaque); |
|
226 |
BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0); |
|
227 |
free(finfo); |
|
228 |
free(handle); |
|
229 |
return(1); |
|
230 |
} /* WAD_fileClose */ |
|
231 |
||
232 |
||
233 |
static int wad_open(const char *filename, int forWriting, |
|
234 |
void **fh, PHYSFS_uint32 *count,PHYSFS_uint32 *offset) |
|
235 |
{ |
|
236 |
PHYSFS_uint8 buf[4]; |
|
237 |
||
238 |
*fh = NULL; |
|
239 |
BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0); |
|
240 |
||
241 |
*fh = __PHYSFS_platformOpenRead(filename); |
|
242 |
BAIL_IF_MACRO(*fh == NULL, NULL, 0); |
|
243 |
||
244 |
if (__PHYSFS_platformRead(*fh, buf, 4, 1) != 1) |
|
245 |
goto openWad_failed; |
|
246 |
||
247 |
if (memcmp(buf, "IWAD", 4) != 0 && memcmp(buf, "PWAD", 4) != 0) |
|
248 |
{ |
|
249 |
__PHYSFS_setError(ERR_UNSUPPORTED_ARCHIVE); |
|
250 |
goto openWad_failed; |
|
251 |
} /* if */ |
|
252 |
||
253 |
if (__PHYSFS_platformRead(*fh, count, sizeof (PHYSFS_uint32), 1) != 1) |
|
254 |
goto openWad_failed; |
|
255 |
||
256 |
*count = PHYSFS_swapULE32(*count); |
|
257 |
||
258 |
if (__PHYSFS_platformRead(*fh, offset, sizeof (PHYSFS_uint32), 1) != 1) |
|
259 |
goto openWad_failed; |
|
260 |
||
261 |
*offset = PHYSFS_swapULE32(*offset); |
|
262 |
||
263 |
return(1); |
|
264 |
||
265 |
openWad_failed: |
|
266 |
if (*fh != NULL) |
|
267 |
__PHYSFS_platformClose(*fh); |
|
268 |
||
269 |
*count = -1; |
|
270 |
*fh = NULL; |
|
271 |
return(0); |
|
272 |
} /* wad_open */ |
|
273 |
||
274 |
||
275 |
static int WAD_isArchive(const char *filename, int forWriting) |
|
276 |
{ |
|
277 |
void *fh; |
|
278 |
PHYSFS_uint32 fileCount,offset; |
|
279 |
int retval = wad_open(filename, forWriting, &fh, &fileCount,&offset); |
|
280 |
||
281 |
if (fh != NULL) |
|
282 |
__PHYSFS_platformClose(fh); |
|
283 |
||
284 |
return(retval); |
|
285 |
} /* WAD_isArchive */ |
|
286 |
||
287 |
||
288 |
static int wad_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) |
|
289 |
{ |
|
290 |
WADentry *a = (WADentry *) _a; |
|
291 |
return(strcmp(a[one].name, a[two].name)); |
|
292 |
} /* wad_entry_cmp */ |
|
293 |
||
294 |
||
295 |
static void wad_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) |
|
296 |
{ |
|
297 |
WADentry tmp; |
|
298 |
WADentry *first = &(((WADentry *) _a)[one]); |
|
299 |
WADentry *second = &(((WADentry *) _a)[two]); |
|
300 |
memcpy(&tmp, first, sizeof (WADentry)); |
|
301 |
memcpy(first, second, sizeof (WADentry)); |
|
302 |
memcpy(second, &tmp, sizeof (WADentry)); |
|
303 |
} /* wad_entry_swap */ |
|
304 |
||
305 |
||
306 |
static int wad_load_entries(const char *name, int forWriting, WADinfo *info) |
|
307 |
{ |
|
308 |
void *fh = NULL; |
|
309 |
PHYSFS_uint32 fileCount; |
|
310 |
PHYSFS_uint32 directoryOffset; |
|
311 |
WADentry *entry; |
|
622
c8e67ca63ad6
Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents:
610
diff
changeset
|
312 |
char lastDirectory[9]; |
610 | 313 |
|
314 |
lastDirectory[8] = 0; /* Make sure lastDirectory stays null-terminated. */ |
|
609 | 315 |
|
316 |
BAIL_IF_MACRO(!wad_open(name, forWriting, &fh, &fileCount,&directoryOffset), NULL, 0); |
|
317 |
info->entryCount = fileCount; |
|
318 |
info->entries = (WADentry *) malloc(sizeof (WADentry) * fileCount); |
|
319 |
if (info->entries == NULL) |
|
320 |
{ |
|
321 |
__PHYSFS_platformClose(fh); |
|
322 |
BAIL_MACRO(ERR_OUT_OF_MEMORY, 0); |
|
323 |
} /* if */ |
|
324 |
||
325 |
__PHYSFS_platformSeek(fh,directoryOffset); |
|
326 |
||
327 |
for (entry = info->entries; fileCount > 0; fileCount--, entry++) |
|
328 |
{ |
|
329 |
if (__PHYSFS_platformRead(fh, &entry->startPos, 4, 1) != 1) |
|
330 |
{ |
|
331 |
__PHYSFS_platformClose(fh); |
|
332 |
return(0); |
|
333 |
} /* if */ |
|
334 |
||
335 |
if (__PHYSFS_platformRead(fh, &entry->size, 4, 1) != 1) |
|
336 |
{ |
|
337 |
__PHYSFS_platformClose(fh); |
|
338 |
return(0); |
|
339 |
} /* if */ |
|
340 |
||
341 |
if (__PHYSFS_platformRead(fh, &entry->name, 8, 1) != 1) |
|
342 |
{ |
|
343 |
__PHYSFS_platformClose(fh); |
|
344 |
return(0); |
|
345 |
} /* if */ |
|
346 |
||
347 |
entry->name[8] = '\0'; /* name might not be null-terminated in file. */ |
|
348 |
entry->size = PHYSFS_swapULE32(entry->size); |
|
349 |
entry->startPos = PHYSFS_swapULE32(entry->startPos); |
|
350 |
} /* for */ |
|
351 |
||
352 |
__PHYSFS_platformClose(fh); |
|
353 |
||
354 |
__PHYSFS_sort(info->entries, info->entryCount, |
|
355 |
wad_entry_cmp, wad_entry_swap); |
|
356 |
return(1); |
|
357 |
} /* wad_load_entries */ |
|
358 |
||
359 |
||
360 |
static DirHandle *WAD_openArchive(const char *name, int forWriting) |
|
361 |
{ |
|
362 |
WADinfo *info; |
|
363 |
DirHandle *retval = malloc(sizeof (DirHandle)); |
|
364 |
PHYSFS_sint64 modtime = __PHYSFS_platformGetLastModTime(name); |
|
365 |
||
366 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
|
367 |
info = retval->opaque = malloc(sizeof (WADinfo)); |
|
368 |
if (info == NULL) |
|
369 |
{ |
|
370 |
__PHYSFS_setError(ERR_OUT_OF_MEMORY); |
|
371 |
goto WAD_openArchive_failed; |
|
372 |
} /* if */ |
|
373 |
||
374 |
memset(info, '\0', sizeof (WADinfo)); |
|
375 |
||
376 |
info->filename = (char *) malloc(strlen(name) + 1); |
|
377 |
if (info->filename == NULL) |
|
378 |
{ |
|
379 |
__PHYSFS_setError(ERR_OUT_OF_MEMORY); |
|
380 |
goto WAD_openArchive_failed; |
|
381 |
} /* if */ |
|
382 |
||
383 |
if (!wad_load_entries(name, forWriting, info)) |
|
384 |
goto WAD_openArchive_failed; |
|
385 |
||
386 |
strcpy(info->filename, name); |
|
387 |
info->last_mod_time = modtime; |
|
388 |
retval->funcs = &__PHYSFS_DirFunctions_WAD; |
|
389 |
return(retval); |
|
390 |
||
391 |
WAD_openArchive_failed: |
|
392 |
if (retval != NULL) |
|
393 |
{ |
|
394 |
if (retval->opaque != NULL) |
|
395 |
{ |
|
396 |
if (info->filename != NULL) |
|
397 |
free(info->filename); |
|
398 |
if (info->entries != NULL) |
|
399 |
free(info->entries); |
|
400 |
free(info); |
|
401 |
} /* if */ |
|
402 |
free(retval); |
|
403 |
} /* if */ |
|
404 |
||
405 |
return(NULL); |
|
406 |
} /* WAD_openArchive */ |
|
407 |
||
408 |
||
409 |
static LinkedStringList *WAD_enumerateFiles(DirHandle *h, |
|
410 |
const char *dirname, |
|
411 |
int omitSymLinks) |
|
412 |
{ |
|
413 |
WADinfo *info = ((WADinfo *) h->opaque); |
|
414 |
WADentry *entry = info->entries; |
|
415 |
LinkedStringList *retval = NULL, *p = NULL; |
|
416 |
PHYSFS_uint32 max = info->entryCount; |
|
417 |
PHYSFS_uint32 i; |
|
610 | 418 |
char *sep; |
609 | 419 |
|
610 | 420 |
if (dirname[0] == 0) |
421 |
{ |
|
422 |
for (i = 0; i < max; i++, entry++) |
|
423 |
{ |
|
424 |
if (strchr(entry->name, '/') == NULL) |
|
425 |
{ |
|
426 |
retval = __PHYSFS_addToLinkedStringList(retval, &p, |
|
427 |
entry->name, -1); |
|
428 |
} /* if */ |
|
429 |
} /* for */ |
|
430 |
} /* if */ |
|
431 |
else |
|
432 |
{ |
|
433 |
for (i = 0; i < max; i++, entry++) |
|
434 |
{ |
|
435 |
sep = strchr(entry->name, '/'); |
|
436 |
if (sep != NULL) |
|
437 |
{ |
|
438 |
if (strncmp(dirname, entry->name, (sep-entry->name)) == 0) |
|
439 |
{ |
|
440 |
retval = __PHYSFS_addToLinkedStringList(retval, &p, |
|
441 |
sep + 1, -1); |
|
442 |
} /* if */ |
|
443 |
} /* if */ |
|
444 |
} /* for */ |
|
445 |
} /* else */ |
|
446 |
||
609 | 447 |
return(retval); |
448 |
} /* WAD_enumerateFiles */ |
|
449 |
||
450 |
||
451 |
static WADentry *wad_find_entry(WADinfo *info, const char *name) |
|
452 |
{ |
|
453 |
WADentry *a = info->entries; |
|
454 |
PHYSFS_sint32 lo = 0; |
|
455 |
PHYSFS_sint32 hi = (PHYSFS_sint32) (info->entryCount - 1); |
|
456 |
PHYSFS_sint32 middle; |
|
457 |
int rc; |
|
458 |
||
459 |
while (lo <= hi) |
|
460 |
{ |
|
461 |
middle = lo + ((hi - lo) / 2); |
|
462 |
rc = strcmp(name, a[middle].name); |
|
463 |
if (rc == 0) /* found it! */ |
|
464 |
return(&a[middle]); |
|
465 |
else if (rc > 0) |
|
466 |
lo = middle + 1; |
|
467 |
else |
|
468 |
hi = middle - 1; |
|
469 |
} /* while */ |
|
470 |
||
471 |
BAIL_MACRO(ERR_NO_SUCH_FILE, NULL); |
|
472 |
} /* wad_find_entry */ |
|
473 |
||
474 |
||
475 |
static int WAD_exists(DirHandle *h, const char *name) |
|
476 |
{ |
|
477 |
return(wad_find_entry(((WADinfo *) h->opaque), name) != NULL); |
|
478 |
} /* WAD_exists */ |
|
479 |
||
480 |
||
481 |
static int WAD_isDirectory(DirHandle *h, const char *name, int *fileExists) |
|
482 |
{ |
|
610 | 483 |
WADentry *entry = wad_find_entry(((WADinfo *) h->opaque), name); |
484 |
if (entry != NULL) |
|
485 |
{ |
|
486 |
char *n; |
|
487 |
||
488 |
*fileExists = 1; |
|
489 |
||
490 |
/* Can't be a directory if it's a subdirectory. */ |
|
491 |
if (strchr(entry->name, '/') != NULL) |
|
492 |
return(0); |
|
493 |
||
494 |
/* Check if it matches "MAP??" or "E?M?" ... */ |
|
495 |
n = entry->name; |
|
496 |
if ((n[0] == 'E' && n[2] == 'M') || |
|
497 |
(n[0] == 'M' && n[1] == 'A' && n[2] == 'P' && n[6] == 0)) |
|
498 |
{ |
|
499 |
return(1); |
|
500 |
} /* if */ |
|
501 |
return(0); |
|
502 |
} /* if */ |
|
503 |
else |
|
504 |
{ |
|
505 |
*fileExists = 0; |
|
506 |
return(0); |
|
507 |
} /* else */ |
|
609 | 508 |
} /* WAD_isDirectory */ |
509 |
||
510 |
||
511 |
static int WAD_isSymLink(DirHandle *h, const char *name, int *fileExists) |
|
512 |
{ |
|
513 |
*fileExists = WAD_exists(h, name); |
|
514 |
return(0); /* never symlinks in a wad. */ |
|
515 |
} /* WAD_isSymLink */ |
|
516 |
||
517 |
||
518 |
static PHYSFS_sint64 WAD_getLastModTime(DirHandle *h, |
|
519 |
const char *name, |
|
520 |
int *fileExists) |
|
521 |
{ |
|
522 |
WADinfo *info = ((WADinfo *) h->opaque); |
|
523 |
PHYSFS_sint64 retval = -1; |
|
524 |
||
525 |
*fileExists = (wad_find_entry(info, name) != NULL); |
|
526 |
if (*fileExists) /* use time of WAD itself in the physical filesystem. */ |
|
527 |
retval = ((WADinfo *) h->opaque)->last_mod_time; |
|
528 |
||
529 |
return(retval); |
|
530 |
} /* WAD_getLastModTime */ |
|
531 |
||
532 |
||
533 |
static FileHandle *WAD_openRead(DirHandle *h, const char *fnm, int *fileExists) |
|
534 |
{ |
|
535 |
WADinfo *info = ((WADinfo *) h->opaque); |
|
536 |
FileHandle *retval; |
|
537 |
WADfileinfo *finfo; |
|
538 |
WADentry *entry; |
|
539 |
||
540 |
entry = wad_find_entry(info, fnm); |
|
541 |
*fileExists = (entry != NULL); |
|
542 |
BAIL_IF_MACRO(entry == NULL, NULL, NULL); |
|
543 |
||
544 |
retval = (FileHandle *) malloc(sizeof (FileHandle)); |
|
545 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
|
546 |
finfo = (WADfileinfo *) malloc(sizeof (WADfileinfo)); |
|
547 |
if (finfo == NULL) |
|
548 |
{ |
|
549 |
free(retval); |
|
550 |
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); |
|
551 |
} /* if */ |
|
552 |
||
553 |
finfo->handle = __PHYSFS_platformOpenRead(info->filename); |
|
554 |
if ( (finfo->handle == NULL) || |
|
555 |
(!__PHYSFS_platformSeek(finfo->handle, entry->startPos)) ) |
|
556 |
{ |
|
557 |
free(finfo); |
|
558 |
free(retval); |
|
559 |
return(NULL); |
|
560 |
} /* if */ |
|
561 |
||
562 |
finfo->curPos = 0; |
|
563 |
finfo->entry = entry; |
|
564 |
retval->opaque = (void *) finfo; |
|
565 |
retval->funcs = &__PHYSFS_FileFunctions_WAD; |
|
566 |
retval->dirHandle = h; |
|
567 |
return(retval); |
|
568 |
} /* WAD_openRead */ |
|
569 |
||
570 |
||
571 |
static FileHandle *WAD_openWrite(DirHandle *h, const char *name) |
|
572 |
{ |
|
573 |
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL); |
|
574 |
} /* WAD_openWrite */ |
|
575 |
||
576 |
||
577 |
static FileHandle *WAD_openAppend(DirHandle *h, const char *name) |
|
578 |
{ |
|
579 |
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL); |
|
580 |
} /* WAD_openAppend */ |
|
581 |
||
582 |
||
583 |
static int WAD_remove(DirHandle *h, const char *name) |
|
584 |
{ |
|
585 |
BAIL_MACRO(ERR_NOT_SUPPORTED, 0); |
|
586 |
} /* WAD_remove */ |
|
587 |
||
588 |
||
589 |
static int WAD_mkdir(DirHandle *h, const char *name) |
|
590 |
{ |
|
591 |
BAIL_MACRO(ERR_NOT_SUPPORTED, 0); |
|
592 |
} /* WAD_mkdir */ |
|
593 |
||
594 |
#endif /* defined PHYSFS_SUPPORTS_WAD */ |
|
595 |
||
596 |
/* end of wad.c ... */ |
|
597 |