src/physfs_archiver_7z.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 17 May 2020 01:41:52 -0400
changeset 1691 c66c9326b05d
parent 1689 1dc6e265fefc
permissions -rw-r--r--
7z: Make error handling a little more robust.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1471
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/*
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
 * 7zip support routines for PhysicsFS.
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
 *
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
 * Please see the file LICENSE.txt in the source's root directory.
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
 *
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
 *  This file was written by Ryan C. Gordon.
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
 */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
#define __PHYSICSFS_INTERNAL__
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
#include "physfs_internal.h"
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
#if PHYSFS_SUPPORTS_7Z
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
#include "physfs_lzmasdk.h"
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
typedef struct
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
{
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
    ISeekInStream seekStream; /* lzma sdk i/o interface (lower level).  */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
    PHYSFS_Io *io;            /* physfs i/o interface for this archive. */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
    CLookToRead lookStream;   /* lzma sdk i/o interface (higher level). */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
} SZIPLookToRead;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
/* One SZIPentry is kept for each file in an open 7zip archive. */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
typedef struct
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
{
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
    __PHYSFS_DirTreeEntry tree;   /* manages directory tree         */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
    PHYSFS_uint32 dbidx;          /* index into lzma sdk database   */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
} SZIPentry;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
/* One SZIPinfo is kept for each open 7zip archive. */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
typedef struct
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
{
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
    __PHYSFS_DirTree tree;    /* manages directory tree.           */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
    PHYSFS_Io *io;            /* physfs i/o interface for this archive. */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
    CSzArEx db;               /* lzma sdk archive database object. */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
} SZIPinfo;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
static PHYSFS_ErrorCode szipErrorCode(const SRes rc)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
{
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
    switch (rc)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
    {
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
        case SZ_OK: return PHYSFS_ERR_OK;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
        case SZ_ERROR_DATA: return PHYSFS_ERR_CORRUPT;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
        case SZ_ERROR_MEM: return PHYSFS_ERR_OUT_OF_MEMORY;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
        case SZ_ERROR_CRC: return PHYSFS_ERR_CORRUPT;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
        case SZ_ERROR_UNSUPPORTED: return PHYSFS_ERR_UNSUPPORTED;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
        case SZ_ERROR_INPUT_EOF: return PHYSFS_ERR_CORRUPT;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
        case SZ_ERROR_OUTPUT_EOF: return PHYSFS_ERR_IO;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
        case SZ_ERROR_READ: return PHYSFS_ERR_IO;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
        case SZ_ERROR_WRITE: return PHYSFS_ERR_IO;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
        case SZ_ERROR_ARCHIVE: return PHYSFS_ERR_CORRUPT;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
        case SZ_ERROR_NO_ARCHIVE: return PHYSFS_ERR_UNSUPPORTED;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
        default: break;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
    } /* switch */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
    return PHYSFS_ERR_OTHER_ERROR;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
} /* szipErrorCode */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
/* LZMA SDK's ISzAlloc interface ... */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
static void *SZIP_ISzAlloc_Alloc(void *p, size_t size)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
{
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
    return allocator.Malloc(size ? size : 1);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
} /* SZIP_ISzAlloc_Alloc */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
static void SZIP_ISzAlloc_Free(void *p, void *address)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
{
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
    if (address)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
        allocator.Free(address);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
} /* SZIP_ISzAlloc_Free */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
static ISzAlloc SZIP_SzAlloc = {
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
    SZIP_ISzAlloc_Alloc, SZIP_ISzAlloc_Free
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
};
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
/* we implement ISeekInStream, and then wrap that in LZMA SDK's CLookToRead,
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
   which implements the higher-level ILookInStream on top of that, handling
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
   buffering and such for us. */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
/* LZMA SDK's ISeekInStream interface ... */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
static SRes SZIP_ISeekInStream_Read(void *p, void *buf, size_t *size)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
{
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
    SZIPLookToRead *stream = (SZIPLookToRead *) p;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
    PHYSFS_Io *io = stream->io;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
    const PHYSFS_uint64 len = (PHYSFS_uint64) *size;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
    const PHYSFS_sint64 rc = (len == 0) ? 0 : io->read(io, buf, len);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
    if (rc < 0)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
    {
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
        *size = 0;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
        return SZ_ERROR_READ;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
    } /* if */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
    *size = (size_t) rc;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
    return SZ_OK;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
} /* SZIP_ISeekInStream_Read */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
static SRes SZIP_ISeekInStream_Seek(void *p, Int64 *pos, ESzSeek origin)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   103
{
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
    SZIPLookToRead *stream = (SZIPLookToRead *) p;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   105
    PHYSFS_Io *io = stream->io;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
    PHYSFS_sint64 base;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
    PHYSFS_uint64 newpos;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   109
    switch (origin)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
    {
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
        case SZ_SEEK_SET:
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
            base = 0;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   113
            break;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
        case SZ_SEEK_CUR:
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
            base = io->tell(io);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
            break;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
        case SZ_SEEK_END:
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
            base = io->length(io);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
            break;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
        default:
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
            return SZ_ERROR_FAIL;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
    } /* switch */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
    if (base < 0)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
        return SZ_ERROR_FAIL;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
    else if ((*pos < 0) && (((Int64) base) < -*pos))
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
        return SZ_ERROR_FAIL;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
    newpos = (PHYSFS_uint64) (((Int64) base) + *pos);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
    if (!io->seek(io, newpos))
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   134
        return SZ_ERROR_FAIL;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   135
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
    *pos = (Int64) newpos;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   137
    return SZ_OK;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   138
} /* SZIP_ISeekInStream_Seek */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
static void szipInitStream(SZIPLookToRead *stream, PHYSFS_Io *io)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
{
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
    stream->seekStream.Read = SZIP_ISeekInStream_Read;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
    stream->seekStream.Seek = SZIP_ISeekInStream_Seek;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146
    stream->io = io;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
    /* !!! FIXME: can we use lookahead? Is there value to it? */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
    LookToRead_Init(&stream->lookStream);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
    LookToRead_CreateVTable(&stream->lookStream, False);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
    stream->lookStream.realStream = &stream->seekStream;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   152
} /* szipInitStream */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   153
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
/* Do this in a separate function so we can smallAlloc without looping. */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   156
static int szipLoadEntry(SZIPinfo *info, const PHYSFS_uint32 idx)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   157
{
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
    const size_t utf16len = SzArEx_GetFileNameUtf16(&info->db, idx, NULL);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
    const size_t utf16buflen = utf16len * 2;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   160
    PHYSFS_uint16 *utf16 = (PHYSFS_uint16 *) __PHYSFS_smallAlloc(utf16buflen);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
    const size_t utf8buflen = utf16len * 4;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   162
    char *utf8 = (char *) __PHYSFS_smallAlloc(utf8buflen);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
    int retval = 0;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   164
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
    if (utf16 && utf8)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
    {
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
        const int isdir = SzArEx_IsDir(&info->db, idx) != 0;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   168
        SZIPentry *entry;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
        SzArEx_GetFileNameUtf16(&info->db, idx, (UInt16 *) utf16);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170
        PHYSFS_utf8FromUtf16(utf16, utf8, utf8buflen);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
        entry = (SZIPentry*) __PHYSFS_DirTreeAdd(&info->tree, utf8, isdir);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
        retval = (entry != NULL);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
        if (retval)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   174
            entry->dbidx = idx;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
    } /* if */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
    __PHYSFS_smallFree(utf8);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
    __PHYSFS_smallFree(utf16);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   179
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   180
    return retval;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   181
} /* szipLoadEntry */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   182
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   183
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
static int szipLoadEntries(SZIPinfo *info)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
{
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
    int retval = 0;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   187
1494
4e2c7ce9bf11 DirTrees and unpacked archives shouldn't demand a count of entries for init.
Ryan C. Gordon <icculus@icculus.org>
parents: 1475
diff changeset
   188
    if (__PHYSFS_DirTreeInit(&info->tree, sizeof (SZIPentry)))
1471
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   189
    {
1494
4e2c7ce9bf11 DirTrees and unpacked archives shouldn't demand a count of entries for init.
Ryan C. Gordon <icculus@icculus.org>
parents: 1475
diff changeset
   190
        const PHYSFS_uint32 count = info->db.NumFiles;
1471
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   191
        PHYSFS_uint32 i;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   192
        for (i = 0; i < count; i++)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
            BAIL_IF_ERRPASS(!szipLoadEntry(info, i), 0);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
        retval = 1;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
    } /* if */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   197
    return retval;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   198
} /* szipLoadEntries */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   200
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   201
static void SZIP_closeArchive(void *opaque)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
{
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
    SZIPinfo *info = (SZIPinfo *) opaque;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
    if (info)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   205
    {
1633
bc6cd61b7628 7zip: don't forget to destroy the PHYSFS_Io when closing the archive!
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
   206
        if (info->io)
bc6cd61b7628 7zip: don't forget to destroy the PHYSFS_Io when closing the archive!
Ryan C. Gordon <icculus@icculus.org>
parents: 1571
diff changeset
   207
            info->io->destroy(info->io);
1471
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
        SzArEx_Free(&info->db, &SZIP_SzAlloc);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   209
        __PHYSFS_DirTreeDeinit(&info->tree);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   210
        allocator.Free(info);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   211
    } /* if */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
} /* SZIP_closeArchive */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   214
1571
fbd9698219c1 Archivers can now specify whether an archive definitely was intended for them.
Ryan C. Gordon <icculus@icculus.org>
parents: 1567
diff changeset
   215
static void *SZIP_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: 1567
diff changeset
   216
                              int forWriting, int *claimed)
1471
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   217
{
1571
fbd9698219c1 Archivers can now specify whether an archive definitely was intended for them.
Ryan C. Gordon <icculus@icculus.org>
parents: 1567
diff changeset
   218
    static const PHYSFS_uint8 wantedsig[] = { '7','z',0xBC,0xAF,0x27,0x1C };
1471
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   219
    SZIPLookToRead stream;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   220
    ISzAlloc *alloc = &SZIP_SzAlloc;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   221
    SZIPinfo *info = NULL;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   222
    SRes rc;
1571
fbd9698219c1 Archivers can now specify whether an archive definitely was intended for them.
Ryan C. Gordon <icculus@icculus.org>
parents: 1567
diff changeset
   223
    PHYSFS_uint8 sig[6];
fbd9698219c1 Archivers can now specify whether an archive definitely was intended for them.
Ryan C. Gordon <icculus@icculus.org>
parents: 1567
diff changeset
   224
    PHYSFS_sint64 pos;
1471
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   226
    BAIL_IF(forWriting, PHYSFS_ERR_READ_ONLY, NULL);
1571
fbd9698219c1 Archivers can now specify whether an archive definitely was intended for them.
Ryan C. Gordon <icculus@icculus.org>
parents: 1567
diff changeset
   227
    pos = io->tell(io);
fbd9698219c1 Archivers can now specify whether an archive definitely was intended for them.
Ryan C. Gordon <icculus@icculus.org>
parents: 1567
diff changeset
   228
    BAIL_IF_ERRPASS(pos == -1, NULL);
fbd9698219c1 Archivers can now specify whether an archive definitely was intended for them.
Ryan C. Gordon <icculus@icculus.org>
parents: 1567
diff changeset
   229
    BAIL_IF_ERRPASS(io->read(io, sig, 6) != 6, NULL);
fbd9698219c1 Archivers can now specify whether an archive definitely was intended for them.
Ryan C. Gordon <icculus@icculus.org>
parents: 1567
diff changeset
   230
    *claimed = (memcmp(sig, wantedsig, 6) == 0);
fbd9698219c1 Archivers can now specify whether an archive definitely was intended for them.
Ryan C. Gordon <icculus@icculus.org>
parents: 1567
diff changeset
   231
    BAIL_IF_ERRPASS(!io->seek(io, pos), NULL);
1471
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   232
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   233
    info = (SZIPinfo *) allocator.Malloc(sizeof (SZIPinfo));
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   234
    BAIL_IF(!info, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   235
    memset(info, '\0', sizeof (*info));
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   236
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   237
    SzArEx_Init(&info->db);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   238
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   239
    info->io = io;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   240
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   241
    szipInitStream(&stream, io);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   242
    rc = SzArEx_Open(&info->db, &stream.lookStream.s, alloc, alloc);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   243
    GOTO_IF(rc != SZ_OK, szipErrorCode(rc), failed);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   244
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   245
    GOTO_IF_ERRPASS(!szipLoadEntries(info), failed);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   246
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   247
    return info;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   248
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   249
failed:
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   250
    info->io = NULL;  /* don't let cleanup destroy the PHYSFS_Io. */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   251
    SZIP_closeArchive(info);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   252
    return NULL;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   253
} /* SZIP_openArchive */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   254
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   255
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   256
static PHYSFS_Io *SZIP_openRead(void *opaque, const char *path)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   257
{
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   258
    /* !!! FIXME: the current lzma sdk C API only allows you to decompress
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   259
       !!! FIXME:  the entire file at once, which isn't ideal. Fix this in the
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   260
       !!! FIXME:  SDK and then convert this all to a streaming interface. */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   261
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   262
    SZIPinfo *info = (SZIPinfo *) opaque;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   263
    SZIPentry *entry = (SZIPentry *) __PHYSFS_DirTreeFind(&info->tree, path);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   264
    ISzAlloc *alloc = &SZIP_SzAlloc;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   265
    SZIPLookToRead stream;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   266
    PHYSFS_Io *retval = NULL;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   267
    PHYSFS_Io *io = NULL;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   268
    UInt32 blockIndex = 0xFFFFFFFF;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   269
    Byte *outBuffer = NULL;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   270
    size_t outBufferSize = 0;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   271
    size_t offset = 0;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   272
    size_t outSizeProcessed = 0;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   273
    void *buf = NULL;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   274
    SRes rc;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   275
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   276
    BAIL_IF_ERRPASS(!entry, NULL);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   277
    BAIL_IF(entry->tree.isdir, PHYSFS_ERR_NOT_A_FILE, NULL);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   278
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   279
    io = info->io->duplicate(info->io);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   280
    GOTO_IF_ERRPASS(!io, SZIP_openRead_failed);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   281
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   282
    szipInitStream(&stream, io);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   283
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   284
    rc = SzArEx_Extract(&info->db, &stream.lookStream.s, entry->dbidx,
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   285
                        &blockIndex, &outBuffer, &outBufferSize, &offset,
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   286
                        &outSizeProcessed, alloc, alloc);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   287
    GOTO_IF(rc != SZ_OK, szipErrorCode(rc), SZIP_openRead_failed);
1691
c66c9326b05d 7z: Make error handling a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 1689
diff changeset
   288
    GOTO_IF(outBuffer == NULL, PHYSFS_ERR_OUT_OF_MEMORY, SZIP_openRead_failed);
1471
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   289
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   290
    io->destroy(io);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   291
    io = NULL;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   292
1691
c66c9326b05d 7z: Make error handling a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 1689
diff changeset
   293
    buf = allocator.Malloc(outSizeProcessed ? outSizeProcessed : 1);
1689
1dc6e265fefc 7z: copy/paste error in error checking, found by static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents: 1633
diff changeset
   294
    GOTO_IF(buf == NULL, PHYSFS_ERR_OUT_OF_MEMORY, SZIP_openRead_failed);
1691
c66c9326b05d 7z: Make error handling a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 1689
diff changeset
   295
c66c9326b05d 7z: Make error handling a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 1689
diff changeset
   296
    if (outSizeProcessed > 0)
c66c9326b05d 7z: Make error handling a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents: 1689
diff changeset
   297
        memcpy(buf, outBuffer + offset, outSizeProcessed);
1471
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   298
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   299
    alloc->Free(alloc, outBuffer);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   300
    outBuffer = NULL;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   301
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   302
    retval = __PHYSFS_createMemoryIo(buf, outSizeProcessed, allocator.Free);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   303
    GOTO_IF_ERRPASS(!retval, SZIP_openRead_failed);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   304
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   305
    return retval;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   306
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   307
SZIP_openRead_failed:
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   308
    if (io != NULL)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   309
        io->destroy(io);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   310
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   311
    if (buf)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   312
        allocator.Free(buf);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   313
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   314
    if (outBuffer)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   315
        alloc->Free(alloc, outBuffer);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   316
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   317
    return NULL;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   318
} /* SZIP_openRead */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   319
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   320
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   321
static PHYSFS_Io *SZIP_openWrite(void *opaque, const char *filename)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   322
{
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   323
    BAIL(PHYSFS_ERR_READ_ONLY, NULL);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   324
} /* SZIP_openWrite */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   325
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   326
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   327
static PHYSFS_Io *SZIP_openAppend(void *opaque, const char *filename)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   328
{
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   329
    BAIL(PHYSFS_ERR_READ_ONLY, NULL);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   330
} /* SZIP_openAppend */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   331
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   332
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   333
static int SZIP_remove(void *opaque, const char *name)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   334
{
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   335
    BAIL(PHYSFS_ERR_READ_ONLY, 0);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   336
} /* SZIP_remove */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   337
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   338
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   339
static int SZIP_mkdir(void *opaque, const char *name)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   340
{
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   341
    BAIL(PHYSFS_ERR_READ_ONLY, 0);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   342
} /* SZIP_mkdir */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   343
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   344
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   345
static inline PHYSFS_uint64 lzmasdkTimeToPhysfsTime(const CNtfsFileTime *t)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   346
{
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   347
    const PHYSFS_uint64 winEpochToUnixEpoch = __PHYSFS_UI64(0x019DB1DED53E8000);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   348
    const PHYSFS_uint64 nanosecToMillisec = __PHYSFS_UI64(10000000);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   349
    const PHYSFS_uint64 quad = (((PHYSFS_uint64) t->High) << 32) | t->Low;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   350
    return (quad - winEpochToUnixEpoch) / nanosecToMillisec;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   351
} /* lzmasdkTimeToPhysfsTime */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   352
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   353
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   354
static int SZIP_stat(void *opaque, const char *path, PHYSFS_Stat *stat)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   355
{
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   356
    SZIPinfo *info = (SZIPinfo *) opaque;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   357
    SZIPentry *entry;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   358
    PHYSFS_uint32 idx;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   359
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   360
    entry = (SZIPentry *) __PHYSFS_DirTreeFind(&info->tree, path);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   361
    BAIL_IF_ERRPASS(!entry, 0);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   362
    idx = entry->dbidx;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   363
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   364
    if (entry->tree.isdir)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   365
    {
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   366
        stat->filesize = -1;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   367
	    stat->filetype = PHYSFS_FILETYPE_DIRECTORY;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   368
    } /* if */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   369
    else
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   370
    {
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   371
        stat->filesize = (PHYSFS_sint64) SzArEx_GetFileSize(&info->db, idx);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   372
	    stat->filetype = PHYSFS_FILETYPE_REGULAR;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   373
    } /* else */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   374
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   375
    if (info->db.MTime.Vals != NULL)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   376
	    stat->modtime = lzmasdkTimeToPhysfsTime(&info->db.MTime.Vals[idx]);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   377
    else if (info->db.CTime.Vals != NULL)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   378
	    stat->modtime = lzmasdkTimeToPhysfsTime(&info->db.CTime.Vals[idx]);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   379
    else
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   380
	    stat->modtime = -1;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   381
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   382
    if (info->db.CTime.Vals != NULL)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   383
	    stat->createtime = lzmasdkTimeToPhysfsTime(&info->db.CTime.Vals[idx]);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   384
    else if (info->db.MTime.Vals != NULL)
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   385
	    stat->createtime = lzmasdkTimeToPhysfsTime(&info->db.MTime.Vals[idx]);
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   386
    else
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   387
	    stat->createtime = -1;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   388
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   389
	stat->accesstime = -1;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   390
	stat->readonly = 1;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   391
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   392
    return 1;
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   393
} /* SZIP_stat */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   394
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   395
1567
539b68269e9f 7z: do global initialization once without risking a race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 1559
diff changeset
   396
void SZIP_global_init(void)
539b68269e9f 7z: do global initialization once without risking a race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 1559
diff changeset
   397
{
539b68269e9f 7z: do global initialization once without risking a race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 1559
diff changeset
   398
    /* this just needs to calculate some things, so it only ever
539b68269e9f 7z: do global initialization once without risking a race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 1559
diff changeset
   399
       has to run once, even after a deinit. */
539b68269e9f 7z: do global initialization once without risking a race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 1559
diff changeset
   400
    static int generatedTable = 0;
539b68269e9f 7z: do global initialization once without risking a race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 1559
diff changeset
   401
    if (!generatedTable)
539b68269e9f 7z: do global initialization once without risking a race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 1559
diff changeset
   402
    {
539b68269e9f 7z: do global initialization once without risking a race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 1559
diff changeset
   403
        generatedTable = 1;
539b68269e9f 7z: do global initialization once without risking a race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 1559
diff changeset
   404
        CrcGenerateTable();
539b68269e9f 7z: do global initialization once without risking a race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 1559
diff changeset
   405
    } /* if */
539b68269e9f 7z: do global initialization once without risking a race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 1559
diff changeset
   406
} /* SZIP_global_init */
539b68269e9f 7z: do global initialization once without risking a race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 1559
diff changeset
   407
539b68269e9f 7z: do global initialization once without risking a race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 1559
diff changeset
   408
1512
fe20ac238ce4 Rename __PHYSFS_Archiver_SZIP to __PHYSFS_Archiver_7Z.
Ryan C. Gordon <icculus@icculus.org>
parents: 1507
diff changeset
   409
const PHYSFS_Archiver __PHYSFS_Archiver_7Z =
1471
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   410
{
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   411
    CURRENT_PHYSFS_ARCHIVER_API_VERSION,
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   412
    {
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   413
        "7Z",
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   414
        "7zip archives",
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   415
        "Ryan C. Gordon <icculus@icculus.org>",
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   416
        "https://icculus.org/physfs/",
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   417
        0,  /* supportsSymlinks */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   418
    },
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   419
    SZIP_openArchive,
1559
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   420
    __PHYSFS_DirTreeEnumerate,
1471
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   421
    SZIP_openRead,
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   422
    SZIP_openWrite,
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   423
    SZIP_openAppend,
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   424
    SZIP_remove,
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   425
    SZIP_mkdir,
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   426
    SZIP_stat,
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   427
    SZIP_closeArchive
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   428
};
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   429
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   430
#endif  /* defined PHYSFS_SUPPORTS_7Z */
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   431
1507
8953b8a171e7 Update filename comments.
Ryan C. Gordon <icculus@icculus.org>
parents: 1506
diff changeset
   432
/* end of physfs_archiver_7z.c ... */
1471
b03e757cdc8f Whoops, forgot to add the file. :)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   433