archivers/lzma.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 05 Nov 2006 10:06:02 +0000
changeset 783 f14fc3210eca
parent 782 5633b9a0c6b6
child 795 0f10cda58a9a
permissions -rw-r--r--
More 7zip work (thanks, Dennis!)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/*
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
 * LZMA support routines for PhysicsFS.
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
 *
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
 * Please see the file LICENSE in the source's root directory.
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
 *
782
5633b9a0c6b6 More corrections to lzma support from Dennis.
Ryan C. Gordon <icculus@icculus.org>
parents: 780
diff changeset
     6
 *  This file is written by Dennis Schridde, with some peeking at "7zMain.c"
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
 *   by Igor Pavlov.
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
 */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
#if HAVE_CONFIG_H
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
#  include <config.h>
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
#endif
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
#if (defined PHYSFS_SUPPORTS_LZMA)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
#include <stdlib.h>
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
#include <string.h>
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
#include "physfs.h"
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
#define __PHYSICSFS_INTERNAL__
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
#include "physfs_internal.h"
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    24
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    25
#define _LZMA_IN_CB
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    26
/* Use callback for input data */
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    27
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    28
/* #define _LZMA_OUT_READ */
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    29
/* Use read function for output data */
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    30
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    31
#define _LZMA_PROB32
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    32
/* It can increase speed on some 32-bit CPUs,
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    33
   but memory usage will be doubled in that case */
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    35
#define _LZMA_SYSTEM_SIZE_T
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    36
/* Use system's size_t. You can use it to enable 64-bit sizes supporting */
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    37
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    39
#include "7zIn.h"
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    40
#include "7zCrc.h"
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    41
#include "7zExtract.h"
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    42
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    43
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    44
/* 7z internal from 7zIn.c */
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    45
int TestSignatureCandidate(Byte *testBytes);
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    46
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    47
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    48
typedef struct _CFileInStream
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
    ISzInStream InStream;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
    void *File;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
} CFileInStream;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
783
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
    54
/*
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
    55
 * In LZMA the archive is splited in blocks, those are called folders
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
    56
 * Set by LZMA_read()
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
    57
*/
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
    58
typedef struct _LZMAfolder
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
    59
{
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
    60
    PHYSFS_uint8 *cache; /* Cached folder */
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
    61
    PHYSFS_uint32 size; /* Size of folder */
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
    62
    PHYSFS_uint32 index; /* Index of folder in archive */
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
    63
    PHYSFS_uint32 references; /* Number of files using this block */
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
    64
} LZMAfolder;
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
    65
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
    66
/*
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
    67
 * Set by LZMA_openArchive(), except folder which gets it's values
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
    68
 *  in LZMA_read()
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
    69
 */
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    70
typedef struct _LZMAarchive
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
{
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    72
    struct _LZMAentry *firstEntry; /* Used for cleanup on shutdown */
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
    struct _LZMAentry *lastEntry;
783
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
    74
    LZMAfolder *folder; /* Array of folders */
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    75
    CArchiveDatabaseEx db; /* For 7z: Database */
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    76
    CFileInStream stream; /* For 7z: Input file incl. read and seek callbacks */
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
} LZMAarchive;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    79
/* Set by LZMA_openRead(), except offset which is set by LZMA_read() */
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
typedef struct _LZMAentry
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
{
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    82
    struct _LZMAentry *next; /* Used for cleanup on shutdown */
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
    struct _LZMAentry *previous;
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    84
    LZMAarchive *archive; /* Link to corresponding archive */
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    85
    CFileItem *file; /* For 7z: File info, eg. name, size */
783
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
    86
    PHYSFS_uint32 fileIndex; /* Index of file in archive */
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
    87
    PHYSFS_uint32 folderIndex; /* Index of folder in archive */
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
    88
    size_t offset; /* Offset in folder */
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    89
    PHYSFS_uint32 position; /* Current "virtual" position in file */
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
} LZMAentry;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    93
/* Memory management implementations to be passed to 7z */
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    94
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
static void *SzAllocPhysicsFS(size_t size)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
    return ((size == 0) ? NULL : allocator.Malloc(size));
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
} /* SzAllocPhysicsFS */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
static void SzFreePhysicsFS(void *address)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   103
    if (address != NULL)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
        allocator.Free(address);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   105
} /* SzFreePhysicsFS */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   108
/* Filesystem implementations to be passed to 7z */
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   109
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   110
#ifdef _LZMA_IN_CB
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   111
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   112
#define kBufferSize (1 << 12)
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   113
static Byte g_Buffer[kBufferSize];  /* !!! FIXME: not thread safe! */
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   114
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   115
SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxReqSize,
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   116
                        size_t *processedSize)
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
{
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   118
    CFileInStream *s = (CFileInStream *)object;
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
    size_t processedSizeLoc;
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   120
    if (maxReqSize > kBufferSize)
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   121
        maxReqSize = kBufferSize;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   122
    processedSizeLoc = __PHYSFS_platformRead(s->File, g_Buffer, 1, maxReqSize);
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   123
    *buffer = g_Buffer;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   124
    if (processedSize != 0)
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
        *processedSize = processedSizeLoc;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
    return SZ_OK;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
} /* SzFileReadImp */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   129
#else
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   130
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   131
SZ_RESULT SzFileReadImp(void *object, void *buffer, size_t size,
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   132
                        size_t *processedSize)
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   133
{
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   134
    CFileInStream *s = (CFileInStream *)object;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   135
    size_t processedSizeLoc = __PHYSFS_platformRead(s->File, buffer, 1, size);
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   136
    if (processedSize != 0)
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   137
        *processedSize = processedSizeLoc;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   138
    return SZ_OK;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   139
} /* SzFileReadImp */
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   140
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   141
#endif
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
SZ_RESULT SzFileSeekImp(void *object, CFileSize pos)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
    CFileInStream *s = (CFileInStream *) object;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146
    if (__PHYSFS_platformSeek(s->File, (PHYSFS_uint64) pos))
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
        return SZ_OK;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
    return SZE_FAIL;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
} /* SzFileSeekImp */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   152
/*
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   153
 * Find entry 'name' in 'archive' and report the 'index' back
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   154
 */
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   155
static int lzma_find_entry(LZMAarchive *archive, const char *name,
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   156
                           PHYSFS_uint32 *index)
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   157
{
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   158
    for (*index = 0; *index < archive->db.Database.NumFiles; (*index)++)
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
    {
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   160
        if (strcmp(archive->db.Database.Files[*index].Name, name) == 0)
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   161
            return 1;
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   162
    } /* for */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   164
    BAIL_MACRO(ERR_NO_SUCH_FILE, 0);
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
} /* lzma_find_entry */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   168
/*
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   169
 * Report the first file index of a directory
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   170
 */
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
static PHYSFS_sint32 lzma_find_start_of_dir(LZMAarchive *archive,
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
                                            const char *path,
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
                                            int stop_on_first_find)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   174
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
    PHYSFS_sint32 lo = 0;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
    PHYSFS_sint32 hi = (PHYSFS_sint32) (archive->db.Database.NumFiles - 1);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
    PHYSFS_sint32 middle;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
    PHYSFS_uint32 dlen = strlen(path);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   179
    PHYSFS_sint32 retval = -1;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   180
    const char *name;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   181
    int rc;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   182
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   183
    if (*path == '\0')  /* root dir? */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
        return(0);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
    if ((dlen > 0) && (path[dlen - 1] == '/')) /* ignore trailing slash. */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   187
        dlen--;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   188
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   189
    while (lo <= hi)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
    {
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   191
        middle = lo + ((hi - lo) / 2);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   192
        name = archive->db.Database.Files[middle].Name;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
        rc = strncmp(path, name, dlen);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
        if (rc == 0)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
        {
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
            char ch = name[dlen];
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   197
            if ('/' < ch) /* make sure this isn't just a substr match. */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   198
                rc = -1;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
            else if ('/' > ch)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   200
                rc = 1;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   201
            else
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
            {
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
                if (stop_on_first_find) /* Just checking dir's existance? */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
                    return(middle);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   205
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
                if (name[dlen + 1] == '\0') /* Skip initial dir entry. */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   207
                    return(middle + 1);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   209
                /* there might be more entries earlier in the list. */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   210
                retval = middle;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   211
                hi = middle - 1;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
            } /* else */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
        } /* if */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   214
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
        if (rc > 0)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   216
            lo = middle + 1;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   217
        else
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   218
            hi = middle - 1;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   219
    } /* while */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   220
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   221
    return(retval);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   222
} /* lzma_find_start_of_dir */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   223
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   224
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225
/*
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   226
 * Wrap all 7z calls in this, so the physfs error state is set appropriately.
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   227
 */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   228
static int lzma_err(SZ_RESULT rc)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   229
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   230
    switch (rc)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   231
    {
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   232
        case SZ_OK: /* Same as LZMA_RESULT_OK */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   233
            break;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   234
        case SZE_DATA_ERROR: /* Same as LZMA_RESULT_DATA_ERROR */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   235
            __PHYSFS_setError(ERR_DATA_ERROR);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   236
            break;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   237
        case SZE_OUTOFMEMORY:
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   238
            __PHYSFS_setError(ERR_OUT_OF_MEMORY);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   239
            break;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   240
        case SZE_CRC_ERROR:
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   241
            __PHYSFS_setError(ERR_CORRUPTED);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   242
            break;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   243
        case SZE_NOTIMPL:
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   244
            __PHYSFS_setError(ERR_NOT_IMPLEMENTED);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   245
            break;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   246
        case SZE_FAIL:
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   247
            __PHYSFS_setError(ERR_UNKNOWN_ERROR);  /* !!! FIXME: right? */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   248
            break;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   249
        case SZE_ARCHIVE_ERROR:
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   250
            __PHYSFS_setError(ERR_CORRUPTED);  /* !!! FIXME: right? */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   251
            break;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   252
        default:
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   253
            __PHYSFS_setError(ERR_UNKNOWN_ERROR);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   254
    } /* switch */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   255
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   256
    return(rc);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   257
} /* lzma_err */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   258
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   259
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   260
static PHYSFS_sint64 LZMA_read(fvoid *opaque, void *outBuffer,
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   261
                               PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   262
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   263
    LZMAentry *entry = (LZMAentry *) opaque;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   264
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   265
    PHYSFS_sint64 wantedSize = objSize*objCount;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   266
    PHYSFS_sint64 remainingSize = entry->file->Size - entry->position;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   267
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   268
    BAIL_IF_MACRO(wantedSize == 0, NULL, 0); /* quick rejection. */
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   269
    BAIL_IF_MACRO(remainingSize == 0, ERR_PAST_EOF, 0);
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   270
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   271
    if (remainingSize < wantedSize)
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   272
    {
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   273
        wantedSize = remainingSize - (remainingSize % objSize);
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   274
        objCount = (PHYSFS_uint32) (remainingSize / objSize);
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   275
        BAIL_IF_MACRO(objCount == 0, ERR_PAST_EOF, 0); /* quick rejection. */
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   276
        __PHYSFS_setError(ERR_PAST_EOF); /* this is always true here. */
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   277
    } /* if */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   278
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   279
    size_t fileSize;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   280
    ISzAlloc allocImp;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   281
    ISzAlloc allocTempImp;
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   282
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   283
    /* Prepare callbacks for 7z */
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   284
    allocImp.Alloc = SzAllocPhysicsFS;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   285
    allocImp.Free = SzFreePhysicsFS;
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   286
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   287
    allocTempImp.Alloc = SzAllocPhysicsFS;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   288
    allocTempImp.Free = SzFreePhysicsFS;
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   289
783
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   290
    /* Only decompress the folder if it is not allready cached */
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   291
    if (entry->archive->folder[entry->folderIndex].cache == NULL)
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   292
        if (lzma_err(SzExtract(
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   293
            &entry->archive->stream.InStream, /* compressed data */
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   294
            &entry->archive->db,
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   295
            entry->fileIndex,
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   296
            /* Index of cached folder, will be changed by SzExtract */
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   297
            &entry->archive->folder[entry->folderIndex].index,
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   298
            /* Cache for decompressed folder, allocated/freed by SzExtract */
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   299
            &entry->archive->folder[entry->folderIndex].cache,
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   300
            /* Size of cache, will be changed by SzExtract */
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   301
            &entry->archive->folder[entry->folderIndex].size,
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   302
            /* Offset of this file inside the cache, set by SzExtract */
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   303
            &entry->offset,
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   304
            &fileSize, /* Size of this file */
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   305
            &allocImp,
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   306
            &allocTempImp
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   307
                )) != SZ_OK)
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   308
            return -1;
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   309
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   310
    /* Copy wanted bytes over from cache to outBuffer */
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   311
    strncpy(outBuffer,
783
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   312
            (void*) (entry->archive->folder[entry->folderIndex].cache +
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   313
                     entry->offset + entry->position),
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   314
            wantedSize);
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   315
    entry->position += wantedSize;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   316
    return objCount;
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   317
} /* LZMA_read */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   318
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   319
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   320
static PHYSFS_sint64 LZMA_write(fvoid *opaque, const void *buf,
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   321
                               PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   322
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   323
    BAIL_MACRO(ERR_NOT_SUPPORTED, -1);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   324
} /* LZMA_write */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   325
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   326
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   327
static int LZMA_eof(fvoid *opaque)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   328
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   329
    LZMAentry *entry = (LZMAentry *) opaque;
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   330
    return (entry->position >= entry->file->Size);
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   331
} /* LZMA_eof */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   332
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   333
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   334
static PHYSFS_sint64 LZMA_tell(fvoid *opaque)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   335
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   336
    LZMAentry *entry = (LZMAentry *) opaque;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   337
    return (entry->position);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   338
} /* LZMA_tell */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   339
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   340
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   341
static int LZMA_seek(fvoid *opaque, PHYSFS_uint64 offset)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   342
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   343
    LZMAentry *entry = (LZMAentry *) opaque;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   344
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   345
    BAIL_IF_MACRO(offset < 0, ERR_SEEK_OUT_OF_RANGE, 0);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   346
    BAIL_IF_MACRO(offset > entry->file->Size, ERR_PAST_EOF, 0);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   347
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   348
    entry->position = offset;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   349
    return 1;
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   350
} /* LZMA_seek */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   351
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   352
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   353
static PHYSFS_sint64 LZMA_fileLength(fvoid *opaque)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   354
{
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   355
    LZMAentry *entry = (LZMAentry *) opaque;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   356
    return (entry->file->Size);
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   357
} /* LZMA_fileLength */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   358
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   359
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   360
static int LZMA_fileClose(fvoid *opaque)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   361
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   362
    LZMAentry *entry = (LZMAentry *) opaque;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   363
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   364
    /* Fix archive */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   365
    if (entry == entry->archive->firstEntry)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   366
        entry->archive->firstEntry = entry->next;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   367
    if (entry == entry->archive->lastEntry)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   368
        entry->archive->lastEntry = entry->previous;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   369
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   370
    /* Fix neighbours */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   371
    if (entry->previous != NULL)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   372
        entry->previous->next = entry->next;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   373
    if (entry->next != NULL)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   374
        entry->next->previous = entry->previous;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   375
783
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   376
    entry->archive->folder[entry->folderIndex].references--;
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   377
    if (entry->archive->folder[entry->folderIndex].references == 0)
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   378
    {
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   379
        allocator.Free(entry->archive->folder[entry->folderIndex].cache);
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   380
        entry->archive->folder[entry->folderIndex].cache = NULL;
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   381
    }
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   382
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   383
    allocator.Free(entry);
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   384
    entry = NULL;
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   385
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   386
    return(1);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   387
} /* LZMA_fileClose */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   388
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   389
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   390
static int LZMA_isArchive(const char *filename, int forWriting)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   391
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   392
    PHYSFS_uint8 sig[k7zSignatureSize];
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   393
    PHYSFS_uint8 res;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   394
    void *in;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   395
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   396
    BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   397
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   398
    in = __PHYSFS_platformOpenRead(filename);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   399
    BAIL_IF_MACRO(in == NULL, NULL, 0);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   400
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   401
    if (__PHYSFS_platformRead(in, sig, k7zSignatureSize, 1) != 1)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   402
        BAIL_MACRO(NULL, 0);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   403
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   404
    /* Test whether sig is the 7z signature */
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   405
    res = TestSignatureCandidate(sig);
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   406
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   407
    __PHYSFS_platformClose(in);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   408
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   409
    return res;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   410
} /* LZMA_isArchive */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   411
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   412
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   413
static void *LZMA_openArchive(const char *name, int forWriting)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   414
{
783
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   415
    PHYSFS_uint64 len;
782
5633b9a0c6b6 More corrections to lzma support from Dennis.
Ryan C. Gordon <icculus@icculus.org>
parents: 780
diff changeset
   416
    LZMAarchive *archive = NULL;
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   417
    ISzAlloc allocImp;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   418
    ISzAlloc allocTempImp;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   419
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   420
    BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, NULL);
783
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   421
    BAIL_IF_MACRO(!LZMA_isArchive(name,forWriting), ERR_UNSUPPORTED_ARCHIVE, 0);
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   422
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   423
    archive = (LZMAarchive *) allocator.Malloc(sizeof (LZMAarchive));
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   424
    BAIL_IF_MACRO(archive == NULL, ERR_OUT_OF_MEMORY, NULL);
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   425
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   426
    archive->firstEntry = NULL;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   427
    archive->lastEntry = NULL;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   428
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   429
    if ((archive->stream.File = __PHYSFS_platformOpenRead(name)) == NULL)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   430
    {
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   431
        allocator.Free(archive);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   432
        return NULL;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   433
    } /* if */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   434
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   435
    /* Prepare structs for 7z */
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   436
    archive->stream.InStream.Read = SzFileReadImp;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   437
    archive->stream.InStream.Seek = SzFileSeekImp;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   438
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   439
    allocImp.Alloc = SzAllocPhysicsFS;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   440
    allocImp.Free = SzFreePhysicsFS;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   441
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   442
    allocTempImp.Alloc = SzAllocPhysicsFS;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   443
    allocTempImp.Free = SzFreePhysicsFS;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   444
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   445
    InitCrcTable();
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   446
    SzArDbExInit(&archive->db);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   447
    if (lzma_err(SzArchiveOpen(&archive->stream.InStream, &archive->db,
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   448
                               &allocImp, &allocTempImp)) != SZ_OK)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   449
    {
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   450
        __PHYSFS_platformClose(archive->stream.File);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   451
        allocator.Free(archive);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   452
        return NULL;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   453
    } /* if */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   454
783
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   455
    len = archive->db.Database.NumFolders * sizeof (LZMAfolder);
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   456
    archive->folder = (LZMAfolder *) allocator.Malloc(len);
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   457
    BAIL_IF_MACRO(archive->folder == NULL, ERR_OUT_OF_MEMORY, NULL);
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   458
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   459
    /*
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   460
     * Init with 0 so we know when a folder is already cached
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   461
     * Values will be set by LZMA_read()
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   462
     */
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   463
    memset(archive->folder, 0, len);
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   464
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   465
    return(archive);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   466
} /* LZMA_openArchive */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   467
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   468
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   469
/*
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   470
 * Moved to seperate function so we can use alloca then immediately throw
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   471
 *  away the allocated stack space...
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   472
 */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   473
static void doEnumCallback(PHYSFS_EnumFilesCallback cb, void *callbackdata,
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   474
                           const char *odir, const char *str, PHYSFS_sint32 ln)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   475
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   476
    char *newstr = alloca(ln + 1);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   477
    if (newstr == NULL)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   478
        return;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   479
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   480
    memcpy(newstr, str, ln);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   481
    newstr[ln] = '\0';
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   482
    cb(callbackdata, odir, newstr);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   483
} /* doEnumCallback */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   484
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   485
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   486
static void LZMA_enumerateFiles(dvoid *opaque, const char *dname,
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   487
                                int omitSymLinks, PHYSFS_EnumFilesCallback cb,
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   488
                                const char *origdir, void *callbackdata)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   489
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   490
    LZMAarchive *archive = (LZMAarchive *) opaque;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   491
    PHYSFS_sint32 dlen;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   492
    PHYSFS_sint32 dlen_inc;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   493
    PHYSFS_sint32 max;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   494
    PHYSFS_sint32 i;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   495
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   496
    i = lzma_find_start_of_dir(archive, dname, 0);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   497
    if (i == -1)  /* no such directory. */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   498
        return;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   499
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   500
    dlen = strlen(dname);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   501
    if ((dlen > 0) && (dname[dlen - 1] == '/')) /* ignore trailing slash. */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   502
        dlen--;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   503
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   504
    dlen_inc = ((dlen > 0) ? 1 : 0) + dlen;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   505
    max = (PHYSFS_sint32) archive->db.Database.NumFiles;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   506
    while (i < max)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   507
    {
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   508
        char *add;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   509
        char *ptr;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   510
        PHYSFS_sint32 ln;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   511
        char *e = archive->db.Database.Files[i].Name;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   512
        if ((dlen) && ((strncmp(e, dname, dlen)) || (e[dlen] != '/')))
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   513
            break;  /* past end of this dir; we're done. */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   514
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   515
        add = e + dlen_inc;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   516
        ptr = strchr(add, '/');
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   517
        ln = (PHYSFS_sint32) ((ptr) ? ptr-add : strlen(add));
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   518
        doEnumCallback(cb, callbackdata, origdir, add, ln);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   519
        ln += dlen_inc;  /* point past entry to children... */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   520
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   521
        /* increment counter and skip children of subdirs... */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   522
        while ((++i < max) && (ptr != NULL))
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   523
        {
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   524
            char *e_new = archive->db.Database.Files[i].Name;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   525
            if ((strncmp(e, e_new, ln) != 0) || (e_new[ln] != '/'))
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   526
                break;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   527
        } /* while */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   528
    } /* while */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   529
} /* LZMA_enumerateFiles */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   530
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   531
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   532
static int LZMA_exists(dvoid *opaque, const char *name)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   533
{
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   534
    LZMAarchive *archive = (LZMAarchive *) opaque;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   535
    PHYSFS_uint32 index = 0;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   536
    return(lzma_find_entry(archive, name, &index));
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   537
} /* LZMA_exists */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   538
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   539
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   540
static PHYSFS_sint64 LZMA_getLastModTime(dvoid *opaque,
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   541
                                         const char *name,
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   542
                                         int *fileExists)
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   543
{
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   544
    /* !!! FIXME: Lacking support in the LZMA C SDK. */
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   545
    BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   546
} /* LZMA_getLastModTime */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   547
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   548
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   549
static int LZMA_isDirectory(dvoid *opaque, const char *name, int *fileExists)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   550
{
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   551
    LZMAarchive *archive = (LZMAarchive *) opaque;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   552
    PHYSFS_uint32 index = 0;
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   553
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   554
    *fileExists = lzma_find_entry(archive, name, &index);
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   555
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   556
    return(archive->db.Database.Files[index].IsDirectory);
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   557
} /* LZMA_isDirectory */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   558
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   559
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   560
static int LZMA_isSymLink(dvoid *opaque, const char *name, int *fileExists)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   561
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   562
    BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   563
} /* LZMA_isSymLink */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   564
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   565
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   566
static fvoid *LZMA_openRead(dvoid *opaque, const char *name, int *fileExists)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   567
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   568
    LZMAarchive *archive = (LZMAarchive *) opaque;
782
5633b9a0c6b6 More corrections to lzma support from Dennis.
Ryan C. Gordon <icculus@icculus.org>
parents: 780
diff changeset
   569
    LZMAentry *entry = NULL;
783
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   570
    PHYSFS_uint32 fileIndex = 0;
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   571
    PHYSFS_uint32 folderIndex = 0;
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   572
783
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   573
    *fileExists = lzma_find_entry(archive, name, &fileIndex);
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   574
    BAIL_IF_MACRO(!*fileExists, ERR_NO_SUCH_FILE, NULL);
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   575
783
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   576
    folderIndex = archive->db.FileIndexToFolderIndexMap[fileIndex];
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   577
    BAIL_IF_MACRO(folderIndex == (PHYSFS_uint32)-1, ERR_UNKNOWN_ERROR, NULL);
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   578
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   579
    entry = (LZMAentry *) allocator.Malloc(sizeof (LZMAentry));
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   580
    BAIL_IF_MACRO(entry == NULL, ERR_OUT_OF_MEMORY, NULL);
782
5633b9a0c6b6 More corrections to lzma support from Dennis.
Ryan C. Gordon <icculus@icculus.org>
parents: 780
diff changeset
   581
783
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   582
    entry->fileIndex = fileIndex;
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   583
    entry->folderIndex = folderIndex;
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   584
    entry->archive = archive;
783
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   585
    entry->file = archive->db.Database.Files + entry->fileIndex;
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   586
    entry->offset = 0; /* Offset will be set by LZMA_read() */
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   587
    entry->position = 0;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   588
783
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   589
    archive->folder[folderIndex].references++;
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   590
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   591
    entry->next = NULL;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   592
    entry->previous = entry->archive->lastEntry;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   593
    if (entry->previous != NULL)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   594
        entry->previous->next = entry;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   595
    entry->archive->lastEntry = entry;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   596
    if (entry->archive->firstEntry == NULL)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   597
        entry->archive->firstEntry = entry;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   598
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   599
    return(entry);
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   600
} /* LZMA_openRead */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   601
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   602
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   603
static fvoid *LZMA_openWrite(dvoid *opaque, const char *filename)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   604
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   605
    BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   606
} /* LZMA_openWrite */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   607
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   608
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   609
static fvoid *LZMA_openAppend(dvoid *opaque, const char *filename)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   610
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   611
    BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   612
} /* LZMA_openAppend */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   613
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   614
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   615
static void LZMA_dirClose(dvoid *opaque)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   616
{
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   617
    LZMAarchive *archive = (LZMAarchive *) opaque;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   618
    LZMAentry *entry = archive->firstEntry;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   619
    LZMAentry *tmpEntry = entry;
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   620
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   621
    while (entry != NULL)
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   622
    {
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   623
        tmpEntry = entry->next;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   624
        LZMA_fileClose(entry);
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   625
        entry = tmpEntry;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   626
    } /* while */
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   627
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   628
    SzArDbExFree(&archive->db, SzFreePhysicsFS);
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   629
    __PHYSFS_platformClose(archive->stream.File);
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   630
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   631
    /* Free the cache which might have been allocated by LZMA_read() */
783
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   632
    allocator.Free(archive->folder);
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   633
    allocator.Free(archive);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   634
} /* LZMA_dirClose */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   635
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   636
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   637
static int LZMA_remove(dvoid *opaque, const char *name)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   638
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   639
    BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   640
} /* LZMA_remove */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   641
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   642
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   643
static int LZMA_mkdir(dvoid *opaque, const char *name)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   644
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   645
    BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   646
} /* LZMA_mkdir */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   647
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   648
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   649
const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_LZMA =
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   650
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   651
    "7Z",
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   652
    LZMA_ARCHIVE_DESCRIPTION,
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   653
    "Dennis Schridde <devurandom@gmx.net>",
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   654
    "http://icculus.org/physfs/",
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   655
};
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   656
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   657
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   658
const PHYSFS_Archiver __PHYSFS_Archiver_LZMA =
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   659
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   660
    &__PHYSFS_ArchiveInfo_LZMA,
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   661
    LZMA_isArchive,          /* isArchive() method      */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   662
    LZMA_openArchive,        /* openArchive() method    */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   663
    LZMA_enumerateFiles,     /* enumerateFiles() method */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   664
    LZMA_exists,             /* exists() method         */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   665
    LZMA_isDirectory,        /* isDirectory() method    */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   666
    LZMA_isSymLink,          /* isSymLink() method      */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   667
    LZMA_getLastModTime,     /* getLastModTime() method */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   668
    LZMA_openRead,           /* openRead() method       */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   669
    LZMA_openWrite,          /* openWrite() method      */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   670
    LZMA_openAppend,         /* openAppend() method     */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   671
    LZMA_remove,             /* remove() method         */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   672
    LZMA_mkdir,              /* mkdir() method          */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   673
    LZMA_dirClose,           /* dirClose() method       */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   674
    LZMA_read,               /* read() method           */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   675
    LZMA_write,              /* write() method          */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   676
    LZMA_eof,                /* eof() method            */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   677
    LZMA_tell,               /* tell() method           */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   678
    LZMA_seek,               /* seek() method           */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   679
    LZMA_fileLength,         /* fileLength() method     */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   680
    LZMA_fileClose           /* fileClose() method      */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   681
};
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   682
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   683
#endif  /* defined PHYSFS_SUPPORTS_LZMA */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   684
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   685
/* end of lzma.c ... */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   686