Skip to content

Commit 596ece7

Browse files
authoredOct 24, 2024
Recursively load components (#920)
* load components recursively * allow the exclusion of components in sub-directories
1 parent 01d70fb commit 596ece7

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed
 

‎Server/Source/core_impl.hpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,20 +1085,25 @@ class Core final : public ICore, public PlayerConnectEventHandler, public Consol
10851085
auto excludeCfg = config.getStrings("exclude");
10861086
if (!componentsCfg || componentsCfg->empty())
10871087
{
1088-
for (auto& de : ghc::filesystem::directory_iterator(path))
1088+
for (auto& de : ghc::filesystem::recursive_directory_iterator(path))
10891089
{
10901090
ghc::filesystem::path p = de.path();
10911091
if (p.extension() == LIBRARY_EXT)
10921092
{
10931093
if (excludeCfg && !excludeCfg->empty())
10941094
{
1095-
p.replace_extension("");
1095+
ghc::filesystem::path rel = ghc::filesystem::relative(p, path);
1096+
rel.replace_extension();
10961097
// Is this in the "don't load" list?
1097-
if (std::find(excludeCfg->begin(), excludeCfg->end(), p.filename().string()) != excludeCfg->end())
1098+
const auto isExcluded = [rel = std::move(rel)](const String& exclude)
1099+
{
1100+
return ghc::filesystem::path(exclude) == rel;
1101+
};
1102+
if (std::find_if(excludeCfg->begin(), excludeCfg->end(), isExcluded)
1103+
!= excludeCfg->end())
10981104
{
10991105
continue;
11001106
}
1101-
p.replace_extension(LIBRARY_EXT);
11021107
}
11031108

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

11221127
if (excludeCfg && !excludeCfg->empty())
11231128
{
1129+
ghc::filesystem::path rel = ghc::filesystem::relative(file, path);
1130+
rel.replace_extension();
11241131
// Is this in the "don't load" list?
1125-
if (std::find(excludeCfg->begin(), excludeCfg->end(), file.filename().string()) != excludeCfg->end())
1132+
const auto isExcluded = [rel = std::move(rel)](const String& exclude)
1133+
{
1134+
return ghc::filesystem::path(exclude) == rel;
1135+
};
1136+
if (std::find_if(excludeCfg->begin(), excludeCfg->end(), isExcluded)
1137+
!= excludeCfg->end())
11261138
{
11271139
continue;
11281140
}

0 commit comments

Comments
 (0)