Skip to content

Commit

Permalink
simplify search in zip file directory
Browse files Browse the repository at this point in the history
Some zip archives do not have separate entries for directories (hrs.zip).
  • Loading branch information
rfomin committed Aug 17, 2024
1 parent 0880d6f commit cfad4e9
Showing 1 changed file with 3 additions and 38 deletions.
41 changes: 3 additions & 38 deletions src/w_zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,58 +108,27 @@ static boolean W_ZIP_AddDir(w_handle_t handle, const char *path,

boolean is_root = (path[0] == '.');

int index = 0;

char *dir = M_StringDuplicate(path);

if (!is_root)
{
ConvertSlashes(dir);

char *s = M_StringJoin(dir, "/");
index = mz_zip_reader_locate_file(zip, s, NULL, 0);
free(s);

if (index < 0)
{
free(dir);
return false;
}

++index;
}
ConvertSlashes(dir);

int startlump = numlumps;

char *subdir = NULL;

for ( ; index < mz_zip_reader_get_num_files(zip); ++index)
for (int index = 0 ; index < mz_zip_reader_get_num_files(zip); ++index)
{
mz_zip_archive_file_stat stat;
mz_zip_reader_file_stat(zip, index, &stat);

if (stat.m_is_directory)
{
if (subdir)
{
free(subdir);
}
subdir = M_StringDuplicate(stat.m_filename);
subdir[strlen(subdir) - 1] = '\0';
continue;
}

char *name = M_DirName(stat.m_filename);
if (subdir && !strcasecmp(name, subdir))
if (!is_root && strcasecmp(name, dir))
{
free(name);
continue;
}
else if (strcasecmp(name, dir))
{
free(name);
break;
}
free(name);

if (is_root && M_StringCaseEndsWith(stat.m_filename, ".wad"))
Expand Down Expand Up @@ -197,10 +166,6 @@ static boolean W_ZIP_AddDir(w_handle_t handle, const char *path,
W_AddMarker(end_marker);
}

if (subdir)
{
free(subdir);
}
free(dir);
return true;
}
Expand Down

0 comments on commit cfad4e9

Please sign in to comment.