fix selecting 7z archive files other than the first one

This commit is contained in:
Brad Parker 2016-09-19 02:43:09 -04:00
parent 1205b12e15
commit 0899cd091e
2 changed files with 38 additions and 28 deletions

View File

@ -330,8 +330,6 @@ static int file_archive_decompress_data_to_file(
goto end; goto end;
} }
handle->backend->stream_free(handle->stream);
#if 0 #if 0
handle->real_checksum = handle->backend->stream_crc_calculate( handle->real_checksum = handle->backend->stream_crc_calculate(
0, handle->data, size); 0, handle->data, size);
@ -350,6 +348,8 @@ static int file_archive_decompress_data_to_file(
} }
end: end:
handle->backend->stream_free(handle->stream);
if (handle && handle->data) if (handle && handle->data)
free(handle->data); free(handle->data);
return ret; return ret;

View File

@ -58,17 +58,17 @@ static void* sevenzip_stream_new(void)
struct sevenzip_context_t *sevenzip_context = struct sevenzip_context_t *sevenzip_context =
(struct sevenzip_context_t*)calloc(1, sizeof(struct sevenzip_context_t)); (struct sevenzip_context_t*)calloc(1, sizeof(struct sevenzip_context_t));
memset(sevenzip_context, 0, sizeof(struct sevenzip_context_t));
/* These are the allocation routines - currently using /* These are the allocation routines - currently using
* the non-standard 7zip choices. */ * the non-standard 7zip choices. */
sevenzip_context->allocImp.Alloc = SzAlloc; sevenzip_context->allocImp.Alloc = SzAlloc;
sevenzip_context->allocImp.Free = SzFree; sevenzip_context->allocImp.Free = SzFree;
sevenzip_context->allocTempImp.Alloc = SzAllocTemp; sevenzip_context->allocTempImp.Alloc = SzAllocTemp;
sevenzip_context->allocTempImp.Free = SzFreeTemp; sevenzip_context->allocTempImp.Free = SzFreeTemp;
sevenzip_context->index = 0;
sevenzip_context->packIndex = 0;
sevenzip_context->temp_size = 0;
sevenzip_context->block_index = 0xFFFFFFFF; sevenzip_context->block_index = 0xFFFFFFFF;
sevenzip_context->output = NULL; sevenzip_context->output = NULL;
sevenzip_context->handle = NULL;
return sevenzip_context; return sevenzip_context;
} }
@ -80,6 +80,13 @@ static void sevenzip_stream_free(void *data)
if (!sevenzip_context) if (!sevenzip_context)
return; return;
if (sevenzip_context->output)
{
IAlloc_Free(&sevenzip_context->allocImp, sevenzip_context->output);
sevenzip_context->output = NULL;
sevenzip_context->handle->data = NULL;
}
SzArEx_Free(&sevenzip_context->db, &sevenzip_context->allocImp); SzArEx_Free(&sevenzip_context->db, &sevenzip_context->allocImp);
File_Close(&sevenzip_context->archiveStream.file); File_Close(&sevenzip_context->archiveStream.file);
} }
@ -253,8 +260,22 @@ static int sevenzip_stream_decompress_data_to_file_iterate(void *data)
struct sevenzip_context_t *sevenzip_context = struct sevenzip_context_t *sevenzip_context =
(struct sevenzip_context_t*)data; (struct sevenzip_context_t*)data;
SRes res = SZ_ERROR_FAIL;
size_t output_size = 0;
size_t offset = 0;
size_t outSizeProcessed = 0;
res = SzArEx_Extract(&sevenzip_context->db,
&sevenzip_context->lookStream.s, sevenzip_context->index,
&sevenzip_context->block_index, &sevenzip_context->output,
&output_size, &offset, &outSizeProcessed,
&sevenzip_context->allocImp, &sevenzip_context->allocTempImp);
if (res != SZ_OK)
return 0;
if (sevenzip_context->handle) if (sevenzip_context->handle)
sevenzip_context->handle->data = sevenzip_context->output; sevenzip_context->handle->data = sevenzip_context->output + offset;
return 1; return 1;
} }
@ -262,14 +283,16 @@ static int sevenzip_stream_decompress_data_to_file_iterate(void *data)
static int sevenzip_parse_file_init(file_archive_transfer_t *state, static int sevenzip_parse_file_init(file_archive_transfer_t *state,
const char *file) const char *file)
{ {
struct sevenzip_context_t *sevenzip_context = NULL; struct sevenzip_context_t *sevenzip_context =
(struct sevenzip_context_t*)sevenzip_stream_new();
if (state->archive_size < SEVENZIP_MAGIC_LEN) if (state->archive_size < SEVENZIP_MAGIC_LEN)
return -1; return -1;
if (memcmp(state->data, SEVENZIP_MAGIC, SEVENZIP_MAGIC_LEN) != 0) if (memcmp(state->data, SEVENZIP_MAGIC, SEVENZIP_MAGIC_LEN) != 0)
return -1; return -1;
sevenzip_context = (struct sevenzip_context_t*)sevenzip_stream_new(); state->stream = sevenzip_context;
/* could not open 7zip archive? */ /* could not open 7zip archive? */
if (InFile_Open(&sevenzip_context->archiveStream.file, file)) if (InFile_Open(&sevenzip_context->archiveStream.file, file))
@ -282,10 +305,11 @@ static int sevenzip_parse_file_init(file_archive_transfer_t *state,
CrcGenerateTable(); CrcGenerateTable();
SzArEx_Init(&sevenzip_context->db); SzArEx_Init(&sevenzip_context->db);
SzArEx_Open(&sevenzip_context->db, &sevenzip_context->lookStream.s, SRes res = SzArEx_Open(&sevenzip_context->db, &sevenzip_context->lookStream.s,
&sevenzip_context->allocImp, &sevenzip_context->allocTempImp); &sevenzip_context->allocImp, &sevenzip_context->allocTempImp);
state->stream = sevenzip_context; if (res != SZ_OK)
return -1;
return 0; return 0;
} }
@ -301,7 +325,8 @@ static int sevenzip_parse_file_iterate_step_internal(
if (sevenzip_context->index < sevenzip_context->db.db.NumFiles) if (sevenzip_context->index < sevenzip_context->db.db.NumFiles)
{ {
size_t len = SzArEx_GetFileNameUtf16(&sevenzip_context->db, sevenzip_context->index, NULL); size_t len = SzArEx_GetFileNameUtf16(&sevenzip_context->db,
sevenzip_context->index, NULL);
uint64_t compressed_size = 0; uint64_t compressed_size = 0;
if (sevenzip_context->packIndex < sevenzip_context->db.db.NumPackStreams) if (sevenzip_context->packIndex < sevenzip_context->db.db.NumPackStreams)
@ -319,7 +344,8 @@ static int sevenzip_parse_file_iterate_step_internal(
if (!temp) if (!temp)
return -1; return -1;
SzArEx_GetFileNameUtf16(&sevenzip_context->db, sevenzip_context->index, temp); SzArEx_GetFileNameUtf16(&sevenzip_context->db, sevenzip_context->index,
temp);
if (temp) if (temp)
{ {
@ -333,22 +359,6 @@ static int sevenzip_parse_file_iterate_step_internal(
strlcpy(filename, infile, PATH_MAX_LENGTH); strlcpy(filename, infile, PATH_MAX_LENGTH);
if (!userdata->list_only)
{
size_t output_size = 0;
size_t offset = 0;
size_t outSizeProcessed = 0;
res = SzArEx_Extract(&sevenzip_context->db,
&sevenzip_context->lookStream.s, sevenzip_context->index,
&sevenzip_context->block_index, &sevenzip_context->output,
&output_size, &offset, &outSizeProcessed,
&sevenzip_context->allocImp, &sevenzip_context->allocTempImp);
}
if (res != SZ_OK)
return -1;
*cmode = ARCHIVE_MODE_COMPRESSED; *cmode = ARCHIVE_MODE_COMPRESSED;
*checksum = file->Crc; *checksum = file->Crc;
*size = file->Size; *size = file->Size;