diff options
Diffstat (limited to 'src/plugincontainer.cpp')
| -rw-r--r-- | src/plugincontainer.cpp | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/src/plugincontainer.cpp b/src/plugincontainer.cpp index c4640cc3..f71d89e4 100644 --- a/src/plugincontainer.cpp +++ b/src/plugincontainer.cpp @@ -467,8 +467,8 @@ IPlugin* PluginContainer::registerPlugin(QObject *plugin, const QString& filepat }
}
else {
- log::warn("Trying to register two plugins with the name '{}', the second one will not be registered.",
- pluginObj->name());
+ log::warn("Trying to register two plugins with the name '{}' (from {} and {}), the second one will not be registered.",
+ pluginObj->name(), this->filepath(other), QDir::cleanPath(filepath));
return nullptr;
}
}
@@ -481,6 +481,7 @@ IPlugin* PluginContainer::registerPlugin(QObject *plugin, const QString& filepat bf::at_key<QObject>(m_Plugins).push_back(plugin);
plugin->setProperty("filepath", QDir::cleanPath(filepath));
+ plugin->setParent(this);
if (m_Organizer) {
m_Organizer->settings().plugins().registerPlugin(pluginObj);
@@ -822,6 +823,33 @@ QObject* PluginContainer::loadQtPlugin(const QString& filepath) return nullptr;
}
+std::optional<QString> PluginContainer::isQtPluginFolder(const QString& filepath) const {
+
+ if (!QFileInfo(filepath).isDir()) {
+ return {};
+ }
+
+ QDirIterator iter(filepath, QDir::Files | QDir::NoDotAndDotDot);
+ while (iter.hasNext()) {
+ iter.next();
+ const auto filePath = iter.filePath();
+
+ // not a library, skip
+ if (!QLibrary::isLibrary(filePath)) {
+ continue;
+ }
+
+ // check if we have proper metadata - this does not load the plugin (metaData() should
+ // be very lightweight)
+ const QPluginLoader loader(filePath);
+ if (!loader.metaData().isEmpty()) {
+ return filePath;
+ }
+ }
+
+ return {};
+}
+
void PluginContainer::loadPlugin(QString const& filepath)
{
std::vector<QObject*> plugins;
@@ -831,6 +859,12 @@ void PluginContainer::loadPlugin(QString const& filepath) plugins.push_back(plugin);
}
}
+ else if (auto p = isQtPluginFolder(filepath)) {
+ QObject* plugin = loadQtPlugin(*p);
+ if (plugin) {
+ plugins.push_back(plugin);
+ }
+ }
else {
// We need to check if this can be handled by a proxy.
for (auto* proxy : this->plugins<IPluginProxy>()) {
@@ -921,6 +955,8 @@ void PluginContainer::unloadPlugin(MOBase::IPlugin* plugin, QObject* object) }
+ object->deleteLater();
+
// Do this at the end.
m_Requirements.erase(plugin);
}
@@ -1046,7 +1082,7 @@ void PluginContainer::loadPlugins() QString pluginPath = qApp->applicationDirPath() + "/" + ToQString(AppConfig::pluginPath());
log::debug("looking for plugins in {}", QDir::toNativeSeparators(pluginPath));
- QDirIterator iter(pluginPath, QDir::Files | QDir::NoDotAndDotDot);
+ QDirIterator iter(pluginPath, QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
while (iter.hasNext()) {
iter.next();
@@ -1073,6 +1109,9 @@ void PluginContainer::loadPlugins() if (QLibrary::isLibrary(filepath)) {
loadQtPlugin(filepath);
}
+ else if (auto p = isQtPluginFolder(filepath)) {
+ loadQtPlugin(*p);
+ }
}
if (skipPlugin.isEmpty()) {
|
