aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDLL/plugins/plugins.cpp
diff options
context:
space:
mode:
authorJan <sentrycraft123@gmail.com>2023-07-27 22:55:42 +0200
committerGeckoEidechse <gecko.eidechse+git@pm.me>2023-07-27 22:57:18 +0200
commitbece6ab2b6890ab538f5685f3d1cdcce233ff0a0 (patch)
tree47856bb29f689804fd2670fc7538a41d28e76b7b /NorthstarDLL/plugins/plugins.cpp
parentabc65788fdbbd5dd82b8a3f640652daeb6e1300b (diff)
downloadNorthstarLauncher-bece6ab2b6890ab538f5685f3d1cdcce233ff0a0.tar.gz
NorthstarLauncher-bece6ab2b6890ab538f5685f3d1cdcce233ff0a0.zip
Add support for loading plugins from Thunderstore packages (#513)v1.17.1-rc4
Adds support for loading plugins from `packages` directory which was missing from the original PR that introduced the `packages` directory. (cherry picked from commit a65cbeacfbaed17f0526fb513f49338f1151d247)
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))