Underp. Don't depend on OneSix. Nicer "menu" style choosing.

This commit is contained in:
Jan Dalheimer 2014-02-15 22:26:44 +01:00
parent 3b236483df
commit 8219dbf612
15 changed files with 96 additions and 125 deletions

View File

@ -439,9 +439,6 @@ void MultiMC::initGlobalSettings()
m_settings->registerSetting("ConsoleWindowGeometry", ""); m_settings->registerSetting("ConsoleWindowGeometry", "");
m_settings->registerSetting("SettingsGeometry", ""); m_settings->registerSetting("SettingsGeometry", "");
// Profilers
m_settings->registerSetting("CurrentProfiler");
} }
void MultiMC::initHttpMetaCache() void MultiMC::initHttpMetaCache()
@ -570,11 +567,6 @@ std::shared_ptr<JavaVersionList> MultiMC::javalist()
return m_javalist; return m_javalist;
} }
std::shared_ptr<BaseProfilerFactory> MultiMC::currentProfiler()
{
return m_profilers.value(m_settings->get("CurrentProfiler").toString());
}
void MultiMC::installUpdates(const QString updateFilesDir, UpdateFlags flags) void MultiMC::installUpdates(const QString updateFilesDir, UpdateFlags flags)
{ {
// if we are going to update on exit, save the params now // if we are going to update on exit, save the params now

View File

@ -132,7 +132,6 @@ public:
{ {
return m_profilers; return m_profilers;
} }
std::shared_ptr<BaseProfilerFactory> currentProfiler();
void installUpdates(const QString updateFilesDir, UpdateFlags flags = None); void installUpdates(const QString updateFilesDir, UpdateFlags flags = None);

View File

@ -61,27 +61,31 @@ public class EntryPoint
private Action parseLine(String inData) throws ParseException private Action parseLine(String inData) throws ParseException
{ {
String[] pair = inData.split(" ", 2); String[] pair = inData.split(" ", 2);
if(pair.length == 1 && pair[0].equals("launch"))
return Action.Launch;
if(pair.length != 2) if(pair.length != 2)
throw new ParseException(); throw new ParseException();
String command = pair[0]; String command = pair[0];
String param = pair[1]; String param = pair[1];
if(command.equals("launch")) if(command.equals("launcher"))
{ {
if(param.equals("legacy")) if(param.equals("legacy"))
{ {
m_launcher = new LegacyLauncher(); m_launcher = new LegacyLauncher();
Utils.log("Using legacy launcher."); Utils.log("Using legacy launcher.");
Utils.log(); Utils.log();
return Action.Launch; return Action.Proceed;
} }
if(param.equals("onesix")) if(param.equals("onesix"))
{ {
m_launcher = new OneSixLauncher(); m_launcher = new OneSixLauncher();
Utils.log("Using onesix launcher."); Utils.log("Using onesix launcher.");
Utils.log(); Utils.log();
return Action.Launch; return Action.Proceed;
} }
else else
throw new ParseException(); throw new ParseException();

View File

@ -99,7 +99,6 @@
#include <logic/tasks/ThreadTask.h> #include <logic/tasks/ThreadTask.h>
#include "logic/profiler/BaseProfiler.h" #include "logic/profiler/BaseProfiler.h"
#include "logic/OneSixInstance.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{ {
@ -1082,7 +1081,7 @@ void MainWindow::on_actionLaunchInstanceOffline_triggered()
} }
} }
void MainWindow::doLaunch(bool online, bool profile) void MainWindow::doLaunch(bool online, BaseProfilerFactory *profiler)
{ {
if (!m_selectedInstance) if (!m_selectedInstance)
return; return;
@ -1198,11 +1197,11 @@ void MainWindow::doLaunch(bool online, bool profile)
// update first if the server actually responded // update first if the server actually responded
if (session->auth_server_online) if (session->auth_server_online)
{ {
updateInstance(m_selectedInstance, session, profile); updateInstance(m_selectedInstance, session, profiler);
} }
else else
{ {
launchInstance(m_selectedInstance, session, profile); launchInstance(m_selectedInstance, session, profiler);
} }
tryagain = false; tryagain = false;
} }
@ -1210,22 +1209,22 @@ void MainWindow::doLaunch(bool online, bool profile)
} }
} }
void MainWindow::updateInstance(BaseInstance *instance, AuthSessionPtr session, bool profile) void MainWindow::updateInstance(BaseInstance *instance, AuthSessionPtr session, BaseProfilerFactory *profiler)
{ {
auto updateTask = instance->doUpdate(); auto updateTask = instance->doUpdate();
if (!updateTask) if (!updateTask)
{ {
launchInstance(instance, session, profile); launchInstance(instance, session, profiler);
return; return;
} }
ProgressDialog tDialog(this); ProgressDialog tDialog(this);
connect(updateTask.get(), &Task::succeeded, [this, instance, session, profile] connect(updateTask.get(), &Task::succeeded, [this, instance, session, profiler]
{ launchInstance(instance, session, profile); }); { launchInstance(instance, session, profiler); });
connect(updateTask.get(), SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString))); connect(updateTask.get(), SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString)));
tDialog.exec(updateTask.get()); tDialog.exec(updateTask.get());
} }
void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session, bool profile) void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session, BaseProfilerFactory *profiler)
{ {
Q_ASSERT_X(instance != NULL, "launchInstance", "instance is NULL"); Q_ASSERT_X(instance != NULL, "launchInstance", "instance is NULL");
Q_ASSERT_X(session.get() != nullptr, "launchInstance", "session is NULL"); Q_ASSERT_X(session.get() != nullptr, "launchInstance", "session is NULL");
@ -1242,17 +1241,22 @@ void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session,
proc->setLogin(session); proc->setLogin(session);
proc->launch(); proc->launch();
if (profile && qobject_cast<OneSixInstance *>(instance)) if (profiler)
{ {
BaseProfiler *profiler = MMC->currentProfiler()->createProfiler( QString error;
qobject_cast<OneSixInstance *>(instance), this); if (!profiler->check(&error))
{
QMessageBox::critical(this, tr("Error"), tr("Couldn't start profiler: %1").arg(error));
return;
}
BaseProfiler *profilerInstance = profiler->createProfiler(instance, this);
QProgressDialog dialog; QProgressDialog dialog;
dialog.setMinimum(0); dialog.setMinimum(0);
dialog.setMaximum(0); dialog.setMaximum(0);
dialog.setValue(0); dialog.setValue(0);
dialog.setLabelText(tr("Waiting for profiler...")); dialog.setLabelText(tr("Waiting for profiler..."));
dialog.show(); dialog.show();
connect(profiler, &BaseProfiler::readyToLaunch, [&dialog, this](const QString &message) connect(profilerInstance, &BaseProfiler::readyToLaunch, [&dialog, this](const QString &message)
{ {
dialog.accept(); dialog.accept();
QMessageBox msg; QMessageBox msg;
@ -1263,11 +1267,15 @@ void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session,
msg.setIcon(QMessageBox::Information); msg.setIcon(QMessageBox::Information);
msg.addButton(tr("Launch"), QMessageBox::AcceptRole); msg.addButton(tr("Launch"), QMessageBox::AcceptRole);
msg.exec(); msg.exec();
proc->write("launch onesix\n"); proc->write("launch\n");
}); });
profiler->beginProfiling(proc); profilerInstance->beginProfiling(proc);
dialog.exec(); dialog.exec();
} }
else
{
proc->write("launch\n");
}
} }
void MainWindow::onGameUpdateError(QString error) void MainWindow::onGameUpdateError(QString error)
@ -1408,6 +1416,21 @@ void MainWindow::instanceChanged(const QModelIndex &current, const QModelIndex &
m_statusLeft->setText(m_selectedInstance->getStatusbarDescription()); m_statusLeft->setText(m_selectedInstance->getStatusbarDescription());
updateInstanceToolIcon(m_selectedInstance->iconKey()); updateInstanceToolIcon(m_selectedInstance->iconKey());
if (ui->actionLaunchInstance->menu())
{
ui->actionLaunchInstance->menu()->deleteLater();
}
QMenu *launchMenu = new QMenu;
QAction *normalLaunch = launchMenu->addAction(tr("Launch"));
connect(normalLaunch, &QAction::triggered, [this](){doLaunch();});
launchMenu->addSeparator()->setText(tr("Profilers"));
for (auto profiler : MMC->profilers().values())
{
QAction *profilerAction = launchMenu->addAction(profiler->name());
connect(profilerAction, &QAction::triggered, [this, profiler](){doLaunch(true, profiler.get());});
}
ui->actionLaunchInstance->setMenu(launchMenu);
MMC->settings()->set("SelectedInstance", m_selectedInstance->id()); MMC->settings()->set("SelectedInstance", m_selectedInstance->id());
} }
else else
@ -1447,15 +1470,6 @@ void MainWindow::on_actionEditInstNotes_triggered()
} }
} }
void MainWindow::on_actionProfileInstance_triggered()
{
if (m_selectedInstance)
{
NagUtils::checkJVMArgs(m_selectedInstance->settings().get("JvmArgs").toString(), this);
doLaunch(true, true);
}
}
void MainWindow::instanceEnded() void MainWindow::instanceEnded()
{ {
this->show(); this->show();

View File

@ -29,6 +29,7 @@ class LabeledToolButton;
class QLabel; class QLabel;
class MinecraftProcess; class MinecraftProcess;
class ConsoleWindow; class ConsoleWindow;
class BaseProfilerFactory;
namespace Ui namespace Ui
{ {
@ -107,24 +108,22 @@ slots:
void on_actionEditInstNotes_triggered(); void on_actionEditInstNotes_triggered();
void on_actionProfileInstance_triggered();
/*! /*!
* Launches the currently selected instance with the default account. * Launches the currently selected instance with the default account.
* If no default account is selected, prompts the user to pick an account. * If no default account is selected, prompts the user to pick an account.
*/ */
void doLaunch(bool online = true, bool profile = false); void doLaunch(bool online = true, BaseProfilerFactory *profiler = 0);
/*! /*!
* Launches the given instance with the given account. * Launches the given instance with the given account.
* This function assumes that the given account has a valid, usable access token. * This function assumes that the given account has a valid, usable access token.
*/ */
void launchInstance(BaseInstance *instance, AuthSessionPtr session, bool profile = false); void launchInstance(BaseInstance *instance, AuthSessionPtr session, BaseProfilerFactory *profiler = 0);
/*! /*!
* Prepares the given instance for launch with the given account. * Prepares the given instance for launch with the given account.
*/ */
void updateInstance(BaseInstance *instance, AuthSessionPtr account, bool profile = false); void updateInstance(BaseInstance *instance, AuthSessionPtr account, BaseProfilerFactory *profiler = 0);
void onGameUpdateError(QString error); void onGameUpdateError(QString error);

View File

@ -108,7 +108,6 @@
<addaction name="actionChangeInstIcon"/> <addaction name="actionChangeInstIcon"/>
<addaction name="actionLaunchInstance"/> <addaction name="actionLaunchInstance"/>
<addaction name="actionLaunchInstanceOffline"/> <addaction name="actionLaunchInstanceOffline"/>
<addaction name="actionProfileInstance"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionEditInstNotes"/> <addaction name="actionEditInstNotes"/>
<addaction name="actionChangeInstGroup"/> <addaction name="actionChangeInstGroup"/>
@ -529,14 +528,6 @@
<string>Launch the selected instance.</string> <string>Launch the selected instance.</string>
</property> </property>
</action> </action>
<action name="actionProfileInstance">
<property name="text">
<string>Profile</string>
</property>
<property name="toolTip">
<string>Starts a profiling session with the current instance</string>
</property>
</action>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<resources> <resources>

View File

@ -374,18 +374,6 @@ void SettingsDialog::applySettings(SettingsObject *s)
// Profilers // Profilers
s->set("JProfilerPath", ui->jprofilerPathEdit->text()); s->set("JProfilerPath", ui->jprofilerPathEdit->text());
s->set("JVisualVMPath", ui->jvisualvmPathEdit->text()); s->set("JVisualVMPath", ui->jvisualvmPathEdit->text());
if (ui->profilerNoneBtn->isChecked())
{
s->set("CurrentProfiler", QString());
}
else if (ui->jprofilerBtn->isChecked())
{
s->set("CurrentProfiler", "jprofiler");
}
else if (ui->jvisualvmBtn->isChecked())
{
s->set("CurrentProfiler", "jvisualvm");
}
} }
void SettingsDialog::loadSettings(SettingsObject *s) void SettingsDialog::loadSettings(SettingsObject *s)
@ -469,19 +457,6 @@ void SettingsDialog::loadSettings(SettingsObject *s)
// Profilers // Profilers
ui->jprofilerPathEdit->setText(s->get("JProfilerPath").toString()); ui->jprofilerPathEdit->setText(s->get("JProfilerPath").toString());
ui->jvisualvmPathEdit->setText(s->get("JVisualVMPath").toString()); ui->jvisualvmPathEdit->setText(s->get("JVisualVMPath").toString());
const QString currentProfiler = s->get("CurrentProfiler").toString();
if (currentProfiler.isEmpty())
{
ui->profilerNoneBtn->setChecked(true);
}
else if (currentProfiler == "jprofiler")
{
ui->jprofilerBtn->setChecked(true);
}
else if (currentProfiler == "jvisualvm")
{
ui->jvisualvmBtn->setChecked(true);
}
} }
void SettingsDialog::on_javaDetectBtn_clicked() void SettingsDialog::on_javaDetectBtn_clicked()

View File

@ -20,7 +20,7 @@
<string>Settings</string> <string>Settings</string>
</property> </property>
<property name="windowIcon"> <property name="windowIcon">
<iconset resource="../../graphics.qrc"> <iconset>
<normaloff>:/icons/toolbar/settings</normaloff>:/icons/toolbar/settings</iconset> <normaloff>:/icons/toolbar/settings</normaloff>:/icons/toolbar/settings</iconset>
</property> </property>
<property name="modal"> <property name="modal">
@ -33,7 +33,7 @@
<enum>QTabWidget::Rounded</enum> <enum>QTabWidget::Rounded</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>5</number>
</property> </property>
<widget class="QWidget" name="featuresTab"> <widget class="QWidget" name="featuresTab">
<attribute name="title"> <attribute name="title">
@ -868,36 +868,6 @@
<string>Profiling</string> <string>Profiling</string>
</attribute> </attribute>
<layout class="QVBoxLayout" name="verticalLayout_13"> <layout class="QVBoxLayout" name="verticalLayout_13">
<item>
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Active profiler</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_12">
<item>
<widget class="QRadioButton" name="profilerNoneBtn">
<property name="text">
<string>None</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="jprofilerBtn">
<property name="text">
<string>JProfiler</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="jvisualvmBtn">
<property name="text">
<string>JVisualVM</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item> <item>
<widget class="QGroupBox" name="groupBox_2"> <widget class="QGroupBox" name="groupBox_2">
<property name="title"> <property name="title">
@ -1010,9 +980,7 @@
<tabstop>postExitCmdTextBox</tabstop> <tabstop>postExitCmdTextBox</tabstop>
<tabstop>settingsTabs</tabstop> <tabstop>settingsTabs</tabstop>
</tabstops> </tabstops>
<resources> <resources/>
<include location="../../graphics.qrc"/>
</resources>
<connections> <connections>
<connection> <connection>
<sender>buttonBox</sender> <sender>buttonBox</sender>

View File

@ -228,6 +228,7 @@ MinecraftProcess *OneSixInstance::prepareForLaunch(AuthSessionPtr session)
launchScript += "ext " + finfo.absoluteFilePath() + "\n"; launchScript += "ext " + finfo.absoluteFilePath() + "\n";
} }
launchScript += "natives " + natives_dir.absolutePath() + "\n"; launchScript += "natives " + natives_dir.absolutePath() + "\n";
launchScript += "launcher onesix\n";
// create the process and set its parameters // create the process and set its parameters
MinecraftProcess *proc = new MinecraftProcess(this); MinecraftProcess *proc = new MinecraftProcess(this);

View File

@ -5,7 +5,7 @@
#include <windows.h> #include <windows.h>
#endif #endif
BaseProfiler::BaseProfiler(OneSixInstance *instance, QObject *parent) BaseProfiler::BaseProfiler(BaseInstance *instance, QObject *parent)
: QObject(parent), m_instance(instance) : QObject(parent), m_instance(instance)
{ {
} }

View File

@ -2,7 +2,7 @@
#include <QObject> #include <QObject>
class OneSixInstance; class BaseInstance;
class SettingsObject; class SettingsObject;
class MinecraftProcess; class MinecraftProcess;
class QProcess; class QProcess;
@ -11,7 +11,7 @@ class BaseProfiler : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit BaseProfiler(OneSixInstance *instance, QObject *parent = 0); explicit BaseProfiler(BaseInstance *instance, QObject *parent = 0);
virtual ~BaseProfiler(); virtual ~BaseProfiler();
public public
@ -19,7 +19,7 @@ slots:
void beginProfiling(MinecraftProcess *process); void beginProfiling(MinecraftProcess *process);
protected: protected:
OneSixInstance *m_instance; BaseInstance *m_instance;
virtual void beginProfilingImpl(MinecraftProcess *process) = 0; virtual void beginProfilingImpl(MinecraftProcess *process) = 0;
@ -34,9 +34,12 @@ class BaseProfilerFactory
public: public:
virtual ~BaseProfilerFactory(); virtual ~BaseProfilerFactory();
virtual QString name() const = 0;
virtual void registerSettings(SettingsObject *settings) = 0; virtual void registerSettings(SettingsObject *settings) = 0;
virtual BaseProfiler *createProfiler(OneSixInstance *instance, QObject *parent = 0) = 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 bool check(const QString &path, QString *error) = 0;
}; };

View File

@ -5,10 +5,10 @@
#include "settingsobject.h" #include "settingsobject.h"
#include "logic/MinecraftProcess.h" #include "logic/MinecraftProcess.h"
#include "logic/OneSixInstance.h" #include "logic/BaseInstance.h"
#include "MultiMC.h" #include "MultiMC.h"
JProfiler::JProfiler(OneSixInstance *instance, QObject *parent) : BaseProfiler(instance, parent) JProfiler::JProfiler(BaseInstance *instance, QObject *parent) : BaseProfiler(instance, parent)
{ {
} }
@ -32,13 +32,23 @@ void JProfilerFactory::registerSettings(SettingsObject *settings)
settings->registerSetting("JProfilerPort", 42042); settings->registerSetting("JProfilerPort", 42042);
} }
BaseProfiler *JProfilerFactory::createProfiler(OneSixInstance *instance, QObject *parent) BaseProfiler *JProfilerFactory::createProfiler(BaseInstance *instance, QObject *parent)
{ {
return new JProfiler(instance, 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) bool JProfilerFactory::check(const QString &path, QString *error)
{ {
if (path.isEmpty())
{
*error = QObject::tr("Empty path");
return false;
}
QDir dir(path); QDir dir(path);
if (!dir.exists()) if (!dir.exists())
{ {

View File

@ -6,7 +6,7 @@ class JProfiler : public BaseProfiler
{ {
Q_OBJECT Q_OBJECT
public: public:
JProfiler(OneSixInstance *instance, QObject *parent = 0); JProfiler(BaseInstance *instance, QObject *parent = 0);
protected: protected:
void beginProfilingImpl(MinecraftProcess *process); void beginProfilingImpl(MinecraftProcess *process);
@ -15,7 +15,9 @@ protected:
class JProfilerFactory : public BaseProfilerFactory class JProfilerFactory : public BaseProfilerFactory
{ {
public: public:
QString name() const override { return "JProfiler"; }
void registerSettings(SettingsObject *settings) override; void registerSettings(SettingsObject *settings) override;
BaseProfiler *createProfiler(OneSixInstance *instance, QObject *parent = 0) override; BaseProfiler *createProfiler(BaseInstance *instance, QObject *parent = 0) override;
bool check(QString *error) override;
bool check(const QString &path, QString *error) override; bool check(const QString &path, QString *error) override;
}; };

View File

@ -5,9 +5,10 @@
#include "settingsobject.h" #include "settingsobject.h"
#include "logic/MinecraftProcess.h" #include "logic/MinecraftProcess.h"
#include "logic/OneSixInstance.h" #include "logic/BaseInstance.h"
#include "MultiMC.h"
JVisualVM::JVisualVM(OneSixInstance *instance, QObject *parent) : BaseProfiler(instance, parent) JVisualVM::JVisualVM(BaseInstance *instance, QObject *parent) : BaseProfiler(instance, parent)
{ {
} }
@ -27,13 +28,23 @@ void JVisualVMFactory::registerSettings(SettingsObject *settings)
settings->registerSetting("JVisualVMPath"); settings->registerSetting("JVisualVMPath");
} }
BaseProfiler *JVisualVMFactory::createProfiler(OneSixInstance *instance, QObject *parent) BaseProfiler *JVisualVMFactory::createProfiler(BaseInstance *instance, QObject *parent)
{ {
return new JVisualVM(instance, 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) bool JVisualVMFactory::check(const QString &path, QString *error)
{ {
if (path.isEmpty())
{
*error = QObject::tr("Empty path");
return false;
}
QString resolved = QStandardPaths::findExecutable(path); QString resolved = QStandardPaths::findExecutable(path);
if (resolved.isEmpty() && !QDir::isAbsolutePath(path)) if (resolved.isEmpty() && !QDir::isAbsolutePath(path))
{ {

View File

@ -6,7 +6,7 @@ class JVisualVM : public BaseProfiler
{ {
Q_OBJECT Q_OBJECT
public: public:
JVisualVM(OneSixInstance *instance, QObject *parent = 0); JVisualVM(BaseInstance *instance, QObject *parent = 0);
protected: protected:
void beginProfilingImpl(MinecraftProcess *process); void beginProfilingImpl(MinecraftProcess *process);
@ -15,7 +15,9 @@ protected:
class JVisualVMFactory : public BaseProfilerFactory class JVisualVMFactory : public BaseProfilerFactory
{ {
public: public:
QString name() const override { return "JVisualVM"; }
void registerSettings(SettingsObject *settings) override; void registerSettings(SettingsObject *settings) override;
BaseProfiler *createProfiler(OneSixInstance *instance, QObject *parent = 0) override; BaseProfiler *createProfiler(BaseInstance *instance, QObject *parent = 0) override;
bool check(QString *error) override;
bool check(const QString &path, QString *error) override; bool check(const QString &path, QString *error) override;
}; };