Merge branch 'feature_profiling' into integration_json_and_tools
This commit is contained in:
@ -77,7 +77,7 @@ MinecraftProcess *LegacyInstance::prepareForLaunch(AuthSessionPtr account)
|
||||
launchScript += "windowTitle " + windowTitle() + "\n";
|
||||
launchScript += "windowParams " + windowParams + "\n";
|
||||
launchScript += "lwjgl " + lwjgl + "\n";
|
||||
launchScript += "launch legacy\n";
|
||||
launchScript += "launcher legacy\n";
|
||||
}
|
||||
proc->setLaunchScript(launchScript);
|
||||
|
||||
|
@ -288,7 +288,7 @@ void MinecraftProcess::killMinecraft()
|
||||
kill();
|
||||
}
|
||||
|
||||
void MinecraftProcess::launch()
|
||||
void MinecraftProcess::arm()
|
||||
{
|
||||
emit log("MultiMC version: " + MMC->version().toString() + "\n\n");
|
||||
emit log("Minecraft folder is:\n" + workingDirectory() + "\n\n");
|
||||
@ -374,3 +374,17 @@ void MinecraftProcess::launch()
|
||||
QByteArray bytes = launchScript.toUtf8();
|
||||
writeData(bytes.constData(), bytes.length());
|
||||
}
|
||||
|
||||
void MinecraftProcess::launch()
|
||||
{
|
||||
QString launchString("launch\n");
|
||||
QByteArray bytes = launchString.toUtf8();
|
||||
writeData(bytes.constData(), bytes.length());
|
||||
}
|
||||
|
||||
void MinecraftProcess::abort()
|
||||
{
|
||||
QString launchString("abort\n");
|
||||
QByteArray bytes = launchString.toUtf8();
|
||||
writeData(bytes.constData(), bytes.length());
|
||||
}
|
||||
|
@ -55,10 +55,20 @@ public:
|
||||
MinecraftProcess(BaseInstance *inst);
|
||||
|
||||
/**
|
||||
* @brief launch minecraft
|
||||
* @brief start the launcher part with the provided launch script
|
||||
*/
|
||||
void arm();
|
||||
|
||||
/**
|
||||
* @brief launch the armed instance!
|
||||
*/
|
||||
void launch();
|
||||
|
||||
/**
|
||||
* @brief abort launch!
|
||||
*/
|
||||
void abort();
|
||||
|
||||
BaseInstance *instance()
|
||||
{
|
||||
return m_instance;
|
||||
|
@ -230,7 +230,7 @@ MinecraftProcess *OneSixInstance::prepareForLaunch(AuthSessionPtr session)
|
||||
launchScript += "ext " + finfo.absoluteFilePath() + "\n";
|
||||
}
|
||||
launchScript += "natives " + natives_dir.absolutePath() + "\n";
|
||||
launchScript += "launch onesix\n";
|
||||
launchScript += "launcher onesix\n";
|
||||
|
||||
// create the process and set its parameters
|
||||
MinecraftProcess *proc = new MinecraftProcess(this);
|
||||
|
77
logic/tools/BaseExternalTool.cpp
Normal file
77
logic/tools/BaseExternalTool.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
#include "BaseExternalTool.h"
|
||||
|
||||
#include <QProcess>
|
||||
#include <QDir>
|
||||
#include <QInputDialog>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "logic/BaseInstance.h"
|
||||
#include "MultiMC.h"
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
QString BaseExternalTool::getSave() const
|
||||
{
|
||||
QDir saves(m_instance->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(
|
||||
MMC->activeWindow(), tr("MCEdit"), tr("Choose which world to open:"),
|
||||
worlds, 0, false, &ok);
|
||||
if (ok)
|
||||
{
|
||||
return saves.absoluteFilePath(save);
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
|
||||
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));
|
||||
}
|
57
logic/tools/BaseExternalTool.h
Normal file
57
logic/tools/BaseExternalTool.h
Normal file
@ -0,0 +1,57 @@
|
||||
#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);
|
||||
QString getSave() const;
|
||||
};
|
||||
|
||||
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);
|
||||
};
|
35
logic/tools/BaseProfiler.cpp
Normal file
35
logic/tools/BaseProfiler.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include "BaseProfiler.h"
|
||||
|
||||
#include <QProcess>
|
||||
|
||||
BaseProfiler::BaseProfiler(BaseInstance *instance, QObject *parent)
|
||||
: BaseExternalTool(instance, parent)
|
||||
{
|
||||
}
|
||||
|
||||
void BaseProfiler::beginProfiling(MinecraftProcess *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(BaseInstance *instance, QObject *parent)
|
||||
{
|
||||
return qobject_cast<BaseProfiler *>(createTool(instance, parent));
|
||||
}
|
36
logic/tools/BaseProfiler.h
Normal file
36
logic/tools/BaseProfiler.h
Normal file
@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include "BaseExternalTool.h"
|
||||
|
||||
class BaseInstance;
|
||||
class SettingsObject;
|
||||
class MinecraftProcess;
|
||||
class QProcess;
|
||||
|
||||
class BaseProfiler : public BaseExternalTool
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit BaseProfiler(BaseInstance *instance, QObject *parent = 0);
|
||||
|
||||
public
|
||||
slots:
|
||||
void beginProfiling(MinecraftProcess *process);
|
||||
void abortProfiling();
|
||||
|
||||
protected:
|
||||
QProcess *m_profilerProcess;
|
||||
|
||||
virtual void beginProfilingImpl(MinecraftProcess *process) = 0;
|
||||
virtual void abortProfilingImpl();
|
||||
|
||||
signals:
|
||||
void readyToLaunch(const QString &message);
|
||||
void abortLaunch(const QString &message);
|
||||
};
|
||||
|
||||
class BaseProfilerFactory : public BaseExternalToolFactory
|
||||
{
|
||||
public:
|
||||
virtual BaseProfiler *createProfiler(BaseInstance *instance, QObject *parent = 0);
|
||||
};
|
78
logic/tools/JProfiler.cpp
Normal file
78
logic/tools/JProfiler.cpp
Normal file
@ -0,0 +1,78 @@
|
||||
#include "JProfiler.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "settingsobject.h"
|
||||
#include "logic/MinecraftProcess.h"
|
||||
#include "logic/BaseInstance.h"
|
||||
#include "MultiMC.h"
|
||||
|
||||
JProfiler::JProfiler(BaseInstance *instance, QObject *parent) : BaseProfiler(instance, parent)
|
||||
{
|
||||
}
|
||||
|
||||
void JProfiler::beginProfilingImpl(MinecraftProcess *process)
|
||||
{
|
||||
int port = MMC->settings()->get("JProfilerPort").toInt();
|
||||
QProcess *profiler = new QProcess(this);
|
||||
profiler->setArguments(QStringList() << "-d" << QString::number(pid(process)) << "--gui"
|
||||
<< "-p" << QString::number(port));
|
||||
profiler->setProgram(QDir(MMC->settings()->get("JProfilerPath").toString())
|
||||
.absoluteFilePath("bin/jpenable"));
|
||||
connect(profiler, &QProcess::started, [this, port]()
|
||||
{ emit readyToLaunch(tr("Listening on port: %1").arg(port)); });
|
||||
connect(profiler,
|
||||
static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
|
||||
[this](int exit, QProcess::ExitStatus status)
|
||||
{
|
||||
if (status == QProcess::CrashExit)
|
||||
{
|
||||
emit abortLaunch(tr("Profiler aborted"));
|
||||
}
|
||||
if (m_profilerProcess)
|
||||
{
|
||||
m_profilerProcess->deleteLater();
|
||||
m_profilerProcess = 0;
|
||||
}
|
||||
});
|
||||
profiler->start();
|
||||
m_profilerProcess = profiler;
|
||||
}
|
||||
|
||||
void JProfilerFactory::registerSettings(SettingsObject *settings)
|
||||
{
|
||||
settings->registerSetting("JProfilerPath");
|
||||
settings->registerSetting("JProfilerPort", 42042);
|
||||
}
|
||||
|
||||
BaseExternalTool *JProfilerFactory::createTool(BaseInstance *instance, QObject *parent)
|
||||
{
|
||||
return new JProfiler(instance, parent);
|
||||
}
|
||||
|
||||
bool JProfilerFactory::check(QString *error)
|
||||
{
|
||||
return check(MMC->settings()->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/agent.jar"))
|
||||
{
|
||||
*error = QObject::tr("Invalid JProfiler install");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
23
logic/tools/JProfiler.h
Normal file
23
logic/tools/JProfiler.h
Normal file
@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "BaseProfiler.h"
|
||||
|
||||
class JProfiler : public BaseProfiler
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
JProfiler(BaseInstance *instance, QObject *parent = 0);
|
||||
|
||||
protected:
|
||||
void beginProfilingImpl(MinecraftProcess *process);
|
||||
};
|
||||
|
||||
class JProfilerFactory : public BaseProfilerFactory
|
||||
{
|
||||
public:
|
||||
QString name() const override { return "JProfiler"; }
|
||||
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;
|
||||
};
|
74
logic/tools/JVisualVM.cpp
Normal file
74
logic/tools/JVisualVM.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
#include "JVisualVM.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include "settingsobject.h"
|
||||
#include "logic/MinecraftProcess.h"
|
||||
#include "logic/BaseInstance.h"
|
||||
#include "MultiMC.h"
|
||||
|
||||
JVisualVM::JVisualVM(BaseInstance *instance, QObject *parent) : BaseProfiler(instance, parent)
|
||||
{
|
||||
}
|
||||
|
||||
void JVisualVM::beginProfilingImpl(MinecraftProcess *process)
|
||||
{
|
||||
QProcess *profiler = new QProcess(this);
|
||||
profiler->setArguments(QStringList() << "--openpid" << QString::number(pid(process)));
|
||||
profiler->setProgram(MMC->settings()->get("JVisualVMPath").toString());
|
||||
connect(profiler, &QProcess::started, [this]()
|
||||
{ emit readyToLaunch(tr("JVisualVM started")); });
|
||||
connect(profiler,
|
||||
static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
|
||||
[this](int exit, QProcess::ExitStatus status)
|
||||
{
|
||||
if (exit != 0 || status == QProcess::CrashExit)
|
||||
{
|
||||
emit abortLaunch(tr("Profiler aborted"));
|
||||
}
|
||||
if (m_profilerProcess)
|
||||
{
|
||||
m_profilerProcess->deleteLater();
|
||||
m_profilerProcess = 0;
|
||||
}
|
||||
});
|
||||
profiler->start();
|
||||
m_profilerProcess = profiler;
|
||||
}
|
||||
|
||||
void JVisualVMFactory::registerSettings(SettingsObject *settings)
|
||||
{
|
||||
QString defaultValue = QStandardPaths::findExecutable("jvisualvm");
|
||||
if (defaultValue.isNull())
|
||||
{
|
||||
defaultValue = QStandardPaths::findExecutable("visualvm");
|
||||
}
|
||||
settings->registerSetting("JVisualVMPath", defaultValue);
|
||||
}
|
||||
|
||||
BaseExternalTool *JVisualVMFactory::createTool(BaseInstance *instance, QObject *parent)
|
||||
{
|
||||
return new JVisualVM(instance, parent);
|
||||
}
|
||||
|
||||
bool JVisualVMFactory::check(QString *error)
|
||||
{
|
||||
return check(MMC->settings()->get("JVisualVMPath").toString(), error);
|
||||
}
|
||||
|
||||
bool JVisualVMFactory::check(const QString &path, QString *error)
|
||||
{
|
||||
if (path.isEmpty())
|
||||
{
|
||||
*error = QObject::tr("Empty path");
|
||||
return false;
|
||||
}
|
||||
QString resolved = QStandardPaths::findExecutable(path);
|
||||
if (resolved.isEmpty() && !QDir::isAbsolutePath(path))
|
||||
{
|
||||
*error = QObject::tr("Invalid path to JVisualVM");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
23
logic/tools/JVisualVM.h
Normal file
23
logic/tools/JVisualVM.h
Normal file
@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "BaseProfiler.h"
|
||||
|
||||
class JVisualVM : public BaseProfiler
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
JVisualVM(BaseInstance *instance, QObject *parent = 0);
|
||||
|
||||
protected:
|
||||
void beginProfilingImpl(MinecraftProcess *process);
|
||||
};
|
||||
|
||||
class JVisualVMFactory : public BaseProfilerFactory
|
||||
{
|
||||
public:
|
||||
QString name() const override { return "JVisualVM"; }
|
||||
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;
|
||||
};
|
77
logic/tools/MCEditTool.cpp
Normal file
77
logic/tools/MCEditTool.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
#include "MCEditTool.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QProcess>
|
||||
#include <QDesktopServices>
|
||||
#include <QUrl>
|
||||
|
||||
#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 = 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;
|
||||
if (mceditDir.exists("mcedit.py"))
|
||||
{
|
||||
program = mceditDir.absoluteFilePath("mcedit.py");
|
||||
}
|
||||
else if (mceditDir.exists("mcedit.exe"))
|
||||
{
|
||||
program = mceditDir.absoluteFilePath("mcedit.exe");
|
||||
}
|
||||
QProcess::startDetached(program, QStringList() << save, mceditPath);
|
||||
#endif
|
||||
}
|
||||
|
||||
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") && !dir.exists("mcedit.exe") && !dir.exists("Contents"))
|
||||
{
|
||||
*error = QObject::tr("Path does not seem to be a MCEdit path");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
23
logic/tools/MCEditTool.h
Normal file
23
logic/tools/MCEditTool.h
Normal file
@ -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;
|
||||
};
|
Reference in New Issue
Block a user