Skip to content

Latest commit

 

History

History
576 lines (461 loc) · 15.6 KB

archiver_qpak.c

File metadata and controls

576 lines (461 loc) · 15.6 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
{
Mar 20, 2012
Mar 20, 2012
101
BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, -1);
102
103
104
} /* 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
int rc;
Mar 20, 2012
Mar 20, 2012
117
BAIL_IF_MACRO(offset >= entry->size, PHYSFS_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
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));
Mar 20, 2012
Mar 20, 2012
139
140
GOTO_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, QPAK_duplicate_failed);
GOTO_IF_MACRO(!finfo, PHYSFS_ERR_OUT_OF_MEMORY, QPAK_duplicate_failed);
141
Aug 30, 2010
Aug 30, 2010
142
io = origfinfo->io->duplicate(origfinfo->io);
Mar 20, 2012
Mar 20, 2012
143
GOTO_IF_MACRO(!io, ERRPASS, QPAK_duplicate_failed);
Aug 30, 2010
Aug 30, 2010
144
145
146
147
148
149
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);
Mar 20, 2012
Mar 20, 2012
218
BAIL_IF_MACRO(info->entries == NULL, PHYSFS_ERR_OUT_OF_MEMORY, 0);
219
220
221
for (entry = info->entries; fileCount > 0; fileCount--, entry++)
{
Mar 20, 2012
Mar 20, 2012
222
223
224
BAIL_IF_MACRO(!__PHYSFS_readAll(io, &entry->name, 56), ERRPASS, 0);
BAIL_IF_MACRO(!__PHYSFS_readAll(io, &entry->startPos, 4), ERRPASS, 0);
BAIL_IF_MACRO(!__PHYSFS_readAll(io, &entry->size, 4), ERRPASS, 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
Mar 20, 2012
Mar 20, 2012
243
BAIL_IF_MACRO(forWriting, PHYSFS_ERR_READ_ONLY, NULL);
244
Mar 20, 2012
Mar 20, 2012
245
246
247
BAIL_IF_MACRO(!__PHYSFS_readAll(io, &val, 4), ERRPASS, NULL);
if (PHYSFS_swapULE32(val) != QPAK_SIG)
BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, NULL);
248
Mar 20, 2012
Mar 20, 2012
249
BAIL_IF_MACRO(!__PHYSFS_readAll(io, &val, 4), ERRPASS, NULL);
Aug 30, 2010
Aug 30, 2010
250
251
pos = PHYSFS_swapULE32(val); /* directory table offset. */
Mar 20, 2012
Mar 20, 2012
252
BAIL_IF_MACRO(!__PHYSFS_readAll(io, &val, 4), ERRPASS, NULL);
Aug 30, 2010
Aug 30, 2010
253
count = PHYSFS_swapULE32(val);
254
Aug 30, 2010
Aug 30, 2010
255
/* corrupted archive? */
Mar 20, 2012
Mar 20, 2012
256
BAIL_IF_MACRO((count % 64) != 0, PHYSFS_ERR_CORRUPT, NULL);
Aug 30, 2010
Aug 30, 2010
257
258
count /= 64;
Mar 20, 2012
Mar 20, 2012
259
BAIL_IF_MACRO(!io->seek(io, pos), ERRPASS, NULL);
Aug 30, 2010
Aug 30, 2010
260
261
info = (QPAKinfo *) allocator.Malloc(sizeof (QPAKinfo));
Mar 20, 2012
Mar 20, 2012
262
BAIL_IF_MACRO(info == NULL, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
Aug 30, 2010
Aug 30, 2010
263
264
265
266
267
memset(info, '\0', sizeof (QPAKinfo));
info->io = io;
info->entryCount = count;
if (!qpak_load_entries(info))
268
{
Sep 26, 2004
Sep 26, 2004
269
if (info->entries != NULL)
Mar 14, 2005
Mar 14, 2005
270
271
allocator.Free(info->entries);
allocator.Free(info);
Aug 30, 2010
Aug 30, 2010
272
return NULL;
273
274
} /* if */
Aug 30, 2010
Aug 30, 2010
275
return info;
276
277
278
279
280
281
282
283
284
} /* 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
285
PHYSFS_uint32 dlen = (PHYSFS_uint32) strlen(path);
286
287
288
289
290
PHYSFS_sint32 retval = -1;
const char *name;
int rc;
if (*path == '\0') /* root dir? */
Jan 28, 2010
Jan 28, 2010
291
return 0;
292
293
294
295
296
297
298
299
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
300
rc = QPAK_strncmp(path, name, dlen);
301
302
303
304
305
306
307
308
309
310
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
311
return middle;
312
313
if (name[dlen + 1] == '\0') /* Skip initial dir entry. */
Jan 28, 2010
Jan 28, 2010
314
return (middle + 1);
315
316
317
318
319
320
321
322
323
324
325
326
327
/* 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
328
return retval;
329
330
331
} /* qpak_find_start_of_dir */
Sep 29, 2004
Sep 29, 2004
332
333
334
335
/*
* Moved to seperate function so we can use alloca then immediately throw
* away the allocated stack space...
*/
Sep 18, 2005
Sep 18, 2005
336
337
static void doEnumCallback(PHYSFS_EnumFilesCallback cb, void *callbackdata,
const char *odir, const char *str, PHYSFS_sint32 ln)
Sep 29, 2004
Sep 29, 2004
338
{
Mar 24, 2007
Mar 24, 2007
339
char *newstr = __PHYSFS_smallAlloc(ln + 1);
Sep 29, 2004
Sep 29, 2004
340
341
342
343
344
if (newstr == NULL)
return;
memcpy(newstr, str, ln);
newstr[ln] = '\0';
Sep 18, 2005
Sep 18, 2005
345
cb(callbackdata, odir, newstr);
Mar 24, 2007
Mar 24, 2007
346
__PHYSFS_smallFree(newstr);
Sep 29, 2004
Sep 29, 2004
347
348
349
350
} /* doEnumCallback */
static void QPAK_enumerateFiles(dvoid *opaque, const char *dname,
Sep 18, 2005
Sep 18, 2005
351
352
int omitSymLinks, PHYSFS_EnumFilesCallback cb,
const char *origdir, void *callbackdata)
353
{
Sep 26, 2004
Sep 26, 2004
354
QPAKinfo *info = ((QPAKinfo *) opaque);
355
356
PHYSFS_sint32 dlen, dlen_inc, max, i;
Sep 29, 2004
Sep 29, 2004
357
358
359
i = qpak_find_start_of_dir(info, dname, 0);
if (i == -1) /* no such directory. */
return;
360
Mar 10, 2012
Mar 10, 2012
361
dlen = (PHYSFS_sint32) strlen(dname);
Sep 29, 2004
Sep 29, 2004
362
if ((dlen > 0) && (dname[dlen - 1] == '/')) /* ignore trailing slash. */
363
364
365
366
367
368
369
370
371
372
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
373
if ((dlen) && ((QPAK_strncmp(e, dname, dlen)) || (e[dlen] != '/')))
374
375
376
377
378
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
379
doEnumCallback(cb, callbackdata, origdir, add, ln);
380
381
382
383
384
385
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
386
if ((QPAK_strncmp(e, e_new, ln) != 0) || (e_new[ln] != '/'))
387
388
389
390
391
392
393
394
395
396
397
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
398
399
static QPAKentry *qpak_find_entry(const QPAKinfo *info, const char *path,
int *isDir)
400
401
{
QPAKentry *a = info->entries;
Mar 10, 2012
Mar 10, 2012
402
PHYSFS_sint32 pathlen = (PHYSFS_sint32) strlen(path);
403
404
405
406
407
408
409
410
411
412
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
413
rc = QPAK_strncmp(path, thispath, pathlen);
414
415
416
417
418
419
420
421
422
423
424
425
426
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
427
return NULL;
428
429
430
} /* if */
if (thispath[pathlen] == '\0') /* found entry? */
Jan 28, 2010
Jan 28, 2010
431
return &a[middle];
Feb 18, 2011
Feb 18, 2011
432
433
434
/* adjust search params, try again. */
else if (thispath[pathlen] > '/')
hi = middle - 1;
435
else
Feb 18, 2011
Feb 18, 2011
436
lo = middle + 1;
437
438
439
440
441
442
} /* if */
} /* while */
if (isDir != NULL)
*isDir = 0;
Mar 20, 2012
Mar 20, 2012
443
BAIL_MACRO(PHYSFS_ERR_NO_SUCH_PATH, NULL);
444
445
446
} /* qpak_find_entry */
Aug 30, 2010
Aug 30, 2010
447
static PHYSFS_Io *QPAK_openRead(dvoid *opaque, const char *fnm, int *fileExists)
448
{
Aug 30, 2010
Aug 30, 2010
449
PHYSFS_Io *io = NULL;
Sep 26, 2004
Sep 26, 2004
450
QPAKinfo *info = ((QPAKinfo *) opaque);
451
452
453
454
455
456
QPAKfileinfo *finfo;
QPAKentry *entry;
int isDir;
entry = qpak_find_entry(info, fnm, &isDir);
*fileExists = ((entry != NULL) || (isDir));
Mar 20, 2012
Mar 20, 2012
457
458
BAIL_IF_MACRO(isDir, PHYSFS_ERR_NOT_A_FILE, NULL);
BAIL_IF_MACRO(entry == NULL, PHYSFS_ERR_NO_SUCH_PATH, NULL);
459
Mar 14, 2005
Mar 14, 2005
460
finfo = (QPAKfileinfo *) allocator.Malloc(sizeof (QPAKfileinfo));
Mar 20, 2012
Mar 20, 2012
461
BAIL_IF_MACRO(finfo == NULL, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
462
Aug 30, 2010
Aug 30, 2010
463
finfo->io = info->io->duplicate(info->io);
Mar 20, 2012
Mar 20, 2012
464
GOTO_IF_MACRO(finfo->io == NULL, ERRPASS, QPAK_openRead_failed);
Aug 30, 2010
Aug 30, 2010
465
if (!finfo->io->seek(finfo->io, entry->startPos))
Mar 20, 2012
Mar 20, 2012
466
goto QPAK_openRead_failed;
Aug 30, 2010
Aug 30, 2010
467
468
469
470
finfo->curPos = 0;
finfo->entry = entry;
io = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io));
Mar 20, 2012
Mar 20, 2012
471
GOTO_IF_MACRO(io == NULL, PHYSFS_ERR_OUT_OF_MEMORY, QPAK_openRead_failed);
Aug 30, 2010
Aug 30, 2010
472
473
474
475
476
477
478
memcpy(io, &QPAK_Io, sizeof (PHYSFS_Io));
io->opaque = finfo;
return io;
QPAK_openRead_failed:
if (finfo != NULL)
479
{
Aug 30, 2010
Aug 30, 2010
480
481
if (finfo->io != NULL)
finfo->io->destroy(finfo->io);
Mar 14, 2005
Mar 14, 2005
482
allocator.Free(finfo);
483
484
} /* if */
Aug 30, 2010
Aug 30, 2010
485
486
487
488
if (io != NULL)
allocator.Free(io);
return NULL;
489
490
491
} /* QPAK_openRead */
Aug 30, 2010
Aug 30, 2010
492
static PHYSFS_Io *QPAK_openWrite(dvoid *opaque, const char *name)
493
{
Mar 20, 2012
Mar 20, 2012
494
BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, NULL);
495
496
497
} /* QPAK_openWrite */
Aug 30, 2010
Aug 30, 2010
498
static PHYSFS_Io *QPAK_openAppend(dvoid *opaque, const char *name)
499
{
Mar 20, 2012
Mar 20, 2012
500
BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, NULL);
501
502
503
} /* QPAK_openAppend */
Sep 26, 2004
Sep 26, 2004
504
static int QPAK_remove(dvoid *opaque, const char *name)
505
{
Mar 20, 2012
Mar 20, 2012
506
BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, 0);
507
508
509
} /* QPAK_remove */
Sep 26, 2004
Sep 26, 2004
510
static int QPAK_mkdir(dvoid *opaque, const char *name)
511
{
Mar 20, 2012
Mar 20, 2012
512
BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, 0);
513
514
} /* QPAK_mkdir */
Sep 29, 2004
Sep 29, 2004
515
Aug 22, 2010
Aug 22, 2010
516
static int QPAK_stat(dvoid *opaque, const char *filename, int *exists,
Feb 15, 2010
Feb 15, 2010
517
518
519
520
521
522
523
524
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
525
*exists = 1;
Feb 15, 2010
Feb 15, 2010
526
527
528
stat->filetype = PHYSFS_FILETYPE_DIRECTORY;
stat->filesize = 0;
} /* if */
Oct 18, 2011
Oct 18, 2011
529
else if (entry != NULL)
Feb 15, 2010
Feb 15, 2010
530
{
Oct 18, 2011
Oct 18, 2011
531
*exists = 1;
Feb 15, 2010
Feb 15, 2010
532
533
stat->filetype = PHYSFS_FILETYPE_REGULAR;
stat->filesize = entry->size;
Oct 18, 2011
Oct 18, 2011
534
535
536
537
538
} /* else if */
else
{
*exists = 0;
return 0;
Feb 15, 2010
Feb 15, 2010
539
540
} /* else */
Aug 25, 2010
Aug 25, 2010
541
542
543
stat->modtime = -1;
stat->createtime = -1;
stat->accesstime = -1;
Feb 15, 2010
Feb 15, 2010
544
545
stat->readonly = 1;
Aug 21, 2010
Aug 21, 2010
546
return 1;
Feb 15, 2010
Feb 15, 2010
547
548
549
} /* QPAK_stat */
Sep 29, 2004
Sep 29, 2004
550
551
552
553
const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_QPAK =
{
"PAK",
QPAK_ARCHIVE_DESCRIPTION,
Jan 1, 2006
Jan 1, 2006
554
"Ryan C. Gordon <icculus@icculus.org>",
Sep 29, 2004
Sep 29, 2004
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
"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
570
QPAK_stat /* stat() method */
Sep 29, 2004
Sep 29, 2004
571
572
};
573
574
575
#endif /* defined PHYSFS_SUPPORTS_QPAK */
/* end of qpak.c ... */