Skip to content

Latest commit

 

History

History
575 lines (457 loc) · 15.3 KB

archiver_qpak.c

File metadata and controls

575 lines (457 loc) · 15.3 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*
* QPAK support routines for PhysicsFS.
*
* This archiver handles the archive format utilized by Quake 1 and 2.
* Quake3-based games use the PkZip/Info-Zip format (which our zip.c
* archiver handles).
*
* ========================================================================
*
* This format info (in more detail) comes from:
* http://debian.fmi.uni-sofia.bg/~sergei/cgsr/docs/pak.txt
*
* Quake PAK Format
*
* Header
* (4 bytes) signature = 'PACK'
* (4 bytes) directory offset
* (4 bytes) directory length
*
* Directory
* (56 bytes) file name
* (4 bytes) file position
* (4 bytes) file length
*
* ========================================================================
*
Mar 11, 2007
Mar 11, 2007
27
* Please see the file LICENSE.txt in the source's root directory.
28
29
30
31
32
33
34
35
36
*
* This file written by Ryan C. Gordon.
*/
#if (defined PHYSFS_SUPPORTS_QPAK)
#define __PHYSICSFS_INTERNAL__
#include "physfs_internal.h"
Aug 30, 2010
Aug 30, 2010
37
/* !!! FIXME: what is this here for? */
Nov 9, 2003
Nov 9, 2003
38
#if 1 /* Make this case insensitive? */
Mar 15, 2007
Mar 15, 2007
39
40
#define QPAK_strcmp(x, y) __PHYSFS_stricmpASCII(x, y)
#define QPAK_strncmp(x, y, z) __PHYSFS_strnicmpASCII(x, y, z)
Nov 9, 2003
Nov 9, 2003
41
42
43
44
45
46
#else
#define QPAK_strcmp(x, y) strcmp(x, y)
#define QPAK_strncmp(x, y, z) strncmp(x, y, z)
#endif
47
48
49
50
51
52
53
54
55
typedef struct
{
char name[56];
PHYSFS_uint32 startPos;
PHYSFS_uint32 size;
} QPAKentry;
typedef struct
{
Aug 30, 2010
Aug 30, 2010
56
PHYSFS_Io *io;
57
58
59
60
61
62
PHYSFS_uint32 entryCount;
QPAKentry *entries;
} QPAKinfo;
typedef struct
{
Aug 30, 2010
Aug 30, 2010
63
PHYSFS_Io *io;
64
65
66
67
68
QPAKentry *entry;
PHYSFS_uint32 curPos;
} QPAKfileinfo;
/* Magic numbers... */
Mar 13, 2005
Mar 13, 2005
69
#define QPAK_SIG 0x4b434150 /* "PACK" in ASCII. */
70
71
Aug 30, 2010
Aug 30, 2010
72
73
74
75
76
77
static inline int readAll(PHYSFS_Io *io, void *buf, const PHYSFS_uint64 len)
{
return (io->read(io, buf, len) == len);
} /* readAll */
Sep 26, 2004
Sep 26, 2004
78
static void QPAK_dirClose(dvoid *opaque)
79
{
Sep 26, 2004
Sep 26, 2004
80
QPAKinfo *info = ((QPAKinfo *) opaque);
Aug 30, 2010
Aug 30, 2010
81
info->io->destroy(info->io);
Mar 14, 2005
Mar 14, 2005
82
83
allocator.Free(info->entries);
allocator.Free(info);
84
85
86
} /* QPAK_dirClose */
Aug 30, 2010
Aug 30, 2010
87
static PHYSFS_sint64 QPAK_read(PHYSFS_Io *io, void *buffer, PHYSFS_uint64 len)
88
{
Aug 30, 2010
Aug 30, 2010
89
QPAKfileinfo *finfo = (QPAKfileinfo *) io->opaque;
Aug 21, 2010
Aug 21, 2010
90
91
const QPAKentry *entry = finfo->entry;
const PHYSFS_uint64 bytesLeft = (PHYSFS_uint64)(entry->size-finfo->curPos);
92
93
PHYSFS_sint64 rc;
Aug 21, 2010
Aug 21, 2010
94
95
if (bytesLeft < len)
len = bytesLeft;
96
Aug 30, 2010
Aug 30, 2010
97
rc = finfo->io->read(finfo->io, buffer, len);
98
if (rc > 0)
Aug 21, 2010
Aug 21, 2010
99
finfo->curPos += (PHYSFS_uint32) rc;
100
Jan 28, 2010
Jan 28, 2010
101
return rc;
102
103
104
} /* QPAK_read */
Aug 30, 2010
Aug 30, 2010
105
static PHYSFS_sint64 QPAK_write(PHYSFS_Io *io, const void *b, PHYSFS_uint64 len)
106
107
108
109
110
{
BAIL_MACRO(ERR_NOT_SUPPORTED, -1);
} /* QPAK_write */
Aug 30, 2010
Aug 30, 2010
111
static PHYSFS_sint64 QPAK_tell(PHYSFS_Io *io)
112
{
Aug 30, 2010
Aug 30, 2010
113
return ((QPAKfileinfo *) io->opaque)->curPos;
114
115
116
} /* QPAK_tell */
Aug 30, 2010
Aug 30, 2010
117
static int QPAK_seek(PHYSFS_Io *io, PHYSFS_uint64 offset)
118
{
Aug 30, 2010
Aug 30, 2010
119
120
QPAKfileinfo *finfo = (QPAKfileinfo *) io->opaque;
const QPAKentry *entry = finfo->entry;
121
122
123
int rc;
BAIL_IF_MACRO(offset >= entry->size, ERR_PAST_EOF, 0);
Aug 30, 2010
Aug 30, 2010
124
rc = finfo->io->seek(finfo->io, entry->startPos + offset);
125
126
127
if (rc)
finfo->curPos = (PHYSFS_uint32) offset;
Jan 28, 2010
Jan 28, 2010
128
return rc;
129
130
131
} /* QPAK_seek */
Aug 30, 2010
Aug 30, 2010
132
static PHYSFS_sint64 QPAK_length(PHYSFS_Io *io)
133
{
Aug 30, 2010
Aug 30, 2010
134
const QPAKfileinfo *finfo = (QPAKfileinfo *) io->opaque;
Jan 28, 2010
Jan 28, 2010
135
return ((PHYSFS_sint64) finfo->entry->size);
Aug 30, 2010
Aug 30, 2010
136
} /* QPAK_length */
137
138
Aug 30, 2010
Aug 30, 2010
139
static PHYSFS_Io *QPAK_duplicate(PHYSFS_Io *_io)
140
{
Aug 30, 2010
Aug 30, 2010
141
142
143
144
145
146
QPAKfileinfo *origfinfo = (QPAKfileinfo *) _io->opaque;
PHYSFS_Io *io = NULL;
PHYSFS_Io *retval = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io));
QPAKfileinfo *finfo = (QPAKfileinfo *) allocator.Malloc(sizeof (QPAKfileinfo));
GOTO_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, QPAK_duplicate_failed);
GOTO_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, QPAK_duplicate_failed);
147
Aug 30, 2010
Aug 30, 2010
148
149
150
151
152
153
154
155
io = origfinfo->io->duplicate(origfinfo->io);
GOTO_IF_MACRO(io == NULL, NULL, QPAK_duplicate_failed);
finfo->io = io;
finfo->entry = origfinfo->entry;
finfo->curPos = 0;
memcpy(retval, _io, sizeof (PHYSFS_Io));
retval->opaque = finfo;
return retval;
156
Aug 30, 2010
Aug 30, 2010
157
158
159
160
161
162
QPAK_duplicate_failed:
if (finfo != NULL) allocator.Free(finfo);
if (retval != NULL) allocator.Free(retval);
if (io != NULL) io->destroy(io);
return NULL;
} /* QPAK_duplicate */
163
Aug 30, 2010
Aug 30, 2010
164
static int QPAK_flush(PHYSFS_Io *io) { return 1; /* no write support. */ }
165
166
Aug 30, 2010
Aug 30, 2010
167
168
169
170
171
172
173
static void QPAK_destroy(PHYSFS_Io *io)
{
QPAKfileinfo *finfo = (QPAKfileinfo *) io->opaque;
finfo->io->destroy(finfo->io);
allocator.Free(finfo);
allocator.Free(io);
} /* QPAK_destroy */
174
175
Aug 30, 2010
Aug 30, 2010
176
177
178
179
180
181
182
183
184
185
186
187
static const PHYSFS_Io QPAK_Io =
{
QPAK_read,
QPAK_write,
QPAK_seek,
QPAK_tell,
QPAK_length,
QPAK_duplicate,
QPAK_flush,
QPAK_destroy,
NULL
};
188
189
190
Aug 30, 2010
Aug 30, 2010
191
static int qpakEntryCmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
192
{
Feb 20, 2008
Feb 20, 2008
193
194
195
if (one != two)
{
const QPAKentry *a = (const QPAKentry *) _a;
Jan 28, 2010
Jan 28, 2010
196
return QPAK_strcmp(a[one].name, a[two].name);
Feb 20, 2008
Feb 20, 2008
197
198
199
} /* if */
return 0;
Aug 30, 2010
Aug 30, 2010
200
} /* qpakEntryCmp */
201
202
Aug 30, 2010
Aug 30, 2010
203
static void qpakEntrySwap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
204
{
Feb 20, 2008
Feb 20, 2008
205
206
207
208
209
210
211
212
213
if (one != two)
{
QPAKentry tmp;
QPAKentry *first = &(((QPAKentry *) _a)[one]);
QPAKentry *second = &(((QPAKentry *) _a)[two]);
memcpy(&tmp, first, sizeof (QPAKentry));
memcpy(first, second, sizeof (QPAKentry));
memcpy(second, &tmp, sizeof (QPAKentry));
} /* if */
Aug 30, 2010
Aug 30, 2010
214
} /* qpakEntrySwap */
215
216
Aug 30, 2010
Aug 30, 2010
217
static int qpak_load_entries(QPAKinfo *info)
218
{
Aug 30, 2010
Aug 30, 2010
219
220
PHYSFS_Io *io = info->io;
PHYSFS_uint32 fileCount = info->entryCount;
221
222
QPAKentry *entry;
Mar 14, 2005
Mar 14, 2005
223
info->entries = (QPAKentry*) allocator.Malloc(sizeof(QPAKentry)*fileCount);
Aug 30, 2010
Aug 30, 2010
224
BAIL_IF_MACRO(info->entries == NULL, ERR_OUT_OF_MEMORY, 0);
225
226
227
for (entry = info->entries; fileCount > 0; fileCount--, entry++)
{
Aug 30, 2010
Aug 30, 2010
228
229
230
BAIL_IF_MACRO(!readAll(io, &entry->name, 56), NULL, 0);
BAIL_IF_MACRO(!readAll(io, &entry->startPos, 4), NULL, 0);
BAIL_IF_MACRO(!readAll(io, &entry->size, 4), NULL, 0);
231
entry->size = PHYSFS_swapULE32(entry->size);
Aug 21, 2010
Aug 21, 2010
232
entry->startPos = PHYSFS_swapULE32(entry->startPos);
233
234
} /* for */
Aug 30, 2010
Aug 30, 2010
235
__PHYSFS_sort(info->entries, info->entryCount, qpakEntryCmp, qpakEntrySwap);
Jan 28, 2010
Jan 28, 2010
236
return 1;
237
238
239
} /* qpak_load_entries */
Aug 30, 2010
Aug 30, 2010
240
static void *QPAK_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
241
{
Aug 30, 2010
Aug 30, 2010
242
243
244
245
QPAKinfo *info = NULL;
PHYSFS_uint32 val = 0;
PHYSFS_uint32 pos = 0;
PHYSFS_uint32 count = 0;
246
Aug 30, 2010
Aug 30, 2010
247
assert(io != NULL); /* shouldn't ever happen. */
248
Aug 30, 2010
Aug 30, 2010
249
BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0);
250
Aug 30, 2010
Aug 30, 2010
251
252
BAIL_IF_MACRO(!readAll(io, &val, 4), NULL, NULL);
BAIL_IF_MACRO(PHYSFS_swapULE32(val) != QPAK_SIG, ERR_NOT_AN_ARCHIVE, NULL);
253
Aug 30, 2010
Aug 30, 2010
254
255
256
257
258
BAIL_IF_MACRO(!readAll(io, &val, 4), NULL, NULL);
pos = PHYSFS_swapULE32(val); /* directory table offset. */
BAIL_IF_MACRO(!readAll(io, &val, 4), NULL, NULL);
count = PHYSFS_swapULE32(val);
259
Aug 30, 2010
Aug 30, 2010
260
261
262
263
/* corrupted archive? */
BAIL_IF_MACRO((count % 64) != 0, ERR_CORRUPTED, NULL);
count /= 64;
Feb 10, 2011
Feb 10, 2011
264
BAIL_IF_MACRO(!io->seek(io, pos), NULL, NULL);
Aug 30, 2010
Aug 30, 2010
265
266
267
268
269
270
271
272
info = (QPAKinfo *) allocator.Malloc(sizeof (QPAKinfo));
BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, NULL);
memset(info, '\0', sizeof (QPAKinfo));
info->io = io;
info->entryCount = count;
if (!qpak_load_entries(info))
273
{
Sep 26, 2004
Sep 26, 2004
274
if (info->entries != NULL)
Mar 14, 2005
Mar 14, 2005
275
276
allocator.Free(info->entries);
allocator.Free(info);
Aug 30, 2010
Aug 30, 2010
277
return NULL;
278
279
} /* if */
Aug 30, 2010
Aug 30, 2010
280
return info;
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
} /* QPAK_openArchive */
static PHYSFS_sint32 qpak_find_start_of_dir(QPAKinfo *info, const char *path,
int stop_on_first_find)
{
PHYSFS_sint32 lo = 0;
PHYSFS_sint32 hi = (PHYSFS_sint32) (info->entryCount - 1);
PHYSFS_sint32 middle;
PHYSFS_uint32 dlen = strlen(path);
PHYSFS_sint32 retval = -1;
const char *name;
int rc;
if (*path == '\0') /* root dir? */
Jan 28, 2010
Jan 28, 2010
296
return 0;
297
298
299
300
301
302
303
304
if ((dlen > 0) && (path[dlen - 1] == '/')) /* ignore trailing slash. */
dlen--;
while (lo <= hi)
{
middle = lo + ((hi - lo) / 2);
name = info->entries[middle].name;
Nov 9, 2003
Nov 9, 2003
305
rc = QPAK_strncmp(path, name, dlen);
306
307
308
309
310
311
312
313
314
315
if (rc == 0)
{
char ch = name[dlen];
if (ch < '/') /* make sure this isn't just a substr match. */
rc = -1;
else if (ch > '/')
rc = 1;
else
{
if (stop_on_first_find) /* Just checking dir's existance? */
Jan 28, 2010
Jan 28, 2010
316
return middle;
317
318
if (name[dlen + 1] == '\0') /* Skip initial dir entry. */
Jan 28, 2010
Jan 28, 2010
319
return (middle + 1);
320
321
322
323
324
325
326
327
328
329
330
331
332
/* there might be more entries earlier in the list. */
retval = middle;
hi = middle - 1;
} /* else */
} /* if */
if (rc > 0)
lo = middle + 1;
else
hi = middle - 1;
} /* while */
Jan 28, 2010
Jan 28, 2010
333
return retval;
334
335
336
} /* qpak_find_start_of_dir */
Sep 29, 2004
Sep 29, 2004
337
338
339
340
/*
* Moved to seperate function so we can use alloca then immediately throw
* away the allocated stack space...
*/
Sep 18, 2005
Sep 18, 2005
341
342
static void doEnumCallback(PHYSFS_EnumFilesCallback cb, void *callbackdata,
const char *odir, const char *str, PHYSFS_sint32 ln)
Sep 29, 2004
Sep 29, 2004
343
{
Mar 24, 2007
Mar 24, 2007
344
char *newstr = __PHYSFS_smallAlloc(ln + 1);
Sep 29, 2004
Sep 29, 2004
345
346
347
348
349
if (newstr == NULL)
return;
memcpy(newstr, str, ln);
newstr[ln] = '\0';
Sep 18, 2005
Sep 18, 2005
350
cb(callbackdata, odir, newstr);
Mar 24, 2007
Mar 24, 2007
351
__PHYSFS_smallFree(newstr);
Sep 29, 2004
Sep 29, 2004
352
353
354
355
} /* doEnumCallback */
static void QPAK_enumerateFiles(dvoid *opaque, const char *dname,
Sep 18, 2005
Sep 18, 2005
356
357
int omitSymLinks, PHYSFS_EnumFilesCallback cb,
const char *origdir, void *callbackdata)
358
{
Sep 26, 2004
Sep 26, 2004
359
QPAKinfo *info = ((QPAKinfo *) opaque);
360
361
PHYSFS_sint32 dlen, dlen_inc, max, i;
Sep 29, 2004
Sep 29, 2004
362
363
364
i = qpak_find_start_of_dir(info, dname, 0);
if (i == -1) /* no such directory. */
return;
365
Sep 29, 2004
Sep 29, 2004
366
367
dlen = strlen(dname);
if ((dlen > 0) && (dname[dlen - 1] == '/')) /* ignore trailing slash. */
368
369
370
371
372
373
374
375
376
377
dlen--;
dlen_inc = ((dlen > 0) ? 1 : 0) + dlen;
max = (PHYSFS_sint32) info->entryCount;
while (i < max)
{
char *add;
char *ptr;
PHYSFS_sint32 ln;
char *e = info->entries[i].name;
Sep 29, 2004
Sep 29, 2004
378
if ((dlen) && ((QPAK_strncmp(e, dname, dlen)) || (e[dlen] != '/')))
379
380
381
382
383
break; /* past end of this dir; we're done. */
add = e + dlen_inc;
ptr = strchr(add, '/');
ln = (PHYSFS_sint32) ((ptr) ? ptr-add : strlen(add));
Sep 18, 2005
Sep 18, 2005
384
doEnumCallback(cb, callbackdata, origdir, add, ln);
385
386
387
388
389
390
ln += dlen_inc; /* point past entry to children... */
/* increment counter and skip children of subdirs... */
while ((++i < max) && (ptr != NULL))
{
char *e_new = info->entries[i].name;
Nov 9, 2003
Nov 9, 2003
391
if ((QPAK_strncmp(e, e_new, ln) != 0) || (e_new[ln] != '/'))
392
393
394
395
396
397
398
399
400
401
402
break;
} /* while */
} /* while */
} /* QPAK_enumerateFiles */
/*
* This will find the QPAKentry associated with a path in platform-independent
* notation. Directories don't have QPAKentries associated with them, but
* (*isDir) will be set to non-zero if a dir was hit.
*/
Feb 15, 2010
Feb 15, 2010
403
404
static QPAKentry *qpak_find_entry(const QPAKinfo *info, const char *path,
int *isDir)
405
406
407
408
409
410
411
412
413
414
415
416
417
{
QPAKentry *a = info->entries;
PHYSFS_sint32 pathlen = strlen(path);
PHYSFS_sint32 lo = 0;
PHYSFS_sint32 hi = (PHYSFS_sint32) (info->entryCount - 1);
PHYSFS_sint32 middle;
const char *thispath = NULL;
int rc;
while (lo <= hi)
{
middle = lo + ((hi - lo) / 2);
thispath = a[middle].name;
Nov 9, 2003
Nov 9, 2003
418
rc = QPAK_strncmp(path, thispath, pathlen);
419
420
421
422
423
424
425
426
427
428
429
430
431
if (rc > 0)
lo = middle + 1;
else if (rc < 0)
hi = middle - 1;
else /* substring match...might be dir or entry or nothing. */
{
if (isDir != NULL)
{
*isDir = (thispath[pathlen] == '/');
if (*isDir)
Jan 28, 2010
Jan 28, 2010
432
return NULL;
433
434
435
} /* if */
if (thispath[pathlen] == '\0') /* found entry? */
Jan 28, 2010
Jan 28, 2010
436
return &a[middle];
437
438
439
440
441
442
443
444
445
446
447
448
else
hi = middle - 1; /* adjust search params, try again. */
} /* if */
} /* while */
if (isDir != NULL)
*isDir = 0;
BAIL_MACRO(ERR_NO_SUCH_FILE, NULL);
} /* qpak_find_entry */
Aug 30, 2010
Aug 30, 2010
449
static PHYSFS_Io *QPAK_openRead(dvoid *opaque, const char *fnm, int *fileExists)
450
{
Aug 30, 2010
Aug 30, 2010
451
PHYSFS_Io *io = NULL;
Sep 26, 2004
Sep 26, 2004
452
QPAKinfo *info = ((QPAKinfo *) opaque);
453
454
455
456
457
458
459
460
461
QPAKfileinfo *finfo;
QPAKentry *entry;
int isDir;
entry = qpak_find_entry(info, fnm, &isDir);
*fileExists = ((entry != NULL) || (isDir));
BAIL_IF_MACRO(isDir, ERR_NOT_A_FILE, NULL);
BAIL_IF_MACRO(entry == NULL, ERR_NO_SUCH_FILE, NULL);
Mar 14, 2005
Mar 14, 2005
462
finfo = (QPAKfileinfo *) allocator.Malloc(sizeof (QPAKfileinfo));
Sep 26, 2004
Sep 26, 2004
463
BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL);
464
Aug 30, 2010
Aug 30, 2010
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
finfo->io = info->io->duplicate(info->io);
GOTO_IF_MACRO(finfo->io == NULL, NULL, QPAK_openRead_failed);
if (!finfo->io->seek(finfo->io, entry->startPos))
GOTO_MACRO(NULL, QPAK_openRead_failed);
finfo->curPos = 0;
finfo->entry = entry;
io = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io));
GOTO_IF_MACRO(io == NULL, ERR_OUT_OF_MEMORY, QPAK_openRead_failed);
memcpy(io, &QPAK_Io, sizeof (PHYSFS_Io));
io->opaque = finfo;
return io;
QPAK_openRead_failed:
if (finfo != NULL)
481
{
Aug 30, 2010
Aug 30, 2010
482
483
if (finfo->io != NULL)
finfo->io->destroy(finfo->io);
Mar 14, 2005
Mar 14, 2005
484
allocator.Free(finfo);
485
486
} /* if */
Aug 30, 2010
Aug 30, 2010
487
488
489
490
if (io != NULL)
allocator.Free(io);
return NULL;
491
492
493
} /* QPAK_openRead */
Aug 30, 2010
Aug 30, 2010
494
static PHYSFS_Io *QPAK_openWrite(dvoid *opaque, const char *name)
495
496
497
498
499
{
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
} /* QPAK_openWrite */
Aug 30, 2010
Aug 30, 2010
500
static PHYSFS_Io *QPAK_openAppend(dvoid *opaque, const char *name)
501
502
503
504
505
{
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
} /* QPAK_openAppend */
Sep 26, 2004
Sep 26, 2004
506
static int QPAK_remove(dvoid *opaque, const char *name)
507
508
509
510
511
{
BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
} /* QPAK_remove */
Sep 26, 2004
Sep 26, 2004
512
static int QPAK_mkdir(dvoid *opaque, const char *name)
513
514
515
516
{
BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
} /* QPAK_mkdir */
Sep 29, 2004
Sep 29, 2004
517
Aug 22, 2010
Aug 22, 2010
518
static int QPAK_stat(dvoid *opaque, const char *filename, int *exists,
Feb 15, 2010
Feb 15, 2010
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
PHYSFS_Stat *stat)
{
int isDir = 0;
const QPAKinfo *info = (const QPAKinfo *) opaque;
const QPAKentry *entry = qpak_find_entry(info, filename, &isDir);
*exists = ((isDir) || (entry != NULL));
if (!exists)
return 0;
if (isDir)
{
stat->filetype = PHYSFS_FILETYPE_DIRECTORY;
stat->filesize = 0;
} /* if */
else
{
stat->filetype = PHYSFS_FILETYPE_REGULAR;
stat->filesize = entry->size;
} /* else */
Aug 25, 2010
Aug 25, 2010
540
541
542
stat->modtime = -1;
stat->createtime = -1;
stat->accesstime = -1;
Feb 15, 2010
Feb 15, 2010
543
544
stat->readonly = 1;
Aug 21, 2010
Aug 21, 2010
545
return 1;
Feb 15, 2010
Feb 15, 2010
546
547
548
} /* QPAK_stat */
Sep 29, 2004
Sep 29, 2004
549
550
551
552
const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_QPAK =
{
"PAK",
QPAK_ARCHIVE_DESCRIPTION,
Jan 1, 2006
Jan 1, 2006
553
"Ryan C. Gordon <icculus@icculus.org>",
Sep 29, 2004
Sep 29, 2004
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
"http://icculus.org/physfs/",
};
const PHYSFS_Archiver __PHYSFS_Archiver_QPAK =
{
&__PHYSFS_ArchiveInfo_QPAK,
QPAK_openArchive, /* openArchive() method */
QPAK_enumerateFiles, /* enumerateFiles() method */
QPAK_openRead, /* openRead() method */
QPAK_openWrite, /* openWrite() method */
QPAK_openAppend, /* openAppend() method */
QPAK_remove, /* remove() method */
QPAK_mkdir, /* mkdir() method */
QPAK_dirClose, /* dirClose() method */
Aug 30, 2010
Aug 30, 2010
569
QPAK_stat /* stat() method */
Sep 29, 2004
Sep 29, 2004
570
571
};
572
573
574
#endif /* defined PHYSFS_SUPPORTS_QPAK */
/* end of qpak.c ... */