Added console coloring and made the log not contain any usernames/session ids
This commit is contained in:
		| @@ -23,7 +23,7 @@ void ConsoleWindow::writeColor(QString text, const char *color) | ||||
| { | ||||
| 	// append a paragraph | ||||
| 	if (color != nullptr) | ||||
| 		ui->text->appendHtml(QString("<font color=%1>%2</font>").arg(color).arg(text)); | ||||
| 		ui->text->appendHtml(QString("<font color=\"%1\">%2</font>").arg(color).arg(text)); | ||||
| 	else | ||||
| 		ui->text->appendPlainText(text); | ||||
| 	// scroll down | ||||
| @@ -46,6 +46,12 @@ void ConsoleWindow::write(QString data, MessageLevel::Enum mode) | ||||
| 	else if (mode == MessageLevel::Warning) | ||||
| 		while(iter.hasNext()) | ||||
| 			writeColor(iter.next(), "orange"); | ||||
| 	else if (mode == MessageLevel::Fatal) | ||||
| 		while(iter.hasNext()) | ||||
| 			writeColor(iter.next(), "pink"); | ||||
| 	else if (mode == MessageLevel::Debug) | ||||
| 		while(iter.hasNext()) | ||||
| 			writeColor(iter.next(), "green"); | ||||
| 	// TODO: implement other MessageLevels | ||||
| 	else | ||||
| 		while(iter.hasNext()) | ||||
|   | ||||
| @@ -556,6 +556,7 @@ void MainWindow::launchInstance(BaseInstance *instance, LoginResponse response) | ||||
| 	connect(proc, SIGNAL(log(QString, MessageLevel::Enum)),  | ||||
| 			console, SLOT(write(QString, MessageLevel::Enum))); | ||||
| 	connect(proc, SIGNAL(ended()), this, SLOT(instanceEnded())); | ||||
| 	proc->setLogin(m_activeLogin.username, m_activeLogin.sessionID); | ||||
| 	proc->launch(); | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -84,17 +84,14 @@ void MinecraftProcess::on_stdErr() | ||||
| 	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); | ||||
| 		emit log(line.replace(username, "<Username>").replace(sessionID, "<Session ID>").toLocal8Bit(), getLevel(line, MessageLevel::Error)); | ||||
| 	} | ||||
| 	if(!complete) | ||||
| 		m_err_leftover = lines.last(); | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
| void MinecraftProcess::on_stdOut() | ||||
| { | ||||
| 	QByteArray data = readAllStandardOutput(); | ||||
| @@ -106,7 +103,7 @@ void MinecraftProcess::on_stdOut() | ||||
| 	for(int i = 0; i < lines.size() - 1; i++) | ||||
| 	{ | ||||
| 		QString & line = lines[i]; | ||||
| 		emit log(lines[i].toLocal8Bit(), MessageLevel::Message); | ||||
| 		emit log(line.replace(username, "<Username>").replace(sessionID, "<Session ID>").toLocal8Bit(), getLevel(line, MessageLevel::Message)); | ||||
| 	} | ||||
| 	if(!complete) | ||||
| 		m_out_leftover = lines.last(); | ||||
| @@ -167,7 +164,7 @@ void MinecraftProcess::launch() | ||||
| 	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()) | ||||
| 	{ | ||||
| @@ -177,4 +174,19 @@ void MinecraftProcess::launch() | ||||
| 	} | ||||
| } | ||||
|  | ||||
|  | ||||
| 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; | ||||
| 	 | ||||
| } | ||||
| @@ -61,6 +61,8 @@ public: | ||||
| 	 | ||||
| 	void killMinecraft(); | ||||
| 	 | ||||
| 	inline void setLogin(QString user, QString sid) { username = user; sessionID = sid; } | ||||
| 	 | ||||
| signals: | ||||
| 	/** | ||||
| 	 * @brief emitted when mc has finished and the PostLaunchCommand was run | ||||
| @@ -87,4 +89,7 @@ protected slots: | ||||
| 	void on_stdOut(); | ||||
| private: | ||||
| 	bool killed; | ||||
| 	MessageLevel::Enum getLevel(const QString &message, MessageLevel::Enum defaultLevel); | ||||
| 	QString sessionID; | ||||
| 	QString username; | ||||
| }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user