From 12be710ccfced44f310c97620c48d75ad7dcbb0f Mon Sep 17 00:00:00 2001 From: zoltanvb Date: Fri, 17 Oct 2025 07:22:24 +0200 Subject: [PATCH] Add support for archived file size query along with crc32 Extend the interface with file_archive_get_file_crc32_and_size, which also returns the uncompressed size of the file. --- libretro-common/file/archive_file.c | 17 ++++++++++++++++- libretro-common/file/archive_file_7z.c | 1 + libretro-common/file/archive_file_zlib.c | 3 ++- libretro-common/include/file/archive_file.h | 12 ++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/libretro-common/file/archive_file.c b/libretro-common/file/archive_file.c index 519bde6a9e82..94f98134ac59 100644 --- a/libretro-common/file/archive_file.c +++ b/libretro-common/file/archive_file.c @@ -654,6 +654,21 @@ const struct file_archive_file_backend* file_archive_get_file_backend(const char * file found inside is used. **/ uint32_t file_archive_get_file_crc32(const char *path) +{ + uint64_t file_size; + return file_archive_get_file_crc32_and_size(path, &file_size); +} + +/** + * file_archive_get_file_crc32_and_size: + * @path : filename path of archive + * @size : size of the file inside the archive + * + * Returns: CRC32 of the specified file in the archive, otherwise 0. + * If no path within the archive is specified, the first + * file found inside is used. + **/ +uint32_t file_archive_get_file_crc32_and_size(const char *path, uint64_t *size) { file_archive_transfer_t state; struct archive_extract_userdata userdata = {0}; @@ -713,6 +728,6 @@ uint32_t file_archive_get_file_crc32(const char *path) } file_archive_parse_file_iterate_stop(&state); - + *size = userdata.size; return userdata.crc; } diff --git a/libretro-common/file/archive_file_7z.c b/libretro-common/file/archive_file_7z.c index 013bf4262a50..31d685fa779f 100644 --- a/libretro-common/file/archive_file_7z.c +++ b/libretro-common/file/archive_file_7z.c @@ -493,6 +493,7 @@ static int sevenzip_parse_file_iterate_step(void *context, return ret; userdata->crc = checksum; + userdata->size = size; if (file_cb && !file_cb(userdata->current_file_path, valid_exts, cdata, cmode, diff --git a/libretro-common/file/archive_file_zlib.c b/libretro-common/file/archive_file_zlib.c index 86332655b283..68062fd355ab 100644 --- a/libretro-common/file/archive_file_zlib.c +++ b/libretro-common/file/archive_file_zlib.c @@ -527,7 +527,8 @@ static int zip_parse_file_iterate_step(void *context, if (ret != 1) return ret; - userdata->crc = checksum; + userdata->crc = checksum; + userdata->size = size; if (file_cb && !file_cb(userdata->current_file_path, valid_exts, cdata, cmode, csize, size, checksum, userdata)) diff --git a/libretro-common/include/file/archive_file.h b/libretro-common/include/file/archive_file.h index 7a0a9f70655f..e979de508846 100644 --- a/libretro-common/include/file/archive_file.h +++ b/libretro-common/include/file/archive_file.h @@ -97,6 +97,7 @@ struct archive_extract_userdata decompress_state_t *dec; void* cb_data; uint32_t crc; + uint64_t size; char archive_path[PATH_MAX_LENGTH]; char current_file_path[PATH_MAX_LENGTH]; bool found_file; @@ -202,6 +203,17 @@ const struct file_archive_file_backend* file_archive_get_file_backend(const char **/ uint32_t file_archive_get_file_crc32(const char *path); +/** + * file_archive_get_file_crc32_and_size: + * @path : filename path of archive + * @size : size of the file inside the archive + * + * Returns: CRC32 of the specified file in the archive, otherwise 0. + * If no path within the archive is specified, the first + * file found inside is used. + **/ +uint32_t file_archive_get_file_crc32_and_size(const char *path, uint64_t *size); + extern const struct file_archive_file_backend zlib_backend; extern const struct file_archive_file_backend sevenzip_backend;