From d24c4823ef8e144a3ffefc208c5a15e86b0b31b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 26 Mar 2013 14:34:34 +0100 Subject: [PATCH] Filter console output, no more sea of red when there's nothing to report. --- libmultimc/include/minecraftprocess.h | 2 ++ libmultimc/src/minecraftprocess.cpp | 33 +++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/libmultimc/include/minecraftprocess.h b/libmultimc/include/minecraftprocess.h index f6272183a..ac4d6be2c 100644 --- a/libmultimc/include/minecraftprocess.h +++ b/libmultimc/include/minecraftprocess.h @@ -104,6 +104,8 @@ protected: InstancePtr m_instance; QString m_user; QString m_session; + QString m_err_leftover; + QString m_out_leftover; QProcess m_prepostlaunchprocess; QStringList m_arguments; diff --git a/libmultimc/src/minecraftprocess.cpp b/libmultimc/src/minecraftprocess.cpp index 1239bc3a0..f1b63e3dd 100644 --- a/libmultimc/src/minecraftprocess.cpp +++ b/libmultimc/src/minecraftprocess.cpp @@ -125,12 +125,41 @@ MinecraftProcess::MinecraftProcess(InstancePtr inst, QString user, QString sessi // console window void MinecraftProcess::on_stdErr() { - emit log(readAllStandardError(), MessageLevel::Error); + QByteArray data = readAllStandardError(); + QString str = m_err_leftover + QString::fromLocal8Bit(data); + m_err_leftover.clear(); + QStringList lines = str.split("\n"); + bool complete = str.endsWith("\n"); + + 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); + } + if(!complete) + m_err_leftover = lines.last(); } void MinecraftProcess::on_stdOut() { - emit log(readAllStandardOutput(), MessageLevel::Message); + QByteArray data = readAllStandardOutput(); + QString str = m_out_leftover + QString::fromLocal8Bit(data); + m_out_leftover.clear(); + QStringList lines = str.split("\n"); + bool complete = str.endsWith("\n"); + + for(int i = 0; i < lines.size() - 1; i++) + { + QString & line = lines[i]; + emit log(lines[i].toLocal8Bit(), MessageLevel::Message); + } + if(!complete) + m_out_leftover = lines.last(); } // exit handler