MCPcopy Create free account
hub / github.com/R2Northstar/NorthstarLauncher / LoadPlugins

Method LoadPlugins

primedev/plugins/pluginmanager.cpp:58–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56}
57
58bool PluginManager::LoadPlugins(bool reloaded)
59{
60 if (strstr(GetCommandLineA(), "-noplugins") != NULL)
61 {
62 NS::log::PLUGINSYS->warn("-noplugins detected; skipping loading plugins");
63 return false;
64 }
65
66 fs::create_directories(GetThunderstoreModFolderPath());
67
68 std::vector<fs::path> paths;
69
70 pluginPath = GetNorthstarPrefix() + "\\plugins";
71
72 fs::path libPath = fs::absolute(pluginPath + "\\lib");
73 if (fs::exists(libPath) && fs::is_directory(libPath))
74 AddDllDirectory(libPath.wstring().c_str());
75
76 FindPlugins(pluginPath, paths);
77
78 // Special case for Thunderstore mods dir
79 std::filesystem::directory_iterator thunderstoreModsDir = fs::directory_iterator(GetThunderstoreModFolderPath());
80 // Set up regex for `AUTHOR-MOD-VERSION` pattern
81 std::regex pattern(R"(.*\\([a-zA-Z0-9_]+)-([a-zA-Z0-9_]+)-(\d+\.\d+\.\d+))");
82 for (fs::directory_entry dir : thunderstoreModsDir)
83 {
84 fs::path pluginsDir = dir.path() / "plugins";
85 // Use regex to match `AUTHOR-MOD-VERSION` pattern
86 if (!std::regex_match(dir.path().string(), pattern))
87 {
88 spdlog::warn("The following directory did not match 'AUTHOR-MOD-VERSION': {}", dir.path().string());
89 continue; // skip loading package that doesn't match
90 }
91
92 fs::path libDir = fs::absolute(pluginsDir / "lib");
93 if (fs::exists(libDir) && fs::is_directory(libDir))
94 AddDllDirectory(libDir.wstring().c_str());
95
96 FindPlugins(pluginsDir, paths);
97 }
98
99 if (paths.empty())
100 {
101 NS::log::PLUGINSYS->warn("Could not find any plugins. Skipped loading plugins");
102 return false;
103 }
104
105 for (fs::path path : paths)
106 {
107 LoadPlugin(path, reloaded);
108 }
109
110 InformAllPluginsInitialized();
111
112 return true;
113}
114
115void PluginManager::ReloadPlugins()

Callers 1

InitialiseNorthstarFunction · 0.80

Calls 3

GetNorthstarPrefixFunction · 0.85
FindPluginsFunction · 0.85

Tested by

no test coverage detected