Skip to content

Commit 82f4f67

Browse files
authored
Add support for archived file size query along with crc32 (#18315)
1 parent b62ee31 commit 82f4f67

4 files changed

Lines changed: 31 additions & 2 deletions

File tree

libretro-common/file/archive_file.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,21 @@ const struct file_archive_file_backend* file_archive_get_file_backend(const char
654654
* file found inside is used.
655655
**/
656656
uint32_t file_archive_get_file_crc32(const char *path)
657+
{
658+
uint64_t file_size;
659+
return file_archive_get_file_crc32_and_size(path, &file_size);
660+
}
661+
662+
/**
663+
* file_archive_get_file_crc32_and_size:
664+
* @path : filename path of archive
665+
* @size : size of the file inside the archive
666+
*
667+
* Returns: CRC32 of the specified file in the archive, otherwise 0.
668+
* If no path within the archive is specified, the first
669+
* file found inside is used.
670+
**/
671+
uint32_t file_archive_get_file_crc32_and_size(const char *path, uint64_t *size)
657672
{
658673
file_archive_transfer_t state;
659674
struct archive_extract_userdata userdata = {0};
@@ -713,6 +728,6 @@ uint32_t file_archive_get_file_crc32(const char *path)
713728
}
714729

715730
file_archive_parse_file_iterate_stop(&state);
716-
731+
*size = userdata.size;
717732
return userdata.crc;
718733
}

libretro-common/file/archive_file_7z.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ static int sevenzip_parse_file_iterate_step(void *context,
493493
return ret;
494494

495495
userdata->crc = checksum;
496+
userdata->size = size;
496497

497498
if (file_cb && !file_cb(userdata->current_file_path, valid_exts,
498499
cdata, cmode,

libretro-common/file/archive_file_zlib.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,8 @@ static int zip_parse_file_iterate_step(void *context,
527527
if (ret != 1)
528528
return ret;
529529

530-
userdata->crc = checksum;
530+
userdata->crc = checksum;
531+
userdata->size = size;
531532

532533
if (file_cb && !file_cb(userdata->current_file_path, valid_exts, cdata, cmode,
533534
csize, size, checksum, userdata))

libretro-common/include/file/archive_file.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ struct archive_extract_userdata
9797
decompress_state_t *dec;
9898
void* cb_data;
9999
uint32_t crc;
100+
uint64_t size;
100101
char archive_path[PATH_MAX_LENGTH];
101102
char current_file_path[PATH_MAX_LENGTH];
102103
bool found_file;
@@ -202,6 +203,17 @@ const struct file_archive_file_backend* file_archive_get_file_backend(const char
202203
**/
203204
uint32_t file_archive_get_file_crc32(const char *path);
204205

206+
/**
207+
* file_archive_get_file_crc32_and_size:
208+
* @path : filename path of archive
209+
* @size : size of the file inside the archive
210+
*
211+
* Returns: CRC32 of the specified file in the archive, otherwise 0.
212+
* If no path within the archive is specified, the first
213+
* file found inside is used.
214+
**/
215+
uint32_t file_archive_get_file_crc32_and_size(const char *path, uint64_t *size);
216+
205217
extern const struct file_archive_file_backend zlib_backend;
206218
extern const struct file_archive_file_backend sevenzip_backend;
207219

0 commit comments

Comments
 (0)