mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-03 08:15:35 +00:00
Make Plugin load order deterministic (alphabetic) (#315)
Add Feature / Fix: #306
This commit is contained in:
commit
ee599e970d
@ -360,18 +360,31 @@ void TLuaEngine::CollectAndInitPlugins() {
|
|||||||
if (!fs::exists(mResourceServerPath)) {
|
if (!fs::exists(mResourceServerPath)) {
|
||||||
fs::create_directories(mResourceServerPath);
|
fs::create_directories(mResourceServerPath);
|
||||||
}
|
}
|
||||||
for (const auto& Dir : fs::directory_iterator(mResourceServerPath)) {
|
|
||||||
auto Path = Dir.path();
|
std::vector<fs::path> PluginsEntries;
|
||||||
Path = fs::relative(Path);
|
for (const auto& Entry : fs::directory_iterator(mResourceServerPath)) {
|
||||||
if (!Dir.is_directory()) {
|
if (Entry.is_directory()) {
|
||||||
beammp_error("\"" + Dir.path().string() + "\" is not a directory, skipping");
|
PluginsEntries.push_back(Entry);
|
||||||
} else {
|
} else {
|
||||||
|
beammp_error("\"" + Entry.path().string() + "\" is not a directory, skipping");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::sort(PluginsEntries.begin(), PluginsEntries.end(), [](const fs::path& first, const fs::path& second) {
|
||||||
|
auto firstStr = first.string();
|
||||||
|
auto secondStr = second.string();
|
||||||
|
std::transform(firstStr.begin(), firstStr.end(), firstStr.begin(), ::tolower);
|
||||||
|
std::transform(secondStr.begin(), secondStr.end(), secondStr.begin(), ::tolower);
|
||||||
|
return firstStr < secondStr;
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const auto& Dir : PluginsEntries) {
|
||||||
|
auto Path = fs::relative(Dir);
|
||||||
TLuaPluginConfig Config { Path.stem().string() };
|
TLuaPluginConfig Config { Path.stem().string() };
|
||||||
FindAndParseConfig(Path, Config);
|
FindAndParseConfig(Path, Config);
|
||||||
InitializePlugin(Path, Config);
|
InitializePlugin(Path, Config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void TLuaEngine::InitializePlugin(const fs::path& Folder, const TLuaPluginConfig& Config) {
|
void TLuaEngine::InitializePlugin(const fs::path& Folder, const TLuaPluginConfig& Config) {
|
||||||
beammp_assert(fs::exists(Folder));
|
beammp_assert(fs::exists(Folder));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user