Skip to content

Latest commit

 

History

History
575 lines (460 loc) · 15.5 KB

archiver_qpak.c

File metadata and controls

575 lines (460 loc) · 15.5 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
Sep 26, 2004
Sep 26, 2004
72
static void QPAK_dirClose(dvoid *opaque)
73
{
Sep 26, 2004
Sep 26, 2004
74
QPAKinfo *info = ((QPAKinfo *) opaque);
Aug 30, 2010
Aug 30, 2010
75
info->io->destroy(info->io);
Mar 14, 2005
Mar 14, 2005
76
77
allocator.Free(info->entries);
allocator.Free(info);
78
79
80
} /* QPAK_dirClose */
Aug 30, 2010
Aug 30, 2010
81
static PHYSFS_sint64 QPAK_read(PHYSFS_Io *io, void *buffer, PHYSFS_uint64 len)
82
{
Aug 30, 2010
Aug 30, 2010
83
QPAKfileinfo *finfo = (QPAKfileinfo *) io->opaque;
Aug 21, 2010
Aug 21, 2010
84
85
const QPAKentry *entry = finfo->entry;
const PHYSFS_uint64 bytesLeft = (PHYSFS_uint64)(entry->size-finfo->curPos);
86
87
PHYSFS_sint64 rc;
Aug 21, 2010
Aug 21, 2010
88
89
if (bytesLeft < len)
len = bytesLeft;
90
Aug 30, 2010
Aug 30, 2010
91
rc = finfo->io->read(finfo->io, buffer, len);
92
if (rc > 0)
Aug 21, 2010
Aug 21, 2010
93
finfo->curPos += (PHYSFS_uint32) rc;
94
Jan 28, 2010
Jan 28, 2010
95
return rc;
96
97
98
} /* QPAK_read */
Aug 30, 2010
Aug 30, 2010
99
static PHYSFS_sint64 QPAK_write(PHYSFS_Io *io, const void *b, PHYSFS_uint64 len)
100
101
102
103
104
{
BAIL_MACRO(ERR_NOT_SUPPORTED, -1);
} /* QPAK_write */
Aug 30, 2010
Aug 30, 2010
105
static PHYSFS_sint64 QPAK_tell(PHYSFS_Io *io)
106
{
Aug 30, 2010
Aug 30, 2010
107
return ((QPAKfileinfo *) io->opaque)->curPos;
108
109
110
} /* QPAK_tell */
Aug 30, 2010
Aug 30, 2010
111
static int QPAK_seek(PHYSFS_Io *io, PHYSFS_uint64 offset)
112
{
Aug 30, 2010
Aug 30, 2010
113
114
QPAKfileinfo *finfo = (QPAKfileinfo *) io->opaque;
const QPAKentry *entry = finfo->entry;
115
116
117
int rc;
BAIL_IF_MACRO(offset >= entry->size, ERR_PAST_EOF, 0);
Aug 30, 2010
Aug 30, 2010
118
rc = finfo->io->seek(finfo->io, entry->startPos + offset);
119
120
121
if (rc)
finfo->curPos = (PHYSFS_uint32) offset;
Jan 28, 2010
Jan 28, 2010
122
return rc;
123
124
125
} /* QPAK_seek */
Aug 30, 2010
Aug 30, 2010
126
static PHYSFS_sint64 QPAK_length(PHYSFS_Io *io)
127
{
Aug 30, 2010
Aug 30, 2010
128
const QPAKfileinfo *finfo = (QPAKfileinfo *) io->opaque;
Jan 28, 2010
Jan 28, 2010
129
return ((PHYSFS_sint64) finfo->entry->size);
Aug 30, 2010
Aug 30, 2010
130
} /* QPAK_length */
131
132
Aug 30, 2010
Aug 30, 2010
133
static PHYSFS_Io *QPAK_duplicate(PHYSFS_Io *_io)
134
{
Aug 30, 2010
Aug 30, 2010
135
136
137
138
139
140
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);
141
Aug 30, 2010
Aug 30, 2010
142
143
144
145
146
147
148
149
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;
150
Aug 30, 2010
Aug 30, 2010
151
152
153
154
155
156
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 */
157
Aug 30, 2010
Aug 30, 2010
158
static int QPAK_flush(PHYSFS_Io *io) { return 1; /* no write support. */ }
159
160
Aug 30, 2010
Aug 30, 2010
161
162
163
164
165
166
167
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 */
168
169
Aug 30, 2010
Aug 30, 2010
170
171
172
173
174
175
176
177
178
179
180
181
static const PHYSFS_Io QPAK_Io =
{
QPAK_read,
QPAK_write,
QPAK_seek,
QPAK_tell,
QPAK_length,
QPAK_duplicate,
QPAK_flush,
QPAK_destroy,
NULL
};
182
183
184
Aug 30, 2010
Aug 30, 2010
185
static int qpakEntryCmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
186
{
Feb 20, 2008
Feb 20, 2008
187
188
189
if (one != two)
{
const QPAKentry *a = (const QPAKentry *) _a;
Jan 28, 2010
Jan 28, 2010
190
return QPAK_strcmp(a[one].name, a[two].name);
Feb 20, 2008
Feb 20, 2008
191
192
193
} /* if */
return 0;
Aug 30, 2010
Aug 30, 2010
194
} /* qpakEntryCmp */
195
196
Aug 30, 2010
Aug 30, 2010
197
static void qpakEntrySwap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
198
{
Feb 20, 2008
Feb 20, 2008
199
200
201
202
203
204
205
206
207
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
208
} /* qpakEntrySwap */
209
210
Aug 30, 2010
Aug 30, 2010
211
static int qpak_load_entries(QPAKinfo *info)
212
{
Aug 30, 2010
Aug 30, 2010
213
214
PHYSFS_Io *io = info->io;
PHYSFS_uint32 fileCount = info->entryCount;
215
216
QPAKentry *entry;
Mar 14, 2005
Mar 14, 2005
217
info->entries = (QPAKentry*) allocator.Malloc(sizeof(QPAKentry)*fileCount);
Aug 30, 2010
Aug 30, 2010
218
BAIL_IF_MACRO(info->entries == NULL, ERR_OUT_OF_MEMORY, 0);
219
220
221
for (entry = info->entries; fileCount > 0; fileCount--, entry++)
{
Mar 9, 2012
Mar 9, 2012
222
223
224
BAIL_IF_MACRO(!__PHYSFS_readAll(io, &entry->name, 56), NULL, 0);
BAIL_IF_MACRO(!__PHYSFS_readAll(io, &entry->startPos, 4), NULL, 0);
BAIL_IF_MACRO(!__PHYSFS_readAll(io, &entry->size, 4), NULL, 0);
225
entry->size = PHYSFS_swapULE32(entry->size);
Aug 21, 2010
Aug 21, 2010
226
entry->startPos = PHYSFS_swapULE32(entry->startPos);
227
228
} /* for */
Aug 30, 2010
Aug 30, 2010
229
__PHYSFS_sort(info->entries, info->entryCount, qpakEntryCmp, qpakEntrySwap);
Jan 28, 2010
Jan 28, 2010
230
return 1;
231
232
233
} /* qpak_load_entries */
Aug 30, 2010
Aug 30, 2010
234
static void *QPAK_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
235
{
Aug 30, 2010
Aug 30, 2010
236
237
238
239
QPAKinfo *info = NULL;
PHYSFS_uint32 val = 0;
PHYSFS_uint32 pos = 0;
PHYSFS_uint32 count = 0;
240
Aug 30, 2010
Aug 30, 2010
241
assert(io != NULL); /* shouldn't ever happen. */
242
Aug 30, 2010
Aug 30, 2010
243
BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0);
244
Mar 9, 2012
Mar 9, 2012
245
BAIL_IF_MACRO(!__PHYSFS_readAll(io, &val, 4), NULL, NULL);
Aug 30, 2010
Aug 30, 2010
246
BAIL_IF_MACRO(PHYSFS_swapULE32(val) != QPAK_SIG, ERR_NOT_AN_ARCHIVE, NULL);
247
Mar 9, 2012
Mar 9, 2012
248
BAIL_IF_MACRO(!__PHYSFS_readAll(io, &val, 4), NULL, NULL);
Aug 30, 2010
Aug 30, 2010
249
250
pos = PHYSFS_swapULE32(val); /* directory table offset. */
Mar 9, 2012
Mar 9, 2012
251
BAIL_IF_MACRO(!__PHYSFS_readAll(io, &val, 4), NULL, NULL);
Aug 30, 2010
Aug 30, 2010
252
count = PHYSFS_swapULE32(val);
253
Aug 30, 2010
Aug 30, 2010
254
255
256
257
/* corrupted archive? */
BAIL_IF_MACRO((count % 64) != 0, ERR_CORRUPTED, NULL);
count /= 64;
Feb 10, 2011
Feb 10, 2011
258
BAIL_IF_MACRO(!io->seek(io, pos), NULL, NULL);
Aug 30, 2010
Aug 30, 2010
259
260
261
262
263
264
265
266
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))
267
{
Sep 26, 2004
Sep 26, 2004
268
if (info->entries != NULL)
Mar 14, 2005
Mar 14, 2005
269
270
allocator.Free(info->entries);
allocator.Free(info);
Aug 30, 2010
Aug 30, 2010
271
return NULL;
272
273
} /* if */
Aug 30, 2010
Aug 30, 2010
274
return info;
275
276
277
278
279
280
281
282
283
} /* 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;
Mar 10, 2012
Mar 10, 2012
284
PHYSFS_uint32 dlen = (PHYSFS_uint32) strlen(path);
285
286
287
288
289
PHYSFS_sint32 retval = -1;
const char *name;
int rc;
if (*path == '\0') /* root dir? */
Jan 28, 2010
Jan 28, 2010
290
return 0;
291
292
293
294
295
296
297
298
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
299
rc = QPAK_strncmp(path, name, dlen);
300
301
302
303
304
305
306
307
308
309
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
310
return middle;
311
312
if (name[dlen + 1] == '\0') /* Skip initial dir entry. */
Jan 28, 2010
Jan 28, 2010
313
return (middle + 1);
314
315
316
317
318
319
320
321
322
323
324
325
326
/* 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
327
return retval;
328
329
330
} /* qpak_find_start_of_dir */
Sep 29, 2004
Sep 29, 2004
331
332
333
334
/*
* Moved to seperate function so we can use alloca then immediately throw
* away the allocated stack space...
*/
Sep 18, 2005
Sep 18, 2005
335
336
static void doEnumCallback(PHYSFS_EnumFilesCallback cb, void *callbackdata,
const char *odir, const char *str, PHYSFS_sint32 ln)
Sep 29, 2004
Sep 29, 2004
337
{
Mar 24, 2007
Mar 24, 2007
338
char *newstr = __PHYSFS_smallAlloc(ln + 1);
Sep 29, 2004
Sep 29, 2004
339
340
341
342
343
if (newstr == NULL)
return;
memcpy(newstr, str, ln);
newstr[ln] = '\0';
Sep 18, 2005
Sep 18, 2005
344
cb(callbackdata, odir, newstr);
Mar 24, 2007
Mar 24, 2007
345
__PHYSFS_smallFree(newstr);
Sep 29, 2004
Sep 29, 2004
346
347
348
349
} /* doEnumCallback */
static void QPAK_enumerateFiles(dvoid *opaque, const char *dname,
Sep 18, 2005
Sep 18, 2005
350
351
int omitSymLinks, PHYSFS_EnumFilesCallback cb,
const char *origdir, void *callbackdata)
352
{
Sep 26, 2004
Sep 26, 2004
353
QPAKinfo *info = ((QPAKinfo *) opaque);
354
355
PHYSFS_sint32 dlen, dlen_inc, max, i;
Sep 29, 2004
Sep 29, 2004
356
357
358
i = qpak_find_start_of_dir(info, dname, 0);
if (i == -1) /* no such directory. */
return;
359
Mar 10, 2012
Mar 10, 2012
360
dlen = (PHYSFS_sint32) strlen(dname);
Sep 29, 2004
Sep 29, 2004
361
if ((dlen > 0) && (dname[dlen - 1] == '/')) /* ignore trailing slash. */
362
363
364
365
366
367
368
369
370
371
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
372
if ((dlen) && ((QPAK_strncmp(e, dname, dlen)) || (e[dlen] != '/')))
373
374
375
376
377
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
378
doEnumCallback(cb, callbackdata, origdir, add, ln);
379
380
381
382
383
384
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
385
if ((QPAK_strncmp(e, e_new, ln) != 0) || (e_new[ln] != '/'))
386
387
388
389
390
391
392
393
394
395
396
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
397
398
static QPAKentry *qpak_find_entry(const QPAKinfo *info, const char *path,
int *isDir)
399
400
{
QPAKentry *a = info->entries;
Mar 10, 2012
Mar 10, 2012
401
PHYSFS_sint32 pathlen = (PHYSFS_sint32) strlen(path);
402
403
404
405
406
407
408
409
410
411
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
412
rc = QPAK_strncmp(path, thispath, pathlen);
413
414
415
416
417
418
419
420
421
422
423
424
425
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
426
return NULL;
427
428
429
} /* if */
if (thispath[pathlen] == '\0') /* found entry? */
Jan 28, 2010
Jan 28, 2010
430
return &a[middle];
Feb 18, 2011
Feb 18, 2011
431
432
433
/* adjust search params, try again. */
else if (thispath[pathlen] > '/')
hi = middle - 1;
434
else
Feb 18, 2011
Feb 18, 2011
435
lo = middle + 1;
436
437
438
439
440
441
442
443
444
445
} /* if */
} /* while */
if (isDir != NULL)
*isDir = 0;
BAIL_MACRO(ERR_NO_SUCH_FILE, NULL);
} /* qpak_find_entry */
Aug 30, 2010
Aug 30, 2010
446
static PHYSFS_Io *QPAK_openRead(dvoid *opaque, const char *fnm, int *fileExists)
447
{
Aug 30, 2010
Aug 30, 2010
448
PHYSFS_Io *io = NULL;
Sep 26, 2004
Sep 26, 2004
449
QPAKinfo *info = ((QPAKinfo *) opaque);
450
451
452
453
454
455
456
457
458
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
459
finfo = (QPAKfileinfo *) allocator.Malloc(sizeof (QPAKfileinfo));
Sep 26, 2004
Sep 26, 2004
460
BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL);
461
Aug 30, 2010
Aug 30, 2010
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
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)
478
{
Aug 30, 2010
Aug 30, 2010
479
480
if (finfo->io != NULL)
finfo->io->destroy(finfo->io);
Mar 14, 2005
Mar 14, 2005
481
allocator.Free(finfo);
482
483
} /* if */
Aug 30, 2010
Aug 30, 2010
484
485
486
487
if (io != NULL)
allocator.Free(io);
return NULL;
488
489
490
} /* QPAK_openRead */
Aug 30, 2010
Aug 30, 2010
491
static PHYSFS_Io *QPAK_openWrite(dvoid *opaque, const char *name)
492
493
494
495
496
{
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
} /* QPAK_openWrite */
Aug 30, 2010
Aug 30, 2010
497
static PHYSFS_Io *QPAK_openAppend(dvoid *opaque, const char *name)
498
499
500
501
502
{
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
} /* QPAK_openAppend */
Sep 26, 2004
Sep 26, 2004
503
static int QPAK_remove(dvoid *opaque, const char *name)
504
505
506
507
508
{
BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
} /* QPAK_remove */
Sep 26, 2004
Sep 26, 2004
509
static int QPAK_mkdir(dvoid *opaque, const char *name)
510
511
512
513
{
BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
} /* QPAK_mkdir */
Sep 29, 2004
Sep 29, 2004
514
Aug 22, 2010
Aug 22, 2010
515
static int QPAK_stat(dvoid *opaque, const char *filename, int *exists,
Feb 15, 2010
Feb 15, 2010
516
517
518
519
520
521
522
523
PHYSFS_Stat *stat)
{
int isDir = 0;
const QPAKinfo *info = (const QPAKinfo *) opaque;
const QPAKentry *entry = qpak_find_entry(info, filename, &isDir);
if (isDir)
{
Oct 18, 2011
Oct 18, 2011
524
*exists = 1;
Feb 15, 2010
Feb 15, 2010
525
526
527
stat->filetype = PHYSFS_FILETYPE_DIRECTORY;
stat->filesize = 0;
} /* if */
Oct 18, 2011
Oct 18, 2011
528
else if (entry != NULL)
Feb 15, 2010
Feb 15, 2010
529
{
Oct 18, 2011
Oct 18, 2011
530
*exists = 1;
Feb 15, 2010
Feb 15, 2010
531
532
stat->filetype = PHYSFS_FILETYPE_REGULAR;
stat->filesize = entry->size;
Oct 18, 2011
Oct 18, 2011
533
534
535
536
537
} /* else if */
else
{
*exists = 0;
return 0;
Feb 15, 2010
Feb 15, 2010
538
539
} /* 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 ... */