author | Ryan C. Gordon <icculus@icculus.org> |
Sun, 14 Feb 2010 23:07:19 -0500 | |
changeset 1052 | f87b0b7cca8e |
parent 1018 | 23aee7da04e0 |
child 1053 | a277a93ac1aa |
permissions | -rw-r--r-- |
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 |
* |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
4 |
* Please see the file lzma.txt in the lzma/ directory. |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
5 |
* |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
6 |
* This file was 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> |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
14 |
#include <time.h> |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
15 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
16 |
#include "physfs.h" |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
17 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
18 |
#define __PHYSICSFS_INTERNAL__ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
19 |
#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
|
20 |
|
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
21 |
#include "lzma/C/7zCrc.h" |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
22 |
#include "lzma/C/Archive/7z/7zIn.h" |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
23 |
#include "lzma/C/Archive/7z/7zExtract.h" |
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 |
|
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
26 |
/* 7z internal from 7zIn.c */ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
27 |
extern int TestSignatureCandidate(Byte *testBytes); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
28 |
|
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
29 |
|
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
30 |
#ifdef _LZMA_IN_CB |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
31 |
# define BUFFER_SIZE (1 << 12) |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
32 |
#endif /* _LZMA_IN_CB */ |
780
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
33 |
|
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
34 |
|
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
35 |
/* |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
36 |
* Carries filestream metadata through 7z |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
37 |
*/ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
38 |
typedef struct _FileInputStream |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
39 |
{ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
40 |
ISzAlloc allocImp; /* Allocation implementation, used by 7z */ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
41 |
ISzAlloc allocTempImp; /* Temporary allocation implementation, used by 7z */ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
42 |
ISzInStream inStream; /* Input stream with read callbacks, used by 7z */ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
43 |
void *file; /* Filehandle, used by read implementation */ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
44 |
#ifdef _LZMA_IN_CB |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
45 |
Byte buffer[BUFFER_SIZE]; /* Buffer, used by read implementation */ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
46 |
#endif /* _LZMA_IN_CB */ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
47 |
} FileInputStream; |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
48 |
|
783
f14fc3210eca
More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
782
diff
changeset
|
49 |
/* |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
50 |
* In the 7z format archives are splited into blocks, those are called folders |
783
f14fc3210eca
More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
782
diff
changeset
|
51 |
* Set by LZMA_read() |
f14fc3210eca
More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
782
diff
changeset
|
52 |
*/ |
f14fc3210eca
More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
782
diff
changeset
|
53 |
typedef struct _LZMAfolder |
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 |
PHYSFS_uint32 index; /* Index of folder in archive */ |
f14fc3210eca
More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
782
diff
changeset
|
56 |
PHYSFS_uint32 references; /* Number of files using this block */ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
57 |
PHYSFS_uint8 *cache; /* Cached folder */ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
58 |
size_t size; /* Size of folder */ |
783
f14fc3210eca
More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
782
diff
changeset
|
59 |
} LZMAfolder; |
f14fc3210eca
More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
782
diff
changeset
|
60 |
|
f14fc3210eca
More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
782
diff
changeset
|
61 |
/* |
f14fc3210eca
More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
782
diff
changeset
|
62 |
* 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
|
63 |
* in LZMA_read() |
f14fc3210eca
More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
782
diff
changeset
|
64 |
*/ |
780
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
65 |
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
|
66 |
{ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
67 |
struct _LZMAfile *files; /* Array of files, size == archive->db.Database.NumFiles */ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
68 |
LZMAfolder *folders; /* Array of folders, size == archive->db.Database.NumFolders */ |
780
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
69 |
CArchiveDatabaseEx db; /* For 7z: Database */ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
70 |
FileInputStream 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
|
71 |
} LZMAarchive; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
72 |
|
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
73 |
/* Set by LZMA_openArchive(), except offset which is set by LZMA_read() */ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
74 |
typedef struct _LZMAfile |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
75 |
{ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
76 |
PHYSFS_uint32 index; /* Index of file in archive */ |
780
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
77 |
LZMAarchive *archive; /* Link to corresponding archive */ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
78 |
LZMAfolder *folder; /* Link to corresponding folder */ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
79 |
CFileItem *item; /* For 7z: File info, eg. name, size */ |
783
f14fc3210eca
More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
782
diff
changeset
|
80 |
size_t offset; /* Offset in folder */ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
81 |
size_t position; /* Current "virtual" position in file */ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
82 |
} LZMAfile; |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
83 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
84 |
|
780
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
85 |
/* 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
|
86 |
|
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
87 |
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
|
88 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
89 |
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
|
90 |
} /* SzAllocPhysicsFS */ |
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 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
93 |
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
|
94 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
95 |
if (address != NULL) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
96 |
allocator.Free(address); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
97 |
} /* SzFreePhysicsFS */ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
98 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
99 |
|
780
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
100 |
/* Filesystem implementations to be passed to 7z */ |
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
101 |
|
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
102 |
#ifdef _LZMA_IN_CB |
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
103 |
|
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
104 |
/* |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
105 |
* Read implementation, to be passed to 7z |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
106 |
* WARNING: If the ISzInStream in 'object' is not contained in a valid FileInputStream this _will_ break horribly! |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
107 |
*/ |
780
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
108 |
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
|
109 |
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
|
110 |
{ |
1018
23aee7da04e0
Fixed some C++-style one-line comments in C code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1016
diff
changeset
|
111 |
FileInputStream *s = (FileInputStream *)(object - offsetof(FileInputStream, inStream)); /* HACK! */ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
112 |
PHYSFS_sint64 processedSizeLoc = 0; |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
113 |
|
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
114 |
if (maxReqSize > BUFFER_SIZE) |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
115 |
maxReqSize = BUFFER_SIZE; |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
116 |
processedSizeLoc = __PHYSFS_platformRead(s->file, s->buffer, 1, maxReqSize); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
117 |
*buffer = s->buffer; |
836
6514fba91816
Patched to compile with latest Platform SDK.
Ryan C. Gordon <icculus@icculus.org>
parents:
821
diff
changeset
|
118 |
if (processedSize != NULL) |
6514fba91816
Patched to compile with latest Platform SDK.
Ryan C. Gordon <icculus@icculus.org>
parents:
821
diff
changeset
|
119 |
*processedSize = (size_t) processedSizeLoc; |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
120 |
|
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
121 |
return SZ_OK; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
122 |
} /* SzFileReadImp */ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
123 |
|
780
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
124 |
#else |
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
125 |
|
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
126 |
/* |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
127 |
* Read implementation, to be passed to 7z |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
128 |
* WARNING: If the ISzInStream in 'object' is not contained in a valid FileInputStream this _will_ break horribly! |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
129 |
*/ |
780
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
130 |
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
|
131 |
size_t *processedSize) |
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
132 |
{ |
1018
23aee7da04e0
Fixed some C++-style one-line comments in C code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1016
diff
changeset
|
133 |
FileInputStream *s = (FileInputStream *)((unsigned long)object - offsetof(FileInputStream, inStream)); /* HACK! */ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
134 |
size_t processedSizeLoc = __PHYSFS_platformRead(s->file, buffer, 1, size); |
780
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
135 |
if (processedSize != 0) |
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
136 |
*processedSize = processedSizeLoc; |
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
137 |
return SZ_OK; |
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
138 |
} /* SzFileReadImp */ |
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
139 |
|
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
140 |
#endif |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
141 |
|
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
142 |
/* |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
143 |
* Seek implementation, to be passed to 7z |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
144 |
* WARNING: If the ISzInStream in 'object' is not contained in a valid FileInputStream this _will_ break horribly! |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
145 |
*/ |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
146 |
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
|
147 |
{ |
1018
23aee7da04e0
Fixed some C++-style one-line comments in C code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1016
diff
changeset
|
148 |
FileInputStream *s = (FileInputStream *)((unsigned long)object - offsetof(FileInputStream, inStream)); /* HACK! */ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
149 |
if (__PHYSFS_platformSeek(s->file, (PHYSFS_uint64) pos)) |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
150 |
return SZ_OK; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
151 |
return SZE_FAIL; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
152 |
} /* SzFileSeekImp */ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
153 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
154 |
|
780
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
155 |
/* |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
156 |
* Translate Microsoft FILETIME (used by 7zip) into UNIX timestamp |
780
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
157 |
*/ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
158 |
static PHYSFS_sint64 lzma_filetime_to_unix_timestamp(CArchiveFileTime *ft) |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
159 |
{ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
160 |
/* MS counts in nanoseconds ... */ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
161 |
const PHYSFS_uint64 FILETIME_NANOTICKS_PER_SECOND = __PHYSFS_UI64(10000000); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
162 |
/* MS likes to count seconds since 01.01.1601 ... */ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
163 |
const PHYSFS_uint64 FILETIME_UNIX_DIFF = __PHYSFS_UI64(11644473600); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
164 |
|
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
165 |
PHYSFS_uint64 filetime = ft->Low | ((PHYSFS_uint64)ft->High << 32); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
166 |
return filetime/FILETIME_NANOTICKS_PER_SECOND - FILETIME_UNIX_DIFF; |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
167 |
} /* lzma_filetime_to_unix_timestamp */ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
168 |
|
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
169 |
|
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
170 |
/* |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
171 |
* Compare a file with a given name, C89 stdlib variant |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
172 |
* Used for sorting |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
173 |
*/ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
174 |
static int lzma_file_cmp_stdlib(const void *key, const void *object) |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
175 |
{ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
176 |
const char *name = (const char *) key; |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
177 |
LZMAfile *file = (LZMAfile *) object; |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
999
diff
changeset
|
178 |
return strcmp(name, file->item->Name); |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
179 |
} /* lzma_file_cmp_posix */ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
180 |
|
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
181 |
|
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
182 |
/* |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
183 |
* Compare two files with each other based on the name |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
184 |
* Used for sorting |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
185 |
*/ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
186 |
static int lzma_file_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
187 |
{ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
188 |
LZMAfile *files = (LZMAfile *) _a; |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
999
diff
changeset
|
189 |
return strcmp(files[one].item->Name, files[two].item->Name); |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
190 |
} /* lzma_file_cmp */ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
191 |
|
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
192 |
|
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
193 |
/* |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
194 |
* Swap two entries in the file array |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
195 |
*/ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
196 |
static void lzma_file_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
197 |
{ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
198 |
LZMAfile tmp; |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
199 |
LZMAfile *first = &(((LZMAfile *) _a)[one]); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
200 |
LZMAfile *second = &(((LZMAfile *) _a)[two]); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
201 |
memcpy(&tmp, first, sizeof (LZMAfile)); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
202 |
memcpy(first, second, sizeof (LZMAfile)); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
203 |
memcpy(second, &tmp, sizeof (LZMAfile)); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
204 |
} /* lzma_file_swap */ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
205 |
|
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
206 |
|
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
207 |
/* |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
208 |
* Find entry 'name' in 'archive' |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
209 |
*/ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
210 |
static LZMAfile * lzma_find_file(LZMAarchive *archive, const char *name) |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
211 |
{ |
1018
23aee7da04e0
Fixed some C++-style one-line comments in C code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1016
diff
changeset
|
212 |
LZMAfile *file = bsearch(name, archive->files, archive->db.Database.NumFiles, sizeof(*archive->files), lzma_file_cmp_stdlib); /* FIXME: Should become __PHYSFS_search!!! */ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
213 |
|
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
214 |
BAIL_IF_MACRO(file == NULL, ERR_NO_SUCH_FILE, NULL); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
215 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
999
diff
changeset
|
216 |
return file; |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
217 |
} /* lzma_find_file */ |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
218 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
219 |
|
780
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
220 |
/* |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
221 |
* Load metadata for the file at given index |
780
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
222 |
*/ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
223 |
static int lzma_file_init(LZMAarchive *archive, PHYSFS_uint32 fileIndex) |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
224 |
{ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
225 |
LZMAfile *file = &archive->files[fileIndex]; |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
226 |
PHYSFS_uint32 folderIndex = archive->db.FileIndexToFolderIndexMap[fileIndex]; |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
227 |
|
1018
23aee7da04e0
Fixed some C++-style one-line comments in C code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1016
diff
changeset
|
228 |
file->index = fileIndex; /* Store index into 7z array, since we sort our own. */ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
229 |
file->archive = archive; |
1018
23aee7da04e0
Fixed some C++-style one-line comments in C code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1016
diff
changeset
|
230 |
file->folder = (folderIndex != (PHYSFS_uint32)-1 ? &archive->folders[folderIndex] : NULL); /* Directories don't have a folder (they contain no own data...) */ |
23aee7da04e0
Fixed some C++-style one-line comments in C code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1016
diff
changeset
|
231 |
file->item = &archive->db.Database.Files[fileIndex]; /* Holds crucial data and is often referenced -> Store link */ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
232 |
file->position = 0; |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
233 |
file->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
|
234 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
999
diff
changeset
|
235 |
return 1; |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
236 |
} /* lzma_load_file */ |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
237 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
238 |
|
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
239 |
/* |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
240 |
* Load metadata for all files |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
241 |
*/ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
242 |
static int lzma_files_init(LZMAarchive *archive) |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
243 |
{ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
244 |
PHYSFS_uint32 fileIndex = 0, numFiles = archive->db.Database.NumFiles; |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
245 |
|
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
246 |
for (fileIndex = 0; fileIndex < numFiles; fileIndex++ ) |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
247 |
{ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
248 |
if (!lzma_file_init(archive, fileIndex)) |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
249 |
{ |
1018
23aee7da04e0
Fixed some C++-style one-line comments in C code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1016
diff
changeset
|
250 |
return 0; /* FALSE on failure */ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
251 |
} |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
252 |
} /* for */ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
253 |
|
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
254 |
__PHYSFS_sort(archive->files, numFiles, lzma_file_cmp, lzma_file_swap); |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
255 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
999
diff
changeset
|
256 |
return 1; |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
257 |
} /* lzma_load_files */ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
258 |
|
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
259 |
|
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
260 |
/* |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
261 |
* Initialise specified archive |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
262 |
*/ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
263 |
static void lzma_archive_init(LZMAarchive *archive) |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
264 |
{ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
265 |
memset(archive, 0, sizeof(*archive)); |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
266 |
|
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
267 |
/* Prepare callbacks for 7z */ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
268 |
archive->stream.inStream.Read = SzFileReadImp; |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
269 |
archive->stream.inStream.Seek = SzFileSeekImp; |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
270 |
|
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
271 |
archive->stream.allocImp.Alloc = SzAllocPhysicsFS; |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
272 |
archive->stream.allocImp.Free = SzFreePhysicsFS; |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
273 |
|
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
274 |
archive->stream.allocTempImp.Alloc = SzAllocPhysicsFS; |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
275 |
archive->stream.allocTempImp.Free = SzFreePhysicsFS; |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
276 |
} |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
277 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
278 |
|
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
279 |
/* |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
280 |
* Deinitialise archive |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
281 |
*/ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
282 |
static void lzma_archive_exit(LZMAarchive *archive) |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
283 |
{ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
284 |
/* Free arrays */ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
285 |
allocator.Free(archive->folders); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
286 |
allocator.Free(archive->files); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
287 |
allocator.Free(archive); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
288 |
} |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
289 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
290 |
/* |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
291 |
* 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
|
292 |
*/ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
293 |
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
|
294 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
295 |
switch (rc) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
296 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
297 |
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
|
298 |
break; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
299 |
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
|
300 |
__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
|
301 |
break; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
302 |
case SZE_OUTOFMEMORY: |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
303 |
__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
|
304 |
break; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
305 |
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
|
306 |
__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
|
307 |
break; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
308 |
case SZE_NOTIMPL: |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
309 |
__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
|
310 |
break; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
311 |
case SZE_FAIL: |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
312 |
__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
|
313 |
break; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
314 |
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
|
315 |
__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
|
316 |
break; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
317 |
default: |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
318 |
__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
|
319 |
} /* switch */ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
320 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
999
diff
changeset
|
321 |
return rc; |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
322 |
} /* lzma_err */ |
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_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
|
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 |
{ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
328 |
LZMAfile *file = (LZMAfile *) opaque; |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
329 |
|
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
330 |
size_t wantedSize = objSize*objCount; |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
331 |
size_t remainingSize = file->item->Size - file->position; |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
332 |
size_t fileSize = 0; |
821
c7dd97edaa4e
Fixes for BeOS and gcc2.
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
333 |
|
780
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
334 |
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
|
335 |
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
|
336 |
|
780
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
337 |
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
|
338 |
{ |
780
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
339 |
wantedSize = remainingSize - (remainingSize % objSize); |
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
340 |
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
|
341 |
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
|
342 |
__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
|
343 |
} /* if */ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
344 |
|
783
f14fc3210eca
More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
782
diff
changeset
|
345 |
/* Only decompress the folder if it is not allready cached */ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
346 |
if (file->folder->cache == NULL) |
797 | 347 |
{ |
348 |
int rc = lzma_err(SzExtract( |
|
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
349 |
&file->archive->stream.inStream, /* compressed data */ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
350 |
&file->archive->db, /* 7z's database, containing everything */ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
351 |
file->index, /* Index into database arrays */ |
783
f14fc3210eca
More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
782
diff
changeset
|
352 |
/* Index of cached folder, will be changed by SzExtract */ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
353 |
&file->folder->index, |
783
f14fc3210eca
More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
782
diff
changeset
|
354 |
/* Cache for decompressed folder, allocated/freed by SzExtract */ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
355 |
&file->folder->cache, |
783
f14fc3210eca
More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
782
diff
changeset
|
356 |
/* Size of cache, will be changed by SzExtract */ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
357 |
&file->folder->size, |
783
f14fc3210eca
More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
782
diff
changeset
|
358 |
/* Offset of this file inside the cache, set by SzExtract */ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
359 |
&file->offset, |
783
f14fc3210eca
More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
782
diff
changeset
|
360 |
&fileSize, /* Size of this file */ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
361 |
&file->archive->stream.allocImp, |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
362 |
&file->archive->stream.allocTempImp)); |
797 | 363 |
|
364 |
if (rc != SZ_OK) |
|
783
f14fc3210eca
More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
782
diff
changeset
|
365 |
return -1; |
797 | 366 |
} /* if */ |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
367 |
|
780
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
368 |
/* Copy wanted bytes over from cache to outBuffer */ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
369 |
memcpy(outBuffer, |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
370 |
(file->folder->cache + |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
371 |
file->offset + file->position), |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
372 |
wantedSize); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
373 |
file->position += wantedSize; /* Increase virtual position */ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
374 |
|
780
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
375 |
return objCount; |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
376 |
} /* LZMA_read */ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
377 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
378 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
379 |
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
|
380 |
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
|
381 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
382 |
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
|
383 |
} /* LZMA_write */ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
384 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
385 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
386 |
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
|
387 |
{ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
388 |
LZMAfile *file = (LZMAfile *) opaque; |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
389 |
return (file->position >= file->item->Size); |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
390 |
} /* LZMA_eof */ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
391 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
392 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
393 |
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
|
394 |
{ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
395 |
LZMAfile *file = (LZMAfile *) opaque; |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
396 |
return (file->position); |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
397 |
} /* LZMA_tell */ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
398 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
399 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
400 |
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
|
401 |
{ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
402 |
LZMAfile *file = (LZMAfile *) opaque; |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
403 |
|
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(offset < 0, ERR_SEEK_OUT_OF_RANGE, 0); |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
405 |
BAIL_IF_MACRO(offset > file->item->Size, 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
|
406 |
|
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
407 |
file->position = offset; /* We only use a virtual position... */ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
408 |
|
780
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
409 |
return 1; |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
410 |
} /* LZMA_seek */ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
411 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
412 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
413 |
static 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
|
414 |
{ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
415 |
LZMAfile *file = (LZMAfile *) opaque; |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
416 |
return (file->item->Size); |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
417 |
} /* LZMA_fileLength */ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
418 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
419 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
420 |
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
|
421 |
{ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
422 |
LZMAfile *file = (LZMAfile *) opaque; |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
423 |
|
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
424 |
BAIL_IF_MACRO(file->folder == NULL, ERR_NOT_A_FILE, 0); |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
425 |
|
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
426 |
/* Only decrease refcount if someone actually requested this file... Prevents from overflows and close-on-open... */ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
427 |
if (file->folder->references > 0) |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
428 |
file->folder->references--; |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
429 |
if (file->folder->references == 0) |
783
f14fc3210eca
More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
782
diff
changeset
|
430 |
{ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
431 |
/* Free the cache which might have been allocated by LZMA_read() */ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
432 |
allocator.Free(file->folder->cache); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
433 |
file->folder->cache = NULL; |
783
f14fc3210eca
More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
782
diff
changeset
|
434 |
} |
f14fc3210eca
More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
782
diff
changeset
|
435 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
999
diff
changeset
|
436 |
return 1; |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
437 |
} /* LZMA_fileClose */ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
438 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
439 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
440 |
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
|
441 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
442 |
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
|
443 |
void *in; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
444 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
445 |
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
|
446 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
447 |
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
|
448 |
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
|
449 |
|
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
450 |
/* Read signature bytes */ |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
451 |
if (__PHYSFS_platformRead(in, sig, k7zSignatureSize, 1) != 1) |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
452 |
{ |
1018
23aee7da04e0
Fixed some C++-style one-line comments in C code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1016
diff
changeset
|
453 |
__PHYSFS_platformClose(in); /* Don't forget to close the file before returning... */ |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
454 |
BAIL_MACRO(NULL, 0); |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
455 |
} |
780
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
456 |
|
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
457 |
__PHYSFS_platformClose(in); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
458 |
|
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
459 |
/* Test whether sig is the 7z signature */ |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
999
diff
changeset
|
460 |
return TestSignatureCandidate(sig); |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
461 |
} /* LZMA_isArchive */ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
462 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
463 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
464 |
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
|
465 |
{ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
466 |
size_t len = 0; |
782
5633b9a0c6b6
More corrections to lzma support from Dennis.
Ryan C. Gordon <icculus@icculus.org>
parents:
780
diff
changeset
|
467 |
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
|
468 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
469 |
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
|
470 |
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
|
471 |
|
780
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
472 |
archive = (LZMAarchive *) allocator.Malloc(sizeof (LZMAarchive)); |
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
473 |
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
|
474 |
|
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
475 |
lzma_archive_init(archive); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
476 |
|
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
477 |
if ( (archive->stream.file = __PHYSFS_platformOpenRead(name)) == NULL ) |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
478 |
{ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
479 |
__PHYSFS_platformClose(archive->stream.file); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
480 |
lzma_archive_exit(archive); |
1018
23aee7da04e0
Fixed some C++-style one-line comments in C code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1016
diff
changeset
|
481 |
return NULL; /* Error is set by platformOpenRead! */ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
482 |
} |
780
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
483 |
|
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
484 |
CrcGenerateTable(); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
485 |
SzArDbExInit(&archive->db); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
486 |
if (lzma_err(SzArchiveOpen(&archive->stream.inStream, |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
487 |
&archive->db, |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
488 |
&archive->stream.allocImp, |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
489 |
&archive->stream.allocTempImp)) != SZ_OK) |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
490 |
{ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
491 |
SzArDbExFree(&archive->db, SzFreePhysicsFS); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
492 |
__PHYSFS_platformClose(archive->stream.file); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
493 |
lzma_archive_exit(archive); |
1018
23aee7da04e0
Fixed some C++-style one-line comments in C code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1016
diff
changeset
|
494 |
return NULL; /* Error is set by lzma_err! */ |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
495 |
} /* if */ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
496 |
|
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
497 |
len = archive->db.Database.NumFiles * sizeof (LZMAfile); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
498 |
archive->files = (LZMAfile *) allocator.Malloc(len); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
499 |
if (archive->files == NULL) |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
500 |
{ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
501 |
SzArDbExFree(&archive->db, SzFreePhysicsFS); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
502 |
__PHYSFS_platformClose(archive->stream.file); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
503 |
lzma_archive_exit(archive); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
504 |
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
505 |
} |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
506 |
|
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
507 |
/* |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
508 |
* Init with 0 so we know when a folder is already cached |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
509 |
* Values will be set by LZMA_openRead() |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
510 |
*/ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
511 |
memset(archive->files, 0, len); |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
512 |
|
783
f14fc3210eca
More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
782
diff
changeset
|
513 |
len = archive->db.Database.NumFolders * sizeof (LZMAfolder); |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
514 |
archive->folders = (LZMAfolder *) allocator.Malloc(len); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
515 |
if (archive->folders == NULL) |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
516 |
{ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
517 |
SzArDbExFree(&archive->db, SzFreePhysicsFS); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
518 |
__PHYSFS_platformClose(archive->stream.file); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
519 |
lzma_archive_exit(archive); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
520 |
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
521 |
} |
783
f14fc3210eca
More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
782
diff
changeset
|
522 |
|
f14fc3210eca
More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
782
diff
changeset
|
523 |
/* |
f14fc3210eca
More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
782
diff
changeset
|
524 |
* 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
|
525 |
* Values will be set by LZMA_read() |
f14fc3210eca
More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
782
diff
changeset
|
526 |
*/ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
527 |
memset(archive->folders, 0, len); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
528 |
|
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
529 |
if(!lzma_files_init(archive)) |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
530 |
{ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
531 |
SzArDbExFree(&archive->db, SzFreePhysicsFS); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
532 |
__PHYSFS_platformClose(archive->stream.file); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
533 |
lzma_archive_exit(archive); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
534 |
BAIL_MACRO(ERR_UNKNOWN_ERROR, NULL); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
535 |
} |
783
f14fc3210eca
More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
782
diff
changeset
|
536 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
999
diff
changeset
|
537 |
return archive; |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
538 |
} /* LZMA_openArchive */ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
539 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
540 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
541 |
/* |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
542 |
* 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
|
543 |
* 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
|
544 |
*/ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
545 |
static void doEnumCallback(PHYSFS_EnumFilesCallback cb, void *callbackdata, |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
546 |
const char *odir, const char *str, size_t flen) |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
547 |
{ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
548 |
char *newstr = __PHYSFS_smallAlloc(flen + 1); |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
549 |
if (newstr == NULL) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
550 |
return; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
551 |
|
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
552 |
memcpy(newstr, str, flen); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
553 |
newstr[flen] = '\0'; |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
554 |
cb(callbackdata, odir, newstr); |
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
836
diff
changeset
|
555 |
__PHYSFS_smallFree(newstr); |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
556 |
} /* doEnumCallback */ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
557 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
558 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
559 |
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
|
560 |
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
|
561 |
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
|
562 |
{ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
563 |
size_t dlen = strlen(dname), |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
564 |
dlen_inc = dlen + ((dlen > 0) ? 1 : 0); |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
565 |
LZMAarchive *archive = (LZMAarchive *) opaque; |
924
fb5bc1b528c9
Date: Sat, 2 Feb 2008 14:28:02 +1300
Ryan C. Gordon <icculus@icculus.org>
parents:
918
diff
changeset
|
566 |
LZMAfile *file = NULL, |
fb5bc1b528c9
Date: Sat, 2 Feb 2008 14:28:02 +1300
Ryan C. Gordon <icculus@icculus.org>
parents:
918
diff
changeset
|
567 |
*lastFile = &archive->files[archive->db.Database.NumFiles]; |
fb5bc1b528c9
Date: Sat, 2 Feb 2008 14:28:02 +1300
Ryan C. Gordon <icculus@icculus.org>
parents:
918
diff
changeset
|
568 |
if (dlen) |
fb5bc1b528c9
Date: Sat, 2 Feb 2008 14:28:02 +1300
Ryan C. Gordon <icculus@icculus.org>
parents:
918
diff
changeset
|
569 |
{ |
fb5bc1b528c9
Date: Sat, 2 Feb 2008 14:28:02 +1300
Ryan C. Gordon <icculus@icculus.org>
parents:
918
diff
changeset
|
570 |
file = lzma_find_file(archive, dname); |
1018
23aee7da04e0
Fixed some C++-style one-line comments in C code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1016
diff
changeset
|
571 |
if (file != NULL) /* if 'file' is NULL it should stay so, otherwise errors will not be handled */ |
924
fb5bc1b528c9
Date: Sat, 2 Feb 2008 14:28:02 +1300
Ryan C. Gordon <icculus@icculus.org>
parents:
918
diff
changeset
|
572 |
file += 1; |
fb5bc1b528c9
Date: Sat, 2 Feb 2008 14:28:02 +1300
Ryan C. Gordon <icculus@icculus.org>
parents:
918
diff
changeset
|
573 |
} |
fb5bc1b528c9
Date: Sat, 2 Feb 2008 14:28:02 +1300
Ryan C. Gordon <icculus@icculus.org>
parents:
918
diff
changeset
|
574 |
else |
fb5bc1b528c9
Date: Sat, 2 Feb 2008 14:28:02 +1300
Ryan C. Gordon <icculus@icculus.org>
parents:
918
diff
changeset
|
575 |
{ |
fb5bc1b528c9
Date: Sat, 2 Feb 2008 14:28:02 +1300
Ryan C. Gordon <icculus@icculus.org>
parents:
918
diff
changeset
|
576 |
file = archive->files; |
fb5bc1b528c9
Date: Sat, 2 Feb 2008 14:28:02 +1300
Ryan C. Gordon <icculus@icculus.org>
parents:
918
diff
changeset
|
577 |
} |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
578 |
|
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
579 |
BAIL_IF_MACRO(file == NULL, ERR_NO_SUCH_FILE, ); |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
580 |
|
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
581 |
while (file < lastFile) |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
582 |
{ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
583 |
const char * fname = file->item->Name; |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
584 |
const char * dirNameEnd = fname + dlen_inc; |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
585 |
|
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
586 |
if (strncmp(dname, fname, dlen) != 0) /* Stop after mismatch, archive->files is sorted */ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
587 |
break; |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
588 |
|
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
589 |
if (strchr(dirNameEnd, '/')) /* Skip subdirs */ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
590 |
{ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
591 |
file++; |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
592 |
continue; |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
593 |
} |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
594 |
|
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
595 |
/* Do the actual callback... */ |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
596 |
doEnumCallback(cb, callbackdata, origdir, dirNameEnd, strlen(dirNameEnd)); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
597 |
|
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
598 |
file++; |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
599 |
} |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
600 |
} /* LZMA_enumerateFiles */ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
601 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
602 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
603 |
static 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
|
604 |
{ |
780
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
605 |
LZMAarchive *archive = (LZMAarchive *) opaque; |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
999
diff
changeset
|
606 |
return (lzma_find_file(archive, name) != NULL); |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
607 |
} /* LZMA_exists */ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
608 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
609 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
610 |
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
|
611 |
const char *name, |
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
612 |
int *fileExists) |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
613 |
{ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
614 |
LZMAarchive *archive = (LZMAarchive *) opaque; |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
615 |
LZMAfile *file = lzma_find_file(archive, name); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
616 |
|
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
617 |
*fileExists = (file != NULL); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
618 |
|
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
619 |
BAIL_IF_MACRO(file == NULL, NULL, -1); |
1018
23aee7da04e0
Fixed some C++-style one-line comments in C code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1016
diff
changeset
|
620 |
BAIL_IF_MACRO(!file->item->IsLastWriteTimeDefined, NULL, -1); /* write-time may not be defined for every file */ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
621 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
999
diff
changeset
|
622 |
return lzma_filetime_to_unix_timestamp(&file->item->LastWriteTime); |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
623 |
} /* LZMA_getLastModTime */ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
624 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
625 |
|
1052
f87b0b7cca8e
Added first work on PHYSFS_stat() API (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents:
1018
diff
changeset
|
626 |
static int LZMA_stat(dvoid *opaque, const char *name, PHYSFS_Stat *st) |
f87b0b7cca8e
Added first work on PHYSFS_stat() API (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents:
1018
diff
changeset
|
627 |
{ |
f87b0b7cca8e
Added first work on PHYSFS_stat() API (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents:
1018
diff
changeset
|
628 |
return -1; /* !!! FIXME: write me */ |
f87b0b7cca8e
Added first work on PHYSFS_stat() API (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents:
1018
diff
changeset
|
629 |
} /* LZMA_stat */ |
f87b0b7cca8e
Added first work on PHYSFS_stat() API (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents:
1018
diff
changeset
|
630 |
|
f87b0b7cca8e
Added first work on PHYSFS_stat() API (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents:
1018
diff
changeset
|
631 |
|
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
632 |
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
|
633 |
{ |
780
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
634 |
LZMAarchive *archive = (LZMAarchive *) opaque; |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
635 |
LZMAfile *file = lzma_find_file(archive, name); |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
636 |
|
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
637 |
*fileExists = (file != NULL); |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
638 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
999
diff
changeset
|
639 |
return ((file == NULL) ? 0 : file->item->IsDirectory); |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
640 |
} /* LZMA_isDirectory */ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
641 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
642 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
643 |
static int LZMA_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
|
644 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
645 |
BAIL_MACRO(ERR_NOT_SUPPORTED, 0); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
646 |
} /* LZMA_isSymLink */ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
647 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
648 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
649 |
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
|
650 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
651 |
LZMAarchive *archive = (LZMAarchive *) opaque; |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
652 |
LZMAfile *file = lzma_find_file(archive, name); |
782
5633b9a0c6b6
More corrections to lzma support from Dennis.
Ryan C. Gordon <icculus@icculus.org>
parents:
780
diff
changeset
|
653 |
|
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
654 |
*fileExists = (file != NULL); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
655 |
BAIL_IF_MACRO(file == NULL, ERR_NO_SUCH_FILE, NULL); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
656 |
BAIL_IF_MACRO(file->folder == NULL, ERR_NOT_A_FILE, NULL); |
783
f14fc3210eca
More 7zip work (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
782
diff
changeset
|
657 |
|
999
54f5a2e925ac
Temporary fix for (re)opening files in lzma archives (thanks, Sam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
972
diff
changeset
|
658 |
file->position = 0; |
1018
23aee7da04e0
Fixed some C++-style one-line comments in C code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1016
diff
changeset
|
659 |
file->folder->references++; /* Increase refcount for automatic cleanup... */ |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
660 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
999
diff
changeset
|
661 |
return file; |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
662 |
} /* LZMA_openRead */ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
663 |
|
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 |
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
|
666 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
667 |
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
|
668 |
} /* LZMA_openWrite */ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
669 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
670 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
671 |
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
|
672 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
673 |
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
|
674 |
} /* LZMA_openAppend */ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
675 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
676 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
677 |
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
|
678 |
{ |
780
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
679 |
LZMAarchive *archive = (LZMAarchive *) opaque; |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
680 |
PHYSFS_uint32 fileIndex = 0, numFiles = archive->db.Database.NumFiles; |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
681 |
|
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
682 |
for (fileIndex = 0; fileIndex < numFiles; fileIndex++) |
780
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
683 |
{ |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
684 |
LZMA_fileClose(&archive->files[fileIndex]); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
685 |
} /* for */ |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
686 |
|
780
8d029fecde3a
Rewritten 7zip/lzma support (thanks, Dennis!)
Ryan C. Gordon <icculus@icculus.org>
parents:
775
diff
changeset
|
687 |
SzArDbExFree(&archive->db, SzFreePhysicsFS); |
918
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
688 |
__PHYSFS_platformClose(archive->stream.file); |
2c7c6c5c23e0
Many improvements to lzma.c (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
898
diff
changeset
|
689 |
lzma_archive_exit(archive); |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
690 |
} /* LZMA_dirClose */ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
691 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
692 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
693 |
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
|
694 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
695 |
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
|
696 |
} /* LZMA_remove */ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
697 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
698 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
699 |
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
|
700 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
701 |
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
|
702 |
} /* LZMA_mkdir */ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
703 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
704 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
705 |
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
|
706 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
707 |
"7Z", |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
708 |
LZMA_ARCHIVE_DESCRIPTION, |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
709 |
"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
|
710 |
"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
|
711 |
}; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
712 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
713 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
714 |
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
|
715 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
716 |
&__PHYSFS_ArchiveInfo_LZMA, |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
717 |
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
|
718 |
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
|
719 |
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
|
720 |
LZMA_exists, /* exists() method */ |
1052
f87b0b7cca8e
Added first work on PHYSFS_stat() API (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents:
1018
diff
changeset
|
721 |
LZMA_stat, /* stat() method */ |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
722 |
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
|
723 |
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
|
724 |
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
|
725 |
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
|
726 |
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
|
727 |
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
|
728 |
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
|
729 |
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
|
730 |
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
|
731 |
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
|
732 |
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
|
733 |
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
|
734 |
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
|
735 |
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
|
736 |
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
|
737 |
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
|
738 |
}; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
739 |
|
795
0f10cda58a9a
Changed PHYSFS_SUPPORTS_LZMA to PHYSFS_SUPPORTS_7Z.
Ryan C. Gordon <icculus@icculus.org>
parents:
783
diff
changeset
|
740 |
#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
|
741 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
742 |
/* 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
|
743 |