summaryrefslogtreecommitdiffstats
path: root/logic/MinecraftProcess.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'logic/MinecraftProcess.cpp')
-rw-r--r--logic/MinecraftProcess.cpp103
1 files changed, 65 insertions, 38 deletions
diff --git a/logic/MinecraftProcess.cpp b/logic/MinecraftProcess.cpp
index d34be835..06b7a1f1 100644
--- a/logic/MinecraftProcess.cpp
+++ b/logic/MinecraftProcess.cpp
@@ -32,46 +32,45 @@
#define IBUS "@im=ibus"
// constructor
-MinecraftProcess::MinecraftProcess( BaseInstance* inst ) :
- m_instance(inst)
+MinecraftProcess::MinecraftProcess(BaseInstance *inst) : m_instance(inst)
{
- connect(this, SIGNAL(finished(int, QProcess::ExitStatus)), SLOT(finish(int, QProcess::ExitStatus)));
-
+ connect(this, SIGNAL(finished(int, QProcess::ExitStatus)),
+ SLOT(finish(int, QProcess::ExitStatus)));
+
// prepare the process environment
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
-
+
#ifdef LINUX
// Strip IBus
if (env.value("XMODIFIERS").contains(IBUS))
env.insert("XMODIFIERS", env.value("XMODIFIERS").replace(IBUS, ""));
#endif
-
+
// export some infos
env.insert("INST_NAME", inst->name());
env.insert("INST_ID", inst->id());
env.insert("INST_DIR", QDir(inst->instanceRoot()).absolutePath());
-
+
this->setProcessEnvironment(env);
m_prepostlaunchprocess.setProcessEnvironment(env);
-
+
// std channels
connect(this, SIGNAL(readyReadStandardError()), SLOT(on_stdErr()));
connect(this, SIGNAL(readyReadStandardOutput()), SLOT(on_stdOut()));
}
-void MinecraftProcess::setMinecraftArguments ( QStringList args )
+void MinecraftProcess::setMinecraftArguments(QStringList args)
{
m_args = args;
}
-void MinecraftProcess::setMinecraftWorkdir ( QString path )
+void MinecraftProcess::setMinecraftWorkdir(QString path)
{
QDir mcDir(path);
this->setWorkingDirectory(mcDir.absolutePath());
m_prepostlaunchprocess.setWorkingDirectory(mcDir.absolutePath());
}
-
// console window
void MinecraftProcess::on_stdErr()
{
@@ -80,18 +79,14 @@ void MinecraftProcess::on_stdErr()
m_err_leftover.clear();
QStringList lines = str.split("\n");
bool complete = str.endsWith("\n");
-
- for(int i = 0; i < lines.size() - 1; i++)
+
+ for (int i = 0; i < lines.size() - 1; i++)
{
- QString & line = lines[i];
- MessageLevel::Enum level = MessageLevel::Error;
- if(line.contains("[INFO]") || line.contains("[CONFIG]") || line.contains("[FINE]") || line.contains("[FINER]") || line.contains("[FINEST]") )
- level = MessageLevel::Message;
- if(line.contains("[SEVERE]") || line.contains("[WARNING]") || line.contains("[STDERR]"))
- level = MessageLevel::Error;
- emit log(lines[i].toLocal8Bit(), level);
+ QString &line = lines[i];
+ emit log(line /*.replace(username, "<Username>").replace(sessionID, "<Session ID>")*/,
+ getLevel(line, MessageLevel::Error));
}
- if(!complete)
+ if (!complete)
m_err_leftover = lines.last();
}
@@ -102,13 +97,14 @@ void MinecraftProcess::on_stdOut()
m_out_leftover.clear();
QStringList lines = str.split("\n");
bool complete = str.endsWith("\n");
-
- for(int i = 0; i < lines.size() - 1; i++)
+
+ for (int i = 0; i < lines.size() - 1; i++)
{
- QString & line = lines[i];
- emit log(lines[i].toLocal8Bit(), MessageLevel::Message);
+ QString &line = lines[i];
+ emit log(line /*.replace(username, "<Username>").replace(sessionID, "<Session ID>")*/,
+ getLevel(line, MessageLevel::Message));
}
- if(!complete)
+ if (!complete)
m_out_leftover = lines.last();
}
@@ -117,13 +113,20 @@ void MinecraftProcess::finish(int code, ExitStatus status)
{
if (status != NormalExit)
{
- //TODO: error handling
+ // TODO: error handling
}
-
- emit log("Minecraft exited.");
-
+
+ // TODO: Localization
+
+ if (!killed)
+ //: Message displayed on instance exit
+ emit log(tr("Minecraft exited with exitcode %1.").arg(status));
+ else
+ //: Message displayed after the instance exits due to kill request
+ emit log(tr("Minecraft was killed by user."), MessageLevel::Error);
+
m_prepostlaunchprocess.processEnvironment().insert("INST_EXITCODE", QString(code));
-
+
// run post-exit
if (!m_instance->settings().get("PostExitCommand").toString().isEmpty())
{
@@ -131,13 +134,19 @@ void MinecraftProcess::finish(int code, ExitStatus status)
m_prepostlaunchprocess.waitForFinished();
if (m_prepostlaunchprocess.exitStatus() != NormalExit)
{
- //TODO: error handling
+ // TODO: error handling
}
}
m_instance->cleanupAfterRun();
emit ended();
}
+void MinecraftProcess::killMinecraft()
+{
+ killed = true;
+ kill();
+}
+
void MinecraftProcess::launch()
{
if (!m_instance->settings().get("PreLaunchCommand").toString().isEmpty())
@@ -146,24 +155,42 @@ void MinecraftProcess::launch()
m_prepostlaunchprocess.waitForFinished();
if (m_prepostlaunchprocess.exitStatus() != NormalExit)
{
- //TODO: error handling
+ // TODO: error handling
return;
}
}
-
+
m_instance->setLastLaunch();
-
+
emit log(QString("Minecraft folder is: '%1'").arg(workingDirectory()));
QString JavaPath = m_instance->settings().get("JavaPath").toString();
emit log(QString("Java path: '%1'").arg(JavaPath));
- emit log(QString("Arguments: '%1'").arg(m_args.join("' '")));
+ emit log(QString("Arguments: '%1'").arg(
+ m_args.join("' '") /*.replace(username, "<Username>").replace(sessionID, "<Session
+ID>")*/));
start(JavaPath, m_args);
if (!waitForStarted())
{
- emit log("Could not launch minecraft!");
+ //: Error message displayed if instace can't start
+ emit log(tr("Could not launch minecraft!"));
return;
- //TODO: error handling
+ // TODO: error handling
}
}
+MessageLevel::Enum MinecraftProcess::getLevel(const QString &line, MessageLevel::Enum level)
+{
+ if (line.contains("[INFO]") || line.contains("[CONFIG]") || line.contains("[FINE]") ||
+ line.contains("[FINER]") || line.contains("[FINEST]"))
+ level = MessageLevel::Message;
+ if (line.contains("[SEVERE]") || line.contains("[STDERR]"))
+ level = MessageLevel::Error;
+ if (line.contains("[WARNING]"))
+ level = MessageLevel::Warning;
+ if (line.contains("Exception in thread") || line.contains(" at "))
+ level = MessageLevel::Fatal;
+ if (line.contains("[DEBUG]"))
+ level = MessageLevel::Debug;
+ return level;
+} \ No newline at end of file