Skip to content

Latest commit

 

History

History
112 lines (93 loc) · 2.95 KB

archiver_hog.c

File metadata and controls

112 lines (93 loc) · 2.95 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*
* HOG support routines for PhysicsFS.
*
* This driver handles Descent I/II HOG archives.
*
* The format is very simple:
*
* The file always starts with the 3-byte signature "DHF" (Descent
* HOG file). After that the files of a HOG are just attached after
* another, divided by a 17 bytes header, which specifies the name
* and length (in bytes) of the forthcoming file! So you just read
* the header with its information of how big the following file is,
* and then skip exact that number of bytes to get to the next file
* in that HOG.
*
* char sig[3] = {'D', 'H', 'F'}; // "DHF"=Descent HOG File
*
* struct {
* char file_name[13]; // Filename, padded to 13 bytes with 0s
* int file_size; // filesize in bytes
* char data[file_size]; // The file data
* } FILE_STRUCT; // Repeated until the end of the file.
*
* (That info is from http://www.descent2.com/ddn/specs/hog/)
*
Mar 11, 2007
Mar 11, 2007
26
* Please see the file LICENSE.txt in the source's root directory.
27
28
29
30
31
32
33
34
*
* This file written by Bradley Bell.
* Based on grp.c by Ryan C. Gordon.
*/
#define __PHYSICSFS_INTERNAL__
#include "physfs_internal.h"
Mar 23, 2012
Mar 23, 2012
35
36
#if PHYSFS_SUPPORTS_HOG
Jul 16, 2017
Jul 16, 2017
37
static int hogLoadEntries(PHYSFS_Io *io, void *unpkarc)
Aug 30, 2010
Aug 30, 2010
39
40
41
42
const PHYSFS_uint64 iolen = io->length(io);
PHYSFS_uint32 pos = 3;
while (pos < iolen)
Jul 16, 2017
Jul 16, 2017
44
45
46
47
48
49
50
51
52
PHYSFS_uint32 size;
char name[13];
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, name, 13), 0);
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &size, 4), 0);
name[12] = '\0'; /* just in case. */
pos += 13 + 4;
size = PHYSFS_swapULE32(size);
Jul 22, 2017
Jul 22, 2017
53
BAIL_IF_ERRPASS(!UNPK_addEntry(unpkarc, name, 0, -1, -1, pos, size), 0);
Aug 30, 2010
Aug 30, 2010
54
55
pos += size;
Sep 6, 2010
Sep 6, 2010
56
/* skip over entry */
Jul 16, 2017
Jul 16, 2017
57
BAIL_IF_ERRPASS(!io->seek(io, pos), 0);
Sep 6, 2010
Sep 6, 2010
58
} /* while */
Jul 16, 2017
Jul 16, 2017
60
return 1;
Sep 6, 2010
Sep 6, 2010
61
} /* hogLoadEntries */
Aug 30, 2010
Aug 30, 2010
64
static void *HOG_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
Aug 30, 2010
Aug 30, 2010
66
PHYSFS_uint8 buf[3];
Mar 9, 2012
Mar 9, 2012
67
PHYSFS_uint32 count = 0;
Jul 16, 2017
Jul 16, 2017
68
void *unpkarc = NULL;
Aug 30, 2010
Aug 30, 2010
70
assert(io != NULL); /* shouldn't ever happen. */
Jul 6, 2017
Jul 6, 2017
71
72
73
BAIL_IF(forWriting, PHYSFS_ERR_READ_ONLY, NULL);
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, buf, 3), NULL);
BAIL_IF(memcmp(buf, "DHF", 3) != 0, PHYSFS_ERR_UNSUPPORTED, NULL);
Sep 26, 2004
Sep 26, 2004
74
Jul 21, 2017
Jul 21, 2017
75
unpkarc = UNPK_openArchive(io);
Jul 16, 2017
Jul 16, 2017
76
77
78
79
BAIL_IF_ERRPASS(!unpkarc, NULL);
if (!hogLoadEntries(io, unpkarc))
{
Jul 21, 2017
Jul 21, 2017
80
UNPK_abandonArchive(unpkarc);
Jul 16, 2017
Jul 16, 2017
81
82
83
84
return NULL;
} /* if */
return unpkarc;
85
86
87
} /* HOG_openArchive */
Sep 29, 2004
Sep 29, 2004
88
89
const PHYSFS_Archiver __PHYSFS_Archiver_HOG =
{
Nov 28, 2012
Nov 28, 2012
90
CURRENT_PHYSFS_ARCHIVER_API_VERSION,
Mar 25, 2012
Mar 25, 2012
91
92
93
94
{
"HOG",
"Descent I/II HOG file format",
"Bradley Bell <btb@icculus.org>",
Feb 25, 2016
Feb 25, 2016
95
"https://icculus.org/physfs/",
Nov 30, 2012
Nov 30, 2012
96
0, /* supportsSymlinks */
Mar 25, 2012
Mar 25, 2012
97
},
Nov 30, 2012
Nov 30, 2012
98
99
100
101
102
103
104
HOG_openArchive,
UNPK_enumerateFiles,
UNPK_openRead,
UNPK_openWrite,
UNPK_openAppend,
UNPK_remove,
UNPK_mkdir,
Nov 30, 2012
Nov 30, 2012
105
106
UNPK_stat,
UNPK_closeArchive
Sep 29, 2004
Sep 29, 2004
107
108
};
109
110
#endif /* defined PHYSFS_SUPPORTS_HOG */
Nov 27, 2012
Nov 27, 2012
111
/* end of archiver_hog.c ... */