aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan <sentrycraft123@gmail.com>2023-07-27 22:55:42 +0200
committerGitHub <noreply@github.com>2023-07-27 22:55:42 +0200
commita65cbeacfbaed17f0526fb513f49338f1151d247 (patch)
treea90d458c8e7020d5ea04e4fa18b29709dcdf3096
parent2e6c1cffabd7528ba1e6ddd2663f1ad34a475df5 (diff)
downloadNorthstarLauncher-a65cbeacfbaed17f0526fb513f49338f1151d247.tar.gz
NorthstarLauncher-a65cbeacfbaed17f0526fb513f49338f1151d247.zip
Add support for loading plugins from Thunderstore packages (#513)
Adds support for loading plugins from `packages` directory which was missing from the original PR that introduced the `packages` directory.
-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))