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