- adapted the Zip root folder eliminator to deal with archives that do not add proper folder records to their central directory.

This commit is contained in:
Christoph Oelckers 2021-07-25 12:18:53 +02:00
parent 3864dcfc17
commit c51c6fa524

View file

@ -208,8 +208,9 @@ bool FZipFile::Open(bool quiet, LumpFilterInfo* filter)
char *dirptr = (char*)directory; char *dirptr = (char*)directory;
FZipLump *lump_p = Lumps; FZipLump *lump_p = Lumps;
FString name0; FString name0, name1;
bool foundspeciallump = false; bool foundspeciallump = false;
bool foundprefix = false;
// Check if all files have the same prefix so that this can be stripped out. // 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. // This will only be done if there is either a MAPINFO, ZMAPINFO or GAMEINFO lump in the subdirectory, denoting a ZDoom mod.
@ -234,22 +235,31 @@ bool FZipFile::Open(bool quiet, LumpFilterInfo* filter)
name.ToLower(); name.ToLower();
if (name.IndexOf("__macosx") == 0) if (name.IndexOf("__macosx") == 0)
continue; // skip Apple garbage. At this stage only the root folder matters, continue; // skip Apple garbage. At this stage only the root folder matters.
if (i == 0) if (!foundprefix)
{ {
// check for special names, if one of these gets found this must be treated as a normal zip. // 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()); bool isspecial = name.IndexOf("/") < 0 || (filter && filter->reservedFolders.Find(name) < filter->reservedFolders.Size());
if (isspecial) break; if (isspecial) break;
name0 = name.Left(name.LastIndexOf("/")+1); name0 = name.Left(name.LastIndexOf("/")+1);
name1 = name.Left(name.IndexOf("/") + 1);
foundprefix = true;
} }
else
if (name.IndexOf(name0) != 0)
{ {
if (name1.IsNotEmpty())
{
name0 = name1;
if (name.IndexOf(name0) != 0) if (name.IndexOf(name0) != 0)
{ {
name0 = ""; name0 = "";
}
}
if (name0.IsEmpty())
break; break;
} }
else if (!foundspeciallump && filter) if (!foundspeciallump && filter)
{ {
// at least one of the more common definition lumps must be present. // at least one of the more common definition lumps must be present.
for (auto &p : filter->requiredPrefixes) for (auto &p : filter->requiredPrefixes)
@ -262,7 +272,6 @@ bool FZipFile::Open(bool quiet, LumpFilterInfo* filter)
} }
} }
} }
}
// If it ran through the list without finding anything it should not attempt any path remapping. // If it ran through the list without finding anything it should not attempt any path remapping.
if (!foundspeciallump) name0 = ""; if (!foundspeciallump) name0 = "";