Merge branch 'master' of https://github.com/Stiepen22/MultiMC5 into develop
Conflicts: AppSettings.cpp MultiMC.pro main.cpp
This commit is contained in:
		@@ -194,6 +194,9 @@ void MultiMC::initGlobalSettings()
 | 
			
		||||
	
 | 
			
		||||
	// The cat
 | 
			
		||||
	m_settings->registerSetting(new Setting("TheCat", false));
 | 
			
		||||
	
 | 
			
		||||
	// Shall the main window hide on instance launch
 | 
			
		||||
	m_settings->registerSetting(new Setting("NoHide", false));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MultiMC::initHttpMetaCache()
 | 
			
		||||
 
 | 
			
		||||
@@ -2,13 +2,16 @@
 | 
			
		||||
#include "ui_consolewindow.h"
 | 
			
		||||
 | 
			
		||||
#include <QScrollBar>
 | 
			
		||||
#include <QMessageBox>
 | 
			
		||||
 | 
			
		||||
ConsoleWindow::ConsoleWindow(QWidget *parent) :
 | 
			
		||||
ConsoleWindow::ConsoleWindow(MinecraftProcess *mcproc, QWidget *parent) :
 | 
			
		||||
	QDialog(parent),
 | 
			
		||||
	ui(new Ui::ConsoleWindow),
 | 
			
		||||
	m_mayclose(true)
 | 
			
		||||
	m_mayclose(true),
 | 
			
		||||
	proc(mcproc)
 | 
			
		||||
{
 | 
			
		||||
	ui->setupUi(this);
 | 
			
		||||
	connect(mcproc, SIGNAL(ended()), this, SLOT(onEnded()));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ConsoleWindow::~ConsoleWindow()
 | 
			
		||||
@@ -20,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
 | 
			
		||||
@@ -40,6 +43,15 @@ void ConsoleWindow::write(QString data, MessageLevel::Enum mode)
 | 
			
		||||
	else if (mode == MessageLevel::Error)
 | 
			
		||||
		while(iter.hasNext())
 | 
			
		||||
			writeColor(iter.next(), "red");
 | 
			
		||||
	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())
 | 
			
		||||
@@ -72,3 +84,25 @@ void ConsoleWindow::closeEvent(QCloseEvent * event)
 | 
			
		||||
	else
 | 
			
		||||
		QDialog::closeEvent(event);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ConsoleWindow::on_btnKillMinecraft_clicked()
 | 
			
		||||
{
 | 
			
		||||
	ui->btnKillMinecraft->setEnabled(false);
 | 
			
		||||
	QMessageBox r_u_sure;
 | 
			
		||||
	r_u_sure.setText("Kill Minecraft?");
 | 
			
		||||
	r_u_sure.setInformativeText("This can cause the instance to get corrupted and should only be used if Minecraft is frozen for some reason");
 | 
			
		||||
	r_u_sure.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
 | 
			
		||||
	r_u_sure.setDefaultButton(QMessageBox::Yes);
 | 
			
		||||
	if (r_u_sure.exec() == QMessageBox::Yes)
 | 
			
		||||
		proc->killMinecraft();
 | 
			
		||||
	else
 | 
			
		||||
		ui->btnKillMinecraft->setEnabled(true);
 | 
			
		||||
	r_u_sure.close();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ConsoleWindow::onEnded()
 | 
			
		||||
{
 | 
			
		||||
	ui->btnKillMinecraft->setEnabled(false);
 | 
			
		||||
	// TODO: Check why this doesn't work
 | 
			
		||||
	if (!proc->exitCode()) this->close(); 
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -13,7 +13,7 @@ class ConsoleWindow : public QDialog
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
	explicit ConsoleWindow(QWidget *parent = 0);
 | 
			
		||||
	explicit ConsoleWindow(MinecraftProcess *proc, QWidget *parent = 0);
 | 
			
		||||
	~ConsoleWindow();
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
@@ -48,12 +48,15 @@ public slots:
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
	void on_closeButton_clicked();
 | 
			
		||||
	void on_btnKillMinecraft_clicked();
 | 
			
		||||
	void onEnded();
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
	void closeEvent(QCloseEvent *);
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
	Ui::ConsoleWindow *ui;
 | 
			
		||||
	MinecraftProcess *proc;
 | 
			
		||||
	bool m_mayclose;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -62,6 +62,13 @@
 | 
			
		||||
       </property>
 | 
			
		||||
      </spacer>
 | 
			
		||||
     </item>
 | 
			
		||||
     <item>
 | 
			
		||||
      <widget class="QPushButton" name="btnKillMinecraft">
 | 
			
		||||
       <property name="text">
 | 
			
		||||
        <string>Kill Minecraft</string>
 | 
			
		||||
       </property>
 | 
			
		||||
      </widget>
 | 
			
		||||
     </item>
 | 
			
		||||
     <item>
 | 
			
		||||
      <widget class="QPushButton" name="closeButton">
 | 
			
		||||
       <property name="text">
 | 
			
		||||
 
 | 
			
		||||
@@ -488,7 +488,10 @@ void MainWindow::doLogin(const QString& errorMsg)
 | 
			
		||||
		}
 | 
			
		||||
		else
 | 
			
		||||
		{
 | 
			
		||||
			m_activeLogin = {loginDlg->getUsername(), QString("Offline"), qint64(-1)};
 | 
			
		||||
			QString user = loginDlg->getUsername();
 | 
			
		||||
			if (user.length() == 0)
 | 
			
		||||
			  user = QString("Offline");
 | 
			
		||||
			m_activeLogin = {user, QString("Offline"), qint64(-1)};
 | 
			
		||||
			m_activeInst = m_selectedInstance;
 | 
			
		||||
			launchInstance(m_activeInst, m_activeLogin);
 | 
			
		||||
		}
 | 
			
		||||
@@ -534,10 +537,22 @@ void MainWindow::launchInstance(BaseInstance *instance, LoginResponse response)
 | 
			
		||||
	if(!proc)
 | 
			
		||||
		return;
 | 
			
		||||
	
 | 
			
		||||
	console = new ConsoleWindow();
 | 
			
		||||
	// Prepare GUI: If it shall stay open disable the required parts
 | 
			
		||||
	if (MMC->settings()->get("NoHide").toBool())
 | 
			
		||||
	{
 | 
			
		||||
		ui->actionLaunchInstance->setEnabled(false);
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		this->hide();
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	console = new ConsoleWindow(proc);
 | 
			
		||||
	console->show();
 | 
			
		||||
	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();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -664,3 +679,9 @@ void MainWindow::on_actionEditInstNotes_triggered()
 | 
			
		||||
		linst->setNotes(noteedit.getText());
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MainWindow::instanceEnded()
 | 
			
		||||
{
 | 
			
		||||
	this->show();
 | 
			
		||||
	ui->actionLaunchInstance->setEnabled(m_selectedInstance);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -111,6 +111,8 @@ private slots:
 | 
			
		||||
 | 
			
		||||
	void on_actionChangeInstLWJGLVersion_triggered();
 | 
			
		||||
	
 | 
			
		||||
	void instanceEnded();
 | 
			
		||||
	
 | 
			
		||||
    void on_actionInstanceSettings_triggered();
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
@@ -128,6 +130,7 @@ protected:
 | 
			
		||||
	bool eventFilter(QObject *obj, QEvent *ev);
 | 
			
		||||
	void setCatBackground(bool enabled);
 | 
			
		||||
private:
 | 
			
		||||
	
 | 
			
		||||
	Ui::MainWindow *ui;
 | 
			
		||||
	KCategoryDrawer * drawer;
 | 
			
		||||
	KCategorizedView * view;
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
@@ -120,7 +117,12 @@ void MinecraftProcess::finish(int code, ExitStatus status)
 | 
			
		||||
		//TODO: error handling
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	// TODO: Localization
 | 
			
		||||
	
 | 
			
		||||
	if (!killed)
 | 
			
		||||
		emit log("Minecraft exited.");
 | 
			
		||||
	else
 | 
			
		||||
		emit log("Minecraft was killed by user.", MessageLevel::Error);
 | 
			
		||||
	
 | 
			
		||||
	m_prepostlaunchprocess.processEnvironment().insert("INST_EXITCODE", QString(code));
 | 
			
		||||
	
 | 
			
		||||
@@ -138,6 +140,12 @@ void MinecraftProcess::finish(int code, ExitStatus status)
 | 
			
		||||
	emit ended();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MinecraftProcess::killMinecraft()
 | 
			
		||||
{
 | 
			
		||||
	killed = true;
 | 
			
		||||
	kill();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MinecraftProcess::launch()
 | 
			
		||||
{
 | 
			
		||||
	if (!m_instance->settings().get("PreLaunchCommand").toString().isEmpty())
 | 
			
		||||
@@ -156,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())
 | 
			
		||||
	{
 | 
			
		||||
@@ -166,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;
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
@@ -59,6 +59,10 @@ public:
 | 
			
		||||
	
 | 
			
		||||
	void setMinecraftArguments(QStringList args);
 | 
			
		||||
	
 | 
			
		||||
	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
 | 
			
		||||
@@ -83,4 +87,9 @@ protected slots:
 | 
			
		||||
	void finish(int, QProcess::ExitStatus status);
 | 
			
		||||
	void on_stdErr();
 | 
			
		||||
	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