mirror of
https://github.com/libretro/RetroArch
synced 2025-03-30 16:20:27 +00:00
Refactor zlib_inflate_data_to_file so that it is nonblocking
This commit is contained in:
parent
db2677de99
commit
a532742b96
@ -58,11 +58,19 @@ static int zlib_cb(const char *name, const char *valid_exts,
|
||||
break;
|
||||
|
||||
case 8: /* Deflate */
|
||||
if (!zlib_inflate_data_to_file(path, valid_exts, cdata,
|
||||
csize, size, crc32))
|
||||
{
|
||||
RARCH_ERR("Failed to deflate to: %s.\n", path);
|
||||
return 0;
|
||||
int ret = 0;
|
||||
zlib_file_handle_t handle = {0};
|
||||
if (!zlib_inflate_data_to_file_init(&handle, cdata, csize, size))
|
||||
goto error;
|
||||
|
||||
do{
|
||||
ret = zlib_inflate_data_to_file_iterate(handle.stream);
|
||||
}while(ret == 0);
|
||||
|
||||
if (!zlib_inflate_data_to_file(&handle, ret, path, valid_exts,
|
||||
cdata, csize, size, crc32))
|
||||
goto error;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -71,6 +79,10 @@ static int zlib_cb(const char *name, const char *valid_exts,
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
error:
|
||||
RARCH_ERR("Failed to deflate to: %s.\n", path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_retroarch_browser_NativeInterface_extractArchiveTo(
|
||||
|
@ -314,40 +314,30 @@ int zlib_inflate_data_to_file_iterate(void *data)
|
||||
*
|
||||
* Returns: true (1) on success, otherwise false (0).
|
||||
**/
|
||||
int zlib_inflate_data_to_file(const char *path, const char *valid_exts,
|
||||
int zlib_inflate_data_to_file(zlib_file_handle_t *handle,
|
||||
int ret, const char *path, const char *valid_exts,
|
||||
const uint8_t *cdata, uint32_t csize, uint32_t size, uint32_t checksum)
|
||||
{
|
||||
int ret = 1;
|
||||
zlib_file_handle_t handle = {0};
|
||||
if (handle)
|
||||
z_stream_free(handle->stream);
|
||||
|
||||
(void)valid_exts;
|
||||
|
||||
if (!zlib_inflate_data_to_file_init(&handle, cdata, csize, size))
|
||||
GOTO_END_ERROR();
|
||||
|
||||
do{
|
||||
ret = zlib_inflate_data_to_file_iterate(handle.stream);
|
||||
}while(ret == 0);
|
||||
|
||||
if (ret == -1)
|
||||
if (!handle || ret == -1)
|
||||
{
|
||||
ret = 0;
|
||||
|
||||
z_stream_free(handle.stream);
|
||||
|
||||
if (ret == 0)
|
||||
goto end;
|
||||
}
|
||||
|
||||
handle.real_checksum = crc32_calculate(handle.data, size);
|
||||
if (handle.real_checksum != checksum)
|
||||
handle->real_checksum = crc32_calculate(handle->data, size);
|
||||
if (handle->real_checksum != checksum)
|
||||
RARCH_WARN("File CRC differs from ZIP CRC. File: 0x%x, ZIP: 0x%x.\n",
|
||||
(unsigned)handle.real_checksum, (unsigned)checksum);
|
||||
(unsigned)handle->real_checksum, (unsigned)checksum);
|
||||
|
||||
if (!write_file(path, handle.data, size))
|
||||
if (!write_file(path, handle->data, size))
|
||||
GOTO_END_ERROR();
|
||||
|
||||
end:
|
||||
if (handle.data)
|
||||
free(handle.data);
|
||||
if (handle->data)
|
||||
free(handle->data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -497,14 +487,25 @@ static int zip_extract_cb(const char *name, const char *valid_exts,
|
||||
data->found_content = write_file(new_path, cdata, size);
|
||||
return false;
|
||||
case ZLIB_MODE_DEFLATE:
|
||||
if (zlib_inflate_data_to_file(new_path, valid_exts,
|
||||
cdata, csize, size, checksum))
|
||||
{
|
||||
strlcpy(data->zip_path, new_path, data->zip_path_size);
|
||||
data->found_content = true;
|
||||
int ret = 0;
|
||||
zlib_file_handle_t handle = {0};
|
||||
if (!zlib_inflate_data_to_file_init(&handle, cdata, csize, size))
|
||||
return 0;
|
||||
|
||||
do{
|
||||
ret = zlib_inflate_data_to_file_iterate(handle.stream);
|
||||
}while(ret == 0);
|
||||
|
||||
if (zlib_inflate_data_to_file(&handle, ret, new_path, valid_exts,
|
||||
cdata, csize, size, checksum))
|
||||
{
|
||||
strlcpy(data->zip_path, new_path, data->zip_path_size);
|
||||
data->found_content = true;
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
|
@ -74,6 +74,12 @@ bool zlib_extract_first_content_file(char *zip_path, size_t zip_path_size,
|
||||
**/
|
||||
struct string_list *zlib_get_file_list(const char *path, const char *valid_exts);
|
||||
|
||||
bool zlib_inflate_data_to_file_init(
|
||||
zlib_file_handle_t *handle,
|
||||
const uint8_t *cdata, uint32_t csize, uint32_t size);
|
||||
|
||||
int zlib_inflate_data_to_file_iterate(void *data);
|
||||
|
||||
/**
|
||||
* zlib_inflate_data_to_file:
|
||||
* @path : filename path of archive.
|
||||
@ -86,8 +92,9 @@ struct string_list *zlib_get_file_list(const char *path, const char *valid_exts)
|
||||
*
|
||||
* Returns: true (1) on success, otherwise false (0).
|
||||
**/
|
||||
int zlib_inflate_data_to_file(const char *path, const char *valid_exts,
|
||||
const uint8_t *data, uint32_t csize, uint32_t size, uint32_t crc32);
|
||||
int zlib_inflate_data_to_file(zlib_file_handle_t *handle,
|
||||
int ret, const char *path, const char *valid_exts,
|
||||
const uint8_t *cdata, uint32_t csize, uint32_t size, uint32_t checksum);
|
||||
|
||||
struct string_list *compressed_file_list_new(const char *filename,
|
||||
const char* ext);
|
||||
|
@ -81,11 +81,28 @@ static int zlib_extract_core_callback(const char *name, const char *valid_exts,
|
||||
write_file(path, cdata, size);
|
||||
break;
|
||||
case 8: /* Deflate */
|
||||
zlib_inflate_data_to_file(path, valid_exts, cdata, csize, size, crc32);
|
||||
{
|
||||
int ret = 0;
|
||||
zlib_file_handle_t handle = {0};
|
||||
if (!zlib_inflate_data_to_file_init(&handle, cdata, csize, size))
|
||||
goto error;
|
||||
|
||||
do{
|
||||
ret = zlib_inflate_data_to_file_iterate(handle.stream);
|
||||
}while(ret == 0);
|
||||
|
||||
if (!zlib_inflate_data_to_file(&handle, ret, path, valid_exts,
|
||||
cdata, csize, size, crc32))
|
||||
goto error;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
error:
|
||||
RARCH_ERR("Failed to deflate to: %s.\n", path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cb_core_updater_download(void *data_, size_t len)
|
||||
|
Loading…
x
Reference in New Issue
Block a user