diff options
author | Petr Mrázek <peterix@gmail.com> | 2016-04-10 04:29:29 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2016-04-30 23:59:23 +0200 |
commit | 47e37635f50c09b4f9a9ee7699e3120bab3e4088 (patch) | |
tree | 061c2f675fb7e244ebe4b54ef206bfbd615c91f8 /logic/tools | |
parent | fcd4a482f759cd58ee319a51082d0146b7e426e2 (diff) | |
download | MultiMC-47e37635f50c09b4f9a9ee7699e3120bab3e4088.tar MultiMC-47e37635f50c09b4f9a9ee7699e3120bab3e4088.tar.gz MultiMC-47e37635f50c09b4f9a9ee7699e3120bab3e4088.tar.lz MultiMC-47e37635f50c09b4f9a9ee7699e3120bab3e4088.tar.xz MultiMC-47e37635f50c09b4f9a9ee7699e3120bab3e4088.zip |
NOISSUE split GUI stuff from logic library
Diffstat (limited to 'logic/tools')
-rw-r--r-- | logic/tools/BaseExternalTool.cpp | 42 | ||||
-rw-r--r-- | logic/tools/BaseExternalTool.h | 60 | ||||
-rw-r--r-- | logic/tools/BaseProfiler.cpp | 35 | ||||
-rw-r--r-- | logic/tools/BaseProfiler.h | 38 | ||||
-rw-r--r-- | logic/tools/JProfiler.cpp | 117 | ||||
-rw-r--r-- | logic/tools/JProfiler.h | 15 | ||||
-rw-r--r-- | logic/tools/JVisualVM.cpp | 103 | ||||
-rw-r--r-- | logic/tools/JVisualVM.h | 15 | ||||
-rw-r--r-- | logic/tools/MCEditTool.cpp | 124 | ||||
-rw-r--r-- | logic/tools/MCEditTool.h | 26 |
10 files changed, 0 insertions, 575 deletions
diff --git a/logic/tools/BaseExternalTool.cpp b/logic/tools/BaseExternalTool.cpp deleted file mode 100644 index af7f9a3f..00000000 --- a/logic/tools/BaseExternalTool.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "BaseExternalTool.h" - -#include <QProcess> -#include <QDir> -#include <QInputDialog> - -#ifdef Q_OS_WIN -#include <windows.h> -#endif - -#include "BaseInstance.h" - -BaseExternalTool::BaseExternalTool(SettingsObjectPtr settings, InstancePtr instance, QObject *parent) - : QObject(parent), m_instance(instance), globalSettings(settings) -{ -} - -BaseExternalTool::~BaseExternalTool() -{ -} - -BaseDetachedTool::BaseDetachedTool(SettingsObjectPtr settings, InstancePtr instance, QObject *parent) - : BaseExternalTool(settings, instance, parent) -{ - -} - -void BaseDetachedTool::run() -{ - runImpl(); -} - - -BaseExternalToolFactory::~BaseExternalToolFactory() -{ -} - -BaseDetachedTool *BaseDetachedToolFactory::createDetachedTool(InstancePtr instance, - QObject *parent) -{ - return qobject_cast<BaseDetachedTool *>(createTool(instance, parent)); -} diff --git a/logic/tools/BaseExternalTool.h b/logic/tools/BaseExternalTool.h deleted file mode 100644 index fe1b5dc6..00000000 --- a/logic/tools/BaseExternalTool.h +++ /dev/null @@ -1,60 +0,0 @@ -#pragma once - -#include <QObject> -#include <BaseInstance.h> - -#include "multimc_logic_export.h" - -class BaseInstance; -class SettingsObject; -class QProcess; - -class MULTIMC_LOGIC_EXPORT BaseExternalTool : public QObject -{ - Q_OBJECT -public: - explicit BaseExternalTool(SettingsObjectPtr settings, InstancePtr instance, QObject *parent = 0); - virtual ~BaseExternalTool(); - -protected: - InstancePtr m_instance; - SettingsObjectPtr globalSettings; -}; - -class MULTIMC_LOGIC_EXPORT BaseDetachedTool : public BaseExternalTool -{ - Q_OBJECT -public: - explicit BaseDetachedTool(SettingsObjectPtr settings, InstancePtr instance, QObject *parent = 0); - -public -slots: - void run(); - -protected: - virtual void runImpl() = 0; -}; - -class MULTIMC_LOGIC_EXPORT BaseExternalToolFactory -{ -public: - virtual ~BaseExternalToolFactory(); - - virtual QString name() const = 0; - - virtual void registerSettings(SettingsObjectPtr settings) = 0; - - virtual BaseExternalTool *createTool(InstancePtr instance, QObject *parent = 0) = 0; - - virtual bool check(QString *error) = 0; - virtual bool check(const QString &path, QString *error) = 0; - -protected: - SettingsObjectPtr globalSettings; -}; - -class MULTIMC_LOGIC_EXPORT BaseDetachedToolFactory : public BaseExternalToolFactory -{ -public: - virtual BaseDetachedTool *createDetachedTool(InstancePtr instance, QObject *parent = 0); -}; diff --git a/logic/tools/BaseProfiler.cpp b/logic/tools/BaseProfiler.cpp deleted file mode 100644 index 5ff0fa44..00000000 --- a/logic/tools/BaseProfiler.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "BaseProfiler.h" - -#include <QProcess> - -BaseProfiler::BaseProfiler(SettingsObjectPtr settings, InstancePtr instance, QObject *parent) - : BaseExternalTool(settings, instance, parent) -{ -} - -void BaseProfiler::beginProfiling(std::shared_ptr<LaunchTask> process) -{ - beginProfilingImpl(process); -} - -void BaseProfiler::abortProfiling() -{ - abortProfilingImpl(); -} - -void BaseProfiler::abortProfilingImpl() -{ - if (!m_profilerProcess) - { - return; - } - m_profilerProcess->terminate(); - m_profilerProcess->deleteLater(); - m_profilerProcess = 0; - emit abortLaunch(tr("Profiler aborted")); -} - -BaseProfiler *BaseProfilerFactory::createProfiler(InstancePtr instance, QObject *parent) -{ - return qobject_cast<BaseProfiler *>(createTool(instance, parent)); -} diff --git a/logic/tools/BaseProfiler.h b/logic/tools/BaseProfiler.h deleted file mode 100644 index 3340b7e4..00000000 --- a/logic/tools/BaseProfiler.h +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -#include "BaseExternalTool.h" - -#include "multimc_logic_export.h" - -class BaseInstance; -class SettingsObject; -class LaunchTask; -class QProcess; - -class MULTIMC_LOGIC_EXPORT BaseProfiler : public BaseExternalTool -{ - Q_OBJECT -public: - explicit BaseProfiler(SettingsObjectPtr settings, InstancePtr instance, QObject *parent = 0); - -public -slots: - void beginProfiling(std::shared_ptr<LaunchTask> process); - void abortProfiling(); - -protected: - QProcess *m_profilerProcess; - - virtual void beginProfilingImpl(std::shared_ptr<LaunchTask> process) = 0; - virtual void abortProfilingImpl(); - -signals: - void readyToLaunch(const QString &message); - void abortLaunch(const QString &message); -}; - -class MULTIMC_LOGIC_EXPORT BaseProfilerFactory : public BaseExternalToolFactory -{ -public: - virtual BaseProfiler *createProfiler(InstancePtr instance, QObject *parent = 0); -}; diff --git a/logic/tools/JProfiler.cpp b/logic/tools/JProfiler.cpp deleted file mode 100644 index 45b33f79..00000000 --- a/logic/tools/JProfiler.cpp +++ /dev/null @@ -1,117 +0,0 @@ -#include "JProfiler.h" - -#include <QDir> -#include <QMessageBox> - -#include "settings/SettingsObject.h" -#include "launch/LaunchTask.h" -#include "BaseInstance.h" - -class JProfiler : public BaseProfiler -{ - Q_OBJECT -public: - JProfiler(SettingsObjectPtr settings, InstancePtr instance, QObject *parent = 0); - -private slots: - void profilerStarted(); - void profilerFinished(int exit, QProcess::ExitStatus status); - -protected: - void beginProfilingImpl(std::shared_ptr<LaunchTask> process); - -private: - int listeningPort = 0; -}; - -JProfiler::JProfiler(SettingsObjectPtr settings, InstancePtr instance, - QObject *parent) - : BaseProfiler(settings, instance, parent) -{ -} - -void JProfiler::profilerStarted() -{ - emit readyToLaunch(tr("Listening on port: %1").arg(listeningPort)); -} - -void JProfiler::profilerFinished(int exit, QProcess::ExitStatus status) -{ - if (status == QProcess::CrashExit) - { - emit abortLaunch(tr("Profiler aborted")); - } - if (m_profilerProcess) - { - m_profilerProcess->deleteLater(); - m_profilerProcess = 0; - } -} - -void JProfiler::beginProfilingImpl(std::shared_ptr<LaunchTask> process) -{ - listeningPort = globalSettings->get("JProfilerPort").toInt(); - QProcess *profiler = new QProcess(this); - QStringList profilerArgs = - { - "-d", QString::number(process->pid()), - "--gui", - "-p", QString::number(listeningPort) - }; - auto basePath = globalSettings->get("JProfilerPath").toString(); - -#ifdef Q_OS_WIN - QString profilerProgram = QDir(basePath).absoluteFilePath("bin/jpenable.exe"); -#else - QString profilerProgram = QDir(basePath).absoluteFilePath("bin/jpenable"); -#endif - - profiler->setArguments(profilerArgs); - profiler->setProgram(profilerProgram); - - connect(profiler, SIGNAL(started()), SLOT(profilerStarted())); - connect(profiler, SIGNAL(finished(int, QProcess::ExitStatus)), SLOT(profilerFinished(int,QProcess::ExitStatus))); - - m_profilerProcess = profiler; - profiler->start(); -} - -void JProfilerFactory::registerSettings(SettingsObjectPtr settings) -{ - settings->registerSetting("JProfilerPath"); - settings->registerSetting("JProfilerPort", 42042); - globalSettings = settings; -} - -BaseExternalTool *JProfilerFactory::createTool(InstancePtr instance, QObject *parent) -{ - return new JProfiler(globalSettings, instance, parent); -} - -bool JProfilerFactory::check(QString *error) -{ - return check(globalSettings->get("JProfilerPath").toString(), error); -} - -bool JProfilerFactory::check(const QString &path, QString *error) -{ - if (path.isEmpty()) - { - *error = QObject::tr("Empty path"); - return false; - } - QDir dir(path); - if (!dir.exists()) - { - *error = QObject::tr("Path does not exist"); - return false; - } - if (!dir.exists("bin") || !(dir.exists("bin/jprofiler") || dir.exists("bin/jprofiler.exe")) || !dir.exists("bin/agent.jar")) - { - *error = QObject::tr("Invalid JProfiler install"); - return false; - } - return true; -} - -#include "JProfiler.moc" diff --git a/logic/tools/JProfiler.h b/logic/tools/JProfiler.h deleted file mode 100644 index d658d6c2..00000000 --- a/logic/tools/JProfiler.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include "BaseProfiler.h" - -#include "multimc_logic_export.h" - -class MULTIMC_LOGIC_EXPORT JProfilerFactory : public BaseProfilerFactory -{ -public: - QString name() const override { return "JProfiler"; } - void registerSettings(SettingsObjectPtr settings) override; - BaseExternalTool *createTool(InstancePtr instance, QObject *parent = 0) override; - bool check(QString *error) override; - bool check(const QString &path, QString *error) override; -}; diff --git a/logic/tools/JVisualVM.cpp b/logic/tools/JVisualVM.cpp deleted file mode 100644 index 169967d9..00000000 --- a/logic/tools/JVisualVM.cpp +++ /dev/null @@ -1,103 +0,0 @@ -#include "JVisualVM.h" - -#include <QDir> -#include <QStandardPaths> - -#include "settings/SettingsObject.h" -#include "launch/LaunchTask.h" -#include "BaseInstance.h" - -class JVisualVM : public BaseProfiler -{ - Q_OBJECT -public: - JVisualVM(SettingsObjectPtr settings, InstancePtr instance, QObject *parent = 0); - -private slots: - void profilerStarted(); - void profilerFinished(int exit, QProcess::ExitStatus status); - -protected: - void beginProfilingImpl(std::shared_ptr<LaunchTask> process); -}; - - -JVisualVM::JVisualVM(SettingsObjectPtr settings, InstancePtr instance, QObject *parent) - : BaseProfiler(settings, instance, parent) -{ -} - -void JVisualVM::profilerStarted() -{ - emit readyToLaunch(tr("JVisualVM started")); -} - -void JVisualVM::profilerFinished(int exit, QProcess::ExitStatus status) -{ - if (status == QProcess::CrashExit) - { - emit abortLaunch(tr("Profiler aborted")); - } - if (m_profilerProcess) - { - m_profilerProcess->deleteLater(); - m_profilerProcess = 0; - } -} - -void JVisualVM::beginProfilingImpl(std::shared_ptr<LaunchTask> process) -{ - QProcess *profiler = new QProcess(this); - QStringList profilerArgs = - { - "--openpid", QString::number(process->pid()) - }; - auto programPath = globalSettings->get("JVisualVMPath").toString(); - - profiler->setArguments(profilerArgs); - profiler->setProgram(programPath); - - connect(profiler, SIGNAL(started()), SLOT(profilerStarted())); - connect(profiler, SIGNAL(finished(int, QProcess::ExitStatus)), SLOT(profilerFinished(int,QProcess::ExitStatus))); - - profiler->start(); - m_profilerProcess = profiler; -} - -void JVisualVMFactory::registerSettings(SettingsObjectPtr settings) -{ - QString defaultValue = QStandardPaths::findExecutable("jvisualvm"); - if (defaultValue.isNull()) - { - defaultValue = QStandardPaths::findExecutable("visualvm"); - } - settings->registerSetting("JVisualVMPath", defaultValue); - globalSettings = settings; -} - -BaseExternalTool *JVisualVMFactory::createTool(InstancePtr instance, QObject *parent) -{ - return new JVisualVM(globalSettings, instance, parent); -} - -bool JVisualVMFactory::check(QString *error) -{ - return check(globalSettings->get("JVisualVMPath").toString(), error); -} - -bool JVisualVMFactory::check(const QString &path, QString *error) -{ - if (path.isEmpty()) - { - *error = QObject::tr("Empty path"); - return false; - } - if (!QDir::isAbsolutePath(path) || !QFileInfo(path).isExecutable() || !path.contains("visualvm")) - { - *error = QObject::tr("Invalid path to JVisualVM"); - return false; - } - return true; -} - -#include "JVisualVM.moc" diff --git a/logic/tools/JVisualVM.h b/logic/tools/JVisualVM.h deleted file mode 100644 index 0674da13..00000000 --- a/logic/tools/JVisualVM.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include "BaseProfiler.h" - -#include "multimc_logic_export.h" - -class MULTIMC_LOGIC_EXPORT JVisualVMFactory : public BaseProfilerFactory -{ -public: - QString name() const override { return "JVisualVM"; } - void registerSettings(SettingsObjectPtr settings) override; - BaseExternalTool *createTool(InstancePtr instance, QObject *parent = 0) override; - bool check(QString *error) override; - bool check(const QString &path, QString *error) override; -}; diff --git a/logic/tools/MCEditTool.cpp b/logic/tools/MCEditTool.cpp deleted file mode 100644 index f0f715c3..00000000 --- a/logic/tools/MCEditTool.cpp +++ /dev/null @@ -1,124 +0,0 @@ -#include "MCEditTool.h" - -#include <QDir> -#include <QProcess> -#include <QUrl> -// FIXME: mixing logic and UI!!!! -#include <QInputDialog> -#include <QApplication> - -#include "settings/SettingsObject.h" -#include "BaseInstance.h" -#include "minecraft/MinecraftInstance.h" -#include <DesktopServices.h> - -MCEditTool::MCEditTool(SettingsObjectPtr settings, InstancePtr instance, QObject *parent) - : BaseDetachedTool(settings, instance, parent) -{ -} - -QString MCEditTool::getSave() const -{ - // FIXME: mixing logic and UI!!!! - auto mcInstance = std::dynamic_pointer_cast<MinecraftInstance>(m_instance); - if(!mcInstance) - { - return QString(); - } - QDir saves(mcInstance->minecraftRoot() + "/saves"); - QStringList worlds = saves.entryList(QDir::Dirs | QDir::NoDotAndDotDot); - QMutableListIterator<QString> it(worlds); - while (it.hasNext()) - { - it.next(); - if (!QDir(saves.absoluteFilePath(it.value())).exists("level.dat")) - { - it.remove(); - } - } - bool ok = true; - const QString save = QInputDialog::getItem(QApplication::activeWindow(), tr("MCEdit"), tr("Choose which world to open:"), - worlds, 0, false, &ok); - if (ok) - { - return saves.absoluteFilePath(save); - } - return QString(); -} - -void MCEditTool::runImpl() -{ - const QString mceditPath = globalSettings->get("MCEditPath").toString(); - const QString save = getSave(); - if (save.isNull()) - { - return; - } -#ifdef Q_OS_OSX - QProcess *process = new QProcess(); - connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), process, SLOT(deleteLater())); - process->setProgram(mceditPath); - process->setArguments(QStringList() << save); - process->start(); -#else - QDir mceditDir(mceditPath); - QString program; - #ifdef Q_OS_LINUX - if (mceditDir.exists("mcedit.py")) - { - program = mceditDir.absoluteFilePath("mcedit.py"); - } - else if (mceditDir.exists("mcedit.sh")) - { - program = mceditDir.absoluteFilePath("mcedit.sh"); - } - #elif defined(Q_OS_WIN32) - if (mceditDir.exists("mcedit.exe")) - { - program = mceditDir.absoluteFilePath("mcedit.exe"); - } - else if (mceditDir.exists("mcedit2.exe")) - { - program = mceditDir.absoluteFilePath("mcedit2.exe"); - } - #endif - if(program.size()) - { - DesktopServices::openFile(program, save, mceditPath); - } -#endif -} - -void MCEditFactory::registerSettings(SettingsObjectPtr settings) -{ - settings->registerSetting("MCEditPath"); - globalSettings = settings; -} -BaseExternalTool *MCEditFactory::createTool(InstancePtr instance, QObject *parent) -{ - return new MCEditTool(globalSettings, instance, parent); -} -bool MCEditFactory::check(QString *error) -{ - return check(globalSettings->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.sh") && !dir.exists("mcedit.py") && !dir.exists("mcedit.exe") && !dir.exists("Contents") && !dir.exists("mcedit2.exe")) - { - *error = QObject::tr("Path does not seem to be a MCEdit path"); - return false; - } - return true; -} diff --git a/logic/tools/MCEditTool.h b/logic/tools/MCEditTool.h deleted file mode 100644 index c287f1ea..00000000 --- a/logic/tools/MCEditTool.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include "BaseExternalTool.h" - -#include "multimc_logic_export.h" - -class MULTIMC_LOGIC_EXPORT MCEditTool : public BaseDetachedTool -{ - Q_OBJECT -public: - explicit MCEditTool(SettingsObjectPtr settings, InstancePtr instance, QObject *parent = 0); - -protected: - QString getSave() const; - void runImpl() override; -}; - -class MULTIMC_LOGIC_EXPORT MCEditFactory : public BaseDetachedToolFactory -{ -public: - QString name() const override { return "MCEdit"; } - void registerSettings(SettingsObjectPtr settings) override; - BaseExternalTool *createTool(InstancePtr instance, QObject *parent = 0) override; - bool check(QString *error) override; - bool check(const QString &path, QString *error) override; -}; |