src/physfs_archiver_unpacked.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 17 May 2020 01:41:52 -0400
changeset 1691 c66c9326b05d
parent 1507 8953b8a171e7
permissions -rw-r--r--
7z: Make error handling a little more robust.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/*
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
 * High-level PhysicsFS archiver for simple unpacked file formats.
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
 *
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
 * This is a framework that basic archivers build on top of. It's for simple
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
 *  formats that can just hand back a list of files and the offsets of their
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
 *  uncompressed data. There are an alarming number of formats like this.
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
 *
1463
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
     8
 * RULES: Archive entries must be uncompressed. Dirs and files allowed, but no
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
     9
 *  symlinks, etc. We can relax some of these rules as necessary.
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
 *
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
 * Please see the file LICENSE.txt in the source's root directory.
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
 *
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
 *  This file written by Ryan C. Gordon.
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
 */
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
#define __PHYSICSFS_INTERNAL__
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
#include "physfs_internal.h"
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
typedef struct
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
{
1463
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    21
    __PHYSFS_DirTree tree;
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
    PHYSFS_Io *io;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
} UNPKinfo;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
1463
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    25
typedef struct
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    26
{
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    27
    __PHYSFS_DirTreeEntry tree;
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    28
    PHYSFS_uint64 startPos;
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    29
    PHYSFS_uint64 size;
1498
5977294d8e4b unpacked: let archivers specify create and modified times, hook up to iso9660.
Ryan C. Gordon <icculus@icculus.org>
parents: 1497
diff changeset
    30
    PHYSFS_sint64 ctime;
5977294d8e4b unpacked: let archivers specify create and modified times, hook up to iso9660.
Ryan C. Gordon <icculus@icculus.org>
parents: 1497
diff changeset
    31
    PHYSFS_sint64 mtime;
1463
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    32
} UNPKentry;
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
typedef struct
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
{
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
    PHYSFS_Io *io;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
    UNPKentry *entry;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
    PHYSFS_uint32 curPos;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
} UNPKfileinfo;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
1322
5476917b8ddf Allow application-supplied archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1315
diff changeset
    42
void UNPK_closeArchive(void *opaque)
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
{
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
    UNPKinfo *info = ((UNPKinfo *) opaque);
1463
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    45
    if (info)
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    46
    {
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    47
        __PHYSFS_DirTreeDeinit(&info->tree);
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    48
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    49
        if (info->io)
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    50
            info->io->destroy(info->io);
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    51
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    52
        allocator.Free(info);
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    53
    } /* if */
1270
f8d3f58561b1 Renamed PHYSFS_Archiver::dirClose() to PHYSFS_Archiver::closeArchive().
Ryan C. Gordon <icculus@icculus.org>
parents: 1261
diff changeset
    54
} /* UNPK_closeArchive */
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
1497
b9d771d6805f unpacked: let archivers "abandon" the archive instead of closing it.
Ryan C. Gordon <icculus@icculus.org>
parents: 1495
diff changeset
    56
void UNPK_abandonArchive(void *opaque)
b9d771d6805f unpacked: let archivers "abandon" the archive instead of closing it.
Ryan C. Gordon <icculus@icculus.org>
parents: 1495
diff changeset
    57
{
b9d771d6805f unpacked: let archivers "abandon" the archive instead of closing it.
Ryan C. Gordon <icculus@icculus.org>
parents: 1495
diff changeset
    58
    UNPKinfo *info = ((UNPKinfo *) opaque);
b9d771d6805f unpacked: let archivers "abandon" the archive instead of closing it.
Ryan C. Gordon <icculus@icculus.org>
parents: 1495
diff changeset
    59
    if (info)
b9d771d6805f unpacked: let archivers "abandon" the archive instead of closing it.
Ryan C. Gordon <icculus@icculus.org>
parents: 1495
diff changeset
    60
    {
b9d771d6805f unpacked: let archivers "abandon" the archive instead of closing it.
Ryan C. Gordon <icculus@icculus.org>
parents: 1495
diff changeset
    61
        info->io = NULL;
b9d771d6805f unpacked: let archivers "abandon" the archive instead of closing it.
Ryan C. Gordon <icculus@icculus.org>
parents: 1495
diff changeset
    62
        UNPK_closeArchive(info);
b9d771d6805f unpacked: let archivers "abandon" the archive instead of closing it.
Ryan C. Gordon <icculus@icculus.org>
parents: 1495
diff changeset
    63
    } /* if */
b9d771d6805f unpacked: let archivers "abandon" the archive instead of closing it.
Ryan C. Gordon <icculus@icculus.org>
parents: 1495
diff changeset
    64
} /* UNPK_abandonArchive */
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
static PHYSFS_sint64 UNPK_read(PHYSFS_Io *io, void *buffer, PHYSFS_uint64 len)
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
{
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
    UNPKfileinfo *finfo = (UNPKfileinfo *) io->opaque;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
    const UNPKentry *entry = finfo->entry;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
    const PHYSFS_uint64 bytesLeft = (PHYSFS_uint64)(entry->size-finfo->curPos);
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
    PHYSFS_sint64 rc;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
    if (bytesLeft < len)
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
        len = bytesLeft;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
    rc = finfo->io->read(finfo->io, buffer, len);
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
    if (rc > 0)
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
        finfo->curPos += (PHYSFS_uint32) rc;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
    return rc;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
} /* UNPK_read */
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
static PHYSFS_sint64 UNPK_write(PHYSFS_Io *io, const void *b, PHYSFS_uint64 len)
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
{
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1329
diff changeset
    86
    BAIL(PHYSFS_ERR_READ_ONLY, -1);
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
} /* UNPK_write */
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
static PHYSFS_sint64 UNPK_tell(PHYSFS_Io *io)
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
{
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
    return ((UNPKfileinfo *) io->opaque)->curPos;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
} /* UNPK_tell */
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
static int UNPK_seek(PHYSFS_Io *io, PHYSFS_uint64 offset)
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
{
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
    UNPKfileinfo *finfo = (UNPKfileinfo *) io->opaque;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
    const UNPKentry *entry = finfo->entry;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
    int rc;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1329
diff changeset
   102
    BAIL_IF(offset >= entry->size, PHYSFS_ERR_PAST_EOF, 0);
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   103
    rc = finfo->io->seek(finfo->io, entry->startPos + offset);
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
    if (rc)
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   105
        finfo->curPos = (PHYSFS_uint32) offset;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
    return rc;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
} /* UNPK_seek */
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   109
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
static PHYSFS_sint64 UNPK_length(PHYSFS_Io *io)
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
{
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   113
    const UNPKfileinfo *finfo = (UNPKfileinfo *) io->opaque;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
    return ((PHYSFS_sint64) finfo->entry->size);
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
} /* UNPK_length */
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
static PHYSFS_Io *UNPK_duplicate(PHYSFS_Io *_io)
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
{
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
    UNPKfileinfo *origfinfo = (UNPKfileinfo *) _io->opaque;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
    PHYSFS_Io *io = NULL;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
    PHYSFS_Io *retval = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io));
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
    UNPKfileinfo *finfo = (UNPKfileinfo *) allocator.Malloc(sizeof (UNPKfileinfo));
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1329
diff changeset
   124
    GOTO_IF(!retval, PHYSFS_ERR_OUT_OF_MEMORY, UNPK_duplicate_failed);
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1329
diff changeset
   125
    GOTO_IF(!finfo, PHYSFS_ERR_OUT_OF_MEMORY, UNPK_duplicate_failed);
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
    io = origfinfo->io->duplicate(origfinfo->io);
1240
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1191
diff changeset
   128
    if (!io) goto UNPK_duplicate_failed;
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
    finfo->io = io;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
    finfo->entry = origfinfo->entry;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
    finfo->curPos = 0;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
    memcpy(retval, _io, sizeof (PHYSFS_Io));
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
    retval->opaque = finfo;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   134
    return retval;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   135
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
UNPK_duplicate_failed:
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   137
    if (finfo != NULL) allocator.Free(finfo);
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   138
    if (retval != NULL) allocator.Free(retval);
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
    if (io != NULL) io->destroy(io);
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
    return NULL;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
} /* UNPK_duplicate */
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
static int UNPK_flush(PHYSFS_Io *io) { return 1;  /* no write support. */ }
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
static void UNPK_destroy(PHYSFS_Io *io)
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146
{
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
    UNPKfileinfo *finfo = (UNPKfileinfo *) io->opaque;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
    finfo->io->destroy(finfo->io);
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
    allocator.Free(finfo);
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
    allocator.Free(io);
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
} /* UNPK_destroy */
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   152
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   153
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154
static const PHYSFS_Io UNPK_Io =
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
{
1280
bd174b99fa5b Add binary compatibility to PHYSFS_Io.
Ryan C. Gordon <icculus@icculus.org>
parents: 1276
diff changeset
   156
    CURRENT_PHYSFS_IO_API_VERSION, NULL,
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   157
    UNPK_read,
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
    UNPK_write,
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
    UNPK_seek,
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   160
    UNPK_tell,
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
    UNPK_length,
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   162
    UNPK_duplicate,
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
    UNPK_flush,
1280
bd174b99fa5b Add binary compatibility to PHYSFS_Io.
Ryan C. Gordon <icculus@icculus.org>
parents: 1276
diff changeset
   164
    UNPK_destroy
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
};
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
1463
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   168
static inline UNPKentry *findEntry(UNPKinfo *info, const char *path)
1261
cd5a31f4602a Moved QPAK support into archiver_unpacked.c
Ryan C. Gordon <icculus@icculus.org>
parents: 1255
diff changeset
   169
{
1463
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   170
    return (UNPKentry *) __PHYSFS_DirTreeFind(&info->tree, path);
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
} /* findEntry */
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
1329
919f885155d8 Cleaned out "exists" nonsense in openRead() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1327
diff changeset
   174
PHYSFS_Io *UNPK_openRead(void *opaque, const char *name)
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
{
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
    PHYSFS_Io *retval = NULL;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
    UNPKinfo *info = (UNPKinfo *) opaque;
1191
f02c977477b9 Fixed up some bugs that clang's static analysis reported.
Ryan C. Gordon <icculus@icculus.org>
parents: 1129
diff changeset
   178
    UNPKfileinfo *finfo = NULL;
1463
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   179
    UNPKentry *entry = findEntry(info, name);
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   180
1463
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   181
    BAIL_IF_ERRPASS(!entry, NULL);
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   182
    BAIL_IF(entry->tree.isdir, PHYSFS_ERR_NOT_A_FILE, NULL);
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   183
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
    retval = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io));
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1329
diff changeset
   185
    GOTO_IF(!retval, PHYSFS_ERR_OUT_OF_MEMORY, UNPK_openRead_failed);
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   187
    finfo = (UNPKfileinfo *) allocator.Malloc(sizeof (UNPKfileinfo));
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1329
diff changeset
   188
    GOTO_IF(!finfo, PHYSFS_ERR_OUT_OF_MEMORY, UNPK_openRead_failed);
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   189
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
    finfo->io = info->io->duplicate(info->io);
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1329
diff changeset
   191
    GOTO_IF_ERRPASS(!finfo->io, UNPK_openRead_failed);
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   192
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
    if (!finfo->io->seek(finfo->io, entry->startPos))
1240
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1191
diff changeset
   194
        goto UNPK_openRead_failed;
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
    finfo->curPos = 0;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   197
    finfo->entry = entry;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   198
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
    memcpy(retval, &UNPK_Io, sizeof (*retval));
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   200
    retval->opaque = finfo;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   201
    return retval;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
UNPK_openRead_failed:
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
    if (finfo != NULL)
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   205
    {
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
        if (finfo->io != NULL)
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   207
            finfo->io->destroy(finfo->io);
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
        allocator.Free(finfo);
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   209
    } /* if */
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   210
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   211
    if (retval != NULL)
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
        allocator.Free(retval);
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   214
    return NULL;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
} /* UNPK_openRead */
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   216
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   217
1322
5476917b8ddf Allow application-supplied archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1315
diff changeset
   218
PHYSFS_Io *UNPK_openWrite(void *opaque, const char *name)
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   219
{
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1329
diff changeset
   220
    BAIL(PHYSFS_ERR_READ_ONLY, NULL);
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   221
} /* UNPK_openWrite */
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   222
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   223
1322
5476917b8ddf Allow application-supplied archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1315
diff changeset
   224
PHYSFS_Io *UNPK_openAppend(void *opaque, const char *name)
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225
{
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1329
diff changeset
   226
    BAIL(PHYSFS_ERR_READ_ONLY, NULL);
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   227
} /* UNPK_openAppend */
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   228
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   229
1322
5476917b8ddf Allow application-supplied archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1315
diff changeset
   230
int UNPK_remove(void *opaque, const char *name)
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   231
{
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1329
diff changeset
   232
    BAIL(PHYSFS_ERR_READ_ONLY, 0);
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   233
} /* UNPK_remove */
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   234
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   235
1322
5476917b8ddf Allow application-supplied archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1315
diff changeset
   236
int UNPK_mkdir(void *opaque, const char *name)
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   237
{
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1329
diff changeset
   238
    BAIL(PHYSFS_ERR_READ_ONLY, 0);
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   239
} /* UNPK_mkdir */
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   240
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   241
1463
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   242
int UNPK_stat(void *opaque, const char *path, PHYSFS_Stat *stat)
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   243
{
1463
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   244
    UNPKinfo *info = (UNPKinfo *) opaque;
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   245
    const UNPKentry *entry = findEntry(info, path);
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   246
1463
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   247
    BAIL_IF_ERRPASS(!entry, 0);
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   248
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   249
    if (entry->tree.isdir)
1261
cd5a31f4602a Moved QPAK support into archiver_unpacked.c
Ryan C. Gordon <icculus@icculus.org>
parents: 1255
diff changeset
   250
    {
cd5a31f4602a Moved QPAK support into archiver_unpacked.c
Ryan C. Gordon <icculus@icculus.org>
parents: 1255
diff changeset
   251
        stat->filetype = PHYSFS_FILETYPE_DIRECTORY;
cd5a31f4602a Moved QPAK support into archiver_unpacked.c
Ryan C. Gordon <icculus@icculus.org>
parents: 1255
diff changeset
   252
        stat->filesize = 0;
cd5a31f4602a Moved QPAK support into archiver_unpacked.c
Ryan C. Gordon <icculus@icculus.org>
parents: 1255
diff changeset
   253
    } /* if */
1463
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   254
    else
1261
cd5a31f4602a Moved QPAK support into archiver_unpacked.c
Ryan C. Gordon <icculus@icculus.org>
parents: 1255
diff changeset
   255
    {
cd5a31f4602a Moved QPAK support into archiver_unpacked.c
Ryan C. Gordon <icculus@icculus.org>
parents: 1255
diff changeset
   256
        stat->filetype = PHYSFS_FILETYPE_REGULAR;
cd5a31f4602a Moved QPAK support into archiver_unpacked.c
Ryan C. Gordon <icculus@icculus.org>
parents: 1255
diff changeset
   257
        stat->filesize = entry->size;
cd5a31f4602a Moved QPAK support into archiver_unpacked.c
Ryan C. Gordon <icculus@icculus.org>
parents: 1255
diff changeset
   258
    } /* else */
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   259
1498
5977294d8e4b unpacked: let archivers specify create and modified times, hook up to iso9660.
Ryan C. Gordon <icculus@icculus.org>
parents: 1497
diff changeset
   260
    stat->modtime = entry->mtime;
5977294d8e4b unpacked: let archivers specify create and modified times, hook up to iso9660.
Ryan C. Gordon <icculus@icculus.org>
parents: 1497
diff changeset
   261
    stat->createtime = entry->ctime;
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   262
    stat->accesstime = -1;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   263
    stat->readonly = 1;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   264
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   265
    return 1;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   266
} /* UNPK_stat */
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   267
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   268
1463
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   269
void *UNPK_addEntry(void *opaque, char *name, const int isdir,
1498
5977294d8e4b unpacked: let archivers specify create and modified times, hook up to iso9660.
Ryan C. Gordon <icculus@icculus.org>
parents: 1497
diff changeset
   270
                    const PHYSFS_sint64 ctime, const PHYSFS_sint64 mtime,
1463
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   271
                    const PHYSFS_uint64 pos, const PHYSFS_uint64 len)
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   272
{
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   273
    UNPKinfo *info = (UNPKinfo *) opaque;
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   274
    UNPKentry *entry;
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   275
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   276
    entry = (UNPKentry *) __PHYSFS_DirTreeAdd(&info->tree, name, isdir);
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   277
    BAIL_IF_ERRPASS(!entry, NULL);
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   278
1495
2ac61188ad60 unpacked: Don't list a position or length for directory entries.
Ryan C. Gordon <icculus@icculus.org>
parents: 1494
diff changeset
   279
    entry->startPos = isdir ? 0 : pos;
2ac61188ad60 unpacked: Don't list a position or length for directory entries.
Ryan C. Gordon <icculus@icculus.org>
parents: 1494
diff changeset
   280
    entry->size = isdir ? 0 : len;
1498
5977294d8e4b unpacked: let archivers specify create and modified times, hook up to iso9660.
Ryan C. Gordon <icculus@icculus.org>
parents: 1497
diff changeset
   281
    entry->ctime = ctime;
5977294d8e4b unpacked: let archivers specify create and modified times, hook up to iso9660.
Ryan C. Gordon <icculus@icculus.org>
parents: 1497
diff changeset
   282
    entry->mtime = mtime;
1463
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   283
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   284
    return entry;
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   285
} /* UNPK_addEntry */
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   286
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   287
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
   288
void *UNPK_openArchive(PHYSFS_Io *io)
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   289
{
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   290
    UNPKinfo *info = (UNPKinfo *) allocator.Malloc(sizeof (UNPKinfo));
1463
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   291
    BAIL_IF(!info, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   292
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
   293
    if (!__PHYSFS_DirTreeInit(&info->tree, sizeof (UNPKentry)))
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   294
    {
1463
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   295
        allocator.Free(info);
c23e55bad32d Reworked the "unpacked" archivers to use DirTree.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   296
        return NULL;
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   297
    } /* if */
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   298
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   299
    info->io = io;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   300
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   301
    return info;
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   302
} /* UNPK_openArchive */
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   303
1507
8953b8a171e7 Update filename comments.
Ryan C. Gordon <icculus@icculus.org>
parents: 1506
diff changeset
   304
/* end of physfs_archiver_unpacked.c ... */
1128
067d8e76261e Moved most the cut-and-paste between simple archivers to one file.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   305