summaryrefslogtreecommitdiff
path: root/src/organizerproxy.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/organizerproxy.cpp')
-rw-r--r--src/organizerproxy.cpp206
1 files changed, 169 insertions, 37 deletions
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 <QObject>
#include <QApplication>
@@ -21,10 +22,17 @@ OrganizerProxy::OrganizerProxy(OrganizerCore* organizer, PluginContainer* plugin
: m_Proxied(organizer)
, m_PluginContainer(pluginContainer)
, m_Plugin(plugin)
- , m_DownloadManagerProxy(std::make_unique<DownloadManagerProxy>(this, organizer->downloadManager()))
- , m_ModListProxy(std::make_unique<ModListProxy>(this, organizer->modList()))
- , m_PluginListProxy(std::make_unique<PluginListProxy>(this, organizer->pluginList()))
{
+ if (m_Proxied) {
+ m_DownloadManagerProxy = std::make_unique<DownloadManagerProxy>(
+ this, m_Proxied->downloadManager());
+
+ m_ModListProxy = std::make_unique<ModListProxy>(
+ this, m_Proxied->modList());
+
+ m_PluginListProxy = std::make_unique<PluginListProxy>(
+ 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<QString> &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<bool(const QString&)> &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<GlobPattern<QChar>> 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<MOBase::IOrganizer::FileInfo> OrganizerProxy::findFileInfos(const QString &path, const std::function<bool (const MOBase::IOrganizer::FileInfo &)> &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<bool(const QString&)>& 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<void(const QString&, unsigned int)>& 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<void(QMainWindow*)> 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<void(IProfile*)> 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<void(IProfile*, QString const&, QString const&)> 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<void(QString const&)> 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<void(MOBase::IProfile*, MOBase::IProfile*)> 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<void(QString const&, const QString& key, const QVariant&, const QVariant&)> 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;
+ }
}