Normalize archive progress calculation

This commit is contained in:
Brad Parker 2019-01-16 17:22:46 -05:00
parent dd4bf2c41f
commit 16fffd67ea
3 changed files with 6 additions and 3 deletions

View File

@ -496,7 +496,6 @@ static bool file_archive_walk(const char *file, const char *valid_exts,
int file_archive_parse_file_progress(file_archive_transfer_t *state)
{
/* FIXME: this estimate is worse than before */
ptrdiff_t delta = 0;
if (!state || state->archive_size == 0)
@ -504,7 +503,10 @@ int file_archive_parse_file_progress(file_archive_transfer_t *state)
delta = state->directory - state->data;
return (int)(delta * 100 / state->archive_size);
if (!state->start_delta)
state->start_delta = delta;
return (int)(((delta - state->start_delta) * 100) / (state->archive_size - state->start_delta));
}
/**

View File

@ -240,7 +240,7 @@ static int zip_file_read(
const char *needle, void **buf,
const char *optional_outfile)
{
file_archive_transfer_t zlib = {ARCHIVE_TRANSFER_NONE, 0, NULL, NULL, NULL, NULL, NULL, NULL };
file_archive_transfer_t zlib = {0};
struct archive_extract_userdata userdata = {{0}};
bool returnerr = true;
int ret = 0;

View File

@ -64,6 +64,7 @@ typedef struct file_archive_transfer
{
enum file_archive_transfer_type type;
int32_t archive_size;
ptrdiff_t start_delta;
file_archive_file_data_t *handle;
void *stream;
const uint8_t *footer;