From c51c6fa524b6de1e55d7a35d506e791e2e69b920 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 25 Jul 2021 12:18:53 +0200 Subject: [PATCH] - adapted the Zip root folder eliminator to deal with archives that do not add proper folder records to their central directory. --- source/common/filesystem/file_zip.cpp | 43 ++++++++++++++++----------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/source/common/filesystem/file_zip.cpp b/source/common/filesystem/file_zip.cpp index f33b60ba4..0096507bf 100644 --- a/source/common/filesystem/file_zip.cpp +++ b/source/common/filesystem/file_zip.cpp @@ -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. @@ -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; } } }