Skip to content

Commit

Permalink
Fixed twice listing plugin files.
Browse files Browse the repository at this point in the history
  • Loading branch information
MiranDMC committed Jun 15, 2024
1 parent 9dfd475 commit 59a7584
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions source/CPluginSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void CPluginSystem::LoadPlugins()
if (pluginsLoaded) return; // already done

std::set<std::string> names;
std::vector<std::string> filenames;
std::set<std::string> filenames;

// load plugins from main CLEO directory
auto ScanPluginsDir = [&](std::string path, const std::string prefix, const std::string extension)
Expand All @@ -25,20 +25,23 @@ void CPluginSystem::LoadPlugins()

for (DWORD i = 0; i < files.count; i++)
{
auto name = FS::path(files.strings[i]).filename().string();
name = name.substr(prefix.length()); // cut off prefix
name.resize(name.length() - extension.length()); // cut off extension
std::transform(name.begin(), name.end(), name.begin(), [](unsigned char c) { return std::toupper(c); });

if (names.find(name) == names.end())
{
names.insert(name);
filenames.emplace_back(files.strings[i]);
TRACE(" - '%s'", files.strings[i]);
}
else
if (filenames.find(files.strings[i]) == filenames.end())
{
LOG_WARNING(0, " - '%s' skipped, duplicate of `%s` plugin.", files.strings[i], name.c_str());
auto name = FS::path(files.strings[i]).filename().string();
name = name.substr(prefix.length()); // cut off prefix
name.resize(name.length() - extension.length()); // cut off extension
std::transform(name.begin(), name.end(), name.begin(), [](unsigned char c) { return std::toupper(c); });

if (names.find(name) == names.end())
{
names.insert(name);
filenames.emplace(files.strings[i]);
TRACE(" - '%s'", files.strings[i]);
}
else
{
LOG_WARNING(0, " - '%s' skipped, duplicate of `%s` plugin.", files.strings[i], name.c_str());
}
}
}

Expand All @@ -53,7 +56,7 @@ void CPluginSystem::LoadPlugins()
// reverse order, so opcodes from CLEO5 plugins can overwrite opcodes from legacy plugins
if (!filenames.empty())
{
for (auto it = filenames.crbegin(); it < filenames.crend(); it++)
for (auto it = filenames.crbegin(); it != filenames.crend(); it++)
{
const auto filename = it->c_str();
TRACE("Loading plugin '%s'", filename);
Expand Down

0 comments on commit 59a7584

Please sign in to comment.