archivers/lzma.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 11 Mar 2007 10:10:28 +0000
changeset 809 116b8fe30371
parent 808 7656f86a9a2c
child 821 c7dd97edaa4e
permissions -rw-r--r--
Renamed LICENSE to LICENSE.txt
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
 *
809
116b8fe30371 Renamed LICENSE to LICENSE.txt
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
     4
 * Please see the file LICENSE.txt in the source's root directory.
774
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
795
0f10cda58a9a Changed PHYSFS_SUPPORTS_LZMA to PHYSFS_SUPPORTS_7Z.
Ryan C. Gordon <icculus@icculus.org>
parents: 783
diff changeset
    10
#if (defined PHYSFS_SUPPORTS_7Z)
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
#include <stdlib.h>
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
#include <string.h>
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
#include "physfs.h"
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
#define __PHYSICSFS_INTERNAL__
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
#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
    19
798
18455baab480 Moved to CMake!
Ryan C. Gordon <icculus@icculus.org>
parents: 797
diff changeset
    20
#ifndef _LZMA_IN_CB
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    21
#define _LZMA_IN_CB
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    22
/* Use callback for input data */
798
18455baab480 Moved to CMake!
Ryan C. Gordon <icculus@icculus.org>
parents: 797
diff changeset
    23
#endif
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_OUT_READ */
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    26
/* Use read function for output data */
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    27
798
18455baab480 Moved to CMake!
Ryan C. Gordon <icculus@icculus.org>
parents: 797
diff changeset
    28
#ifndef _LZMA_PROB32
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    29
#define _LZMA_PROB32
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
    30
/* 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
    31
   but memory usage will be doubled in that case */
798
18455baab480 Moved to CMake!
Ryan C. Gordon <icculus@icculus.org>
parents: 797
diff changeset
    32
#endif
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
798
18455baab480 Moved to CMake!
Ryan C. Gordon <icculus@icculus.org>
parents: 797
diff changeset
    34
#ifndef _LZMA_SYSTEM_SIZE_T
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 */
798
18455baab480 Moved to CMake!
Ryan C. Gordon <icculus@icculus.org>
parents: 797
diff changeset
    37
#endif
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)
797
c575b78bf2fe Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 795
diff changeset
   292
    {
c575b78bf2fe Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 795
diff changeset
   293
        size_t tmpsize = entry->archive->folder[entry->folderIndex].size;
c575b78bf2fe Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 795
diff changeset
   294
        int rc = lzma_err(SzExtract(
783
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   295
            &entry->archive->stream.InStream, /* compressed data */
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   296
            &entry->archive->db,
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   297
            entry->fileIndex,
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   298
            /* 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
   299
            &entry->archive->folder[entry->folderIndex].index,
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   300
            /* Cache for decompressed folder, allocated/freed by SzExtract */
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   301
            &entry->archive->folder[entry->folderIndex].cache,
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   302
            /* Size of cache, will be changed by SzExtract */
797
c575b78bf2fe Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 795
diff changeset
   303
            &tmpsize,
783
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   304
            /* 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
   305
            &entry->offset,
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   306
            &fileSize, /* Size of this file */
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   307
            &allocImp,
797
c575b78bf2fe Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 795
diff changeset
   308
            &allocTempImp));
c575b78bf2fe Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 795
diff changeset
   309
c575b78bf2fe Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 795
diff changeset
   310
        entry->archive->folder[entry->folderIndex].size = tmpsize;
c575b78bf2fe Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 795
diff changeset
   311
        if (rc != SZ_OK)
783
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   312
            return -1;
797
c575b78bf2fe Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 795
diff changeset
   313
    } /* if */
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   314
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   315
    /* 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
   316
    strncpy(outBuffer,
783
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   317
            (void*) (entry->archive->folder[entry->folderIndex].cache +
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   318
                     entry->offset + entry->position),
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   319
            wantedSize);
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   320
    entry->position += wantedSize;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   321
    return objCount;
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   322
} /* LZMA_read */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   323
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   324
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   325
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
   326
                               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
   327
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   328
    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
   329
} /* LZMA_write */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   330
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   331
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   332
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
   333
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   334
    LZMAentry *entry = (LZMAentry *) opaque;
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   335
    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
   336
} /* LZMA_eof */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   337
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   338
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   339
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
   340
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   341
    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
   342
    return (entry->position);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   343
} /* LZMA_tell */
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
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   346
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
   347
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   348
    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
   349
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   350
    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
   351
    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
   352
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   353
    entry->position = offset;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   354
    return 1;
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   355
} /* LZMA_seek */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   356
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   357
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   358
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
   359
{
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   360
    LZMAentry *entry = (LZMAentry *) opaque;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   361
    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
   362
} /* LZMA_fileLength */
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
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   365
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
   366
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   367
    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
   368
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   369
    /* Fix archive */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   370
    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
   371
        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
   372
    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
   373
        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
   374
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   375
    /* Fix neighbours */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   376
    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
   377
        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
   378
    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
   379
        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
   380
783
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   381
    entry->archive->folder[entry->folderIndex].references--;
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   382
    if (entry->archive->folder[entry->folderIndex].references == 0)
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   383
    {
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   384
        allocator.Free(entry->archive->folder[entry->folderIndex].cache);
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   385
        entry->archive->folder[entry->folderIndex].cache = NULL;
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   386
    }
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   387
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   388
    allocator.Free(entry);
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   389
    entry = NULL;
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   390
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   391
    return(1);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   392
} /* LZMA_fileClose */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   393
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   394
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   395
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
   396
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   397
    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
   398
    PHYSFS_uint8 res;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   399
    void *in;
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
    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
   402
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   403
    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
   404
    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
   405
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   406
    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
   407
        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
   408
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   409
    /* 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
   410
    res = TestSignatureCandidate(sig);
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   411
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   412
    __PHYSFS_platformClose(in);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   413
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   414
    return res;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   415
} /* LZMA_isArchive */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   416
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   417
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   418
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
   419
{
783
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   420
    PHYSFS_uint64 len;
782
5633b9a0c6b6 More corrections to lzma support from Dennis.
Ryan C. Gordon <icculus@icculus.org>
parents: 780
diff changeset
   421
    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
   422
    ISzAlloc allocImp;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   423
    ISzAlloc allocTempImp;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   424
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   425
    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
   426
    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
   427
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   428
    archive = (LZMAarchive *) allocator.Malloc(sizeof (LZMAarchive));
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   429
    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
   430
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   431
    archive->firstEntry = NULL;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   432
    archive->lastEntry = NULL;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   433
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   434
    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
   435
    {
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   436
        allocator.Free(archive);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   437
        return NULL;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   438
    } /* if */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   439
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   440
    /* 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
   441
    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
   442
    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
   443
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   444
    allocImp.Alloc = SzAllocPhysicsFS;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   445
    allocImp.Free = SzFreePhysicsFS;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   446
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   447
    allocTempImp.Alloc = SzAllocPhysicsFS;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   448
    allocTempImp.Free = SzFreePhysicsFS;
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
    InitCrcTable();
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   451
    SzArDbExInit(&archive->db);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   452
    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
   453
                               &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
   454
    {
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   455
        __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
   456
        allocator.Free(archive);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   457
        return NULL;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   458
    } /* if */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   459
783
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   460
    len = archive->db.Database.NumFolders * sizeof (LZMAfolder);
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   461
    archive->folder = (LZMAfolder *) allocator.Malloc(len);
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   462
    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
   463
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   464
    /*
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   465
     * 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
   466
     * Values will be set by LZMA_read()
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   467
     */
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   468
    memset(archive->folder, 0, len);
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   469
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   470
    return(archive);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   471
} /* LZMA_openArchive */
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
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   474
/*
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   475
 * 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
   476
 *  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
   477
 */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   478
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
   479
                           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
   480
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   481
    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
   482
    if (newstr == NULL)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   483
        return;
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
    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
   486
    newstr[ln] = '\0';
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   487
    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
   488
} /* doEnumCallback */
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
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   491
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
   492
                                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
   493
                                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
   494
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   495
    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
   496
    PHYSFS_sint32 dlen;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   497
    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
   498
    PHYSFS_sint32 max;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   499
    PHYSFS_sint32 i;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   500
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   501
    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
   502
    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
   503
        return;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   504
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   505
    dlen = strlen(dname);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   506
    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
   507
        dlen--;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   508
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   509
    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
   510
    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
   511
    while (i < max)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   512
    {
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   513
        char *add;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   514
        char *ptr;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   515
        PHYSFS_sint32 ln;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   516
        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
   517
        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
   518
            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
   519
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   520
        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
   521
        ptr = strchr(add, '/');
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   522
        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
   523
        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
   524
        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
   525
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   526
        /* 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
   527
        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
   528
        {
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   529
            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
   530
            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
   531
                break;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   532
        } /* while */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   533
    } /* while */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   534
} /* LZMA_enumerateFiles */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   535
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   536
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   537
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
   538
{
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   539
    LZMAarchive *archive = (LZMAarchive *) opaque;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   540
    PHYSFS_uint32 index = 0;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   541
    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
   542
} /* LZMA_exists */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   543
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   544
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   545
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
   546
                                         const char *name,
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   547
                                         int *fileExists)
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   548
{
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   549
    /* !!! 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
   550
    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
   551
} /* LZMA_getLastModTime */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   552
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   553
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   554
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
   555
{
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   556
    LZMAarchive *archive = (LZMAarchive *) opaque;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   557
    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
   558
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   559
    *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
   560
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   561
    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
   562
} /* LZMA_isDirectory */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   563
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
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
   566
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   567
    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
   568
} /* LZMA_isSymLink */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   569
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   570
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   571
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
   572
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   573
    LZMAarchive *archive = (LZMAarchive *) opaque;
782
5633b9a0c6b6 More corrections to lzma support from Dennis.
Ryan C. Gordon <icculus@icculus.org>
parents: 780
diff changeset
   574
    LZMAentry *entry = NULL;
783
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   575
    PHYSFS_uint32 fileIndex = 0;
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   576
    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
   577
783
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   578
    *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
   579
    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
   580
783
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   581
    folderIndex = archive->db.FileIndexToFolderIndexMap[fileIndex];
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   582
    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
   583
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   584
    entry = (LZMAentry *) allocator.Malloc(sizeof (LZMAentry));
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   585
    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
   586
783
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   587
    entry->fileIndex = fileIndex;
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   588
    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
   589
    entry->archive = archive;
783
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   590
    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
   591
    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
   592
    entry->position = 0;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   593
783
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   594
    archive->folder[folderIndex].references++;
f14fc3210eca More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 782
diff changeset
   595
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   596
    entry->next = NULL;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   597
    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
   598
    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
   599
        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
   600
    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
   601
    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
   602
        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
   603
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   604
    return(entry);
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   605
} /* LZMA_openRead */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   606
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
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
   609
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   610
    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
   611
} /* LZMA_openWrite */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   612
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
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
   615
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   616
    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
   617
} /* LZMA_openAppend */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   618
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   619
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   620
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
   621
{
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   622
    LZMAarchive *archive = (LZMAarchive *) opaque;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   623
    LZMAentry *entry = archive->firstEntry;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   624
    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
   625
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   626
    while (entry != NULL)
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   627
    {
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   628
        tmpEntry = entry->next;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   629
        LZMA_fileClose(entry);
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   630
        entry = tmpEntry;
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   631
    } /* while */
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   632
780
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   633
    SzArDbExFree(&archive->db, SzFreePhysicsFS);
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   634
    __PHYSFS_platformClose(archive->stream.File);
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   635
8d029fecde3a Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents: 775
diff changeset
   636
    /* 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
   637
    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
   638
    allocator.Free(archive);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   639
} /* LZMA_dirClose */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   640
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
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
   643
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   644
    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
   645
} /* LZMA_remove */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   646
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
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
   649
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   650
    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
   651
} /* LZMA_mkdir */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   652
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   653
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   654
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
   655
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   656
    "7Z",
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   657
    LZMA_ARCHIVE_DESCRIPTION,
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   658
    "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
   659
    "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
   660
};
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   661
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   662
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   663
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
   664
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   665
    &__PHYSFS_ArchiveInfo_LZMA,
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   666
    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
   667
    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
   668
    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
   669
    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
   670
    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
   671
    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
   672
    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
   673
    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
   674
    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
   675
    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
   676
    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
   677
    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
   678
    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
   679
    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
   680
    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
   681
    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
   682
    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
   683
    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
   684
    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
   685
    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
   686
};
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   687
795
0f10cda58a9a Changed PHYSFS_SUPPORTS_LZMA to PHYSFS_SUPPORTS_7Z.
Ryan C. Gordon <icculus@icculus.org>
parents: 783
diff changeset
   688
#endif  /* defined PHYSFS_SUPPORTS_7Z */
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   689
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   690
/* 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
   691