From 7ceb2cacb129d5924087f616cfc0b949689ed4fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 16 Feb 2014 00:10:45 +0100 Subject: [PATCH] Fix a few bugs in profilers. * Legacy was launching before the profiler. * Some clarity changes. * Report problem with empty strings as profiler paths. --- depends/launcher/org/multimc/EntryPoint.java | 30 +++++++++++++++++--- gui/MainWindow.cpp | 7 +++-- gui/dialogs/SettingsDialog.cpp | 30 +++++++++++--------- logic/LegacyInstance.cpp | 2 +- logic/MinecraftProcess.cpp | 16 ++++++++++- logic/MinecraftProcess.h | 12 +++++++- 6 files changed, 73 insertions(+), 24 deletions(-) diff --git a/depends/launcher/org/multimc/EntryPoint.java b/depends/launcher/org/multimc/EntryPoint.java index 9e4ea0c1..f9fe68d6 100644 --- a/depends/launcher/org/multimc/EntryPoint.java +++ b/depends/launcher/org/multimc/EntryPoint.java @@ -29,7 +29,8 @@ public class EntryPoint private enum Action { Proceed, - Launch + Launch, + Abort } public static void main(String[] args) @@ -62,8 +63,17 @@ public class EntryPoint { String[] pair = inData.split(" ", 2); - if(pair.length == 1 && pair[0].equals("launch")) - return Action.Launch; + if(pair.length == 1) + { + String command = pair[0]; + if (pair[0].equals("launch")) + return Action.Launch; + + else if (pair[0].equals("abort")) + return Action.Abort; + + else throw new ParseException(); + } if(pair.length != 2) throw new ParseException(); @@ -109,6 +119,7 @@ public class EntryPoint return 1; } boolean isListening = true; + boolean isAborted = false; // Main loop while (isListening) { @@ -119,7 +130,13 @@ public class EntryPoint inData = buffer.readLine(); if (inData != null) { - if(parseLine(inData) == Action.Launch) + Action a = parseLine(inData); + if(a == Action.Abort) + { + isListening = false; + isAborted = true; + } + if(a == Action.Launch) { isListening = false; } @@ -138,6 +155,11 @@ public class EntryPoint return 1; } } + if(isAborted) + { + System.err.println("Launch aborted by MultiMC."); + return 1; + } if(m_launcher != null) { return m_launcher.launch(m_params); diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index b4811579..7c61ca9d 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -1239,7 +1239,7 @@ void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session, connect(console, SIGNAL(isClosing()), this, SLOT(instanceEnded())); proc->setLogin(session); - proc->launch(); + proc->arm(); if (profiler) { @@ -1247,6 +1247,7 @@ void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session, if (!profiler->check(&error)) { QMessageBox::critical(this, tr("Error"), tr("Couldn't start profiler: %1").arg(error)); + proc->abort(); return; } BaseProfiler *profilerInstance = profiler->createProfiler(instance, this); @@ -1267,14 +1268,14 @@ void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session, msg.setIcon(QMessageBox::Information); msg.addButton(tr("Launch"), QMessageBox::AcceptRole); msg.exec(); - proc->write("launch\n"); + proc->launch(); }); profilerInstance->beginProfiling(proc); dialog.exec(); } else { - proc->write("launch\n"); + proc->launch(); } } diff --git a/gui/dialogs/SettingsDialog.cpp b/gui/dialogs/SettingsDialog.cpp index ba2052c6..7afb6565 100644 --- a/gui/dialogs/SettingsDialog.cpp +++ b/gui/dialogs/SettingsDialog.cpp @@ -528,14 +528,15 @@ void SettingsDialog::on_jprofilerPathBtn_clicked() } void SettingsDialog::on_jprofilerCheckBtn_clicked() { - if (!ui->jprofilerPathEdit->text().isEmpty()) + QString error; + if (!MMC->profilers()["jprofiler"]->check(ui->jprofilerPathEdit->text(), &error)) { - QString error; - if (!MMC->profilers()["jprofiler"]->check(ui->jprofilerPathEdit->text(), &error)) - { - QMessageBox::critical(this, tr("Error"), - tr("Error while checking JProfiler install:\n%1").arg(error)); - } + QMessageBox::critical(this, tr("Error"), + tr("Error while checking JProfiler install:\n%1").arg(error)); + } + else + { + QMessageBox::information(this, tr("OK"), tr("JProfiler setup seems to be OK")); } } @@ -553,13 +554,14 @@ void SettingsDialog::on_jvisualvmPathBtn_clicked() } void SettingsDialog::on_jvisualvmCheckBtn_clicked() { - if (!ui->jvisualvmPathEdit->text().isEmpty()) + QString error; + if (!MMC->profilers()["jvisualvm"]->check(ui->jvisualvmPathEdit->text(), &error)) { - QString error; - if (!MMC->profilers()["jvisualvm"]->check(ui->jvisualvmPathEdit->text(), &error)) - { - QMessageBox::critical(this, tr("Error"), - tr("Error while checking JVisualVM install:\n%1").arg(error)); - } + QMessageBox::critical(this, tr("Error"), + tr("Error while checking JVisualVM install:\n%1").arg(error)); + } + else + { + QMessageBox::information(this, tr("OK"), tr("JVisualVM setup seems to be OK")); } } diff --git a/logic/LegacyInstance.cpp b/logic/LegacyInstance.cpp index a9f0d112..6cd17fea 100644 --- a/logic/LegacyInstance.cpp +++ b/logic/LegacyInstance.cpp @@ -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); diff --git a/logic/MinecraftProcess.cpp b/logic/MinecraftProcess.cpp index 70a9d55f..89cd71ed 100644 --- a/logic/MinecraftProcess.cpp +++ b/logic/MinecraftProcess.cpp @@ -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()); +} diff --git a/logic/MinecraftProcess.h b/logic/MinecraftProcess.h index 26214026..56340962 100644 --- a/logic/MinecraftProcess.h +++ b/logic/MinecraftProcess.h @@ -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;