From 6c5f265a55f1a12a7a016cd2962feff91cff5d2e Mon Sep 17 00:00:00 2001 From: Nathan Moinvaziri Date: Sun, 17 Dec 2023 09:34:25 -0800 Subject: [PATCH] Added back unzLocateFile variant for minizip 1.2 with MZ_COMPAT_VERSION. --- mz_compat.c | 38 ++++++++++++++++++++++++++++++++++++++ mz_compat.h | 8 ++++++++ 2 files changed, 46 insertions(+) diff --git a/mz_compat.c b/mz_compat.c index 1193ee45..5be4c8a1 100644 --- a/mz_compat.c +++ b/mz_compat.c @@ -1099,6 +1099,7 @@ int unzGoToNextFile(unzFile file) { return err; } +#if MZ_COMPAT_VERSION < 110 #ifdef WIN32 # define UNZ_DEFAULT_IGNORE_CASE 1 #else @@ -1141,6 +1142,43 @@ int unzLocateFile(unzFile file, const char *filename, unzFileNameCase filename_c compat->entry_index = preserve_index; return err; } +#else +int unzLocateFile(unzFile file, const char* filename, unzFileNameComparer filename_compare_func) { + mz_compat* compat = (mz_compat*)file; + mz_zip_file* file_info = NULL; + uint64_t preserve_index = 0; + int32_t err = MZ_OK; + int32_t result = 0; + + if (!compat) + return UNZ_PARAMERROR; + + preserve_index = compat->entry_index; + + err = mz_zip_goto_first_entry(compat->handle); + while (err == MZ_OK) { + err = mz_zip_entry_get_info(compat->handle, &file_info); + if (err != MZ_OK) + break; + + if ((intptr_t)filename_compare_func > 2) { + result = filename_compare_func(file, filename, file_info->filename); + } + else { + int32_t case_sensitive = (int32_t)(intptr_t)filename_compare_func; + result = mz_path_compare_wc(filename, file_info->filename, !case_sensitive); + } + + if (result == 0) + return MZ_OK; + + err = mz_zip_goto_next_entry(compat->handle); + } + + compat->entry_index = preserve_index; + return err; +} +#endif /***************************************************************************/ diff --git a/mz_compat.h b/mz_compat.h index dc158a5f..24b6899f 100644 --- a/mz_compat.h +++ b/mz_compat.h @@ -308,12 +308,16 @@ typedef struct unz_file_info_s { /***************************************************************************/ +#if MZ_COMPAT_VERSION < 110 /* Possible values: 0 - Uses OS default, e.g. Windows ignores case. 1 - Is case sensitive. >= 2 - Ignore case. */ typedef int unzFileNameCase; +#else +typedef int (*unzFileNameComparer)(unzFile file, const char* filename1, const char* filename2); +#endif typedef int (*unzIteratorFunction)(unzFile file); typedef int (*unzIteratorFunction2)(unzFile file, unz_file_info64 *pfile_info, char *filename, uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, @@ -354,7 +358,11 @@ ZEXPORT int unzGetCurrentFileInfo64(unzFile file, unz_file_info64 * pfile_in ZEXPORT int unzGoToFirstFile(unzFile file); ZEXPORT int unzGoToNextFile(unzFile file); +#if MZ_COMPAT_VERSION < 110 ZEXPORT int unzLocateFile(unzFile file, const char *filename, unzFileNameCase filename_case); +#else +ZEXPORT int unzLocateFile(unzFile file, const char* filename, unzFileNameComparer filename_compare_func); +#endif ZEXPORT int unzGetLocalExtrafield(unzFile file, void *buf, unsigned int len);