Replace wildcards with something that is faster overall and for debug builds in particular
This commit is contained in:
parent
87bda3d8d4
commit
b8078fdb32
4 changed files with 51 additions and 1843 deletions
|
|
@ -24,7 +24,8 @@ struct LumpFilterInfo
|
|||
std::vector<std::string> reservedFolders;
|
||||
std::vector<std::string> requiredPrefixes;
|
||||
std::vector<std::string> embeddings;
|
||||
std::vector<std::string> blockednames; // File names that will never be accepted (e.g. dehacked.exe for Doom)
|
||||
std::vector<std::string> blockedextensions; // File extensions that will never be accepted (e.g. .exe and .bat)
|
||||
std::vector<std::string> blockedfolders; // File folders that will never be accepted (e.g. __macosx)
|
||||
std::function<bool(const char*, const char*)> filenamecheck; // for scanning directories, this allows to eliminate unwanted content.
|
||||
std::function<void()> postprocessFunc;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@
|
|||
#include "unicode.h"
|
||||
#include "fs_findfile.h"
|
||||
#include "fs_decompress.h"
|
||||
#include "wildcards.hpp"
|
||||
#include <string_view>
|
||||
#include <algorithm>
|
||||
|
||||
namespace FileSys {
|
||||
|
|
@ -344,6 +344,46 @@ void FResourceFile::GenerateHash()
|
|||
}
|
||||
}
|
||||
|
||||
static bool IsBlockedExt(LumpFilterInfo* filter, const std::string_view& name)
|
||||
{
|
||||
size_t extpos = name.find_last_of('.');
|
||||
if (extpos != std::string::npos)
|
||||
{
|
||||
std::string_view ext = name.substr(extpos);
|
||||
for (const auto& blockedext : filter->blockedextensions)
|
||||
{
|
||||
if (ext == blockedext)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool IsBlockedFolder(LumpFilterInfo* filter, const std::string_view& name)
|
||||
{
|
||||
size_t start = 0;
|
||||
while (true)
|
||||
{
|
||||
size_t end = std::min(name.find_first_of("/\\", start), name.size());
|
||||
std::string_view folder = name.substr(start, end - start);
|
||||
|
||||
if (folder.empty())
|
||||
break;
|
||||
|
||||
for (const auto& blockedfolder : filter->blockedfolders)
|
||||
{
|
||||
if (folder == blockedfolder)
|
||||
return true;
|
||||
}
|
||||
|
||||
if (end == name.size())
|
||||
break;
|
||||
|
||||
start = end + 1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// FResourceFile :: PostProcessArchive
|
||||
|
|
@ -365,14 +405,13 @@ void FResourceFile::PostProcessArchive(LumpFilterInfo *filter)
|
|||
{
|
||||
for (uint32_t i = 0; i < NumLumps; i++)
|
||||
{
|
||||
std::string name = Entries[i].FileName;
|
||||
for (auto& pattern : filter->blockednames)
|
||||
// Note: this used wildcards::match before. That was super slow in debug builds in particular.
|
||||
// Do not change it back to wildcards, please.
|
||||
|
||||
std::string_view name = Entries[i].FileName;
|
||||
if (IsBlockedExt(filter, name) || IsBlockedFolder(filter, name))
|
||||
{
|
||||
if (wildcards::match(name, pattern))
|
||||
{
|
||||
Entries[i].FileName = "";
|
||||
continue;
|
||||
}
|
||||
Entries[i].FileName = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1986,7 +1986,8 @@ void GetReserved(LumpFilterInfo& lfi)
|
|||
lfi.reservedFolders = { "flats/", "textures/", "hires/", "sprites/", "voxels/", "colormaps/", "acs/", "maps/", "voices/", "patches/", "graphics/", "sounds/", "music/",
|
||||
"materials/", "models/", "fonts/", "brightmaps/" };
|
||||
lfi.requiredPrefixes = { "mapinfo", "zmapinfo", "umapinfo", "gameinfo", "sndinfo", "sndseq", "sbarinfo", "menudef", "gldefs", "animdefs", "decorate", "zscript", "iwadinfo", "complvl", "terrain", "maps/" };
|
||||
lfi.blockednames = { "*.bat", "*.exe", "__macosx/*", "*/__macosx/*" };
|
||||
lfi.blockedextensions = { ".bat", ".exe" };
|
||||
lfi.blockedfolders = { "__macosx" };
|
||||
}
|
||||
|
||||
static FString CheckGameInfo(std::vector<std::string> & pwads)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue