summaryrefslogtreecommitdiff
path: root/src/plugincontainer.cpp
diff options
context:
space:
mode:
authorMikaƫl Capelle <capelle.mikael@gmail.com>2022-05-02 20:32:00 +0200
committerGitHub <noreply@github.com>2022-05-02 20:32:00 +0200
commit060ca725bf7ae097797d507f232a539122e81a76 (patch)
tree3794c9de48bbc29fa9b2bcaf2ac5f0953c238f4f /src/plugincontainer.cpp
parent7a4cdc8f810dc1ae49e9b53e4641f1419f5d66c5 (diff)
parentabe926dc1519e7a29769a1a050e80cc5512146a3 (diff)
Merge pull request #1696 from ModOrganizer2/python-rework
Plugin updates (python rework)
Diffstat (limited to 'src/plugincontainer.cpp')
-rw-r--r--src/plugincontainer.cpp45
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()) {