@ -1,7 +1,7 @@
|
||||
#include "BaseExternalTool.h"
|
||||
|
||||
#include <QProcess>
|
||||
#include <QDir>
|
||||
#include <QProcess>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <windows.h>
|
||||
@ -9,33 +9,24 @@
|
||||
|
||||
#include "BaseInstance.h"
|
||||
|
||||
BaseExternalTool::BaseExternalTool(SettingsObjectPtr settings, InstancePtr instance, QObject *parent)
|
||||
BaseExternalTool::BaseExternalTool(SettingsObjectPtr settings, InstancePtr instance, QObject* parent)
|
||||
: QObject(parent), m_instance(instance), globalSettings(settings)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
BaseExternalTool::~BaseExternalTool()
|
||||
{
|
||||
}
|
||||
BaseExternalTool::~BaseExternalTool() {}
|
||||
|
||||
BaseDetachedTool::BaseDetachedTool(SettingsObjectPtr settings, InstancePtr instance, QObject *parent)
|
||||
BaseDetachedTool::BaseDetachedTool(SettingsObjectPtr settings, InstancePtr instance, QObject* parent)
|
||||
: BaseExternalTool(settings, instance, parent)
|
||||
{
|
||||
|
||||
}
|
||||
{}
|
||||
|
||||
void BaseDetachedTool::run()
|
||||
{
|
||||
runImpl();
|
||||
}
|
||||
|
||||
BaseExternalToolFactory::~BaseExternalToolFactory() {}
|
||||
|
||||
BaseExternalToolFactory::~BaseExternalToolFactory()
|
||||
BaseDetachedTool* BaseDetachedToolFactory::createDetachedTool(InstancePtr instance, QObject* parent)
|
||||
{
|
||||
}
|
||||
|
||||
BaseDetachedTool *BaseDetachedToolFactory::createDetachedTool(InstancePtr instance,
|
||||
QObject *parent)
|
||||
{
|
||||
return qobject_cast<BaseDetachedTool *>(createTool(instance, parent));
|
||||
return qobject_cast<BaseDetachedTool*>(createTool(instance, parent));
|
||||
}
|
||||
|
@ -1,58 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <BaseInstance.h>
|
||||
#include <QObject>
|
||||
|
||||
class BaseInstance;
|
||||
class SettingsObject;
|
||||
class QProcess;
|
||||
|
||||
class BaseExternalTool : public QObject
|
||||
{
|
||||
class BaseExternalTool : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit BaseExternalTool(SettingsObjectPtr settings, InstancePtr instance, QObject *parent = 0);
|
||||
public:
|
||||
explicit BaseExternalTool(SettingsObjectPtr settings, InstancePtr instance, QObject* parent = 0);
|
||||
virtual ~BaseExternalTool();
|
||||
|
||||
protected:
|
||||
protected:
|
||||
InstancePtr m_instance;
|
||||
SettingsObjectPtr globalSettings;
|
||||
};
|
||||
|
||||
class BaseDetachedTool : public BaseExternalTool
|
||||
{
|
||||
class BaseDetachedTool : public BaseExternalTool {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit BaseDetachedTool(SettingsObjectPtr settings, InstancePtr instance, QObject *parent = 0);
|
||||
public:
|
||||
explicit BaseDetachedTool(SettingsObjectPtr settings, InstancePtr instance, QObject* parent = 0);
|
||||
|
||||
public
|
||||
slots:
|
||||
public slots:
|
||||
void run();
|
||||
|
||||
protected:
|
||||
protected:
|
||||
virtual void runImpl() = 0;
|
||||
};
|
||||
|
||||
class BaseExternalToolFactory
|
||||
{
|
||||
public:
|
||||
class 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 BaseExternalTool* createTool(InstancePtr instance, QObject* parent = 0) = 0;
|
||||
|
||||
virtual bool check(QString *error) = 0;
|
||||
virtual bool check(const QString &path, QString *error) = 0;
|
||||
virtual bool check(QString* error) = 0;
|
||||
virtual bool check(const QString& path, QString* error) = 0;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
SettingsObjectPtr globalSettings;
|
||||
};
|
||||
|
||||
class BaseDetachedToolFactory : public BaseExternalToolFactory
|
||||
{
|
||||
public:
|
||||
virtual BaseDetachedTool *createDetachedTool(InstancePtr instance, QObject *parent = 0);
|
||||
class BaseDetachedToolFactory : public BaseExternalToolFactory {
|
||||
public:
|
||||
virtual BaseDetachedTool* createDetachedTool(InstancePtr instance, QObject* parent = 0);
|
||||
};
|
||||
|
@ -3,10 +3,8 @@
|
||||
|
||||
#include <QProcess>
|
||||
|
||||
BaseProfiler::BaseProfiler(SettingsObjectPtr settings, InstancePtr instance, QObject *parent)
|
||||
: BaseExternalTool(settings, instance, parent)
|
||||
{
|
||||
}
|
||||
BaseProfiler::BaseProfiler(SettingsObjectPtr settings, InstancePtr instance, QObject* parent) : BaseExternalTool(settings, instance, parent)
|
||||
{}
|
||||
|
||||
void BaseProfiler::beginProfiling(shared_qobject_ptr<LaunchTask> process)
|
||||
{
|
||||
@ -20,8 +18,7 @@ void BaseProfiler::abortProfiling()
|
||||
|
||||
void BaseProfiler::abortProfilingImpl()
|
||||
{
|
||||
if (!m_profilerProcess)
|
||||
{
|
||||
if (!m_profilerProcess) {
|
||||
return;
|
||||
}
|
||||
m_profilerProcess->terminate();
|
||||
@ -30,7 +27,7 @@ void BaseProfiler::abortProfilingImpl()
|
||||
emit abortLaunch(tr("Profiler aborted"));
|
||||
}
|
||||
|
||||
BaseProfiler *BaseProfilerFactory::createProfiler(InstancePtr instance, QObject *parent)
|
||||
BaseProfiler* BaseProfilerFactory::createProfiler(InstancePtr instance, QObject* parent)
|
||||
{
|
||||
return qobject_cast<BaseProfiler *>(createTool(instance, parent));
|
||||
return qobject_cast<BaseProfiler*>(createTool(instance, parent));
|
||||
}
|
||||
|
@ -8,30 +8,27 @@ class SettingsObject;
|
||||
class LaunchTask;
|
||||
class QProcess;
|
||||
|
||||
class BaseProfiler : public BaseExternalTool
|
||||
{
|
||||
class BaseProfiler : public BaseExternalTool {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit BaseProfiler(SettingsObjectPtr settings, InstancePtr instance, QObject *parent = 0);
|
||||
public:
|
||||
explicit BaseProfiler(SettingsObjectPtr settings, InstancePtr instance, QObject* parent = 0);
|
||||
|
||||
public
|
||||
slots:
|
||||
public slots:
|
||||
void beginProfiling(shared_qobject_ptr<LaunchTask> process);
|
||||
void abortProfiling();
|
||||
|
||||
protected:
|
||||
QProcess *m_profilerProcess;
|
||||
protected:
|
||||
QProcess* m_profilerProcess;
|
||||
|
||||
virtual void beginProfilingImpl(shared_qobject_ptr<LaunchTask> process) = 0;
|
||||
virtual void abortProfilingImpl();
|
||||
|
||||
signals:
|
||||
void readyToLaunch(const QString &message);
|
||||
void abortLaunch(const QString &message);
|
||||
signals:
|
||||
void readyToLaunch(const QString& message);
|
||||
void abortLaunch(const QString& message);
|
||||
};
|
||||
|
||||
class BaseProfilerFactory : public BaseExternalToolFactory
|
||||
{
|
||||
public:
|
||||
virtual BaseProfiler *createProfiler(InstancePtr instance, QObject *parent = 0);
|
||||
class BaseProfilerFactory : public BaseExternalToolFactory {
|
||||
public:
|
||||
virtual BaseProfiler* createProfiler(InstancePtr instance, QObject* parent = 0);
|
||||
};
|
||||
|
@ -2,32 +2,27 @@
|
||||
|
||||
#include <QDir>
|
||||
|
||||
#include "settings/SettingsObject.h"
|
||||
#include "launch/LaunchTask.h"
|
||||
#include "BaseInstance.h"
|
||||
#include "launch/LaunchTask.h"
|
||||
#include "settings/SettingsObject.h"
|
||||
|
||||
class JProfiler : public BaseProfiler
|
||||
{
|
||||
class JProfiler : public BaseProfiler {
|
||||
Q_OBJECT
|
||||
public:
|
||||
JProfiler(SettingsObjectPtr settings, InstancePtr instance, QObject *parent = 0);
|
||||
public:
|
||||
JProfiler(SettingsObjectPtr settings, InstancePtr instance, QObject* parent = 0);
|
||||
|
||||
private slots:
|
||||
private slots:
|
||||
void profilerStarted();
|
||||
void profilerFinished(int exit, QProcess::ExitStatus status);
|
||||
|
||||
protected:
|
||||
protected:
|
||||
void beginProfilingImpl(shared_qobject_ptr<LaunchTask> process);
|
||||
|
||||
private:
|
||||
private:
|
||||
int listeningPort = 0;
|
||||
};
|
||||
|
||||
JProfiler::JProfiler(SettingsObjectPtr settings, InstancePtr instance,
|
||||
QObject *parent)
|
||||
: BaseProfiler(settings, instance, parent)
|
||||
{
|
||||
}
|
||||
JProfiler::JProfiler(SettingsObjectPtr settings, InstancePtr instance, QObject* parent) : BaseProfiler(settings, instance, parent) {}
|
||||
|
||||
void JProfiler::profilerStarted()
|
||||
{
|
||||
@ -36,12 +31,10 @@ void JProfiler::profilerStarted()
|
||||
|
||||
void JProfiler::profilerFinished([[maybe_unused]] int exit, QProcess::ExitStatus status)
|
||||
{
|
||||
if (status == QProcess::CrashExit)
|
||||
{
|
||||
if (status == QProcess::CrashExit) {
|
||||
emit abortLaunch(tr("Profiler aborted"));
|
||||
}
|
||||
if (m_profilerProcess)
|
||||
{
|
||||
if (m_profilerProcess) {
|
||||
m_profilerProcess->deleteLater();
|
||||
m_profilerProcess = 0;
|
||||
}
|
||||
@ -50,13 +43,8 @@ void JProfiler::profilerFinished([[maybe_unused]] int exit, QProcess::ExitStatus
|
||||
void JProfiler::beginProfilingImpl(shared_qobject_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)
|
||||
};
|
||||
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
|
||||
@ -82,31 +70,28 @@ void JProfilerFactory::registerSettings(SettingsObjectPtr settings)
|
||||
globalSettings = settings;
|
||||
}
|
||||
|
||||
BaseExternalTool *JProfilerFactory::createTool(InstancePtr instance, QObject *parent)
|
||||
BaseExternalTool* JProfilerFactory::createTool(InstancePtr instance, QObject* parent)
|
||||
{
|
||||
return new JProfiler(globalSettings, instance, parent);
|
||||
}
|
||||
|
||||
bool JProfilerFactory::check(QString *error)
|
||||
bool JProfilerFactory::check(QString* error)
|
||||
{
|
||||
return check(globalSettings->get("JProfilerPath").toString(), error);
|
||||
}
|
||||
|
||||
bool JProfilerFactory::check(const QString &path, QString *error)
|
||||
bool JProfilerFactory::check(const QString& path, QString* error)
|
||||
{
|
||||
if (path.isEmpty())
|
||||
{
|
||||
if (path.isEmpty()) {
|
||||
*error = QObject::tr("Empty path");
|
||||
return false;
|
||||
}
|
||||
QDir dir(path);
|
||||
if (!dir.exists())
|
||||
{
|
||||
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"))
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
@ -2,12 +2,11 @@
|
||||
|
||||
#include "BaseProfiler.h"
|
||||
|
||||
class JProfilerFactory : public BaseProfilerFactory
|
||||
{
|
||||
public:
|
||||
class 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;
|
||||
BaseExternalTool* createTool(InstancePtr instance, QObject* parent = 0) override;
|
||||
bool check(QString* error) override;
|
||||
bool check(const QString& path, QString* error) override;
|
||||
};
|
||||
|
@ -3,29 +3,24 @@
|
||||
#include <QDir>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include "settings/SettingsObject.h"
|
||||
#include "launch/LaunchTask.h"
|
||||
#include "BaseInstance.h"
|
||||
#include "launch/LaunchTask.h"
|
||||
#include "settings/SettingsObject.h"
|
||||
|
||||
class JVisualVM : public BaseProfiler
|
||||
{
|
||||
class JVisualVM : public BaseProfiler {
|
||||
Q_OBJECT
|
||||
public:
|
||||
JVisualVM(SettingsObjectPtr settings, InstancePtr instance, QObject *parent = 0);
|
||||
public:
|
||||
JVisualVM(SettingsObjectPtr settings, InstancePtr instance, QObject* parent = 0);
|
||||
|
||||
private slots:
|
||||
private slots:
|
||||
void profilerStarted();
|
||||
void profilerFinished(int exit, QProcess::ExitStatus status);
|
||||
|
||||
protected:
|
||||
protected:
|
||||
void beginProfilingImpl(shared_qobject_ptr<LaunchTask> process);
|
||||
};
|
||||
|
||||
|
||||
JVisualVM::JVisualVM(SettingsObjectPtr settings, InstancePtr instance, QObject *parent)
|
||||
: BaseProfiler(settings, instance, parent)
|
||||
{
|
||||
}
|
||||
JVisualVM::JVisualVM(SettingsObjectPtr settings, InstancePtr instance, QObject* parent) : BaseProfiler(settings, instance, parent) {}
|
||||
|
||||
void JVisualVM::profilerStarted()
|
||||
{
|
||||
@ -34,12 +29,10 @@ void JVisualVM::profilerStarted()
|
||||
|
||||
void JVisualVM::profilerFinished([[maybe_unused]] int exit, QProcess::ExitStatus status)
|
||||
{
|
||||
if (status == QProcess::CrashExit)
|
||||
{
|
||||
if (status == QProcess::CrashExit) {
|
||||
emit abortLaunch(tr("Profiler aborted"));
|
||||
}
|
||||
if (m_profilerProcess)
|
||||
{
|
||||
if (m_profilerProcess) {
|
||||
m_profilerProcess->deleteLater();
|
||||
m_profilerProcess = 0;
|
||||
}
|
||||
@ -47,18 +40,15 @@ void JVisualVM::profilerFinished([[maybe_unused]] int exit, QProcess::ExitStatus
|
||||
|
||||
void JVisualVM::beginProfilingImpl(shared_qobject_ptr<LaunchTask> process)
|
||||
{
|
||||
QProcess *profiler = new QProcess(this);
|
||||
QStringList profilerArgs =
|
||||
{
|
||||
"--openpid", QString::number(process->pid())
|
||||
};
|
||||
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, &QProcess::started, this, &JVisualVM::profilerStarted);
|
||||
connect(profiler, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, &JVisualVM::profilerFinished);
|
||||
connect(profiler, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, &JVisualVM::profilerFinished);
|
||||
|
||||
profiler->start();
|
||||
m_profilerProcess = profiler;
|
||||
@ -67,34 +57,31 @@ void JVisualVM::beginProfilingImpl(shared_qobject_ptr<LaunchTask> process)
|
||||
void JVisualVMFactory::registerSettings(SettingsObjectPtr settings)
|
||||
{
|
||||
QString defaultValue = QStandardPaths::findExecutable("jvisualvm");
|
||||
if (defaultValue.isNull())
|
||||
{
|
||||
if (defaultValue.isNull()) {
|
||||
defaultValue = QStandardPaths::findExecutable("visualvm");
|
||||
}
|
||||
settings->registerSetting("JVisualVMPath", defaultValue);
|
||||
globalSettings = settings;
|
||||
}
|
||||
|
||||
BaseExternalTool *JVisualVMFactory::createTool(InstancePtr instance, QObject *parent)
|
||||
BaseExternalTool* JVisualVMFactory::createTool(InstancePtr instance, QObject* parent)
|
||||
{
|
||||
return new JVisualVM(globalSettings, instance, parent);
|
||||
}
|
||||
|
||||
bool JVisualVMFactory::check(QString *error)
|
||||
bool JVisualVMFactory::check(QString* error)
|
||||
{
|
||||
return check(globalSettings->get("JVisualVMPath").toString(), error);
|
||||
}
|
||||
|
||||
bool JVisualVMFactory::check(const QString &path, QString *error)
|
||||
bool JVisualVMFactory::check(const QString& path, QString* error)
|
||||
{
|
||||
if (path.isEmpty())
|
||||
{
|
||||
if (path.isEmpty()) {
|
||||
*error = QObject::tr("Empty path");
|
||||
return false;
|
||||
}
|
||||
QFileInfo finfo(path);
|
||||
if (!finfo.isExecutable() || !finfo.fileName().contains("visualvm"))
|
||||
{
|
||||
if (!finfo.isExecutable() || !finfo.fileName().contains("visualvm")) {
|
||||
*error = QObject::tr("Invalid path to JVisualVM");
|
||||
return false;
|
||||
}
|
||||
|
@ -2,12 +2,11 @@
|
||||
|
||||
#include "BaseProfiler.h"
|
||||
|
||||
class JVisualVMFactory : public BaseProfilerFactory
|
||||
{
|
||||
public:
|
||||
class 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;
|
||||
BaseExternalTool* createTool(InstancePtr instance, QObject* parent = 0) override;
|
||||
bool check(QString* error) override;
|
||||
bool check(const QString& path, QString* error) override;
|
||||
};
|
||||
|
@ -4,9 +4,9 @@
|
||||
#include <QProcess>
|
||||
#include <QUrl>
|
||||
|
||||
#include "settings/SettingsObject.h"
|
||||
#include "BaseInstance.h"
|
||||
#include "minecraft/MinecraftInstance.h"
|
||||
#include "settings/SettingsObject.h"
|
||||
|
||||
MCEditTool::MCEditTool(SettingsObjectPtr settings)
|
||||
{
|
||||
@ -26,19 +26,17 @@ QString MCEditTool::path() const
|
||||
|
||||
bool MCEditTool::check(const QString& toolPath, QString& error)
|
||||
{
|
||||
if (toolPath.isEmpty())
|
||||
{
|
||||
if (toolPath.isEmpty()) {
|
||||
error = QObject::tr("Path is empty");
|
||||
return false;
|
||||
}
|
||||
const QDir dir(toolPath);
|
||||
if (!dir.exists())
|
||||
{
|
||||
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"))
|
||||
{
|
||||
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;
|
||||
}
|
||||
@ -53,22 +51,16 @@ QString MCEditTool::getProgramPath()
|
||||
const QString mceditPath = path();
|
||||
QDir mceditDir(mceditPath);
|
||||
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD)
|
||||
if (mceditDir.exists("mcedit.sh"))
|
||||
{
|
||||
if (mceditDir.exists("mcedit.sh")) {
|
||||
return mceditDir.absoluteFilePath("mcedit.sh");
|
||||
}
|
||||
else if (mceditDir.exists("mcedit.py"))
|
||||
{
|
||||
} else if (mceditDir.exists("mcedit.py")) {
|
||||
return mceditDir.absoluteFilePath("mcedit.py");
|
||||
}
|
||||
return QString();
|
||||
#elif defined(Q_OS_WIN32)
|
||||
if (mceditDir.exists("mcedit.exe"))
|
||||
{
|
||||
if (mceditDir.exists("mcedit.exe")) {
|
||||
return mceditDir.absoluteFilePath("mcedit.exe");
|
||||
}
|
||||
else if (mceditDir.exists("mcedit2.exe"))
|
||||
{
|
||||
} else if (mceditDir.exists("mcedit2.exe")) {
|
||||
return mceditDir.absoluteFilePath("mcedit2.exe");
|
||||
}
|
||||
return QString();
|
||||
|
@ -3,14 +3,14 @@
|
||||
#include <QString>
|
||||
#include "settings/SettingsObject.h"
|
||||
|
||||
class MCEditTool
|
||||
{
|
||||
public:
|
||||
class MCEditTool {
|
||||
public:
|
||||
MCEditTool(SettingsObjectPtr settings);
|
||||
void setPath(QString & path);
|
||||
void setPath(QString& path);
|
||||
QString path() const;
|
||||
bool check(const QString &toolPath, QString &error);
|
||||
bool check(const QString& toolPath, QString& error);
|
||||
QString getProgramPath();
|
||||
private:
|
||||
|
||||
private:
|
||||
SettingsObjectPtr m_settings;
|
||||
};
|
||||
|
Reference in New Issue
Block a user