From 8219dbf612f4e6f603d304348fc388e364602f98 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Sat, 15 Feb 2014 22:26:44 +0100 Subject: Underp. Don't depend on OneSix. Nicer "menu" style choosing. --- MultiMC.cpp | 8 ---- MultiMC.h | 1 - depends/launcher/org/multimc/EntryPoint.java | 10 +++-- gui/MainWindow.cpp | 62 +++++++++++++++++----------- gui/MainWindow.h | 9 ++-- gui/MainWindow.ui | 9 ---- gui/dialogs/SettingsDialog.cpp | 25 ----------- gui/dialogs/SettingsDialog.ui | 38 ++--------------- logic/OneSixInstance.cpp | 1 + logic/profiler/BaseProfiler.cpp | 2 +- logic/profiler/BaseProfiler.h | 11 +++-- logic/profiler/JProfiler.cpp | 16 +++++-- logic/profiler/JProfiler.h | 6 ++- logic/profiler/JVisualVM.cpp | 17 ++++++-- logic/profiler/JVisualVM.h | 6 ++- 15 files changed, 96 insertions(+), 125 deletions(-) diff --git a/MultiMC.cpp b/MultiMC.cpp index b17afdc6..e3f60049 100644 --- a/MultiMC.cpp +++ b/MultiMC.cpp @@ -439,9 +439,6 @@ void MultiMC::initGlobalSettings() m_settings->registerSetting("ConsoleWindowGeometry", ""); m_settings->registerSetting("SettingsGeometry", ""); - - // Profilers - m_settings->registerSetting("CurrentProfiler"); } void MultiMC::initHttpMetaCache() @@ -570,11 +567,6 @@ std::shared_ptr MultiMC::javalist() return m_javalist; } -std::shared_ptr MultiMC::currentProfiler() -{ - return m_profilers.value(m_settings->get("CurrentProfiler").toString()); -} - void MultiMC::installUpdates(const QString updateFilesDir, UpdateFlags flags) { // if we are going to update on exit, save the params now diff --git a/MultiMC.h b/MultiMC.h index 69bfb4a4..854de59b 100644 --- a/MultiMC.h +++ b/MultiMC.h @@ -132,7 +132,6 @@ public: { return m_profilers; } - std::shared_ptr currentProfiler(); void installUpdates(const QString updateFilesDir, UpdateFlags flags = None); diff --git a/depends/launcher/org/multimc/EntryPoint.java b/depends/launcher/org/multimc/EntryPoint.java index e2721ffa..9e4ea0c1 100644 --- a/depends/launcher/org/multimc/EntryPoint.java +++ b/depends/launcher/org/multimc/EntryPoint.java @@ -61,27 +61,31 @@ public class EntryPoint private Action parseLine(String inData) throws ParseException { String[] pair = inData.split(" ", 2); + + if(pair.length == 1 && pair[0].equals("launch")) + return Action.Launch; + if(pair.length != 2) throw new ParseException(); String command = pair[0]; String param = pair[1]; - if(command.equals("launch")) + if(command.equals("launcher")) { if(param.equals("legacy")) { m_launcher = new LegacyLauncher(); Utils.log("Using legacy launcher."); Utils.log(); - return Action.Launch; + return Action.Proceed; } if(param.equals("onesix")) { m_launcher = new OneSixLauncher(); Utils.log("Using onesix launcher."); Utils.log(); - return Action.Launch; + return Action.Proceed; } else throw new ParseException(); diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index ddeb9947..b4811579 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -99,7 +99,6 @@ #include #include "logic/profiler/BaseProfiler.h" -#include "logic/OneSixInstance.h" 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) return; @@ -1198,11 +1197,11 @@ void MainWindow::doLaunch(bool online, bool profile) // update first if the server actually responded if (session->auth_server_online) { - updateInstance(m_selectedInstance, session, profile); + updateInstance(m_selectedInstance, session, profiler); } else { - launchInstance(m_selectedInstance, session, profile); + launchInstance(m_selectedInstance, session, profiler); } 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(); if (!updateTask) { - launchInstance(instance, session, profile); + launchInstance(instance, session, profiler); return; } ProgressDialog tDialog(this); - connect(updateTask.get(), &Task::succeeded, [this, instance, session, profile] - { launchInstance(instance, session, profile); }); + connect(updateTask.get(), &Task::succeeded, [this, instance, session, profiler] + { launchInstance(instance, session, profiler); }); connect(updateTask.get(), SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString))); 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(session.get() != nullptr, "launchInstance", "session is NULL"); @@ -1242,17 +1241,22 @@ void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session, proc->setLogin(session); proc->launch(); - if (profile && qobject_cast(instance)) + if (profiler) { - BaseProfiler *profiler = MMC->currentProfiler()->createProfiler( - qobject_cast(instance), this); + QString error; + 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; dialog.setMinimum(0); dialog.setMaximum(0); dialog.setValue(0); dialog.setLabelText(tr("Waiting for profiler...")); dialog.show(); - connect(profiler, &BaseProfiler::readyToLaunch, [&dialog, this](const QString &message) + connect(profilerInstance, &BaseProfiler::readyToLaunch, [&dialog, this](const QString &message) { dialog.accept(); QMessageBox msg; @@ -1263,11 +1267,15 @@ void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session, msg.setIcon(QMessageBox::Information); msg.addButton(tr("Launch"), QMessageBox::AcceptRole); msg.exec(); - proc->write("launch onesix\n"); + proc->write("launch\n"); }); - profiler->beginProfiling(proc); + profilerInstance->beginProfiling(proc); dialog.exec(); } + else + { + proc->write("launch\n"); + } } void MainWindow::onGameUpdateError(QString error) @@ -1408,6 +1416,21 @@ void MainWindow::instanceChanged(const QModelIndex ¤t, const QModelIndex & m_statusLeft->setText(m_selectedInstance->getStatusbarDescription()); 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()); } 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() { this->show(); diff --git a/gui/MainWindow.h b/gui/MainWindow.h index 66d98bc5..682c711d 100644 --- a/gui/MainWindow.h +++ b/gui/MainWindow.h @@ -29,6 +29,7 @@ class LabeledToolButton; class QLabel; class MinecraftProcess; class ConsoleWindow; +class BaseProfilerFactory; namespace Ui { @@ -107,24 +108,22 @@ slots: void on_actionEditInstNotes_triggered(); - void on_actionProfileInstance_triggered(); - /*! * Launches the currently selected instance with the default 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. * 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. */ - void updateInstance(BaseInstance *instance, AuthSessionPtr account, bool profile = false); + void updateInstance(BaseInstance *instance, AuthSessionPtr account, BaseProfilerFactory *profiler = 0); void onGameUpdateError(QString error); diff --git a/gui/MainWindow.ui b/gui/MainWindow.ui index 81f66136..90c86075 100644 --- a/gui/MainWindow.ui +++ b/gui/MainWindow.ui @@ -108,7 +108,6 @@ - @@ -529,14 +528,6 @@ Launch the selected instance. - - - Profile - - - Starts a profiling session with the current instance - - diff --git a/gui/dialogs/SettingsDialog.cpp b/gui/dialogs/SettingsDialog.cpp index 3039acc1..ba2052c6 100644 --- a/gui/dialogs/SettingsDialog.cpp +++ b/gui/dialogs/SettingsDialog.cpp @@ -374,18 +374,6 @@ void SettingsDialog::applySettings(SettingsObject *s) // Profilers s->set("JProfilerPath", ui->jprofilerPathEdit->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) @@ -469,19 +457,6 @@ void SettingsDialog::loadSettings(SettingsObject *s) // Profilers ui->jprofilerPathEdit->setText(s->get("JProfilerPath").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() diff --git a/gui/dialogs/SettingsDialog.ui b/gui/dialogs/SettingsDialog.ui index 29cbbcba..8d9a7f87 100644 --- a/gui/dialogs/SettingsDialog.ui +++ b/gui/dialogs/SettingsDialog.ui @@ -20,7 +20,7 @@ Settings - + :/icons/toolbar/settings:/icons/toolbar/settings @@ -33,7 +33,7 @@ QTabWidget::Rounded - 0 + 5 @@ -868,36 +868,6 @@ Profiling - - - - Active profiler - - - - - - None - - - - - - - JProfiler - - - - - - - JVisualVM - - - - - - @@ -1010,9 +980,7 @@ postExitCmdTextBox settingsTabs - - - + buttonBox diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp index d987b693..dbae891d 100644 --- a/logic/OneSixInstance.cpp +++ b/logic/OneSixInstance.cpp @@ -228,6 +228,7 @@ MinecraftProcess *OneSixInstance::prepareForLaunch(AuthSessionPtr session) launchScript += "ext " + finfo.absoluteFilePath() + "\n"; } launchScript += "natives " + natives_dir.absolutePath() + "\n"; + launchScript += "launcher onesix\n"; // create the process and set its parameters MinecraftProcess *proc = new MinecraftProcess(this); diff --git a/logic/profiler/BaseProfiler.cpp b/logic/profiler/BaseProfiler.cpp index 94891fc4..4765c67d 100644 --- a/logic/profiler/BaseProfiler.cpp +++ b/logic/profiler/BaseProfiler.cpp @@ -5,7 +5,7 @@ #include #endif -BaseProfiler::BaseProfiler(OneSixInstance *instance, QObject *parent) +BaseProfiler::BaseProfiler(BaseInstance *instance, QObject *parent) : QObject(parent), m_instance(instance) { } diff --git a/logic/profiler/BaseProfiler.h b/logic/profiler/BaseProfiler.h index e7bc4c2d..4c5f63fc 100644 --- a/logic/profiler/BaseProfiler.h +++ b/logic/profiler/BaseProfiler.h @@ -2,7 +2,7 @@ #include -class OneSixInstance; +class BaseInstance; class SettingsObject; class MinecraftProcess; class QProcess; @@ -11,7 +11,7 @@ class BaseProfiler : public QObject { Q_OBJECT public: - explicit BaseProfiler(OneSixInstance *instance, QObject *parent = 0); + explicit BaseProfiler(BaseInstance *instance, QObject *parent = 0); virtual ~BaseProfiler(); public @@ -19,7 +19,7 @@ slots: void beginProfiling(MinecraftProcess *process); protected: - OneSixInstance *m_instance; + BaseInstance *m_instance; virtual void beginProfilingImpl(MinecraftProcess *process) = 0; @@ -34,9 +34,12 @@ class BaseProfilerFactory public: virtual ~BaseProfilerFactory(); + virtual QString name() const = 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; }; diff --git a/logic/profiler/JProfiler.cpp b/logic/profiler/JProfiler.cpp index eddf46d9..cec614ae 100644 --- a/logic/profiler/JProfiler.cpp +++ b/logic/profiler/JProfiler.cpp @@ -5,10 +5,10 @@ #include "settingsobject.h" #include "logic/MinecraftProcess.h" -#include "logic/OneSixInstance.h" +#include "logic/BaseInstance.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); } -BaseProfiler *JProfilerFactory::createProfiler(OneSixInstance *instance, QObject *parent) +BaseProfiler *JProfilerFactory::createProfiler(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()) { diff --git a/logic/profiler/JProfiler.h b/logic/profiler/JProfiler.h index 9fa3591a..8a5bc561 100644 --- a/logic/profiler/JProfiler.h +++ b/logic/profiler/JProfiler.h @@ -6,7 +6,7 @@ class JProfiler : public BaseProfiler { Q_OBJECT public: - JProfiler(OneSixInstance *instance, QObject *parent = 0); + JProfiler(BaseInstance *instance, QObject *parent = 0); protected: void beginProfilingImpl(MinecraftProcess *process); @@ -15,7 +15,9 @@ protected: class JProfilerFactory : public BaseProfilerFactory { public: + QString name() const override { return "JProfiler"; } 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; }; diff --git a/logic/profiler/JVisualVM.cpp b/logic/profiler/JVisualVM.cpp index a1aa6951..3850ff40 100644 --- a/logic/profiler/JVisualVM.cpp +++ b/logic/profiler/JVisualVM.cpp @@ -5,9 +5,10 @@ #include "settingsobject.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"); } -BaseProfiler *JVisualVMFactory::createProfiler(OneSixInstance *instance, QObject *parent) +BaseProfiler *JVisualVMFactory::createProfiler(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)) { diff --git a/logic/profiler/JVisualVM.h b/logic/profiler/JVisualVM.h index e72b75d9..154180b4 100644 --- a/logic/profiler/JVisualVM.h +++ b/logic/profiler/JVisualVM.h @@ -6,7 +6,7 @@ class JVisualVM : public BaseProfiler { Q_OBJECT public: - JVisualVM(OneSixInstance *instance, QObject *parent = 0); + JVisualVM(BaseInstance *instance, QObject *parent = 0); protected: void beginProfilingImpl(MinecraftProcess *process); @@ -15,7 +15,9 @@ protected: class JVisualVMFactory : public BaseProfilerFactory { public: + QString name() const override { return "JVisualVM"; } 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; }; -- cgit v1.2.3