aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDLL/plugins/plugins.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'NorthstarDLL/plugins/plugins.cpp')
-rw-r--r--NorthstarDLL/plugins/plugins.cpp54
1 files changed, 38 insertions, 16 deletions
diff --git a/NorthstarDLL/plugins/plugins.cpp b/NorthstarDLL/plugins/plugins.cpp
index 1c426f09..9ba4707a 100644
--- a/NorthstarDLL/plugins/plugins.cpp
+++ b/NorthstarDLL/plugins/plugins.cpp
@@ -188,8 +188,36 @@ std::optional<Plugin> PluginManager::LoadPlugin(fs::path path, PluginInitFuncs*
return plugin;
}
+inline void FindPlugins(fs::path pluginPath, std::vector<fs::path>& paths)
+{
+ // ensure dirs exist
+ if (!fs::exists(pluginPath) || !fs::is_directory(pluginPath))
+ {
+ return;
+ }
+
+ fs::recursive_directory_iterator iterator(pluginPath);
+ // 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());
+ }
+}
+
bool PluginManager::LoadPlugins()
{
+ if (strstr(GetCommandLineA(), "-noplugins") != NULL)
+ {
+ NS::log::PLUGINSYS->warn("-noplugins detected; skipping loading plugins");
+ return false;
+ }
+
std::vector<fs::path> paths;
pluginPath = GetNorthstarPrefix() + "/plugins";
@@ -207,28 +235,22 @@ bool PluginManager::LoadPlugins()
data.version = ns_version.c_str();
data.northstarModule = g_NorthstarModule;
- if (strstr(GetCommandLineA(), "-noplugins") != NULL)
- {
- NS::log::PLUGINSYS->warn("-noplugins detected; skipping loading plugins");
- return false;
- }
- if (!fs::exists(pluginPath))
+ FindPlugins(pluginPath, paths);
+
+ // Special case for Thunderstore plugin dirs
+
+ for (fs::directory_entry dir : fs::directory_iterator(GetThunderstoreModFolderPath()))
{
- NS::log::PLUGINSYS->warn("Could not find a plugins directory. Skipped loading plugins");
- return false;
+ fs::path pluginDir = dir.path() / "plugins";
+ FindPlugins(pluginDir, paths);
}
- // ensure dirs exist
- fs::recursive_directory_iterator iterator(pluginPath);
- if (std::filesystem::begin(iterator) == std::filesystem::end(iterator))
+
+ if (paths.empty())
{
NS::log::PLUGINSYS->warn("Could not find any plugins. Skipped loading plugins");
return false;
}
- for (auto const& entry : iterator)
- {
- if (fs::is_regular_file(entry) && entry.path().extension() == ".dll")
- paths.emplace_back(entry.path());
- }
+
for (fs::path path : paths)
{
if (LoadPlugin(path, &funcs, &data))