diff options
Diffstat (limited to 'logic')
-rw-r--r-- | logic/BaseExternalTool.cpp | 47 | ||||
-rw-r--r-- | logic/BaseExternalTool.h | 56 | ||||
-rw-r--r-- | logic/MCEditTool.cpp | 62 | ||||
-rw-r--r-- | logic/MCEditTool.h | 23 | ||||
-rw-r--r-- | logic/profiler/BaseProfiler.cpp | 22 | ||||
-rw-r--r-- | logic/profiler/BaseProfiler.h | 21 | ||||
-rw-r--r-- | logic/profiler/JProfiler.cpp | 2 | ||||
-rw-r--r-- | logic/profiler/JProfiler.h | 2 | ||||
-rw-r--r-- | logic/profiler/JVisualVM.cpp | 2 | ||||
-rw-r--r-- | logic/profiler/JVisualVM.h | 2 |
10 files changed, 199 insertions, 40 deletions
diff --git a/logic/BaseExternalTool.cpp b/logic/BaseExternalTool.cpp new file mode 100644 index 00000000..6dffb4d6 --- /dev/null +++ b/logic/BaseExternalTool.cpp @@ -0,0 +1,47 @@ +#include "BaseExternalTool.h" + +#include <QProcess> +#ifdef Q_OS_WIN +#include <windows.h> +#endif + +BaseExternalTool::BaseExternalTool(BaseInstance *instance, QObject *parent) + : QObject(parent), m_instance(instance) +{ +} + +BaseExternalTool::~BaseExternalTool() +{ +} + +qint64 BaseExternalTool::pid(QProcess *process) +{ +#ifdef Q_OS_WIN + struct _PROCESS_INFORMATION *procinfo = process->pid(); + return procinfo->dwProcessId; +#else + return process->pid(); +#endif +} + + +BaseDetachedTool::BaseDetachedTool(BaseInstance *instance, QObject *parent) + : BaseExternalTool(instance, parent) +{ + +} + +void BaseDetachedTool::run() +{ + runImpl(); +} + + +BaseExternalToolFactory::~BaseExternalToolFactory() +{ +} + +BaseDetachedTool *BaseDetachedToolFactory::createDetachedTool(BaseInstance *instance, QObject *parent) +{ + return qobject_cast<BaseDetachedTool *>(createTool(instance, parent)); +} diff --git a/logic/BaseExternalTool.h b/logic/BaseExternalTool.h new file mode 100644 index 00000000..184b1f80 --- /dev/null +++ b/logic/BaseExternalTool.h @@ -0,0 +1,56 @@ +#pragma once + +#include <QObject> + +class BaseInstance; +class SettingsObject; +class MinecraftProcess; +class QProcess; + +class BaseExternalTool : public QObject +{ + Q_OBJECT +public: + explicit BaseExternalTool(BaseInstance *instance, QObject *parent = 0); + virtual ~BaseExternalTool(); + +protected: + BaseInstance *m_instance; + + qint64 pid(QProcess *process); +}; + +class BaseDetachedTool : public BaseExternalTool +{ + Q_OBJECT +public: + explicit BaseDetachedTool(BaseInstance *instance, QObject *parent = 0); + +public +slots: + void run(); + +protected: + virtual void runImpl() = 0; +}; + +class BaseExternalToolFactory +{ +public: + virtual ~BaseExternalToolFactory(); + + virtual QString name() const = 0; + + virtual void registerSettings(SettingsObject *settings) = 0; + + virtual BaseExternalTool *createTool(BaseInstance *instance, QObject *parent = 0) = 0; + + virtual bool check(QString *error) = 0; + virtual bool check(const QString &path, QString *error) = 0; +}; + +class BaseDetachedToolFactory : public BaseExternalToolFactory +{ +public: + virtual BaseDetachedTool *createDetachedTool(BaseInstance *instance, QObject *parent = 0); +}; diff --git a/logic/MCEditTool.cpp b/logic/MCEditTool.cpp new file mode 100644 index 00000000..93ffb7a5 --- /dev/null +++ b/logic/MCEditTool.cpp @@ -0,0 +1,62 @@ +#include "MCEditTool.h" + +#include <QDir> +#include <QProcess> +#include <QFileDialog> + +#include "settingsobject.h" +#include "logic/BaseInstance.h" +#include "MultiMC.h" + +MCEditTool::MCEditTool(BaseInstance *instance, QObject *parent) + : BaseDetachedTool(instance, parent) +{ +} + +void MCEditTool::runImpl() +{ + const QString mceditPath = MMC->settings()->get("MCEditPath").toString(); + const QString save = QFileDialog::getExistingDirectory( + MMC->activeWindow(), tr("MCEdit"), + QDir(m_instance->minecraftRoot()).absoluteFilePath("saves")); + if (save.isEmpty()) + { + return; + } + const QString program = + QDir(mceditPath).absoluteFilePath("mcedit.py"); + QProcess::startDetached(program, QStringList() << save, mceditPath); +} + +void MCEditFactory::registerSettings(SettingsObject *settings) +{ + settings->registerSetting("MCEditPath"); +} +BaseExternalTool *MCEditFactory::createTool(BaseInstance *instance, QObject *parent) +{ + return new MCEditTool(instance, parent); +} +bool MCEditFactory::check(QString *error) +{ + return check(MMC->settings()->get("MCEditPath").toString(), error); +} +bool MCEditFactory::check(const QString &path, QString *error) +{ + if (path.isEmpty()) + { + *error = QObject::tr("Path is empty"); + return false; + } + const QDir dir(path); + if (!dir.exists()) + { + *error = QObject::tr("Path does not exist"); + return false; + } + if (!dir.exists("mcedit.py")) + { + *error = QObject::tr("Path does not contain mcedit.py"); + return false; + } + return true; +} diff --git a/logic/MCEditTool.h b/logic/MCEditTool.h new file mode 100644 index 00000000..b0ed1ad4 --- /dev/null +++ b/logic/MCEditTool.h @@ -0,0 +1,23 @@ +#pragma once + +#include "BaseExternalTool.h" + +class MCEditTool : public BaseDetachedTool +{ + Q_OBJECT +public: + explicit MCEditTool(BaseInstance *instance, QObject *parent = 0); + +protected: + void runImpl() override; +}; + +class MCEditFactory : public BaseDetachedToolFactory +{ +public: + QString name() const override { return "MCEdit"; } + void registerSettings(SettingsObject *settings) override; + BaseExternalTool *createTool(BaseInstance *instance, QObject *parent = 0) override; + bool check(QString *error) override; + bool check(const QString &path, QString *error) override; +}; diff --git a/logic/profiler/BaseProfiler.cpp b/logic/profiler/BaseProfiler.cpp index b58e88be..9aaca793 100644 --- a/logic/profiler/BaseProfiler.cpp +++ b/logic/profiler/BaseProfiler.cpp @@ -1,16 +1,9 @@ #include "BaseProfiler.h" #include <QProcess> -#ifdef Q_OS_WIN -#include <windows.h> -#endif BaseProfiler::BaseProfiler(BaseInstance *instance, QObject *parent) - : QObject(parent), m_instance(instance) -{ -} - -BaseProfiler::~BaseProfiler() + : BaseExternalTool(instance, parent) { } @@ -36,16 +29,7 @@ void BaseProfiler::abortProfilingImpl() emit abortLaunch(tr("Profiler aborted")); } -qint64 BaseProfiler::pid(QProcess *process) -{ -#ifdef Q_OS_WIN - struct _PROCESS_INFORMATION *procinfo = process->pid(); - return procinfo->dwProcessId; -#else - return process->pid(); -#endif -} - -BaseProfilerFactory::~BaseProfilerFactory() +BaseProfiler *BaseProfilerFactory::createProfiler(BaseInstance *instance, QObject *parent) { + return qobject_cast<BaseProfiler *>(createTool(instance, parent)); } diff --git a/logic/profiler/BaseProfiler.h b/logic/profiler/BaseProfiler.h index e0d1d5f6..082cb65a 100644 --- a/logic/profiler/BaseProfiler.h +++ b/logic/profiler/BaseProfiler.h @@ -1,18 +1,17 @@ #pragma once -#include <QObject> +#include "logic/BaseExternalTool.h" class BaseInstance; class SettingsObject; class MinecraftProcess; class QProcess; -class BaseProfiler : public QObject +class BaseProfiler : public BaseExternalTool { Q_OBJECT public: explicit BaseProfiler(BaseInstance *instance, QObject *parent = 0); - virtual ~BaseProfiler(); public slots: @@ -20,30 +19,18 @@ slots: void abortProfiling(); protected: - BaseInstance *m_instance; QProcess *m_profilerProcess; virtual void beginProfilingImpl(MinecraftProcess *process) = 0; virtual void abortProfilingImpl(); - qint64 pid(QProcess *process); - signals: void readyToLaunch(const QString &message); void abortLaunch(const QString &message); }; -class BaseProfilerFactory +class BaseProfilerFactory : public BaseExternalToolFactory { public: - virtual ~BaseProfilerFactory(); - - virtual QString name() const = 0; - - virtual void registerSettings(SettingsObject *settings) = 0; - - virtual BaseProfiler *createProfiler(BaseInstance *instance, QObject *parent = 0) = 0; - - virtual bool check(QString *error) = 0; - virtual bool check(const QString &path, QString *error) = 0; + virtual BaseProfiler *createProfiler(BaseInstance *instance, QObject *parent = 0); }; diff --git a/logic/profiler/JProfiler.cpp b/logic/profiler/JProfiler.cpp index 1cd8d128..bb851f0b 100644 --- a/logic/profiler/JProfiler.cpp +++ b/logic/profiler/JProfiler.cpp @@ -46,7 +46,7 @@ void JProfilerFactory::registerSettings(SettingsObject *settings) settings->registerSetting("JProfilerPort", 42042); } -BaseProfiler *JProfilerFactory::createProfiler(BaseInstance *instance, QObject *parent) +BaseExternalTool *JProfilerFactory::createTool(BaseInstance *instance, QObject *parent) { return new JProfiler(instance, parent); } diff --git a/logic/profiler/JProfiler.h b/logic/profiler/JProfiler.h index 8a5bc561..88a02462 100644 --- a/logic/profiler/JProfiler.h +++ b/logic/profiler/JProfiler.h @@ -17,7 +17,7 @@ class JProfilerFactory : public BaseProfilerFactory public: QString name() const override { return "JProfiler"; } void registerSettings(SettingsObject *settings) override; - BaseProfiler *createProfiler(BaseInstance *instance, QObject *parent = 0) override; + BaseExternalTool *createTool(BaseInstance *instance, QObject *parent = 0) override; bool check(QString *error) override; bool check(const QString &path, QString *error) override; }; diff --git a/logic/profiler/JVisualVM.cpp b/logic/profiler/JVisualVM.cpp index c4bc851b..7b79b2e8 100644 --- a/logic/profiler/JVisualVM.cpp +++ b/logic/profiler/JVisualVM.cpp @@ -42,7 +42,7 @@ void JVisualVMFactory::registerSettings(SettingsObject *settings) settings->registerSetting("JVisualVMPath"); } -BaseProfiler *JVisualVMFactory::createProfiler(BaseInstance *instance, QObject *parent) +BaseExternalTool *JVisualVMFactory::createTool(BaseInstance *instance, QObject *parent) { return new JVisualVM(instance, parent); } diff --git a/logic/profiler/JVisualVM.h b/logic/profiler/JVisualVM.h index 154180b4..af94fe55 100644 --- a/logic/profiler/JVisualVM.h +++ b/logic/profiler/JVisualVM.h @@ -17,7 +17,7 @@ class JVisualVMFactory : public BaseProfilerFactory public: QString name() const override { return "JVisualVM"; } void registerSettings(SettingsObject *settings) override; - BaseProfiler *createProfiler(BaseInstance *instance, QObject *parent = 0) override; + BaseExternalTool *createTool(BaseInstance *instance, QObject *parent = 0) override; bool check(QString *error) override; bool check(const QString &path, QString *error) override; }; |