Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed doubled listing plugin files. #153

Merged
merged 1 commit into from
Jun 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions source/CPluginSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,27 @@ void CPluginSystem::LoadPlugins()

for (DWORD i = 0; i < files.count; i++)
{
if (std::find(filenames.begin(), filenames.end(), files.strings[i]) != filenames.end())
continue; // file already listed

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())
// case insensitive search in already listed plugin names
auto found = std::find_if(names.begin(), names.end(), [&](const std::string& s) {
return _stricmp(s.c_str(), name.c_str()) == 0;
});

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

Expand All @@ -53,7 +60,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