Skip to content

Commit

Permalink
Recursively load components (#920)
Browse files Browse the repository at this point in the history
* load components recursively

* allow the exclusion of components in sub-directories
  • Loading branch information
myudev authored Oct 24, 2024
1 parent 01d70fb commit 596ece7
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions Server/Source/core_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1085,20 +1085,25 @@ class Core final : public ICore, public PlayerConnectEventHandler, public Consol
auto excludeCfg = config.getStrings("exclude");
if (!componentsCfg || componentsCfg->empty())
{
for (auto& de : ghc::filesystem::directory_iterator(path))
for (auto& de : ghc::filesystem::recursive_directory_iterator(path))
{
ghc::filesystem::path p = de.path();
if (p.extension() == LIBRARY_EXT)
{
if (excludeCfg && !excludeCfg->empty())
{
p.replace_extension("");
ghc::filesystem::path rel = ghc::filesystem::relative(p, path);
rel.replace_extension();
// Is this in the "don't load" list?
if (std::find(excludeCfg->begin(), excludeCfg->end(), p.filename().string()) != excludeCfg->end())
const auto isExcluded = [rel = std::move(rel)](const String& exclude)
{
return ghc::filesystem::path(exclude) == rel;
};
if (std::find_if(excludeCfg->begin(), excludeCfg->end(), isExcluded)
!= excludeCfg->end())
{
continue;
}
p.replace_extension(LIBRARY_EXT);
}

IComponent* component = loadComponent(p);
Expand All @@ -1121,8 +1126,15 @@ class Core final : public ICore, public PlayerConnectEventHandler, public Consol

if (excludeCfg && !excludeCfg->empty())
{
ghc::filesystem::path rel = ghc::filesystem::relative(file, path);
rel.replace_extension();
// Is this in the "don't load" list?
if (std::find(excludeCfg->begin(), excludeCfg->end(), file.filename().string()) != excludeCfg->end())
const auto isExcluded = [rel = std::move(rel)](const String& exclude)
{
return ghc::filesystem::path(exclude) == rel;
};
if (std::find_if(excludeCfg->begin(), excludeCfg->end(), isExcluded)
!= excludeCfg->end())
{
continue;
}
Expand Down

0 comments on commit 596ece7

Please sign in to comment.