Skip to content

Commit

Permalink
- adapted the Zip root folder eliminator to deal with archives that d…
Browse files Browse the repository at this point in the history
…o not add proper folder records to their central directory.
  • Loading branch information
coelckers committed Jul 25, 2021
1 parent 3864dcf commit c51c6fa
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions source/common/filesystem/file_zip.cpp
Expand Up @@ -208,8 +208,9 @@ bool FZipFile::Open(bool quiet, LumpFilterInfo* filter)
char *dirptr = (char*)directory;
FZipLump *lump_p = Lumps;

FString name0;
FString name0, name1;
bool foundspeciallump = false;
bool foundprefix = false;

// Check if all files have the same prefix so that this can be stripped out.
// This will only be done if there is either a MAPINFO, ZMAPINFO or GAMEINFO lump in the subdirectory, denoting a ZDoom mod.
Expand All @@ -234,31 +235,39 @@ bool FZipFile::Open(bool quiet, LumpFilterInfo* filter)

name.ToLower();
if (name.IndexOf("__macosx") == 0)
continue; // skip Apple garbage. At this stage only the root folder matters,
if (i == 0)
continue; // skip Apple garbage. At this stage only the root folder matters.
if (!foundprefix)
{
// check for special names, if one of these gets found this must be treated as a normal zip.
bool isspecial = name.IndexOf("/") < 0 || (filter && filter->reservedFolders.Find(name) < filter->reservedFolders.Size());
if (isspecial) break;
name0 = name.Left(name.LastIndexOf("/")+1);
name1 = name.Left(name.IndexOf("/") + 1);
foundprefix = true;
}
else

if (name.IndexOf(name0) != 0)
{
if (name.IndexOf(name0) != 0)
if (name1.IsNotEmpty())
{
name0 = "";
break;
name0 = name1;
if (name.IndexOf(name0) != 0)
{
name0 = "";
}
}
else if (!foundspeciallump && filter)
{
// at least one of the more common definition lumps must be present.
for (auto &p : filter->requiredPrefixes)
{
if (name.IndexOf(name0 + p) == 0 || name.LastIndexOf(p) == name.Len() - strlen(p))
{
foundspeciallump = true;
break;
}
if (name0.IsEmpty())
break;
}
if (!foundspeciallump && filter)
{
// at least one of the more common definition lumps must be present.
for (auto &p : filter->requiredPrefixes)
{
if (name.IndexOf(name0 + p) == 0 || name.LastIndexOf(p) == name.Len() - strlen(p))
{
foundspeciallump = true;
break;
}
}
}
Expand Down

0 comments on commit c51c6fa

Please sign in to comment.