Skip to content

Latest commit

 

History

History
695 lines (549 loc) · 19.9 KB

lzma.c

File metadata and controls

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