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

Add support for loading plugins from Thunderstore packages #513

Merged
merged 4 commits into from
Jul 27, 2023
Merged
Changes from 1 commit
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
27 changes: 16 additions & 11 deletions NorthstarDLL/plugins/plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,23 @@ std::optional<Plugin> PluginManager::LoadPlugin(fs::path path, PluginInitFuncs*

inline void findPlugins(fs::path pluginPath, std::vector<fs::path>& paths)
Jan200101 marked this conversation as resolved.
Show resolved Hide resolved
{
if (fs::exists(pluginPath) && fs::is_directory(pluginPath))
// ensure dirs exist
if (!fs::exists(pluginPath) || !fs::is_directory(pluginPath))
GeckoEidechse marked this conversation as resolved.
Show resolved Hide resolved
{
// ensure dirs exist
fs::recursive_directory_iterator iterator(pluginPath);
if (std::filesystem::begin(iterator) != std::filesystem::end(iterator))
{
for (auto const& entry : iterator)
{
if (fs::is_regular_file(entry) && entry.path().extension() == ".dll")
paths.emplace_back(entry.path());
}
}
return;
}

fs::recursive_directory_iterator iterator(pluginPath);
Copy link
Member

@GeckoEidechse GeckoEidechse Jul 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, I just realised another issue with this.

This doesn't do the regex check that the modmanager.cpp code does to ensure that package is installed correctly.

// Set up regex for `AUTHOR-MOD-VERSION` pattern
std::regex pattern(R"(.*\\([a-zA-Z0-9_]+)-([a-zA-Z0-9_]+)-(\d+\.\d+\.\d+))");

Also I'm pretty sure it still loads plugins recursively which we shouldn't need to do anymore. The only reason we added recursive load was to have a plugin -> Thunderstore-package mapping with the old plugin system, i.e. #460 which can also be reverted now.

// ensure iterator is not empty
if (std::filesystem::begin(iterator) != std::filesystem::end(iterator))
{
return;
}

for (auto const& entry : iterator)
{
if (fs::is_regular_file(entry) && entry.path().extension() == ".dll")
paths.emplace_back(entry.path());
}
}

Expand Down