From 4c5e3da2334a1d0c474148be8881b46d6ca6d3fa Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Mon, 17 Aug 2020 05:06:26 -0400 Subject: moved nexus api stuff to GlobalSettings pass a pointer to Settings around for things that can be called without settings, when creating the first instance added dummy plugin list, mod list and iorganizer to initialize plugins without an instance moved PluginContainer into the core filter, had nothing to do with the plugins list NexusInterface is now created manually instead of being a static singleton because it needs to know if the settings are available --- src/plugincontainer.cpp | 88 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 59 insertions(+), 29 deletions(-) (limited to 'src/plugincontainer.cpp') diff --git a/src/plugincontainer.cpp b/src/plugincontainer.cpp index 4771359d..6f2670dd 100644 --- a/src/plugincontainer.cpp +++ b/src/plugincontainer.cpp @@ -173,10 +173,21 @@ bool PluginContainer::verifyPlugin(IPlugin *plugin) { if (plugin == nullptr) { return false; - } else if (!plugin->init(new OrganizerProxy(m_Organizer, this, plugin))) { + } + + IOrganizer* proxy = nullptr; + + if (m_Organizer) { + proxy = new OrganizerProxy(m_Organizer, this, plugin); + } else { + proxy = new DummyOrganizerProxy(plugin); + } + + if (!plugin->init(proxy)) { log::warn("plugin failed to initialize"); return false; } + return true; } @@ -200,7 +211,9 @@ bool PluginContainer::registerPlugin(QObject *plugin, const QString &fileName) return false; } plugin->setProperty("filename", fileName); - m_Organizer->settings().plugins().registerPlugin(pluginObj); + if (m_Organizer) { + m_Organizer->settings().plugins().registerPlugin(pluginObj); + } } { // diagnosis plugin @@ -244,7 +257,9 @@ bool PluginContainer::registerPlugin(QObject *plugin, const QString &fileName) IPluginInstaller *installer = qobject_cast(plugin); if (verifyPlugin(installer)) { bf::at_key(m_Plugins).push_back(installer); - m_Organizer->installationManager()->registerInstaller(installer); + if (m_Organizer) { + m_Organizer->installationManager()->registerInstaller(installer); + } return true; } } @@ -317,7 +332,7 @@ void PluginContainer::unloadPlugins() } // disconnect all slots before unloading plugins so plugins don't have to take care of that - if (m_Organizer != nullptr) { + if (m_Organizer) { m_Organizer->disconnectPlugins(); } @@ -363,24 +378,28 @@ void PluginContainer::loadPlugins() registerPlugin(plugin, ""); } - QFile loadCheck(qApp->property("dataPath").toString() + "/plugin_loadcheck.tmp"); - if (loadCheck.exists() && loadCheck.open(QIODevice::ReadOnly)) { - // oh, there was a failed plugin load last time. Find out which plugin was loaded last - QString fileName; - while (!loadCheck.atEnd()) { - fileName = QString::fromUtf8(loadCheck.readLine().constData()).trimmed(); - } - if (QMessageBox::question(nullptr, QObject::tr("Plugin error"), - QObject::tr("It appears the plugin \"%1\" failed to load last startup and caused MO to crash. Do you want to disable it?\n" - "(Please note: If this is the first time you see this message for this plugin you may want to give it another try. " - "The plugin may be able to recover from the problem)").arg(fileName), - QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes) { - m_Organizer->settings().plugins().addBlacklist(fileName); + QFile loadCheck; + + if (m_Organizer) { + loadCheck.setFileName(qApp->property("dataPath").toString() + "/plugin_loadcheck.tmp"); + if (loadCheck.exists() && loadCheck.open(QIODevice::ReadOnly)) { + // oh, there was a failed plugin load last time. Find out which plugin was loaded last + QString fileName; + while (!loadCheck.atEnd()) { + fileName = QString::fromUtf8(loadCheck.readLine().constData()).trimmed(); + } + if (QMessageBox::question(nullptr, QObject::tr("Plugin error"), + QObject::tr("It appears the plugin \"%1\" failed to load last startup and caused MO to crash. Do you want to disable it?\n" + "(Please note: If this is the first time you see this message for this plugin you may want to give it another try. " + "The plugin may be able to recover from the problem)").arg(fileName), + QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes) { + m_Organizer->settings().plugins().addBlacklist(fileName); + } + loadCheck.close(); } - loadCheck.close(); - } - loadCheck.open(QIODevice::WriteOnly); + loadCheck.open(QIODevice::WriteOnly); + } QString pluginPath = qApp->applicationDirPath() + "/" + ToQString(AppConfig::pluginPath()); log::debug("looking for plugins in {}", QDir::toNativeSeparators(pluginPath)); @@ -388,13 +407,20 @@ void PluginContainer::loadPlugins() while (iter.hasNext()) { iter.next(); - if (m_Organizer->settings().plugins().blacklisted(iter.fileName())) { - log::debug("plugin \"{}\" blacklisted", iter.fileName()); - continue; + + if (m_Organizer) { + if (m_Organizer->settings().plugins().blacklisted(iter.fileName())) { + log::debug("plugin \"{}\" blacklisted", iter.fileName()); + continue; + } } - loadCheck.write(iter.fileName().toUtf8()); - loadCheck.write("\n"); - loadCheck.flush(); + + if (loadCheck.isOpen()) { + loadCheck.write(iter.fileName().toUtf8()); + loadCheck.write("\n"); + loadCheck.flush(); + } + QString pluginName = iter.filePath(); if (QLibrary::isLibrary(pluginName)) { std::unique_ptr pluginLoader(new QPluginLoader(pluginName, this)); @@ -416,12 +442,16 @@ void PluginContainer::loadPlugins() } // remove the load check file on success - loadCheck.remove(); + if (loadCheck.isOpen()) { + loadCheck.remove(); + } - bf::at_key(m_Plugins).push_back(m_Organizer); bf::at_key(m_Plugins).push_back(this); - m_Organizer->connectPlugins(this); + if (m_Organizer) { + bf::at_key(m_Plugins).push_back(m_Organizer); + m_Organizer->connectPlugins(this); + } } -- cgit v1.3.1 From e6a87a17987de5d8e462634777df31e2cae5c1a6 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Wed, 4 Nov 2020 20:57:50 -0500 Subject: added IPlugin::registered() removed useless dummy interfaces because init() isn't called anymore python plugins currently broken because init() isn't called on them fixed create instance dialog being shown on startup even if portable instance existed display a message when the last instance can't be found fixed instance manager dialog failing to open the portable instance --- src/instancemanager.cpp | 8 +- src/instancemanagerdialog.cpp | 6 +- src/main.cpp | 37 ++++++-- src/modlist.cpp | 71 --------------- src/modlist.h | 20 ---- src/organizerproxy.cpp | 206 ------------------------------------------ src/organizerproxy.h | 56 ------------ src/plugincontainer.cpp | 35 ++++--- src/plugincontainer.h | 2 +- src/pluginlist.cpp | 65 ------------- src/pluginlist.h | 19 ---- 11 files changed, 54 insertions(+), 471 deletions(-) (limited to 'src/plugincontainer.cpp') diff --git a/src/instancemanager.cpp b/src/instancemanager.cpp index c79c5254..61c442be 100644 --- a/src/instancemanager.cpp +++ b/src/instancemanager.cpp @@ -334,13 +334,7 @@ std::optional InstanceManager::currentInstance() const } } - QString path = instancePath(name); - if (!QFileInfo::exists(path)) { - // the previously used instance doesn't exist anymore - return {}; - } - - return Instance(QDir(path), false, profile); + return Instance(QDir(instancePath(name)), false, profile); } void InstanceManager::clearCurrentInstance() diff --git a/src/instancemanagerdialog.cpp b/src/instancemanagerdialog.cpp index 231835ba..282329a5 100644 --- a/src/instancemanagerdialog.cpp +++ b/src/instancemanagerdialog.cpp @@ -462,7 +462,11 @@ void InstanceManagerDialog::openSelectedInstance() return; } - InstanceManager::instance().setCurrentInstance(m_instances[i]->name()); + if (m_instances[i]->isPortable()) { + InstanceManager::instance().setCurrentInstance(""); + } else { + InstanceManager::instance().setCurrentInstance(m_instances[i]->name()); + } if (m_restartOnSelect) { ExitModOrganizer(Exit::Restart); diff --git a/src/main.cpp b/src/main.cpp index 8f7af77d..7b489aee 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -272,22 +272,22 @@ std::optional handleCommandLine( return {}; } -void openInstanceManager(PluginContainer& pc, QWidget* parent); - std::optional selectInstance() { + auto& m = InstanceManager::instance(); + NexusInterface ni(nullptr); PluginContainer pc(nullptr); pc.loadPlugins(); - if (InstanceManager::instance().instancePaths().empty()) { + if (m.instancePaths().empty() && !m.portableInstanceExists()) { // no instances configured CreateInstanceDialog dlg(pc, nullptr); if (dlg.exec() != QDialog::Accepted) { return {}; } - return InstanceManager::instance().currentInstance(); + return m.currentInstance(); } @@ -302,7 +302,7 @@ std::optional selectInstance() return {}; } - return InstanceManager::instance().currentInstance(); + return m.currentInstance(); } enum class SetupInstanceResults @@ -650,13 +650,36 @@ int doOneRun( // resets things when MO is "restarted" resetForRestart(cl); - auto currentInstance = InstanceManager::instance().currentInstance(); + auto& m = InstanceManager::instance(); + auto currentInstance = m.currentInstance(); if (!currentInstance) { currentInstance = selectInstance(); - if (!currentInstance) + if (!currentInstance) { return 1; + } + } + else + { + if (!currentInstance->directory().exists()) { + // the previously used instance doesn't exist anymore + + if (m.instanceNames().empty() && !m.portableInstanceExists()) { + criticalOnTop(QObject::tr( + "Instance at '%1' not found. You must create a new instance") + .arg(currentInstance->directory().absolutePath())); + } else { + criticalOnTop(QObject::tr( + "Instance at '%1' not found. Select another instance.") + .arg(currentInstance->directory().absolutePath())); + } + + currentInstance = selectInstance(); + if (!currentInstance) { + return 1; + } + } } const QString dataPath = currentInstance->directory().path(); diff --git a/src/modlist.cpp b/src/modlist.cpp index c98464a9..04abfb01 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -1528,74 +1528,3 @@ void ModList::disableSelected(const QItemSelectionModel *selectionModel) m_Profile->setModsEnabled(QList(), modsToDisable); } } - - -QString DummyModList::displayName(const QString&) const -{ - return {}; -} - -QStringList DummyModList::allMods() const -{ - return {}; -} - -QStringList DummyModList::allModsByProfilePriority(MOBase::IProfile*) const -{ - return {}; -} - -IModInterface* DummyModList::getMod(const QString&) const -{ - return nullptr; -} - -bool DummyModList::removeMod(MOBase::IModInterface*) -{ - return true; -} - -IModList::ModStates DummyModList::state(const QString&) const -{ - return 0; -} - -bool DummyModList::setActive(const QString&, bool) -{ - return true; -} - -int DummyModList::setActive(const QStringList&, bool) -{ - return 0; -} - -int DummyModList::priority(const QString&) const -{ - return -1; -} - -bool DummyModList::setPriority(const QString&, int) -{ - return true; -} - -bool DummyModList::onModInstalled(const std::function&) -{ - return true; -} - -bool DummyModList::onModRemoved(const std::function&) -{ - return true; -} - -bool DummyModList::onModStateChanged(const std::function&)>&) -{ - return true; -} - -bool DummyModList::onModMoved(const std::function&) -{ - return true; -} diff --git a/src/modlist.h b/src/modlist.h index 1a469ee7..385ca04c 100644 --- a/src/modlist.h +++ b/src/modlist.h @@ -397,25 +397,5 @@ private: }; - -class DummyModList : public MOBase::IModList -{ -public: - QString displayName(const QString &internalName) const override; - QStringList allMods() const override; - QStringList allModsByProfilePriority(MOBase::IProfile *profile = nullptr) const override; - MOBase::IModInterface* getMod(const QString& name) const override; - bool removeMod(MOBase::IModInterface *mod) override; - ModStates state(const QString &name) const override; - bool setActive(const QString &name, bool active) override; - int setActive(const QStringList& names, bool active) override; - int priority(const QString &name) const override; - bool setPriority(const QString &name, int newPriority) override; - bool onModInstalled(const std::function& func) override; - bool onModRemoved(const std::function& func) override; - bool onModStateChanged(const std::function&)> &func) override; - bool onModMoved(const std::function &func) override; -}; - #endif // MODLIST_H diff --git a/src/organizerproxy.cpp b/src/organizerproxy.cpp index b2a4f791..45efc00c 100644 --- a/src/organizerproxy.cpp +++ b/src/organizerproxy.cpp @@ -287,209 +287,3 @@ bool OrganizerProxy::onPluginSettingChanged(std::functiononPluginSettingChanged(func); } - - - -DummyOrganizerProxy::DummyOrganizerProxy(MOBase::IPlugin* plugin) - : m_mods(new DummyModList), m_plugins(new DummyPluginList) -{ -} - -DummyOrganizerProxy::~DummyOrganizerProxy() = default; - -IModRepositoryBridge *DummyOrganizerProxy::createNexusBridge() const -{ - return nullptr; -} - -QString DummyOrganizerProxy::profileName() const -{ - return {}; -} - -QString DummyOrganizerProxy::profilePath() const -{ - return {}; -} - -QString DummyOrganizerProxy::downloadsPath() const -{ - return {}; -} - -QString DummyOrganizerProxy::overwritePath() const -{ - return {}; -} - -QString DummyOrganizerProxy::basePath() const -{ - return {}; -} - -QString DummyOrganizerProxy::modsPath() const -{ - return {}; -} - -VersionInfo DummyOrganizerProxy::appVersion() const -{ - return {}; -} - -IPluginGame *DummyOrganizerProxy::getGame(const QString &gameName) const -{ - return nullptr; -} - -IModInterface *DummyOrganizerProxy::createMod(MOBase::GuessedValue &name) -{ - return nullptr; -} - -void DummyOrganizerProxy::modDataChanged(IModInterface *mod) -{ -} - -QVariant DummyOrganizerProxy::pluginSetting(const QString &pluginName, const QString &key) const -{ - if (key == "enabled") { - return true; - } - - return {}; -} - -void DummyOrganizerProxy::setPluginSetting(const QString &pluginName, const QString &key, const QVariant &value) -{ -} - -QVariant DummyOrganizerProxy::persistent(const QString &pluginName, const QString &key, const QVariant &def) const -{ - return {}; -} - -void DummyOrganizerProxy::setPersistent(const QString &pluginName, const QString &key, const QVariant &value, bool sync) -{ -} - -QString DummyOrganizerProxy::pluginDataPath() const -{ - return qApp->applicationDirPath() + "/" + ToQString(AppConfig::pluginPath()) + "/data"; -} - -HANDLE DummyOrganizerProxy::startApplication( - const QString& exe, const QStringList& args, const QString &cwd, - const QString& profile, const QString &overwrite, bool ignoreOverwrite) -{ - return INVALID_HANDLE_VALUE; -} - -bool DummyOrganizerProxy::waitForApplication(HANDLE handle, LPDWORD exitCode) const -{ - return true; -} - -bool DummyOrganizerProxy::onAboutToRun(const std::function &func) -{ - return true; -} - -bool DummyOrganizerProxy::onFinishedRun(const std::function &func) -{ - return true; -} - -bool DummyOrganizerProxy::onUserInterfaceInitialized(std::function const& func) -{ - return true; -} - -bool DummyOrganizerProxy::onProfileCreated(std::function const& func) -{ - return true; -} - -bool DummyOrganizerProxy::onProfileRenamed(std::function const& func) -{ - return true; -} - -bool DummyOrganizerProxy::onProfileRemoved(std::function const& func) -{ - return true; -} - -bool DummyOrganizerProxy::onProfileChanged(std::function const& func) -{ - return true; -} - -bool DummyOrganizerProxy::onPluginSettingChanged(std::function const& func) -{ - return true; -} - -void DummyOrganizerProxy::refresh(bool saveChanges) -{ -} - -IModInterface *DummyOrganizerProxy::installMod(const QString &fileName, const QString &nameSuggestion) -{ - return nullptr; -} - -QString DummyOrganizerProxy::resolvePath(const QString &fileName) const -{ - return {}; -} - -QStringList DummyOrganizerProxy::listDirectories(const QString &directoryName) const -{ - return {}; -} - -QStringList DummyOrganizerProxy::findFiles(const QString &path, const std::function &filter) const -{ - return {}; -} - -QStringList DummyOrganizerProxy::findFiles(const QString& path, const QStringList& globFilters) const -{ - return {}; -} - -QStringList DummyOrganizerProxy::getFileOrigins(const QString &fileName) const -{ - return {}; -} - -QList DummyOrganizerProxy::findFileInfos(const QString &path, const std::function &filter) const -{ - return {}; -} - -MOBase::IDownloadManager *DummyOrganizerProxy::downloadManager() const -{ - return nullptr; -} - -MOBase::IPluginList *DummyOrganizerProxy::pluginList() const -{ - return m_plugins.get(); -} - -MOBase::IModList *DummyOrganizerProxy::modList() const -{ - return m_mods.get(); -} - -MOBase::IProfile *DummyOrganizerProxy::profile() const -{ - return nullptr; -} - -MOBase::IPluginGame const *DummyOrganizerProxy::managedGame() const -{ - return nullptr; -} diff --git a/src/organizerproxy.h b/src/organizerproxy.h index 144a7732..6690d612 100644 --- a/src/organizerproxy.h +++ b/src/organizerproxy.h @@ -81,60 +81,4 @@ private: }; - -class DummyOrganizerProxy : public MOBase::IOrganizer -{ -public: - DummyOrganizerProxy(MOBase::IPlugin* plugin); - ~DummyOrganizerProxy(); - - MOBase::IModRepositoryBridge *createNexusBridge() const override; - QString profileName() const override; - QString profilePath() const override; - QString downloadsPath() const override; - QString overwritePath() const override; - QString basePath() const override; - QString modsPath() const override; - MOBase::VersionInfo appVersion() const override; - MOBase::IPluginGame *getGame(const QString &gameName) const override; - MOBase::IModInterface *createMod(MOBase::GuessedValue &name) override; - void modDataChanged(MOBase::IModInterface *mod) override; - QVariant pluginSetting(const QString &pluginName, const QString &key) const override; - void setPluginSetting(const QString &pluginName, const QString &key, const QVariant &value) override; - QVariant persistent(const QString &pluginName, const QString &key, const QVariant &def = QVariant()) const override; - void setPersistent(const QString &pluginName, const QString &key, const QVariant &value, bool sync = true) override; - QString pluginDataPath() const override; - MOBase::IModInterface *installMod(const QString &fileName, const QString &nameSuggestion = QString()) override; - QString resolvePath(const QString &fileName) const override; - QStringList listDirectories(const QString &directoryName) const override; - QStringList findFiles(const QString &path, const std::function &filter) const override; - QStringList findFiles(const QString &path, const QStringList &globFilters) const override; - QStringList getFileOrigins(const QString &fileName) const override; - QList findFileInfos(const QString &path, const std::function &filter) const override; - - MOBase::IDownloadManager *downloadManager() const override; - MOBase::IPluginList *pluginList() const override; - MOBase::IModList *modList() const override; - MOBase::IProfile *profile() const override; - HANDLE startApplication(const QString &executable, const QStringList &args = QStringList(), const QString &cwd = "", - const QString &profile = "", const QString &forcedCustomOverwrite = "", bool ignoreCustomOverwrite = false) override; - bool waitForApplication(HANDLE handle, LPDWORD exitCode = nullptr) const override; - void refresh(bool saveChanges = true) override; - - bool onAboutToRun(const std::function &func) override; - bool onFinishedRun(const std::function &func) override; - bool onUserInterfaceInitialized(std::function const& func) override; - bool onProfileCreated(std::function const& func) override; - bool onProfileRenamed(std::function const& func) override; - bool onProfileRemoved(std::function const& func) override; - bool onProfileChanged(std::function const& func) override; - bool onPluginSettingChanged(std::function const& func) override; - - MOBase::IPluginGame const *managedGame() const override; - -private: - std::unique_ptr m_plugins; - std::unique_ptr m_mods; -}; - #endif // ORGANIZERPROXY_H diff --git a/src/plugincontainer.cpp b/src/plugincontainer.cpp index 6f2670dd..0c71e491 100644 --- a/src/plugincontainer.cpp +++ b/src/plugincontainer.cpp @@ -169,23 +169,19 @@ QObject* PluginContainer::as_qobject(MOBase::IPlugin* plugin) const return *it; } -bool PluginContainer::verifyPlugin(IPlugin *plugin) +bool PluginContainer::initPlugin(IPlugin *plugin) { if (plugin == nullptr) { return false; } - IOrganizer* proxy = nullptr; - if (m_Organizer) { - proxy = new OrganizerProxy(m_Organizer, this, plugin); - } else { - proxy = new DummyOrganizerProxy(plugin); - } + auto* proxy = new OrganizerProxy(m_Organizer, this, plugin); - if (!plugin->init(proxy)) { - log::warn("plugin failed to initialize"); - return false; + if (!plugin->init(proxy)) { + log::warn("plugin failed to initialize"); + return false; + } } return true; @@ -197,7 +193,6 @@ void PluginContainer::registerGame(IPluginGame *game) m_SupportedGames.insert({ game->gameName(), game }); } - bool PluginContainer::registerPlugin(QObject *plugin, const QString &fileName) { // Storing the original QObject* is a bit of a hack as I couldn't figure out any @@ -210,10 +205,14 @@ bool PluginContainer::registerPlugin(QObject *plugin, const QString &fileName) log::debug("not an IPlugin"); return false; } + plugin->setProperty("filename", fileName); + if (m_Organizer) { m_Organizer->settings().plugins().registerPlugin(pluginObj); } + + pluginObj->registered(); } { // diagnosis plugin @@ -233,14 +232,14 @@ bool PluginContainer::registerPlugin(QObject *plugin, const QString &fileName) } { // mod page plugin IPluginModPage *modPage = qobject_cast(plugin); - if (verifyPlugin(modPage)) { + if (initPlugin(modPage)) { bf::at_key(m_Plugins).push_back(modPage); return true; } } { // game plugin IPluginGame *game = qobject_cast(plugin); - if (verifyPlugin(game)) { + if (initPlugin(game)) { bf::at_key(m_Plugins).push_back(game); registerGame(game); return true; @@ -248,14 +247,14 @@ bool PluginContainer::registerPlugin(QObject *plugin, const QString &fileName) } { // tool plugins IPluginTool *tool = qobject_cast(plugin); - if (verifyPlugin(tool)) { + if (initPlugin(tool)) { bf::at_key(m_Plugins).push_back(tool); return true; } } { // installer plugins IPluginInstaller *installer = qobject_cast(plugin); - if (verifyPlugin(installer)) { + if (initPlugin(installer)) { bf::at_key(m_Plugins).push_back(installer); if (m_Organizer) { m_Organizer->installationManager()->registerInstaller(installer); @@ -265,7 +264,7 @@ bool PluginContainer::registerPlugin(QObject *plugin, const QString &fileName) } { // preview plugins IPluginPreview *preview = qobject_cast(plugin); - if (verifyPlugin(preview)) { + if (initPlugin(preview)) { bf::at_key(m_Plugins).push_back(preview); m_PreviewGenerator.registerPlugin(preview); return true; @@ -273,7 +272,7 @@ bool PluginContainer::registerPlugin(QObject *plugin, const QString &fileName) } { // proxy plugins IPluginProxy *proxy = qobject_cast(plugin); - if (verifyPlugin(proxy)) { + if (initPlugin(proxy)) { bf::at_key(m_Plugins).push_back(proxy); QStringList pluginNames = proxy->pluginList( QCoreApplication::applicationDirPath() + "/" + ToQString(AppConfig::pluginPath())); @@ -305,7 +304,7 @@ bool PluginContainer::registerPlugin(QObject *plugin, const QString &fileName) { // dummy plugins // only initialize these, no processing otherwise IPlugin *dummy = qobject_cast(plugin); - if (verifyPlugin(dummy)) { + if (initPlugin(dummy)) { bf::at_key(m_Plugins).push_back(dummy); return true; } diff --git a/src/plugincontainer.h b/src/plugincontainer.h index 07363ee7..bfbf1fa8 100644 --- a/src/plugincontainer.h +++ b/src/plugincontainer.h @@ -168,7 +168,7 @@ private: QObject* as_qobject(MOBase::IPlugin* plugin) const; - bool verifyPlugin(MOBase::IPlugin *plugin); + bool initPlugin(MOBase::IPlugin *plugin); void registerGame(MOBase::IPluginGame *game); bool registerPlugin(QObject *pluginObj, const QString &fileName); bool unregisterPlugin(QObject *pluginObj, const QString &fileName); diff --git a/src/pluginlist.cpp b/src/pluginlist.cpp index bda360ba..8d04b592 100644 --- a/src/pluginlist.cpp +++ b/src/pluginlist.cpp @@ -1671,68 +1671,3 @@ void PluginList::managedGameChanged(const IPluginGame *gamePlugin) { m_GamePlugin = gamePlugin; } - - - -QStringList DummyPluginList::pluginNames() const -{ - return {}; -} - -IPluginList::PluginStates DummyPluginList::state(const QString &name) const -{ - return 0; -} - -void DummyPluginList::setState(const QString &name, PluginStates state) -{ -} - -int DummyPluginList::priority(const QString &name) const -{ - return -1; -} - -int DummyPluginList::loadOrder(const QString &name) const -{ - return -1; -} - -void DummyPluginList::setLoadOrder(const QStringList &pluginList) -{ -} - -bool DummyPluginList::setPriority(const QString&, int) -{ - return true; -} - -bool DummyPluginList::isMaster(const QString &name) const -{ - return false; -} - -QStringList DummyPluginList::masters(const QString &name) const -{ - return {}; -} - -QString DummyPluginList::origin(const QString &name) const -{ - return {}; -} - -bool DummyPluginList::onRefreshed(const std::function &callback) -{ - return true; -} - -bool DummyPluginList::onPluginMoved(const std::function &func) -{ - return true; -} - -bool DummyPluginList::onPluginStateChanged(const std::function&)> &func) -{ - return true; -} diff --git a/src/pluginlist.h b/src/pluginlist.h index 27c15056..0b49b86f 100644 --- a/src/pluginlist.h +++ b/src/pluginlist.h @@ -410,25 +410,6 @@ private: bool hasInfo(const ESPInfo& esp, const AdditionalInfo* info) const; }; - -class DummyPluginList : public MOBase::IPluginList -{ -public: - QStringList pluginNames() const override; - PluginStates state(const QString &name) const override; - void setState(const QString &name, PluginStates state) override; - int priority(const QString &name) const override; - int loadOrder(const QString &name) const override; - void setLoadOrder(const QStringList &pluginList) override; - bool setPriority(const QString& name, int newPriority) override; - bool isMaster(const QString &name) const override; - QStringList masters(const QString &name) const override; - QString origin(const QString &name) const override; - bool onRefreshed(const std::function &callback) override; - bool onPluginMoved(const std::function &func) override; - bool onPluginStateChanged(const std::function&)> &func) override; -}; - #pragma warning(pop) #endif // PLUGINLIST_H -- cgit v1.3.1 From dc9de3696519fab6403c386a48c84cd6781ab99c Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Wed, 4 Nov 2020 22:50:51 -0500 Subject: call init() on proxy plugins OrganizerProxy now handles a null OrganizerCore, used for proxy plugins changed appVersion() and pluginDataPath() so they don't need OrganizerCore --- src/organizercore.cpp | 2 +- src/organizercore.h | 2 +- src/organizerproxy.cpp | 206 +++++++++++++++++++++++++++++++++++++++--------- src/plugincontainer.cpp | 34 +++++++- src/plugincontainer.h | 2 +- 5 files changed, 205 insertions(+), 41 deletions(-) (limited to 'src/plugincontainer.cpp') diff --git a/src/organizercore.cpp b/src/organizercore.cpp index 550f61d4..d01aab96 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -758,7 +758,7 @@ void OrganizerCore::setPersistent(const QString &pluginName, const QString &key, m_Settings.plugins().setPersistent(pluginName, key, value, sync); } -QString OrganizerCore::pluginDataPath() const +QString OrganizerCore::pluginDataPath() { return qApp->applicationDirPath() + "/" + ToQString(AppConfig::pluginPath()) + "/data"; diff --git a/src/organizercore.h b/src/organizercore.h index 1452bf08..80b89a43 100644 --- a/src/organizercore.h +++ b/src/organizercore.h @@ -314,7 +314,7 @@ public: void setPluginSetting(const QString &pluginName, const QString &key, const QVariant &value); QVariant persistent(const QString &pluginName, const QString &key, const QVariant &def) const; void setPersistent(const QString &pluginName, const QString &key, const QVariant &value, bool sync); - QString pluginDataPath() const; + static QString pluginDataPath(); virtual MOBase::IModInterface *installMod(const QString &fileName, bool reinstallation, ModInfo::Ptr currentMod, const QString &initModName); QString resolvePath(const QString &fileName) const; QStringList listDirectories(const QString &directoryName) const; diff --git a/src/organizerproxy.cpp b/src/organizerproxy.cpp index 45efc00c..5fa1f4ef 100644 --- a/src/organizerproxy.cpp +++ b/src/organizerproxy.cpp @@ -9,6 +9,7 @@ #include "modlistproxy.h" #include "pluginlistproxy.h" #include "proxyutils.h" +#include "shared/util.h" #include #include @@ -21,10 +22,17 @@ OrganizerProxy::OrganizerProxy(OrganizerCore* organizer, PluginContainer* plugin : m_Proxied(organizer) , m_PluginContainer(pluginContainer) , m_Plugin(plugin) - , m_DownloadManagerProxy(std::make_unique(this, organizer->downloadManager())) - , m_ModListProxy(std::make_unique(this, organizer->modList())) - , m_PluginListProxy(std::make_unique(this, organizer->pluginList())) { + if (m_Proxied) { + m_DownloadManagerProxy = std::make_unique( + this, m_Proxied->downloadManager()); + + m_ModListProxy = std::make_unique( + this, m_Proxied->modList()); + + m_PluginListProxy = std::make_unique( + this, m_Proxied->pluginList()); + } } IModRepositoryBridge *OrganizerProxy::createNexusBridge() const @@ -34,83 +42,133 @@ IModRepositoryBridge *OrganizerProxy::createNexusBridge() const QString OrganizerProxy::profileName() const { - return m_Proxied->profileName(); + if (m_Proxied) { + return m_Proxied->profileName(); + } else { + return {}; + } } QString OrganizerProxy::profilePath() const { - return m_Proxied->profilePath(); + if (m_Proxied) { + return m_Proxied->profilePath(); + } else { + return {}; + } } QString OrganizerProxy::downloadsPath() const { - return m_Proxied->downloadsPath(); + if (m_Proxied) { + return m_Proxied->downloadsPath(); + } else { + return {}; + } } QString OrganizerProxy::overwritePath() const { - return m_Proxied->overwritePath(); + if (m_Proxied) { + return m_Proxied->overwritePath(); + } else { + return {}; + } } QString OrganizerProxy::basePath() const { - return m_Proxied->basePath(); + if (m_Proxied) { + return m_Proxied->basePath(); + } else { + return {}; + } } QString OrganizerProxy::modsPath() const { - return m_Proxied->modsPath(); + if (m_Proxied) { + return m_Proxied->modsPath(); + } else { + return {}; + } } VersionInfo OrganizerProxy::appVersion() const { - return m_Proxied->appVersion(); + return createVersionInfo(); } IPluginGame *OrganizerProxy::getGame(const QString &gameName) const { - return m_Proxied->getGame(gameName); + if (m_Proxied) { + return m_Proxied->getGame(gameName); + } else { + return nullptr; + } } IModInterface *OrganizerProxy::createMod(MOBase::GuessedValue &name) { - return m_Proxied->createMod(name); + if (m_Proxied) { + return m_Proxied->createMod(name); + } else { + return nullptr; + } } void OrganizerProxy::modDataChanged(IModInterface *mod) { - m_Proxied->modDataChanged(mod); + if (m_Proxied) { + m_Proxied->modDataChanged(mod); + } } QVariant OrganizerProxy::pluginSetting(const QString &pluginName, const QString &key) const { - return m_Proxied->pluginSetting(pluginName, key); + if (m_Proxied) { + return m_Proxied->pluginSetting(pluginName, key); + } else { + return {}; + } } void OrganizerProxy::setPluginSetting(const QString &pluginName, const QString &key, const QVariant &value) { - m_Proxied->setPluginSetting(pluginName, key, value); + if (m_Proxied) { + m_Proxied->setPluginSetting(pluginName, key, value); + } } QVariant OrganizerProxy::persistent(const QString &pluginName, const QString &key, const QVariant &def) const { - return m_Proxied->persistent(pluginName, key, def); + if (m_Proxied) { + return m_Proxied->persistent(pluginName, key, def); + } else { + return {}; + } } void OrganizerProxy::setPersistent(const QString &pluginName, const QString &key, const QVariant &value, bool sync) { - m_Proxied->setPersistent(pluginName, key, value, sync); + if (m_Proxied) { + m_Proxied->setPersistent(pluginName, key, value, sync); + } } QString OrganizerProxy::pluginDataPath() const { - return m_Proxied->pluginDataPath(); + return OrganizerCore::pluginDataPath(); } HANDLE OrganizerProxy::startApplication( const QString& exe, const QStringList& args, const QString &cwd, const QString& profile, const QString &overwrite, bool ignoreOverwrite) { + if (!m_Proxied) { + return INVALID_HANDLE_VALUE; + } + log::debug( "a plugin has requested to start an application:\n" " . executable: '{}'\n" @@ -135,6 +193,10 @@ HANDLE OrganizerProxy::startApplication( bool OrganizerProxy::waitForApplication(HANDLE handle, LPDWORD exitCode) const { + if (!m_Proxied) { + return false; + } + const auto pid = ::GetProcessId(handle); log::debug( @@ -170,31 +232,53 @@ bool OrganizerProxy::waitForApplication(HANDLE handle, LPDWORD exitCode) const void OrganizerProxy::refresh(bool saveChanges) { - m_Proxied->refresh(saveChanges); + if (m_Proxied) { + m_Proxied->refresh(saveChanges); + } } IModInterface *OrganizerProxy::installMod(const QString &fileName, const QString &nameSuggestion) { - return m_Proxied->installMod(fileName, false, nullptr, nameSuggestion); + if (m_Proxied) { + return m_Proxied->installMod(fileName, false, nullptr, nameSuggestion); + } else { + return nullptr; + } } QString OrganizerProxy::resolvePath(const QString &fileName) const { - return m_Proxied->resolvePath(fileName); + if (m_Proxied) { + return m_Proxied->resolvePath(fileName); + } else { + return {}; + } } QStringList OrganizerProxy::listDirectories(const QString &directoryName) const { - return m_Proxied->listDirectories(directoryName); + if (m_Proxied) { + return m_Proxied->listDirectories(directoryName); + } else { + return {}; + } } QStringList OrganizerProxy::findFiles(const QString &path, const std::function &filter) const { - return m_Proxied->findFiles(path, filter); + if (m_Proxied) { + return m_Proxied->findFiles(path, filter); + } else { + return {}; + } } QStringList OrganizerProxy::findFiles(const QString& path, const QStringList& globFilters) const { + if (!m_Proxied) { + return {}; + } + QList> patterns; for (auto& gfilter : globFilters) { patterns.append(GlobPattern(gfilter)); @@ -211,12 +295,20 @@ QStringList OrganizerProxy::findFiles(const QString& path, const QStringList& gl QStringList OrganizerProxy::getFileOrigins(const QString &fileName) const { - return m_Proxied->getFileOrigins(fileName); + if (m_Proxied) { + return m_Proxied->getFileOrigins(fileName); + } else { + return {}; + } } QList OrganizerProxy::findFileInfos(const QString &path, const std::function &filter) const { - return m_Proxied->findFileInfos(path, filter); + if (m_Proxied) { + return m_Proxied->findFileInfos(path, filter); + } else { + return {}; + } } MOBase::IDownloadManager *OrganizerProxy::downloadManager() const @@ -236,54 +328,94 @@ MOBase::IModList *OrganizerProxy::modList() const MOBase::IProfile *OrganizerProxy::profile() const { - return m_Proxied->currentProfile(); + if (m_Proxied) { + return m_Proxied->currentProfile(); + } else { + return nullptr; + } } MOBase::IPluginGame const *OrganizerProxy::managedGame() const { - return m_Proxied->managedGame(); + if (m_Proxied) { + return m_Proxied->managedGame(); + } else { + return nullptr; + } } // CALLBACKS bool OrganizerProxy::onAboutToRun(const std::function& func) { - return m_Proxied->onAboutToRun(MOShared::callIfPluginActive(this, func, true)); + if (m_Proxied) { + return m_Proxied->onAboutToRun(MOShared::callIfPluginActive(this, func, true)); + } else { + return false; + } } bool OrganizerProxy::onFinishedRun(const std::function& func) { - return m_Proxied->onFinishedRun(MOShared::callIfPluginActive(this, func)); + if (m_Proxied) { + return m_Proxied->onFinishedRun(MOShared::callIfPluginActive(this, func)); + } else { + return false; + } } bool OrganizerProxy::onUserInterfaceInitialized(std::function const& func) { - // Always call this one to allow plugin to initialize themselves even when not active: - return m_Proxied->onUserInterfaceInitialized(func); + if (m_Proxied) { + // Always call this one to allow plugin to initialize themselves even when not active: + return m_Proxied->onUserInterfaceInitialized(func); + } else { + return false; + } } bool OrganizerProxy::onProfileCreated(std::function const& func) { - return m_Proxied->onProfileCreated(MOShared::callIfPluginActive(this, func)); + if (m_Proxied) { + return m_Proxied->onProfileCreated(MOShared::callIfPluginActive(this, func)); + } else { + return false; + } } bool OrganizerProxy::onProfileRenamed(std::function const& func) { - return m_Proxied->onProfileRenamed(MOShared::callIfPluginActive(this, func)); + if (m_Proxied) { + return m_Proxied->onProfileRenamed(MOShared::callIfPluginActive(this, func)); + } else { + return false; + } } bool OrganizerProxy::onProfileRemoved(std::function const& func) { - return m_Proxied->onProfileRemoved(MOShared::callIfPluginActive(this, func)); + if (m_Proxied) { + return m_Proxied->onProfileRemoved(MOShared::callIfPluginActive(this, func)); + } else { + return false; + } } bool OrganizerProxy::onProfileChanged(std::function const& func) { - return m_Proxied->onProfileChanged(MOShared::callIfPluginActive(this, func)); + if (m_Proxied) { + return m_Proxied->onProfileChanged(MOShared::callIfPluginActive(this, func)); + } else { + return false; + } } bool OrganizerProxy::onPluginSettingChanged(std::function const& func) { - // Always call this one, otherwise plugin cannot detect they are being enabled / disabled: - return m_Proxied->onPluginSettingChanged(func); + if (m_Proxied) { + // Always call this one, otherwise plugin cannot detect they are being enabled / disabled: + return m_Proxied->onPluginSettingChanged(func); + } else { + return false; + } } diff --git a/src/plugincontainer.cpp b/src/plugincontainer.cpp index 0c71e491..3ad3da21 100644 --- a/src/plugincontainer.cpp +++ b/src/plugincontainer.cpp @@ -171,6 +171,22 @@ QObject* PluginContainer::as_qobject(MOBase::IPlugin* plugin) const bool PluginContainer::initPlugin(IPlugin *plugin) { + // when MO has no instance loaded, `init()` is not called on plugins, except + // for proxy plugins + // + // proxy plugins are given an OrganizerProxy that has a null OrganizerCore, + // so there's not a lot it can do, but it can return some information; the + // majority of its functions are no-ops + // + // so initPlugin() (this function) is called for all plugins except proxies, + // and does not call init() if m_Organizer is null; initProxyPlugin() below + // is called only for proxy plugins and will call init() with the crippled + // OrganizerProxy + // + // note that after proxies are initialized, instantiate() is called for all + // the plugins they've discovered, but as for regular plugins, init() won't be + // called on them if m_OrganizerCore is null + if (plugin == nullptr) { return false; } @@ -187,6 +203,22 @@ bool PluginContainer::initPlugin(IPlugin *plugin) return true; } +bool PluginContainer::initProxyPlugin(IPlugin *plugin) +{ + // see initPlugin() above for info + + if (plugin == nullptr) { + return false; + } + + if (!plugin->init(new OrganizerProxy(m_Organizer, this, plugin))) { + log::warn("proxy plugin failed to initialize"); + return false; + } + + return true; +} + void PluginContainer::registerGame(IPluginGame *game) { @@ -272,7 +304,7 @@ bool PluginContainer::registerPlugin(QObject *plugin, const QString &fileName) } { // proxy plugins IPluginProxy *proxy = qobject_cast(plugin); - if (initPlugin(proxy)) { + if (initProxyPlugin(proxy)) { bf::at_key(m_Plugins).push_back(proxy); QStringList pluginNames = proxy->pluginList( QCoreApplication::applicationDirPath() + "/" + ToQString(AppConfig::pluginPath())); diff --git a/src/plugincontainer.h b/src/plugincontainer.h index bfbf1fa8..2b39726b 100644 --- a/src/plugincontainer.h +++ b/src/plugincontainer.h @@ -169,9 +169,9 @@ private: bool initPlugin(MOBase::IPlugin *plugin); + bool initProxyPlugin(MOBase::IPlugin *plugin); void registerGame(MOBase::IPluginGame *game); bool registerPlugin(QObject *pluginObj, const QString &fileName); - bool unregisterPlugin(QObject *pluginObj, const QString &fileName); OrganizerCore *m_Organizer; -- cgit v1.3.1 From be9c39a3b47a8f93388eaf624b6d007eac22b68e Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Fri, 6 Nov 2020 09:05:45 -0500 Subject: pass null IOrganizer to proxy plugins instead of one with a null OrganizerCore removed now useless null checks in OrganizerProxy call setPluginDataPath() early so plugins can have it, since it's now a static function in IOrganizer --- src/main.cpp | 6 +- src/organizerproxy.cpp | 203 +++++++++--------------------------------------- src/plugincontainer.cpp | 24 +++--- 3 files changed, 51 insertions(+), 182 deletions(-) (limited to 'src/plugincontainer.cpp') diff --git a/src/main.cpp b/src/main.cpp index 7b489aee..7005d374 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,10 +32,10 @@ along with Mod Organizer. If not, see . #include "env.h" #include "envmodule.h" #include "commandline.h" - #include "shared/util.h" #include "shared/appconfig.h" +#include #include #include #include @@ -730,6 +730,10 @@ int main(int argc, char *argv[]) InstanceManager::instance().overrideProfile(*cl.profile()); } + // makes plugin data path available to plugins, see + // IOrganizer::getPluginDataPath() + MOBase::details::setPluginDataPath(OrganizerCore::pluginDataPath()); + for (;;) { const auto r = doOneRun(cl, application, instance); diff --git a/src/organizerproxy.cpp b/src/organizerproxy.cpp index 5fa1f4ef..a988ba9f 100644 --- a/src/organizerproxy.cpp +++ b/src/organizerproxy.cpp @@ -22,17 +22,10 @@ OrganizerProxy::OrganizerProxy(OrganizerCore* organizer, PluginContainer* plugin : m_Proxied(organizer) , m_PluginContainer(pluginContainer) , m_Plugin(plugin) + , m_DownloadManagerProxy(std::make_unique(this, organizer->downloadManager())) + , m_ModListProxy(std::make_unique(this, organizer->modList())) + , m_PluginListProxy(std::make_unique(this, organizer->pluginList())) { - if (m_Proxied) { - m_DownloadManagerProxy = std::make_unique( - this, m_Proxied->downloadManager()); - - m_ModListProxy = std::make_unique( - this, m_Proxied->modList()); - - m_PluginListProxy = std::make_unique( - this, m_Proxied->pluginList()); - } } IModRepositoryBridge *OrganizerProxy::createNexusBridge() const @@ -42,118 +35,72 @@ IModRepositoryBridge *OrganizerProxy::createNexusBridge() const QString OrganizerProxy::profileName() const { - if (m_Proxied) { - return m_Proxied->profileName(); - } else { - return {}; - } + return m_Proxied->profileName(); } QString OrganizerProxy::profilePath() const { - if (m_Proxied) { - return m_Proxied->profilePath(); - } else { - return {}; - } + return m_Proxied->profilePath(); } QString OrganizerProxy::downloadsPath() const { - if (m_Proxied) { - return m_Proxied->downloadsPath(); - } else { - return {}; - } + return m_Proxied->downloadsPath(); } QString OrganizerProxy::overwritePath() const { - if (m_Proxied) { - return m_Proxied->overwritePath(); - } else { - return {}; - } + return m_Proxied->overwritePath(); } QString OrganizerProxy::basePath() const { - if (m_Proxied) { - return m_Proxied->basePath(); - } else { - return {}; - } + return m_Proxied->basePath(); } QString OrganizerProxy::modsPath() const { - if (m_Proxied) { - return m_Proxied->modsPath(); - } else { - return {}; - } + return m_Proxied->modsPath(); } VersionInfo OrganizerProxy::appVersion() const { - return createVersionInfo(); + return m_Proxied->appVersion(); } IPluginGame *OrganizerProxy::getGame(const QString &gameName) const { - if (m_Proxied) { - return m_Proxied->getGame(gameName); - } else { - return nullptr; - } + return m_Proxied->getGame(gameName); } IModInterface *OrganizerProxy::createMod(MOBase::GuessedValue &name) { - if (m_Proxied) { - return m_Proxied->createMod(name); - } else { - return nullptr; - } + return m_Proxied->createMod(name); } void OrganizerProxy::modDataChanged(IModInterface *mod) { - if (m_Proxied) { - m_Proxied->modDataChanged(mod); - } + m_Proxied->modDataChanged(mod); } QVariant OrganizerProxy::pluginSetting(const QString &pluginName, const QString &key) const { - if (m_Proxied) { - return m_Proxied->pluginSetting(pluginName, key); - } else { - return {}; - } + return m_Proxied->pluginSetting(pluginName, key); } void OrganizerProxy::setPluginSetting(const QString &pluginName, const QString &key, const QVariant &value) { - if (m_Proxied) { - m_Proxied->setPluginSetting(pluginName, key, value); - } + m_Proxied->setPluginSetting(pluginName, key, value); } QVariant OrganizerProxy::persistent(const QString &pluginName, const QString &key, const QVariant &def) const { - if (m_Proxied) { - return m_Proxied->persistent(pluginName, key, def); - } else { - return {}; - } + return m_Proxied->persistent(pluginName, key, def); } void OrganizerProxy::setPersistent(const QString &pluginName, const QString &key, const QVariant &value, bool sync) { - if (m_Proxied) { - m_Proxied->setPersistent(pluginName, key, value, sync); - } + m_Proxied->setPersistent(pluginName, key, value, sync); } QString OrganizerProxy::pluginDataPath() const @@ -165,10 +112,6 @@ HANDLE OrganizerProxy::startApplication( const QString& exe, const QStringList& args, const QString &cwd, const QString& profile, const QString &overwrite, bool ignoreOverwrite) { - if (!m_Proxied) { - return INVALID_HANDLE_VALUE; - } - log::debug( "a plugin has requested to start an application:\n" " . executable: '{}'\n" @@ -193,10 +136,6 @@ HANDLE OrganizerProxy::startApplication( bool OrganizerProxy::waitForApplication(HANDLE handle, LPDWORD exitCode) const { - if (!m_Proxied) { - return false; - } - const auto pid = ::GetProcessId(handle); log::debug( @@ -232,53 +171,31 @@ bool OrganizerProxy::waitForApplication(HANDLE handle, LPDWORD exitCode) const void OrganizerProxy::refresh(bool saveChanges) { - if (m_Proxied) { - m_Proxied->refresh(saveChanges); - } + m_Proxied->refresh(saveChanges); } IModInterface *OrganizerProxy::installMod(const QString &fileName, const QString &nameSuggestion) { - if (m_Proxied) { - return m_Proxied->installMod(fileName, false, nullptr, nameSuggestion); - } else { - return nullptr; - } + return m_Proxied->installMod(fileName, false, nullptr, nameSuggestion); } QString OrganizerProxy::resolvePath(const QString &fileName) const { - if (m_Proxied) { - return m_Proxied->resolvePath(fileName); - } else { - return {}; - } + return m_Proxied->resolvePath(fileName); } QStringList OrganizerProxy::listDirectories(const QString &directoryName) const { - if (m_Proxied) { - return m_Proxied->listDirectories(directoryName); - } else { - return {}; - } + return m_Proxied->listDirectories(directoryName); } QStringList OrganizerProxy::findFiles(const QString &path, const std::function &filter) const { - if (m_Proxied) { - return m_Proxied->findFiles(path, filter); - } else { - return {}; - } + return m_Proxied->findFiles(path, filter); } QStringList OrganizerProxy::findFiles(const QString& path, const QStringList& globFilters) const { - if (!m_Proxied) { - return {}; - } - QList> patterns; for (auto& gfilter : globFilters) { patterns.append(GlobPattern(gfilter)); @@ -295,20 +212,12 @@ QStringList OrganizerProxy::findFiles(const QString& path, const QStringList& gl QStringList OrganizerProxy::getFileOrigins(const QString &fileName) const { - if (m_Proxied) { - return m_Proxied->getFileOrigins(fileName); - } else { - return {}; - } + return m_Proxied->getFileOrigins(fileName); } QList OrganizerProxy::findFileInfos(const QString &path, const std::function &filter) const { - if (m_Proxied) { - return m_Proxied->findFileInfos(path, filter); - } else { - return {}; - } + return m_Proxied->findFileInfos(path, filter); } MOBase::IDownloadManager *OrganizerProxy::downloadManager() const @@ -328,94 +237,54 @@ MOBase::IModList *OrganizerProxy::modList() const MOBase::IProfile *OrganizerProxy::profile() const { - if (m_Proxied) { - return m_Proxied->currentProfile(); - } else { - return nullptr; - } + return m_Proxied->currentProfile(); } MOBase::IPluginGame const *OrganizerProxy::managedGame() const { - if (m_Proxied) { - return m_Proxied->managedGame(); - } else { - return nullptr; - } + return m_Proxied->managedGame(); } // CALLBACKS bool OrganizerProxy::onAboutToRun(const std::function& func) { - if (m_Proxied) { - return m_Proxied->onAboutToRun(MOShared::callIfPluginActive(this, func, true)); - } else { - return false; - } + return m_Proxied->onAboutToRun(MOShared::callIfPluginActive(this, func, true)); } bool OrganizerProxy::onFinishedRun(const std::function& func) { - if (m_Proxied) { - return m_Proxied->onFinishedRun(MOShared::callIfPluginActive(this, func)); - } else { - return false; - } + return m_Proxied->onFinishedRun(MOShared::callIfPluginActive(this, func)); } bool OrganizerProxy::onUserInterfaceInitialized(std::function const& func) { - if (m_Proxied) { - // Always call this one to allow plugin to initialize themselves even when not active: - return m_Proxied->onUserInterfaceInitialized(func); - } else { - return false; - } + // Always call this one to allow plugin to initialize themselves even when not active: + return m_Proxied->onUserInterfaceInitialized(func); } bool OrganizerProxy::onProfileCreated(std::function const& func) { - if (m_Proxied) { - return m_Proxied->onProfileCreated(MOShared::callIfPluginActive(this, func)); - } else { - return false; - } + return m_Proxied->onProfileCreated(MOShared::callIfPluginActive(this, func)); } bool OrganizerProxy::onProfileRenamed(std::function const& func) { - if (m_Proxied) { - return m_Proxied->onProfileRenamed(MOShared::callIfPluginActive(this, func)); - } else { - return false; - } + return m_Proxied->onProfileRenamed(MOShared::callIfPluginActive(this, func)); } bool OrganizerProxy::onProfileRemoved(std::function const& func) { - if (m_Proxied) { - return m_Proxied->onProfileRemoved(MOShared::callIfPluginActive(this, func)); - } else { - return false; - } + return m_Proxied->onProfileRemoved(MOShared::callIfPluginActive(this, func)); } bool OrganizerProxy::onProfileChanged(std::function const& func) { - if (m_Proxied) { - return m_Proxied->onProfileChanged(MOShared::callIfPluginActive(this, func)); - } else { - return false; - } + return m_Proxied->onProfileChanged(MOShared::callIfPluginActive(this, func)); } bool OrganizerProxy::onPluginSettingChanged(std::function const& func) { - if (m_Proxied) { - // Always call this one, otherwise plugin cannot detect they are being enabled / disabled: - return m_Proxied->onPluginSettingChanged(func); - } else { - return false; - } + // Always call this one, otherwise plugin cannot detect they are being enabled / disabled: + return m_Proxied->onPluginSettingChanged(func); } diff --git a/src/plugincontainer.cpp b/src/plugincontainer.cpp index 3ad3da21..a571a0aa 100644 --- a/src/plugincontainer.cpp +++ b/src/plugincontainer.cpp @@ -171,20 +171,11 @@ QObject* PluginContainer::as_qobject(MOBase::IPlugin* plugin) const bool PluginContainer::initPlugin(IPlugin *plugin) { - // when MO has no instance loaded, `init()` is not called on plugins, except - // for proxy plugins + // when MO has no instance loaded, init() is not called on plugins, except + // for proxy plugins, where init() is called with a null IOrganizer // - // proxy plugins are given an OrganizerProxy that has a null OrganizerCore, - // so there's not a lot it can do, but it can return some information; the - // majority of its functions are no-ops - // - // so initPlugin() (this function) is called for all plugins except proxies, - // and does not call init() if m_Organizer is null; initProxyPlugin() below - // is called only for proxy plugins and will call init() with the crippled - // OrganizerProxy - // - // note that after proxies are initialized, instantiate() is called for all - // the plugins they've discovered, but as for regular plugins, init() won't be + // after proxies are initialized, instantiate() is called for all the plugins + // they've discovered, but as for regular plugins, init() won't be // called on them if m_OrganizerCore is null if (plugin == nullptr) { @@ -211,7 +202,12 @@ bool PluginContainer::initProxyPlugin(IPlugin *plugin) return false; } - if (!plugin->init(new OrganizerProxy(m_Organizer, this, plugin))) { + IOrganizer* proxy = nullptr; + if (m_Organizer) { + proxy = new OrganizerProxy(m_Organizer, this, plugin); + } + + if (!plugin->init(proxy)) { log::warn("proxy plugin failed to initialize"); return false; } -- cgit v1.3.1