diff options
| author | Mikaël Capelle <capelle.mikael@gmail.com> | 2022-04-28 19:36:39 +0200 |
|---|---|---|
| committer | Mikaël Capelle <capelle.mikael@gmail.com> | 2022-05-02 17:04:04 +0200 |
| commit | abe926dc1519e7a29769a1a050e80cc5512146a3 (patch) | |
| tree | 3794c9de48bbc29fa9b2bcaf2ac5f0953c238f4f | |
| parent | 14c6ee4d27b443d271b59d894ac6c06028aa45ff (diff) | |
Allow Qt plugins in subfolder.
| -rw-r--r-- | src/organizer_en.ts | 20 | ||||
| -rw-r--r-- | src/plugincontainer.cpp | 38 | ||||
| -rw-r--r-- | src/plugincontainer.h | 10 |
3 files changed, 57 insertions, 11 deletions
diff --git a/src/organizer_en.ts b/src/organizer_en.ts index d5b32741..0d7854ff 100644 --- a/src/organizer_en.ts +++ b/src/organizer_en.ts @@ -5909,48 +5909,48 @@ Continue?</source> <context> <name>PluginContainer</name> <message> - <location filename="plugincontainer.cpp" line="1013"/> + <location filename="plugincontainer.cpp" line="1046"/> <source>Plugin error</source> <translation type="unfinished"></translation> </message> <message> - <location filename="plugincontainer.cpp" line="1014"/> + <location filename="plugincontainer.cpp" line="1047"/> <source>Mod Organizer failed to load the plugin '%1' last time it was started.</source> <translation type="unfinished"></translation> </message> <message> - <location filename="plugincontainer.cpp" line="1017"/> + <location filename="plugincontainer.cpp" line="1050"/> <source>The plugin can be skipped for this session, blacklisted, or loaded normally, in which case it might fail again. Blacklisted plugins can be re-enabled later in the settings.</source> <translation type="unfinished"></translation> </message> <message> - <location filename="plugincontainer.cpp" line="1022"/> + <location filename="plugincontainer.cpp" line="1055"/> <source>Skip this plugin</source> <translation type="unfinished"></translation> </message> <message> - <location filename="plugincontainer.cpp" line="1023"/> + <location filename="plugincontainer.cpp" line="1056"/> <source>Blacklist this plugin</source> <translation type="unfinished"></translation> </message> <message> - <location filename="plugincontainer.cpp" line="1024"/> + <location filename="plugincontainer.cpp" line="1057"/> <source>Load this plugin</source> <translation type="unfinished"></translation> </message> <message> - <location filename="plugincontainer.cpp" line="1121"/> + <location filename="plugincontainer.cpp" line="1157"/> <source>Some plugins could not be loaded</source> <translation type="unfinished"></translation> </message> <message> - <location filename="plugincontainer.cpp" line="1124"/> - <location filename="plugincontainer.cpp" line="1142"/> + <location filename="plugincontainer.cpp" line="1160"/> + <location filename="plugincontainer.cpp" line="1178"/> <source>Description missing</source> <translation type="unfinished"></translation> </message> <message> - <location filename="plugincontainer.cpp" line="1133"/> + <location filename="plugincontainer.cpp" line="1169"/> <source>The following plugins could not be loaded. The reason may be missing dependencies (i.e. python) or an outdated version:</source> <translation type="unfinished"></translation> </message> diff --git a/src/plugincontainer.cpp b/src/plugincontainer.cpp index 61169196..f71d89e4 100644 --- a/src/plugincontainer.cpp +++ b/src/plugincontainer.cpp @@ -823,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;
@@ -832,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>()) {
@@ -1049,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();
@@ -1076,6 +1109,9 @@ void PluginContainer::loadPlugins() if (QLibrary::isLibrary(filepath)) {
loadQtPlugin(filepath);
}
+ else if (auto p = isQtPluginFolder(filepath)) {
+ loadQtPlugin(*p);
+ }
}
if (skipPlugin.isEmpty()) {
diff --git a/src/plugincontainer.h b/src/plugincontainer.h index b250573a..2ab9a4b7 100644 --- a/src/plugincontainer.h +++ b/src/plugincontainer.h @@ -396,6 +396,16 @@ private: // Load the Qt plugin from the given file.
QObject* loadQtPlugin(const QString& filepath);
+ // check if a plugin is folder containing a Qt plugin, it is, return the path to the
+ // DLL containing the plugin in the folder, otherwise return an empty optional
+ //
+ // a Qt plugin folder is a folder with a DLL containing a library (not in a subdirectory),
+ // if multiple plugins are present, only the first one is returned
+ //
+ // extra DLLs are ignored by Qt so can be present in the folder
+ //
+ std::optional<QString> isQtPluginFolder(const QString& filepath) const;
+
// See startPlugins for more details. This is simply an intermediate function
// that can be used when loading plugins after initialization. This uses the
// user interface in m_UserInterface.
|
