src/physfs_archiver_hog.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 17 May 2020 01:41:52 -0400
changeset 1691 c66c9326b05d
parent 1673 3d3c9d9386a8
permissions -rw-r--r--
7z: Make error handling a little more robust.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
 *
1672
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
     4
 * This driver handles Descent I/II/III HOG archives.
553
4338d9c0bbcd Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
 *
1672
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
     6
 * The Descent I/II format is very simple:
553
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
 *
1672
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    26
 * Descent 3 moved to HOG2 format, which starts with the chars "HOG2",
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    27
 *  then 32-bits for the number of contained files, 32 bits for the offset
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    28
 *  to the first file's data, then 56 bytes of 0xFF (reserved?). Then for
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    29
 *  each file, there's 36 bytes for filename (null-terminated, rest of bytes
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    30
 *  are garbage), 32-bits unknown/reserved (always zero?), 32-bits of length
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    31
 *  of file data, 32-bits of time since Unix epoch. Then immediately following,
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    32
 *  for each file is their uncompressed content, you can find its offset
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    33
 *  by starting at the initial data offset and adding the filesize of each
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    34
 *  prior file.
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    35
 *
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    36
 * This information was found at:
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    37
 *  https://web.archive.org/web/20020213004051/http://descent-3.com/ddn/specs/hog/
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    38
 *
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    39
 *
809
116b8fe30371 Renamed LICENSE to LICENSE.txt
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
    40
 * 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
    41
 *
1672
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    42
 * This file written by Bradley Bell and Ryan C. Gordon.
553
4338d9c0bbcd Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
 */
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
#define __PHYSICSFS_INTERNAL__
4338d9c0bbcd Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
#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
    47
1258
074d08049aa7 Changed so that this builds a reasonable default with no command line #defines.
Ryan C. Gordon <icculus@icculus.org>
parents: 1240
diff changeset
    48
#if PHYSFS_SUPPORTS_HOG
074d08049aa7 Changed so that this builds a reasonable default with no command line #defines.
Ryan C. Gordon <icculus@icculus.org>
parents: 1240
diff changeset
    49
1672
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    50
static int readui32(PHYSFS_Io *io, PHYSFS_uint32 *val)
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    51
{
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    52
    PHYSFS_uint32 v;
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    53
    BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &v, sizeof (v)), 0);
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    54
    *val = PHYSFS_swapULE32(v);
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    55
    return 1;
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    56
} /* readui32 */
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    57
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    58
static int hog1LoadEntries(PHYSFS_Io *io, void *arc)
553
4338d9c0bbcd Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
{
1118
2e09fc635fdd Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 1115
diff changeset
    60
    const PHYSFS_uint64 iolen = io->length(io);
2e09fc635fdd Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 1115
diff changeset
    61
    PHYSFS_uint32 pos = 3;
553
4338d9c0bbcd Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
1118
2e09fc635fdd Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 1115
diff changeset
    63
    while (pos < iolen)
553
4338d9c0bbcd Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
    {
1463
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    65
        PHYSFS_uint32 size;
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    66
        char name[13];
553
4338d9c0bbcd Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
1463
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    68
        BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, name, 13), 0);
1672
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    69
        BAIL_IF_ERRPASS(!readui32(io, &size), 0);
1463
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    70
        name[12] = '\0';  /* just in case. */
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    71
        pos += 13 + 4;
1098
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
    72
1504
803282f78987 Minor code cleanups: whitespace fixes, 80-column overflows, wrong comments.
Ryan C. Gordon <icculus@icculus.org>
parents: 1499
diff changeset
    73
        BAIL_IF_ERRPASS(!UNPK_addEntry(arc, name, 0, -1, -1, pos, size), 0);
1118
2e09fc635fdd Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 1115
diff changeset
    74
        pos += size;
2e09fc635fdd Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 1115
diff changeset
    75
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
    76
        /* skip over entry */
1463
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    77
        BAIL_IF_ERRPASS(!io->seek(io, pos), 0);
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
    78
    } /* while */
553
4338d9c0bbcd Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
1463
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    80
    return 1;
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
    81
} /* hogLoadEntries */
553
4338d9c0bbcd Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
1672
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    83
static int hog2LoadEntries(PHYSFS_Io *io, void *arc)
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    84
{
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    85
    PHYSFS_uint32 numfiles;
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    86
    PHYSFS_uint32 pos;
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    87
    PHYSFS_uint32 i;
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    88
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    89
    BAIL_IF_ERRPASS(!readui32(io, &numfiles), 0);
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    90
    BAIL_IF_ERRPASS(!readui32(io, &pos), 0);
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    91
    BAIL_IF_ERRPASS(!io->seek(io, 68), 0);  /* skip to end of header. */
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    92
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    93
    for (i = 0; i < numfiles; i++) {
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    94
        char name[37];
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    95
        PHYSFS_uint32 reserved;
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    96
        PHYSFS_uint32 size;
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    97
        PHYSFS_uint32 mtime;
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    98
        BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, name, 36), 0);
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
    99
        BAIL_IF_ERRPASS(!readui32(io, &reserved), 0);
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
   100
        BAIL_IF_ERRPASS(!readui32(io, &size), 0);
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
   101
        BAIL_IF_ERRPASS(!readui32(io, &mtime), 0);
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
   102
        name[36] = '\0';  /* just in case */
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
   103
        BAIL_IF_ERRPASS(!UNPK_addEntry(arc, name, 0, mtime, mtime, pos, size), 0);
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
   104
        pos += size;
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
   105
    }
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
   106
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
   107
    return 1;
1673
3d3c9d9386a8 Fixed comment typo.
Ryan C. Gordon <icculus@icculus.org>
parents: 1672
diff changeset
   108
} /* hog2LoadEntries */
1672
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
   109
553
4338d9c0bbcd Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
1571
fbd9698219c1 Archivers can now specify whether an archive definitely was intended for them.
Ryan C. Gordon <icculus@icculus.org>
parents: 1559
diff changeset
   111
static void *HOG_openArchive(PHYSFS_Io *io, const char *name,
fbd9698219c1 Archivers can now specify whether an archive definitely was intended for them.
Ryan C. Gordon <icculus@icculus.org>
parents: 1559
diff changeset
   112
                             int forWriting, int *claimed)
553
4338d9c0bbcd Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   113
{
1118
2e09fc635fdd Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 1115
diff changeset
   114
    PHYSFS_uint8 buf[3];
1463
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   115
    void *unpkarc = NULL;
1672
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
   116
    int hog1 = 0;
1118
2e09fc635fdd Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 1115
diff changeset
   117
2e09fc635fdd Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 1115
diff changeset
   118
    assert(io != NULL);  /* shouldn't ever happen. */
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1373
diff changeset
   119
    BAIL_IF(forWriting, PHYSFS_ERR_READ_ONLY, NULL);
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1373
diff changeset
   120
    BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, buf, 3), NULL);
1672
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
   121
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
   122
    if (memcmp(buf, "DHF", 3) == 0)
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
   123
        hog1 = 1;  /* original HOG (Descent 1 and 2) archive */
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
   124
    else
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
   125
    {
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
   126
        BAIL_IF(memcmp(buf, "HOG", 3) != 0, PHYSFS_ERR_UNSUPPORTED, NULL); /* Not HOG2 */
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
   127
        BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, buf, 1), NULL);
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
   128
        BAIL_IF(buf[0] != '2', PHYSFS_ERR_UNSUPPORTED, NULL); /* Not HOG2 */
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
   129
    } /* else */
553
4338d9c0bbcd Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
1571
fbd9698219c1 Archivers can now specify whether an archive definitely was intended for them.
Ryan C. Gordon <icculus@icculus.org>
parents: 1559
diff changeset
   131
    *claimed = 1;
fbd9698219c1 Archivers can now specify whether an archive definitely was intended for them.
Ryan C. Gordon <icculus@icculus.org>
parents: 1559
diff changeset
   132
1494
4e2c7ce9bf11 DirTrees and unpacked archives shouldn't demand a count of entries for init.
Ryan C. Gordon <icculus@icculus.org>
parents: 1463
diff changeset
   133
    unpkarc = UNPK_openArchive(io);
1463
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   134
    BAIL_IF_ERRPASS(!unpkarc, NULL);
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   135
1672
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
   136
    if (!(hog1 ? hog1LoadEntries(io, unpkarc) : hog2LoadEntries(io, unpkarc)))
1463
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   137
    {
1497
b9d771d6805f unpacked: let archivers "abandon" the archive instead of closing it.
Ryan C. Gordon <icculus@icculus.org>
parents: 1494
diff changeset
   138
        UNPK_abandonArchive(unpkarc);
1463
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   139
        return NULL;
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   140
    } /* if */
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   141
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   142
    return unpkarc;
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
   143
} /* HOG_openArchive */
1054
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   144
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   145
658
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   146
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
   147
{
1322
5476917b8ddf Allow application-supplied archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1320
diff changeset
   148
    CURRENT_PHYSFS_ARCHIVER_API_VERSION,
1281
cd136b8d3b1a Moved PHYSFS_ArchiveInfo into PHYSFS_Archiver.
Ryan C. Gordon <icculus@icculus.org>
parents: 1270
diff changeset
   149
    {
cd136b8d3b1a Moved PHYSFS_ArchiveInfo into PHYSFS_Archiver.
Ryan C. Gordon <icculus@icculus.org>
parents: 1270
diff changeset
   150
        "HOG",
1672
48deae7ff957 hog: Added support for HOG2 (Descent 3) archives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
   151
        "Descent I/II/III HOG file format",
1281
cd136b8d3b1a Moved PHYSFS_ArchiveInfo into PHYSFS_Archiver.
Ryan C. Gordon <icculus@icculus.org>
parents: 1270
diff changeset
   152
        "Bradley Bell <btb@icculus.org>",
1373
527ef3c6a2d6 HTTPS all the things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1331
diff changeset
   153
        "https://icculus.org/physfs/",
1326
ac0fac4fe6d6 Moved supportsSymlinks into PHYSFS_ArchiveInfo.
Ryan C. Gordon <icculus@icculus.org>
parents: 1324
diff changeset
   154
        0,  /* supportsSymlinks */
1281
cd136b8d3b1a Moved PHYSFS_ArchiveInfo into PHYSFS_Archiver.
Ryan C. Gordon <icculus@icculus.org>
parents: 1270
diff changeset
   155
    },
1330
ce6b4a66b3eb Removed comments added by Captain Obvious.
Ryan C. Gordon <icculus@icculus.org>
parents: 1326
diff changeset
   156
    HOG_openArchive,
1559
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1507
diff changeset
   157
    UNPK_enumerate,
1330
ce6b4a66b3eb Removed comments added by Captain Obvious.
Ryan C. Gordon <icculus@icculus.org>
parents: 1326
diff changeset
   158
    UNPK_openRead,
ce6b4a66b3eb Removed comments added by Captain Obvious.
Ryan C. Gordon <icculus@icculus.org>
parents: 1326
diff changeset
   159
    UNPK_openWrite,
ce6b4a66b3eb Removed comments added by Captain Obvious.
Ryan C. Gordon <icculus@icculus.org>
parents: 1326
diff changeset
   160
    UNPK_openAppend,
ce6b4a66b3eb Removed comments added by Captain Obvious.
Ryan C. Gordon <icculus@icculus.org>
parents: 1326
diff changeset
   161
    UNPK_remove,
ce6b4a66b3eb Removed comments added by Captain Obvious.
Ryan C. Gordon <icculus@icculus.org>
parents: 1326
diff changeset
   162
    UNPK_mkdir,
1331
eb06a37afa7e Rearranged PHYSFS_Archiver struct.
Ryan C. Gordon <icculus@icculus.org>
parents: 1330
diff changeset
   163
    UNPK_stat,
eb06a37afa7e Rearranged PHYSFS_Archiver struct.
Ryan C. Gordon <icculus@icculus.org>
parents: 1330
diff changeset
   164
    UNPK_closeArchive
658
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   165
};
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   166
553
4338d9c0bbcd Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
#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
   168
1507
8953b8a171e7 Update filename comments.
Ryan C. Gordon <icculus@icculus.org>
parents: 1506
diff changeset
   169
/* end of physfs_archiver_hog.c ... */
553
4338d9c0bbcd Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170