src/physfs_archiver_vdf.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 17 May 2020 01:41:52 -0400
changeset 1691 c66c9326b05d
parent 1599 463b79e656c4
permissions -rw-r--r--
7z: Make error handling a little more robust.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1391
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
     1
/*
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
     2
 * VDF support routines for PhysicsFS.
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
     3
 *
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
     4
 * This driver handles Gothic I/II VDF archives.
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
     5
 * This format (but not this driver) was designed by Piranha Bytes for
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
     6
 *  use wih the ZenGin engine.
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
     7
 *
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
     8
 * This file was written by Francesco Bertolaccini, based on the UNPK archiver
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
     9
 *  by Ryan C. Gordon and the works of degenerated1123 and Nico Bendlin.
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
    10
 */
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
    11
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
    12
#define __PHYSICSFS_INTERNAL__
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
    13
#include "physfs_internal.h"
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
    14
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
    15
#if PHYSFS_SUPPORTS_VDF
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
    16
1503
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    17
#include <time.h>
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    18
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    19
#define VDF_COMMENT_LENGTH 256
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    20
#define VDF_SIGNATURE_LENGTH 16
1391
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
    21
#define VDF_ENTRY_NAME_LENGTH 64
1599
463b79e656c4 vdf: Don't add directories; UNPK_addEntry()/DirTree will fill in parents.
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents: 1571
diff changeset
    22
#define VDF_ENTRY_DIR 0x80000000
1391
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
    23
1449
6df9e1a43f7c Cleaned up what symbols are exported from the library.
Ryan C. Gordon <icculus@icculus.org>
parents: 1439
diff changeset
    24
static const char* VDF_SIGNATURE_G1 = "PSVDSC_V2.00\r\n\r\n";
6df9e1a43f7c Cleaned up what symbols are exported from the library.
Ryan C. Gordon <icculus@icculus.org>
parents: 1439
diff changeset
    25
static const char* VDF_SIGNATURE_G2 = "PSVDSC_V2.00\n\r\n\r";
1391
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
    26
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
    27
1503
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    28
static inline int readui32(PHYSFS_Io *io, PHYSFS_uint32 *val)
1391
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
    29
{
1503
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    30
    PHYSFS_uint32 v;
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    31
    BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &v, sizeof (v)), 0);
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    32
    *val = PHYSFS_swapULE32(v);
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    33
    return 1;
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    34
} /* readui32 */
1391
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
    35
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
    36
1503
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    37
static PHYSFS_sint64 vdfDosTimeToEpoch(const PHYSFS_uint32 dostime)
1391
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
    38
{
1503
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    39
    /* VDF stores timestamps as 32bit DOS dates: the seconds are counted in
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    40
       2-seconds intervals and the years are counted since 1 Jan. 1980 */
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    41
    struct tm t;
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    42
    memset(&t, '\0', sizeof (t));
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    43
    t.tm_year = ((int) ((dostime >> 25) & 0x7F)) + 80; /* 1980 to 1900 */
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    44
    t.tm_mon = ((int) ((dostime >> 21) & 0xF)) - 1;  /* 1-12 to 0-11 */
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    45
    t.tm_mday = (int) ((dostime >> 16) & 0x1F);
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    46
    t.tm_hour = (int) ((dostime >> 11) & 0x1F);
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    47
    t.tm_min = (int) ((dostime >> 5) & 0x3F);
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    48
    t.tm_sec = ((int) ((dostime >> 0) & 0x1F)) * 2;  /* 2 seconds to 1. */
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    49
    return (PHYSFS_sint64) mktime(&t);
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    50
} /* vdfDosTimeToEpoch */
1391
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
    51
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
    52
1503
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    53
static int vdfLoadEntries(PHYSFS_Io *io, const PHYSFS_uint32 count,
1504
803282f78987 Minor code cleanups: whitespace fixes, 80-column overflows, wrong comments.
Ryan C. Gordon <icculus@icculus.org>
parents: 1503
diff changeset
    54
                          const PHYSFS_sint64 ts, void *arc)
1391
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
    55
{
1503
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    56
    PHYSFS_uint32 i;
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    57
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    58
    for (i = 0; i < count; i++)
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    59
    {
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    60
        char name[VDF_ENTRY_NAME_LENGTH + 1];
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    61
        int namei;
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    62
        PHYSFS_uint32 jump, size, type, attr;
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    63
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    64
        BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, name, sizeof (name) - 1), 0);
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    65
        BAIL_IF_ERRPASS(!readui32(io, &jump), 0);
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    66
        BAIL_IF_ERRPASS(!readui32(io, &size), 0);
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    67
        BAIL_IF_ERRPASS(!readui32(io, &type), 0);
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    68
        BAIL_IF_ERRPASS(!readui32(io, &attr), 0);
1391
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
    69
1503
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    70
        /* Trim whitespace off the end of the filename */
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    71
        name[VDF_ENTRY_NAME_LENGTH] = '\0';  /* always null-terminated. */
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    72
        for (namei = VDF_ENTRY_NAME_LENGTH - 1; namei >= 0; namei--)
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    73
        {
1569
2d7183f702ed Sanity check archivers that should only have low-ASCII filename.
Ryan C. Gordon <icculus@icculus.org>
parents: 1559
diff changeset
    74
            /* We assume the filenames are low-ASCII; consider the archive
2d7183f702ed Sanity check archivers that should only have low-ASCII filename.
Ryan C. Gordon <icculus@icculus.org>
parents: 1559
diff changeset
    75
               corrupt if we see something above 127, since we don't know the
2d7183f702ed Sanity check archivers that should only have low-ASCII filename.
Ryan C. Gordon <icculus@icculus.org>
parents: 1559
diff changeset
    76
               encoding. (We can change this later if we find out these exist
2d7183f702ed Sanity check archivers that should only have low-ASCII filename.
Ryan C. Gordon <icculus@icculus.org>
parents: 1559
diff changeset
    77
               and are intended to be, say, latin-1 or UTF-8 encoding). */
2d7183f702ed Sanity check archivers that should only have low-ASCII filename.
Ryan C. Gordon <icculus@icculus.org>
parents: 1559
diff changeset
    78
            BAIL_IF(((PHYSFS_uint8) name[namei]) > 127, PHYSFS_ERR_CORRUPT, 0);
2d7183f702ed Sanity check archivers that should only have low-ASCII filename.
Ryan C. Gordon <icculus@icculus.org>
parents: 1559
diff changeset
    79
1503
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    80
            if (name[namei] == ' ')
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    81
                name[namei] = '\0';
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    82
            else
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    83
                break;
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    84
        } /* for */
1391
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
    85
1503
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    86
        BAIL_IF(!name[0], PHYSFS_ERR_CORRUPT, 0);
1599
463b79e656c4 vdf: Don't add directories; UNPK_addEntry()/DirTree will fill in parents.
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents: 1571
diff changeset
    87
        if (!(type & VDF_ENTRY_DIR)) {
463b79e656c4 vdf: Don't add directories; UNPK_addEntry()/DirTree will fill in parents.
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents: 1571
diff changeset
    88
            BAIL_IF_ERRPASS(!UNPK_addEntry(arc, name, 0, ts, ts, jump, size), 0);
463b79e656c4 vdf: Don't add directories; UNPK_addEntry()/DirTree will fill in parents.
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents: 1571
diff changeset
    89
        }
1391
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
    90
    } /* for */
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
    91
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
    92
    return 1;
1503
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    93
} /* vdfLoadEntries */
1391
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
    94
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
    95
1571
fbd9698219c1 Archivers can now specify whether an archive definitely was intended for them.
Ryan C. Gordon <icculus@icculus.org>
parents: 1569
diff changeset
    96
static void *VDF_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: 1569
diff changeset
    97
                             int forWriting, int *claimed)
1391
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
    98
{
1503
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
    99
    PHYSFS_uint8 ignore[16];
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
   100
    PHYSFS_uint8 sig[VDF_SIGNATURE_LENGTH];
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
   101
    PHYSFS_uint32 count, timestamp, version, dataSize, rootCatOffset;
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
   102
    void *unpkarc;
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
   103
1391
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
   104
    assert(io != NULL); /* shouldn't ever happen. */
1599
463b79e656c4 vdf: Don't add directories; UNPK_addEntry()/DirTree will fill in parents.
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents: 1571
diff changeset
   105
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1394
diff changeset
   106
    BAIL_IF(forWriting, PHYSFS_ERR_READ_ONLY, NULL);
1503
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
   107
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
   108
    /* skip the 256-byte comment field. */
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
   109
    BAIL_IF_ERRPASS(!io->seek(io, VDF_COMMENT_LENGTH), NULL);
1394
1bf095c96aca vdf: Remove unused chunks of code, fix endianness.
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents: 1391
diff changeset
   110
1503
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
   111
    BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, sig, sizeof (sig)), NULL);
1571
fbd9698219c1 Archivers can now specify whether an archive definitely was intended for them.
Ryan C. Gordon <icculus@icculus.org>
parents: 1569
diff changeset
   112
fbd9698219c1 Archivers can now specify whether an archive definitely was intended for them.
Ryan C. Gordon <icculus@icculus.org>
parents: 1569
diff changeset
   113
    if ((memcmp(sig, VDF_SIGNATURE_G1, VDF_SIGNATURE_LENGTH) != 0) &&
fbd9698219c1 Archivers can now specify whether an archive definitely was intended for them.
Ryan C. Gordon <icculus@icculus.org>
parents: 1569
diff changeset
   114
        (memcmp(sig, VDF_SIGNATURE_G2, VDF_SIGNATURE_LENGTH) != 0))
fbd9698219c1 Archivers can now specify whether an archive definitely was intended for them.
Ryan C. Gordon <icculus@icculus.org>
parents: 1569
diff changeset
   115
    {
fbd9698219c1 Archivers can now specify whether an archive definitely was intended for them.
Ryan C. Gordon <icculus@icculus.org>
parents: 1569
diff changeset
   116
        BAIL(PHYSFS_ERR_UNSUPPORTED, NULL);
fbd9698219c1 Archivers can now specify whether an archive definitely was intended for them.
Ryan C. Gordon <icculus@icculus.org>
parents: 1569
diff changeset
   117
    } /* if */
fbd9698219c1 Archivers can now specify whether an archive definitely was intended for them.
Ryan C. Gordon <icculus@icculus.org>
parents: 1569
diff changeset
   118
fbd9698219c1 Archivers can now specify whether an archive definitely was intended for them.
Ryan C. Gordon <icculus@icculus.org>
parents: 1569
diff changeset
   119
    *claimed = 1;
fbd9698219c1 Archivers can now specify whether an archive definitely was intended for them.
Ryan C. Gordon <icculus@icculus.org>
parents: 1569
diff changeset
   120
1503
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
   121
    BAIL_IF_ERRPASS(!readui32(io, &count), NULL);
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
   122
    BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, ignore, 4), NULL);  /* numFiles */
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
   123
    BAIL_IF_ERRPASS(!readui32(io, &timestamp), NULL);
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
   124
    BAIL_IF_ERRPASS(!readui32(io, &dataSize), NULL);  /* dataSize */
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
   125
    BAIL_IF_ERRPASS(!readui32(io, &rootCatOffset), NULL);  /* rootCatOff */
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
   126
    BAIL_IF_ERRPASS(!readui32(io, &version), NULL);
1394
1bf095c96aca vdf: Remove unused chunks of code, fix endianness.
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents: 1391
diff changeset
   127
1503
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
   128
    BAIL_IF(version != 0x50, PHYSFS_ERR_UNSUPPORTED, NULL);
1391
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
   129
1503
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
   130
    BAIL_IF_ERRPASS(!io->seek(io, rootCatOffset), NULL);
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
   131
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
   132
    unpkarc = UNPK_openArchive(io);
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
   133
    BAIL_IF_ERRPASS(!unpkarc, NULL);
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
   134
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
   135
    if (!vdfLoadEntries(io, count, vdfDosTimeToEpoch(timestamp), unpkarc))
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
   136
    {
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
   137
        UNPK_abandonArchive(unpkarc);
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
   138
        return NULL;
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
   139
    } /* if */
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
   140
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
   141
    return unpkarc;
1391
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
   142
} /* VDF_openArchive */
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
   143
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
   144
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
   145
const PHYSFS_Archiver __PHYSFS_Archiver_VDF =
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
   146
{
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
   147
    CURRENT_PHYSFS_ARCHIVER_API_VERSION,
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
   148
    {
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
   149
        "VDF",
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
   150
        "Gothic I/II engine format",
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
   151
        "Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>",
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
   152
        "https://github.com/frabert",
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
   153
        0,  /* supportsSymlinks */
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
   154
    },
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
   155
    VDF_openArchive,
1559
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   156
    UNPK_enumerate,
1503
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
   157
    UNPK_openRead,
1391
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
   158
    UNPK_openWrite,
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
   159
    UNPK_openAppend,
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
   160
    UNPK_remove,
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
   161
    UNPK_mkdir,
1503
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
   162
    UNPK_stat,
5e0afac26199 vdf: Migrated to new, improved unpacked archiver infrastructure.
Ryan C. Gordon <icculus@icculus.org>
parents: 1449
diff changeset
   163
    UNPK_closeArchive
1391
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
   164
};
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
   165
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
   166
#endif /* defined PHYSFS_SUPPORTS_VDF */
06aa5aca8518 Add support for VDF
Francesco Bertolaccini <bertolaccinifrancesco@gmail.com>
parents:
diff changeset
   167
1507
8953b8a171e7 Update filename comments.
Ryan C. Gordon <icculus@icculus.org>
parents: 1506
diff changeset
   168
/* end of physfs_archiver_vdf.c ... */