Skip to content

Commit

Permalink
Added back unzLocateFile variant for minizip 1.2 with MZ_COMPAT_VERSION.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmoinvaz committed Dec 17, 2023
1 parent fbd8443 commit 6c5f265
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
38 changes: 38 additions & 0 deletions mz_compat.c
Expand Up @@ -1099,6 +1099,7 @@ int unzGoToNextFile(unzFile file) {
return err;
}

#if MZ_COMPAT_VERSION < 110
#ifdef WIN32
# define UNZ_DEFAULT_IGNORE_CASE 1
#else
Expand Down Expand Up @@ -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

/***************************************************************************/

Expand Down
8 changes: 8 additions & 0 deletions mz_compat.h
Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 6c5f265

Please sign in to comment.