author | Ryan C. Gordon <icculus@icculus.org> |
Sat, 21 Aug 2010 19:10:42 -0400 | |
changeset 1106 | 94c3669d0311 |
parent 1098 | 4e86cec1143f |
child 1108 | b63e39d5be04 |
permissions | -rw-r--r-- |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1 |
/* |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
2 |
* HOG support routines for PhysicsFS. |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
3 |
* |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
4 |
* This driver handles Descent I/II HOG archives. |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
5 |
* |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
6 |
* The format is very simple: |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
7 |
* |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
8 |
* The file always starts with the 3-byte signature "DHF" (Descent |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
9 |
* HOG file). After that the files of a HOG are just attached after |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
10 |
* another, divided by a 17 bytes header, which specifies the name |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
11 |
* and length (in bytes) of the forthcoming file! So you just read |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
12 |
* the header with its information of how big the following file is, |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
13 |
* and then skip exact that number of bytes to get to the next file |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
14 |
* in that HOG. |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
15 |
* |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
16 |
* char sig[3] = {'D', 'H', 'F'}; // "DHF"=Descent HOG File |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
17 |
* |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
18 |
* struct { |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
19 |
* char file_name[13]; // Filename, padded to 13 bytes with 0s |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
20 |
* int file_size; // filesize in bytes |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
21 |
* char data[file_size]; // The file data |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
22 |
* } FILE_STRUCT; // Repeated until the end of the file. |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
23 |
* |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
24 |
* (That info is from http://www.descent2.com/ddn/specs/hog/) |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
25 |
* |
809
116b8fe30371
Renamed LICENSE to LICENSE.txt
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
26 |
* Please see the file LICENSE.txt in the source's root directory. |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
27 |
* |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
28 |
* This file written by Bradley Bell. |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
29 |
* Based on grp.c by Ryan C. Gordon. |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
30 |
*/ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
31 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
32 |
#if (defined PHYSFS_SUPPORTS_HOG) |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
33 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
34 |
#include <stdio.h> |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
35 |
#include <stdlib.h> |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
36 |
#include <string.h> |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
37 |
#include "physfs.h" |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
38 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
39 |
#define __PHYSICSFS_INTERNAL__ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
40 |
#include "physfs_internal.h" |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
41 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
42 |
/* |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
43 |
* One HOGentry is kept for each file in an open HOG archive. |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
44 |
*/ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
45 |
typedef struct |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
46 |
{ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
47 |
char name[13]; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
48 |
PHYSFS_uint32 startPos; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
49 |
PHYSFS_uint32 size; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
50 |
} HOGentry; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
51 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
52 |
/* |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
53 |
* One HOGinfo is kept for each open HOG archive. |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
54 |
*/ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
55 |
typedef struct |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
56 |
{ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
57 |
char *filename; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
58 |
PHYSFS_sint64 last_mod_time; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
59 |
PHYSFS_uint32 entryCount; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
60 |
HOGentry *entries; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
61 |
} HOGinfo; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
62 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
63 |
/* |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
64 |
* One HOGfileinfo is kept for each open file in a HOG archive. |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
65 |
*/ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
66 |
typedef struct |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
67 |
{ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
68 |
void *handle; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
69 |
HOGentry *entry; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
70 |
PHYSFS_uint32 curPos; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
71 |
} HOGfileinfo; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
72 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
73 |
|
1098
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
74 |
static inline int readAll(void *fh, void *buf, const PHYSFS_uint64 len) |
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
75 |
{ |
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
76 |
return (__PHYSFS_platformRead(fh, buf, len) == len); |
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
77 |
} /* readAll */ |
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
78 |
|
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
79 |
|
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
|
80 |
static void HOG_dirClose(dvoid *opaque) |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
81 |
{ |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
622
diff
changeset
|
82 |
HOGinfo *info = ((HOGinfo *) opaque); |
691
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->filename); |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
678
diff
changeset
|
84 |
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
|
85 |
allocator.Free(info); |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
86 |
} /* HOG_dirClose */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
87 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
88 |
|
1098
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
89 |
static PHYSFS_sint64 HOG_read(fvoid *opaque, void *buffer, PHYSFS_uint64 len) |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
90 |
{ |
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
|
91 |
HOGfileinfo *finfo = (HOGfileinfo *) 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
|
92 |
const HOGentry *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
|
93 |
const PHYSFS_uint64 bytesLeft = (PHYSFS_uint64)(entry->size-finfo->curPos); |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
94 |
PHYSFS_sint64 rc; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
95 |
|
1098
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
96 |
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
|
97 |
len = bytesLeft; |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
98 |
|
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 |
rc = __PHYSFS_platformRead(finfo->handle, buffer, len); |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
100 |
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
|
101 |
finfo->curPos += (PHYSFS_uint32) rc; |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
102 |
|
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
|
103 |
return rc; |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
104 |
} /* HOG_read */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
105 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
106 |
|
1098
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
107 |
static PHYSFS_sint64 HOG_write(fvoid *f, const void *buf, PHYSFS_uint64 len) |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
108 |
{ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
109 |
BAIL_MACRO(ERR_NOT_SUPPORTED, -1); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
110 |
} /* HOG_write */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
111 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
112 |
|
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
|
113 |
static int HOG_eof(fvoid *opaque) |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
114 |
{ |
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
|
115 |
HOGfileinfo *finfo = (HOGfileinfo *) opaque; |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
116 |
HOGentry *entry = finfo->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
|
117 |
return (finfo->curPos >= entry->size); |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
118 |
} /* HOG_eof */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
119 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
120 |
|
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
|
121 |
static PHYSFS_sint64 HOG_tell(fvoid *opaque) |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
122 |
{ |
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
|
123 |
return ((HOGfileinfo *) opaque)->curPos; |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
124 |
} /* HOG_tell */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
125 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
126 |
|
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
|
127 |
static int HOG_seek(fvoid *opaque, PHYSFS_uint64 offset) |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
128 |
{ |
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
|
129 |
HOGfileinfo *finfo = (HOGfileinfo *) opaque; |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
130 |
HOGentry *entry = finfo->entry; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
131 |
int rc; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
132 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
133 |
BAIL_IF_MACRO(offset < 0, ERR_INVALID_ARGUMENT, 0); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
134 |
BAIL_IF_MACRO(offset >= entry->size, ERR_PAST_EOF, 0); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
135 |
rc = __PHYSFS_platformSeek(finfo->handle, entry->startPos + offset); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
136 |
if (rc) |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
137 |
finfo->curPos = (PHYSFS_uint32) offset; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
138 |
|
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
|
139 |
return rc; |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
140 |
} /* HOG_seek */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
141 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
142 |
|
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
|
143 |
static PHYSFS_sint64 HOG_fileLength(fvoid *opaque) |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
144 |
{ |
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
|
145 |
HOGfileinfo *finfo = (HOGfileinfo *) 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
|
146 |
return ((PHYSFS_sint64) finfo->entry->size); |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
147 |
} /* HOG_fileLength */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
148 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
149 |
|
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
|
150 |
static int HOG_fileClose(fvoid *opaque) |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
151 |
{ |
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
|
152 |
HOGfileinfo *finfo = (HOGfileinfo *) opaque; |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
153 |
BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0); |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
678
diff
changeset
|
154 |
allocator.Free(finfo); |
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
|
155 |
return 1; |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
156 |
} /* HOG_fileClose */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
157 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
158 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
159 |
static int hog_open(const char *filename, int forWriting, |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
160 |
void **fh, PHYSFS_uint32 *count) |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
161 |
{ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
162 |
PHYSFS_uint8 buf[13]; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
163 |
PHYSFS_uint32 size; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
164 |
PHYSFS_sint64 pos; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
165 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
166 |
*count = 0; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
167 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
168 |
*fh = NULL; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
169 |
BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
170 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
171 |
*fh = __PHYSFS_platformOpenRead(filename); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
172 |
BAIL_IF_MACRO(*fh == NULL, NULL, 0); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
173 |
|
1098
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
174 |
if (!readAll(*fh, buf, 3)) |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
175 |
goto openHog_failed; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
176 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
177 |
if (memcmp(buf, "DHF", 3) != 0) |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
178 |
{ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
179 |
__PHYSFS_setError(ERR_UNSUPPORTED_ARCHIVE); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
180 |
goto openHog_failed; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
181 |
} /* if */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
182 |
|
622
c8e67ca63ad6
Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents:
591
diff
changeset
|
183 |
while (1) |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
184 |
{ |
1098
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
185 |
if (!readAll(*fh, buf, 13)) |
622
c8e67ca63ad6
Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents:
591
diff
changeset
|
186 |
break; /* eof here is ok */ |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
187 |
|
1098
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
188 |
if (!readAll(*fh, &size, sizeof (PHYSFS_uint32))) |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
189 |
goto openHog_failed; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
190 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
191 |
size = PHYSFS_swapULE32(size); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
192 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
193 |
(*count)++; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
194 |
|
622
c8e67ca63ad6
Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents:
591
diff
changeset
|
195 |
/* Skip over entry... */ |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
196 |
pos = __PHYSFS_platformTell(*fh); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
197 |
if (pos == -1) |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
198 |
goto openHog_failed; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
199 |
if (!__PHYSFS_platformSeek(*fh, pos + size)) |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
200 |
goto openHog_failed; |
622
c8e67ca63ad6
Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents:
591
diff
changeset
|
201 |
} /* while */ |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
202 |
|
622
c8e67ca63ad6
Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents:
591
diff
changeset
|
203 |
/* Rewind to start of entries... */ |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
204 |
if (!__PHYSFS_platformSeek(*fh, 3)) |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
205 |
goto openHog_failed; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
206 |
|
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
|
207 |
return 1; |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
208 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
209 |
openHog_failed: |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
210 |
if (*fh != NULL) |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
211 |
__PHYSFS_platformClose(*fh); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
212 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
213 |
*count = -1; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
214 |
*fh = NULL; |
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
|
215 |
return 0; |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
216 |
} /* hog_open */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
217 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
218 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
219 |
static int HOG_isArchive(const char *filename, int forWriting) |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
220 |
{ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
221 |
void *fh; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
222 |
PHYSFS_uint32 fileCount; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
223 |
int retval = hog_open(filename, forWriting, &fh, &fileCount); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
224 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
225 |
if (fh != NULL) |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
226 |
__PHYSFS_platformClose(fh); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
227 |
|
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
|
228 |
return retval; |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
229 |
} /* HOG_isArchive */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
230 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
231 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
232 |
static int hog_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
233 |
{ |
928
0e37b8163248
Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents:
866
diff
changeset
|
234 |
if (one != two) |
0e37b8163248
Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents:
866
diff
changeset
|
235 |
{ |
0e37b8163248
Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents:
866
diff
changeset
|
236 |
const HOGentry *a = (const HOGentry *) _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
|
237 |
return __PHYSFS_stricmpASCII(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:
866
diff
changeset
|
238 |
} /* if */ |
0e37b8163248
Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents:
866
diff
changeset
|
239 |
|
0e37b8163248
Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents:
866
diff
changeset
|
240 |
return 0; |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
241 |
} /* hog_entry_cmp */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
242 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
243 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
244 |
static void hog_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
245 |
{ |
928
0e37b8163248
Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents:
866
diff
changeset
|
246 |
if (one != two) |
0e37b8163248
Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents:
866
diff
changeset
|
247 |
{ |
0e37b8163248
Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents:
866
diff
changeset
|
248 |
HOGentry tmp; |
0e37b8163248
Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents:
866
diff
changeset
|
249 |
HOGentry *first = &(((HOGentry *) _a)[one]); |
0e37b8163248
Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents:
866
diff
changeset
|
250 |
HOGentry *second = &(((HOGentry *) _a)[two]); |
0e37b8163248
Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents:
866
diff
changeset
|
251 |
memcpy(&tmp, first, sizeof (HOGentry)); |
0e37b8163248
Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents:
866
diff
changeset
|
252 |
memcpy(first, second, sizeof (HOGentry)); |
0e37b8163248
Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents:
866
diff
changeset
|
253 |
memcpy(second, &tmp, sizeof (HOGentry)); |
0e37b8163248
Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents:
866
diff
changeset
|
254 |
} /* if */ |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
255 |
} /* hog_entry_swap */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
256 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
257 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
258 |
static int hog_load_entries(const char *name, int forWriting, HOGinfo *info) |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
259 |
{ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
260 |
void *fh = NULL; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
261 |
PHYSFS_uint32 fileCount; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
262 |
HOGentry *entry; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
263 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
264 |
BAIL_IF_MACRO(!hog_open(name, forWriting, &fh, &fileCount), NULL, 0); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
265 |
info->entryCount = fileCount; |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
678
diff
changeset
|
266 |
info->entries = (HOGentry *) allocator.Malloc(sizeof(HOGentry)*fileCount); |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
267 |
if (info->entries == NULL) |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
268 |
{ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
269 |
__PHYSFS_platformClose(fh); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
270 |
BAIL_MACRO(ERR_OUT_OF_MEMORY, 0); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
271 |
} /* if */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
272 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
273 |
for (entry = info->entries; fileCount > 0; fileCount--, entry++) |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
274 |
{ |
1098
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
275 |
if ( (!readAll(fh, &entry->name, 13)) || |
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
276 |
(!readAll(fh, &entry->size, sizeof (PHYSFS_uint32))) ) |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
277 |
{ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
278 |
__PHYSFS_platformClose(fh); |
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
|
279 |
return 0; |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
280 |
} /* if */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
281 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
282 |
entry->size = PHYSFS_swapULE32(entry->size); |
591 | 283 |
entry->startPos = (unsigned int) __PHYSFS_platformTell(fh); |
1098
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
284 |
|
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
285 |
/* Skip over entry */ |
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
286 |
if ( (entry->startPos == -1) || |
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
287 |
(!__PHYSFS_platformSeek(fh, entry->startPos + entry->size)) ) |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
288 |
{ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
289 |
__PHYSFS_platformClose(fh); |
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
|
290 |
return 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
|
291 |
} /* if */ |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
292 |
} /* for */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
293 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
294 |
__PHYSFS_platformClose(fh); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
295 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
296 |
__PHYSFS_sort(info->entries, info->entryCount, |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
297 |
hog_entry_cmp, hog_entry_swap); |
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
|
298 |
return 1; |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
299 |
} /* hog_load_entries */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
300 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
301 |
|
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
622
diff
changeset
|
302 |
static void *HOG_openArchive(const char *name, int forWriting) |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
303 |
{ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
304 |
PHYSFS_sint64 modtime = __PHYSFS_platformGetLastModTime(name); |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
678
diff
changeset
|
305 |
HOGinfo *info = (HOGinfo *) allocator.Malloc(sizeof (HOGinfo)); |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
306 |
|
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
622
diff
changeset
|
307 |
BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, 0); |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
308 |
memset(info, '\0', sizeof (HOGinfo)); |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
678
diff
changeset
|
309 |
info->filename = (char *) allocator.Malloc(strlen(name) + 1); |
678
73a2641375a0
Cleaned up some minor bloat with my new evil GOTO_*_MACRO macros.
Ryan C. Gordon <icculus@icculus.org>
parents:
671
diff
changeset
|
310 |
GOTO_IF_MACRO(!info->filename, ERR_OUT_OF_MEMORY, HOG_openArchive_failed); |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
311 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
312 |
if (!hog_load_entries(name, forWriting, info)) |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
313 |
goto HOG_openArchive_failed; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
314 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
315 |
strcpy(info->filename, name); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
316 |
info->last_mod_time = modtime; |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
622
diff
changeset
|
317 |
|
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
|
318 |
return info; |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
319 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
320 |
HOG_openArchive_failed: |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
622
diff
changeset
|
321 |
if (info != NULL) |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
322 |
{ |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
622
diff
changeset
|
323 |
if (info->filename != 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
|
324 |
allocator.Free(info->filename); |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
622
diff
changeset
|
325 |
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
|
326 |
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
|
327 |
allocator.Free(info); |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
328 |
} /* if */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
329 |
|
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
|
330 |
return NULL; |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
331 |
} /* HOG_openArchive */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
332 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
333 |
|
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
650
diff
changeset
|
334 |
static void HOG_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
|
335 |
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
|
336 |
const char *origdir, void *callbackdata) |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
337 |
{ |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
650
diff
changeset
|
338 |
/* no directories in HOG files. */ |
866
d790fca8f7f7
Logic bug in MVL/HOG/GRP archivers: these archives never contain subdirs...but they
Ryan C. Gordon <icculus@icculus.org>
parents:
828
diff
changeset
|
339 |
if (*dname == '\0') |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
650
diff
changeset
|
340 |
{ |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
650
diff
changeset
|
341 |
HOGinfo *info = (HOGinfo *) opaque; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
650
diff
changeset
|
342 |
HOGentry *entry = info->entries; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
650
diff
changeset
|
343 |
PHYSFS_uint32 max = info->entryCount; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
650
diff
changeset
|
344 |
PHYSFS_uint32 i; |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
345 |
|
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
650
diff
changeset
|
346 |
for (i = 0; i < max; i++, entry++) |
754
e7cd7411eadf
API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents:
691
diff
changeset
|
347 |
cb(callbackdata, origdir, entry->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
|
348 |
} /* if */ |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
349 |
} /* HOG_enumerateFiles */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
350 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
351 |
|
1054
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
352 |
static HOGentry *hog_find_entry(const HOGinfo *info, const char *name) |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
353 |
{ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
354 |
char *ptr = strchr(name, '.'); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
355 |
HOGentry *a = info->entries; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
356 |
PHYSFS_sint32 lo = 0; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
357 |
PHYSFS_sint32 hi = (PHYSFS_sint32) (info->entryCount - 1); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
358 |
PHYSFS_sint32 middle; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
359 |
int rc; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
360 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
361 |
/* |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
362 |
* Rule out filenames to avoid unneeded processing...no dirs, |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
363 |
* big filenames, or extensions > 3 chars. |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
364 |
*/ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
365 |
BAIL_IF_MACRO((ptr) && (strlen(ptr) > 4), ERR_NO_SUCH_FILE, NULL); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
366 |
BAIL_IF_MACRO(strlen(name) > 12, ERR_NO_SUCH_FILE, NULL); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
367 |
BAIL_IF_MACRO(strchr(name, '/') != NULL, ERR_NO_SUCH_FILE, NULL); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
368 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
369 |
while (lo <= hi) |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
370 |
{ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
371 |
middle = lo + ((hi - lo) / 2); |
828
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
372 |
rc = __PHYSFS_stricmpASCII(name, a[middle].name); |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
373 |
if (rc == 0) /* found it! */ |
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
|
374 |
return &a[middle]; |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
375 |
else if (rc > 0) |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
376 |
lo = middle + 1; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
377 |
else |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
378 |
hi = middle - 1; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
379 |
} /* while */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
380 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
381 |
BAIL_MACRO(ERR_NO_SUCH_FILE, NULL); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
382 |
} /* hog_find_entry */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
383 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
384 |
|
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
|
385 |
static int HOG_exists(dvoid *opaque, const char *name) |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
386 |
{ |
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
|
387 |
return (hog_find_entry(((HOGinfo *) opaque), name) != NULL); |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
388 |
} /* HOG_exists */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
389 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
390 |
|
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
|
391 |
static int HOG_isDirectory(dvoid *opaque, const char *name, int *fileExists) |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
392 |
{ |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
622
diff
changeset
|
393 |
*fileExists = HOG_exists(opaque, name); |
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
|
394 |
return 0; /* never directories in a groupfile. */ |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
395 |
} /* HOG_isDirectory */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
396 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
397 |
|
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
|
398 |
static int HOG_isSymLink(dvoid *opaque, const char *name, int *fileExists) |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
399 |
{ |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
622
diff
changeset
|
400 |
*fileExists = HOG_exists(opaque, name); |
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
|
401 |
return 0; /* never symlinks in a groupfile. */ |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
402 |
} /* HOG_isSymLink */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
403 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
404 |
|
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
|
405 |
static PHYSFS_sint64 HOG_getLastModTime(dvoid *opaque, |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
406 |
const char *name, |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
407 |
int *fileExists) |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
408 |
{ |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
622
diff
changeset
|
409 |
HOGinfo *info = ((HOGinfo *) opaque); |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
410 |
PHYSFS_sint64 retval = -1; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
411 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
412 |
*fileExists = (hog_find_entry(info, name) != NULL); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
413 |
if (*fileExists) /* use time of HOG itself in the physical filesystem. */ |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
622
diff
changeset
|
414 |
retval = info->last_mod_time; |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
415 |
|
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
|
416 |
return retval; |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
417 |
} /* HOG_getLastModTime */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
418 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
419 |
|
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
|
420 |
static fvoid *HOG_openRead(dvoid *opaque, const char *fnm, int *fileExists) |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
421 |
{ |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
622
diff
changeset
|
422 |
HOGinfo *info = ((HOGinfo *) opaque); |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
423 |
HOGfileinfo *finfo; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
424 |
HOGentry *entry; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
425 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
426 |
entry = hog_find_entry(info, fnm); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
427 |
*fileExists = (entry != NULL); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
428 |
BAIL_IF_MACRO(entry == NULL, NULL, NULL); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
429 |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
678
diff
changeset
|
430 |
finfo = (HOGfileinfo *) allocator.Malloc(sizeof (HOGfileinfo)); |
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
|
431 |
BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL); |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
432 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
433 |
finfo->handle = __PHYSFS_platformOpenRead(info->filename); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
434 |
if ( (finfo->handle == NULL) || |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
435 |
(!__PHYSFS_platformSeek(finfo->handle, entry->startPos)) ) |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
436 |
{ |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
678
diff
changeset
|
437 |
allocator.Free(finfo); |
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
|
438 |
return NULL; |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
439 |
} /* if */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
440 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
441 |
finfo->curPos = 0; |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
442 |
finfo->entry = 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
|
443 |
return finfo; |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
444 |
} /* HOG_openRead */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
445 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
446 |
|
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
|
447 |
static fvoid *HOG_openWrite(dvoid *opaque, const char *name) |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
448 |
{ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
449 |
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
450 |
} /* HOG_openWrite */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
451 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
452 |
|
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
|
453 |
static fvoid *HOG_openAppend(dvoid *opaque, const char *name) |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
454 |
{ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
455 |
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
456 |
} /* HOG_openAppend */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
457 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
458 |
|
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
|
459 |
static int HOG_remove(dvoid *opaque, const char *name) |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
460 |
{ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
461 |
BAIL_MACRO(ERR_NOT_SUPPORTED, 0); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
462 |
} /* HOG_remove */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
463 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
464 |
|
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
|
465 |
static int HOG_mkdir(dvoid *opaque, const char *name) |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
466 |
{ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
467 |
BAIL_MACRO(ERR_NOT_SUPPORTED, 0); |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
468 |
} /* HOG_mkdir */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
469 |
|
658
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
470 |
|
1054
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
471 |
static int HOG_stat(fvoid *opaque, const char *filename, int *exists, |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
472 |
PHYSFS_Stat *stat) |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
473 |
{ |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
474 |
const HOGinfo *info = (const HOGinfo *) opaque; |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
475 |
const HOGentry *entry = hog_find_entry(info, filename); |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
476 |
|
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
477 |
*exists = (entry != 0); |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
478 |
if (!entry) |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
479 |
return 0; |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
480 |
|
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
481 |
stat->filesize = entry->size; |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
482 |
stat->filetype = PHYSFS_FILETYPE_REGULAR; |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
483 |
stat->modtime = info->last_mod_time; |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
484 |
stat->createtime = info->last_mod_time; |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
485 |
stat->accesstime = -1; |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
486 |
stat->readonly = 1; |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
487 |
|
1106
94c3669d0311
Fixed PHYSFS_stat()'s return value to match rest of PhysicsFS API.
Ryan C. Gordon <icculus@icculus.org>
parents:
1098
diff
changeset
|
488 |
return 1; |
1054
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
489 |
} /* HOG_stat */ |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
490 |
|
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
491 |
|
658
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
492 |
const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_HOG = |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
493 |
{ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
494 |
"HOG", |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
495 |
HOG_ARCHIVE_DESCRIPTION, |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
496 |
"Bradley Bell <btb@icculus.org>", |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
497 |
"http://icculus.org/physfs/", |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
498 |
}; |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
499 |
|
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
500 |
|
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
501 |
const PHYSFS_Archiver __PHYSFS_Archiver_HOG = |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
502 |
{ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
503 |
&__PHYSFS_ArchiveInfo_HOG, |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
504 |
HOG_isArchive, /* isArchive() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
505 |
HOG_openArchive, /* openArchive() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
506 |
HOG_enumerateFiles, /* enumerateFiles() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
507 |
HOG_exists, /* exists() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
508 |
HOG_isDirectory, /* isDirectory() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
509 |
HOG_isSymLink, /* isSymLink() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
510 |
HOG_getLastModTime, /* getLastModTime() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
511 |
HOG_openRead, /* openRead() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
512 |
HOG_openWrite, /* openWrite() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
513 |
HOG_openAppend, /* openAppend() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
514 |
HOG_remove, /* remove() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
515 |
HOG_mkdir, /* mkdir() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
516 |
HOG_dirClose, /* dirClose() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
517 |
HOG_read, /* read() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
518 |
HOG_write, /* write() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
519 |
HOG_eof, /* eof() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
520 |
HOG_tell, /* tell() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
521 |
HOG_seek, /* seek() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
522 |
HOG_fileLength, /* fileLength() method */ |
1054
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
523 |
HOG_fileClose, /* fileClose() method */ |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
524 |
HOG_stat /* stat() method */ |
658
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
525 |
}; |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
526 |
|
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
527 |
#endif /* defined PHYSFS_SUPPORTS_HOG */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
528 |
|
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
529 |
/* end of hog.c ... */ |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
530 |