chore: reformat

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
Sefa Eyeoglu
2023-08-02 18:35:35 +02:00
parent ce2ca13815
commit 1d468ac35a
594 changed files with 16040 additions and 16536 deletions

View File

@ -16,7 +16,7 @@
#include "LaunchStep.h"
#include "LaunchTask.h"
void LaunchStep::bind(LaunchTask *parent)
void LaunchStep::bind(LaunchTask* parent)
{
m_parent = parent;
connect(this, &LaunchStep::readyForLaunch, parent, &LaunchTask::onReadyForLaunch);

View File

@ -15,36 +15,32 @@
#pragma once
#include "tasks/Task.h"
#include "MessageLevel.h"
#include "tasks/Task.h"
#include <QStringList>
class LaunchTask;
class LaunchStep: public Task
{
class LaunchStep : public Task {
Q_OBJECT
public: /* methods */
explicit LaunchStep(LaunchTask *parent):Task(nullptr), m_parent(parent)
{
bind(parent);
};
virtual ~LaunchStep() {};
public: /* methods */
explicit LaunchStep(LaunchTask* parent) : Task(nullptr), m_parent(parent) { bind(parent); };
virtual ~LaunchStep(){};
private: /* methods */
void bind(LaunchTask *parent);
private: /* methods */
void bind(LaunchTask* parent);
signals:
signals:
void logLines(QStringList lines, MessageLevel::Enum level);
void logLine(QString line, MessageLevel::Enum level);
void readyForLaunch();
void progressReportingRequest();
public slots:
virtual void proceed() {};
public slots:
virtual void proceed(){};
// called in the opposite order than the Task launch(), used to clean up or otherwise undo things after the launch ends
virtual void finalize() {};
virtual void finalize(){};
protected: /* data */
LaunchTask *m_parent;
protected: /* data */
LaunchTask* m_parent;
};

View File

@ -36,16 +36,16 @@
*/
#include "launch/LaunchTask.h"
#include "MessageLevel.h"
#include "java/JavaChecker.h"
#include "tasks/Task.h"
#include <assert.h>
#include <QCoreApplication>
#include <QDebug>
#include <QDir>
#include <QEventLoop>
#include <QRegularExpression>
#include <QCoreApplication>
#include <QStandardPaths>
#include <assert.h>
#include "MessageLevel.h"
#include "java/JavaChecker.h"
#include "tasks/Task.h"
void LaunchTask::init()
{
@ -59,9 +59,7 @@ shared_qobject_ptr<LaunchTask> LaunchTask::create(InstancePtr inst)
return proc;
}
LaunchTask::LaunchTask(InstancePtr instance): m_instance(instance)
{
}
LaunchTask::LaunchTask(InstancePtr instance) : m_instance(instance) {}
void LaunchTask::appendStep(shared_qobject_ptr<LaunchStep> step)
{
@ -76,8 +74,7 @@ void LaunchTask::prependStep(shared_qobject_ptr<LaunchStep> step)
void LaunchTask::executeTask()
{
m_instance->setCrashed(false);
if(!m_steps.size())
{
if (!m_steps.size()) {
state = LaunchTask::Finished;
emitSucceeded();
}
@ -94,46 +91,35 @@ void LaunchTask::onReadyForLaunch()
void LaunchTask::onStepFinished()
{
// initial -> just start the first step
if(currentStep == -1)
{
currentStep ++;
if (currentStep == -1) {
currentStep++;
m_steps[currentStep]->start();
return;
}
auto step = m_steps[currentStep];
if(step->wasSuccessful())
{
if (step->wasSuccessful()) {
// end?
if(currentStep == m_steps.size() - 1)
{
if (currentStep == m_steps.size() - 1) {
finalizeSteps(true, QString());
}
else
{
currentStep ++;
} else {
currentStep++;
step = m_steps[currentStep];
step->start();
}
}
else
{
} else {
finalizeSteps(false, step->failReason());
}
}
void LaunchTask::finalizeSteps(bool successful, const QString& error)
{
for(auto step = currentStep; step >= 0; step--)
{
for (auto step = currentStep; step >= 0; step--) {
m_steps[step]->finalize();
}
if(successful)
{
if (successful) {
emitSucceeded();
}
else
{
} else {
emitFailed(error);
}
}
@ -152,8 +138,7 @@ void LaunchTask::setCensorFilter(QMap<QString, QString> filter)
QString LaunchTask::censorPrivateInfo(QString in)
{
auto iter = m_censorFilter.begin();
while (iter != m_censorFilter.end())
{
while (iter != m_censorFilter.end()) {
in.replace(iter.key(), iter.value());
iter++;
}
@ -162,8 +147,7 @@ QString LaunchTask::censorPrivateInfo(QString in)
void LaunchTask::proceed()
{
if(state != LaunchTask::Waiting)
{
if (state != LaunchTask::Waiting) {
return;
}
m_steps[currentStep]->proceed();
@ -171,8 +155,7 @@ void LaunchTask::proceed()
bool LaunchTask::canAbort() const
{
switch(state)
{
switch (state) {
case LaunchTask::Aborted:
case LaunchTask::Failed:
case LaunchTask::Finished:
@ -180,8 +163,7 @@ bool LaunchTask::canAbort() const
case LaunchTask::NotStarted:
return true;
case LaunchTask::Running:
case LaunchTask::Waiting:
{
case LaunchTask::Waiting: {
auto step = m_steps[currentStep];
return step->canAbort();
}
@ -191,28 +173,23 @@ bool LaunchTask::canAbort() const
bool LaunchTask::abort()
{
switch(state)
{
switch (state) {
case LaunchTask::Aborted:
case LaunchTask::Failed:
case LaunchTask::Finished:
return true;
case LaunchTask::NotStarted:
{
case LaunchTask::NotStarted: {
state = LaunchTask::Aborted;
emitFailed("Aborted");
return true;
}
case LaunchTask::Running:
case LaunchTask::Waiting:
{
case LaunchTask::Waiting: {
auto step = m_steps[currentStep];
if(!step->canAbort())
{
if (!step->canAbort()) {
return false;
}
if(step->abort())
{
if (step->abort()) {
state = LaunchTask::Aborted;
return true;
}
@ -225,23 +202,22 @@ bool LaunchTask::abort()
shared_qobject_ptr<LogModel> LaunchTask::getLogModel()
{
if(!m_logModel)
{
if (!m_logModel) {
m_logModel.reset(new LogModel());
m_logModel->setMaxLines(m_instance->getConsoleMaxLines());
m_logModel->setStopOnOverflow(m_instance->shouldStopOnConsoleOverflow());
// FIXME: should this really be here?
m_logModel->setOverflowMessage(tr("Stopped watching the game log because the log length surpassed %1 lines.\n"
"You may have to fix your mods because the game is still logging to files and"
" likely wasting harddrive space at an alarming rate!").arg(m_logModel->getMaxLines()));
"You may have to fix your mods because the game is still logging to files and"
" likely wasting harddrive space at an alarming rate!")
.arg(m_logModel->getMaxLines()));
}
return m_logModel;
}
void LaunchTask::onLogLines(const QStringList &lines, MessageLevel::Enum defaultLevel)
void LaunchTask::onLogLines(const QStringList& lines, MessageLevel::Enum defaultLevel)
{
for (auto & line: lines)
{
for (auto& line : lines) {
onLogLine(line, defaultLevel);
}
}
@ -250,21 +226,19 @@ void LaunchTask::onLogLine(QString line, MessageLevel::Enum level)
{
// if the launcher part set a log level, use it
auto innerLevel = MessageLevel::fromLine(line);
if(innerLevel != MessageLevel::Unknown)
{
if (innerLevel != MessageLevel::Unknown) {
level = innerLevel;
}
// If the level is still undetermined, guess level
if (level == MessageLevel::StdErr || level == MessageLevel::StdOut || level == MessageLevel::Unknown)
{
if (level == MessageLevel::StdErr || level == MessageLevel::StdOut || level == MessageLevel::Unknown) {
level = m_instance->guessLevel(line, level);
}
// censor private user info
line = censorPrivateInfo(line);
auto &model = *getLogModel();
auto& model = *getLogModel();
model.append(level, line);
}
@ -281,22 +255,20 @@ void LaunchTask::emitFailed(QString reason)
Task::emitFailed(reason);
}
void LaunchTask::substituteVariables(QStringList &args) const
void LaunchTask::substituteVariables(QStringList& args) const
{
auto env = m_instance->createEnvironment();
for (auto key : env.keys())
{
for (auto key : env.keys()) {
args.replaceInStrings("$" + key, env.value(key));
}
}
void LaunchTask::substituteVariables(QString &cmd) const
void LaunchTask::substituteVariables(QString& cmd) const
{
auto env = m_instance->createEnvironment();
for (auto key : env.keys())
{
for (auto key : env.keys()) {
cmd.replace("$" + key, env.value(key));
}
}

View File

@ -36,54 +36,36 @@
*/
#pragma once
#include <QProcess>
#include <QObjectPtr.h>
#include "LogModel.h"
#include <QProcess>
#include "BaseInstance.h"
#include "MessageLevel.h"
#include "LoggedProcess.h"
#include "LaunchStep.h"
#include "LogModel.h"
#include "LoggedProcess.h"
#include "MessageLevel.h"
class LaunchTask: public Task
{
class LaunchTask : public Task {
Q_OBJECT
protected:
protected:
explicit LaunchTask(InstancePtr instance);
void init();
public:
enum State
{
NotStarted,
Running,
Waiting,
Failed,
Aborted,
Finished
};
public:
enum State { NotStarted, Running, Waiting, Failed, Aborted, Finished };
public: /* methods */
public: /* methods */
static shared_qobject_ptr<LaunchTask> create(InstancePtr inst);
virtual ~LaunchTask() {};
virtual ~LaunchTask(){};
void appendStep(shared_qobject_ptr<LaunchStep> step);
void prependStep(shared_qobject_ptr<LaunchStep> step);
void setCensorFilter(QMap<QString, QString> filter);
InstancePtr instance()
{
return m_instance;
}
InstancePtr instance() { return m_instance; }
void setPid(qint64 pid)
{
m_pid = pid;
}
void setPid(qint64 pid) { m_pid = pid; }
qint64 pid()
{
return m_pid;
}
qint64 pid() { return m_pid; }
/**
* @brief prepare the process for launch (for multi-stage launch)
@ -104,39 +86,39 @@ public: /* methods */
shared_qobject_ptr<LogModel> getLogModel();
public:
void substituteVariables(QStringList &args) const;
void substituteVariables(QString &cmd) const;
public:
void substituteVariables(QStringList& args) const;
void substituteVariables(QString& cmd) const;
QString censorPrivateInfo(QString in);
protected: /* methods */
protected: /* methods */
virtual void emitFailed(QString reason) override;
virtual void emitSucceeded() override;
signals:
signals:
/**
* @brief emitted when the launch preparations are done
*/
void readyForLaunch();
void requestProgress(Task *task);
void requestProgress(Task* task);
void requestLogging();
public slots:
public slots:
void onLogLines(const QStringList& lines, MessageLevel::Enum defaultLevel = MessageLevel::Launcher);
void onLogLine(QString line, MessageLevel::Enum defaultLevel = MessageLevel::Launcher);
void onReadyForLaunch();
void onStepFinished();
void onProgressReportingRequested();
private: /*methods */
void finalizeSteps(bool successful, const QString & error);
private: /*methods */
void finalizeSteps(bool successful, const QString& error);
protected: /* data */
protected: /* data */
InstancePtr m_instance;
shared_qobject_ptr<LogModel> m_logModel;
QList <shared_qobject_ptr<LaunchStep>> m_steps;
QList<shared_qobject_ptr<LaunchStep>> m_steps;
QMap<QString, QString> m_censorFilter;
int currentStep = -1;
State state = NotStarted;

View File

@ -1,11 +1,11 @@
#include "LogModel.h"
LogModel::LogModel(QObject *parent):QAbstractListModel(parent)
LogModel::LogModel(QObject* parent) : QAbstractListModel(parent)
{
m_content.resize(m_maxLines);
}
int LogModel::rowCount(const QModelIndex &parent) const
int LogModel::rowCount(const QModelIndex& parent) const
{
if (parent.isValid())
return 0;
@ -13,19 +13,17 @@ int LogModel::rowCount(const QModelIndex &parent) const
return m_numLines;
}
QVariant LogModel::data(const QModelIndex &index, int role) const
QVariant LogModel::data(const QModelIndex& index, int role) const
{
if (index.row() < 0 || index.row() >= m_numLines)
return QVariant();
auto row = index.row();
auto realRow = (row + m_firstLine) % m_maxLines;
if (role == Qt::DisplayRole || role == Qt::EditRole)
{
if (role == Qt::DisplayRole || role == Qt::EditRole) {
return m_content[realRow].line;
}
if(role == LevelRole)
{
if (role == LevelRole) {
return m_content[realRow].level;
}
@ -34,31 +32,26 @@ QVariant LogModel::data(const QModelIndex &index, int role) const
void LogModel::append(MessageLevel::Enum level, QString line)
{
if(m_suspended)
{
if (m_suspended) {
return;
}
int lineNum = (m_firstLine + m_numLines) % m_maxLines;
// overflow
if(m_numLines == m_maxLines)
{
if(m_stopOnOverflow)
{
if (m_numLines == m_maxLines) {
if (m_stopOnOverflow) {
// nothing more to do, the buffer is full
return;
}
beginRemoveRows(QModelIndex(), 0, 0);
m_firstLine = (m_firstLine + 1) % m_maxLines;
m_numLines --;
m_numLines--;
endRemoveRows();
}
else if (m_numLines == m_maxLines - 1 && m_stopOnOverflow)
{
} else if (m_numLines == m_maxLines - 1 && m_stopOnOverflow) {
level = MessageLevel::Fatal;
line = m_overflowMessage;
}
beginInsertRows(QModelIndex(), m_numLines, m_numLines);
m_numLines ++;
m_numLines++;
m_content[lineNum].level = level;
m_content[lineNum].line = line;
endInsertRows();
@ -86,9 +79,8 @@ QString LogModel::toPlainText()
{
QString out;
out.reserve(m_numLines * 80);
for(int i = 0; i < m_numLines; i++)
{
QString & line = m_content[(m_firstLine + i) % m_maxLines].line;
for (int i = 0; i < m_numLines; i++) {
QString& line = m_content[(m_firstLine + i) % m_maxLines].line;
out.append(line + '\n');
}
out.squeeze();
@ -98,13 +90,11 @@ QString LogModel::toPlainText()
void LogModel::setMaxLines(int maxLines)
{
// no-op
if(maxLines == m_maxLines)
{
if (maxLines == m_maxLines) {
return;
}
// if it all still fits in the buffer, just resize it
if(m_firstLine + m_numLines < m_maxLines)
{
if (m_firstLine + m_numLines < m_maxLines) {
m_maxLines = maxLines;
m_content.resize(maxLines);
return;
@ -112,22 +102,17 @@ void LogModel::setMaxLines(int maxLines)
// otherwise, we need to reorganize the data because it crosses the wrap boundary
QVector<entry> newContent;
newContent.resize(maxLines);
if(m_numLines <= maxLines)
{
if (m_numLines <= maxLines) {
// if it all fits in the new buffer, just copy it over
for(int i = 0; i < m_numLines; i++)
{
for (int i = 0; i < m_numLines; i++) {
newContent[i] = m_content[(m_firstLine + i) % m_maxLines];
}
m_content.swap(newContent);
}
else
{
} else {
// if it doesn't fit, part of the data needs to be thrown away (the oldest log messages)
int lead = m_numLines - maxLines;
beginRemoveRows(QModelIndex(), 0, lead - 1);
for(int i = 0; i < maxLines; i++)
{
for (int i = 0; i < maxLines; i++) {
newContent[i] = m_content[(m_firstLine + lead + i) % m_maxLines];
}
m_numLines = m_maxLines;
@ -155,8 +140,7 @@ void LogModel::setOverflowMessage(const QString& overflowMessage)
void LogModel::setLineWrap(bool state)
{
if(m_lineWrap != state)
{
if (m_lineWrap != state) {
m_lineWrap = state;
}
}

View File

@ -4,14 +4,13 @@
#include <QString>
#include "MessageLevel.h"
class LogModel : public QAbstractListModel
{
class LogModel : public QAbstractListModel {
Q_OBJECT
public:
explicit LogModel(QObject *parent = 0);
public:
explicit LogModel(QObject* parent = 0);
int rowCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role) const;
int rowCount(const QModelIndex& parent = QModelIndex()) const;
QVariant data(const QModelIndex& index, int role) const;
void append(MessageLevel::Enum, QString line);
void clear();
@ -24,25 +23,21 @@ public:
int getMaxLines();
void setMaxLines(int maxLines);
void setStopOnOverflow(bool stop);
void setOverflowMessage(const QString & overflowMessage);
void setOverflowMessage(const QString& overflowMessage);
void setLineWrap(bool state);
bool wrapLines() const;
enum Roles
{
LevelRole = Qt::UserRole
};
enum Roles { LevelRole = Qt::UserRole };
private /* types */:
struct entry
{
private /* types */:
struct entry {
MessageLevel::Enum level;
QString line;
};
private: /* data */
QVector <entry> m_content;
private: /* data */
QVector<entry> m_content;
int m_maxLines = 1000;
// first line in the circular buffer
int m_firstLine = 0;
@ -53,6 +48,6 @@ private: /* data */
bool m_suspended = false;
bool m_lineWrap = true;
private:
private:
Q_DISABLE_COPY(LogModel)
};

View File

@ -34,12 +34,12 @@
*/
#include "CheckJava.h"
#include "java/JavaUtils.h"
#include <launch/LaunchTask.h>
#include <FileSystem.h>
#include <QStandardPaths>
#include <QFileInfo>
#include <launch/LaunchTask.h>
#include <sys.h>
#include <QFileInfo>
#include <QStandardPaths>
#include "java/JavaUtils.h"
void CheckJava::executeTask()
{
@ -49,32 +49,26 @@ void CheckJava::executeTask()
bool perInstance = settings->get("OverrideJava").toBool() || settings->get("OverrideJavaLocation").toBool();
auto realJavaPath = QStandardPaths::findExecutable(m_javaPath);
if (realJavaPath.isEmpty())
{
if (perInstance)
{
emit logLine(
QString("The java binary \"%1\" couldn't be found. Please fix the java path "
"override in the instance's settings or disable it.").arg(m_javaPath),
MessageLevel::Warning);
}
else
{
if (realJavaPath.isEmpty()) {
if (perInstance) {
emit logLine(QString("The java binary \"%1\" couldn't be found. Please fix the java path "
"override in the instance's settings or disable it.")
.arg(m_javaPath),
MessageLevel::Warning);
} else {
emit logLine(QString("The java binary \"%1\" couldn't be found. Please set up java in "
"the settings.").arg(m_javaPath),
"the settings.")
.arg(m_javaPath),
MessageLevel::Warning);
}
emitFailed(QString("Java path is not valid."));
return;
}
else
{
} else {
emit logLine("Java path is:\n" + m_javaPath + "\n\n", MessageLevel::Launcher);
}
if (JavaUtils::getJavaCheckPath().isEmpty())
{
const char *reason = QT_TR_NOOP("Java checker library could not be found. Please check your installation.");
if (JavaUtils::getJavaCheckPath().isEmpty()) {
const char* reason = QT_TR_NOOP("Java checker library could not be found. Please check your installation.");
emit logLine(tr(reason), MessageLevel::Fatal);
emitFailed(tr(reason));
return;
@ -94,19 +88,15 @@ void CheckJava::executeTask()
m_javaSignature = hash.result().toHex();
// if timestamps are not the same, or something is missing, check!
if (m_javaSignature != storedSignature || storedVersion.size() == 0
|| storedArchitecture.size() == 0 || storedRealArchitecture.size() == 0
|| storedVendor.size() == 0)
{
if (m_javaSignature != storedSignature || storedVersion.size() == 0 || storedArchitecture.size() == 0 ||
storedRealArchitecture.size() == 0 || storedVendor.size() == 0) {
m_JavaChecker.reset(new JavaChecker);
emit logLine(QString("Checking Java version..."), MessageLevel::Launcher);
connect(m_JavaChecker.get(), &JavaChecker::checkFinished, this, &CheckJava::checkJavaFinished);
m_JavaChecker->m_path = realJavaPath;
m_JavaChecker->performCheck();
return;
}
else
{
} else {
auto verString = instance->settings()->get("JavaVersion").toString();
auto archString = instance->settings()->get("JavaArchitecture").toString();
auto realArchString = settings->get("JavaRealArchitecture").toString();
@ -118,10 +108,8 @@ void CheckJava::executeTask()
void CheckJava::checkJavaFinished(JavaCheckResult result)
{
switch (result.validity)
{
case JavaCheckResult::Validity::Errored:
{
switch (result.validity) {
case JavaCheckResult::Validity::Errored: {
// Error message displayed if java can't start
emit logLine(QString("Could not start java:"), MessageLevel::Error);
emit logLines(result.errorLog.split('\n'), MessageLevel::Error);
@ -129,16 +117,14 @@ void CheckJava::checkJavaFinished(JavaCheckResult result)
emitFailed(QString("Could not start java!"));
return;
}
case JavaCheckResult::Validity::ReturnedInvalidData:
{
case JavaCheckResult::Validity::ReturnedInvalidData: {
emit logLine(QString("Java checker returned some invalid data we don't understand:"), MessageLevel::Error);
emit logLines(result.outLog.split('\n'), MessageLevel::Warning);
emit logLine("\nMinecraft might not start properly.", MessageLevel::Launcher);
emitSucceeded();
return;
}
case JavaCheckResult::Validity::Valid:
{
case JavaCheckResult::Validity::Valid: {
auto instance = m_parent->instance();
printJavaInfo(result.javaVersion.toString(), result.mojangPlatform, result.realPlatform, result.javaVendor);
instance->settings()->set("JavaVersion", result.javaVersion.toString());
@ -152,8 +138,9 @@ void CheckJava::checkJavaFinished(JavaCheckResult result)
}
}
void CheckJava::printJavaInfo(const QString& version, const QString& architecture, const QString& realArchitecture, const QString & vendor)
void CheckJava::printJavaInfo(const QString& version, const QString& architecture, const QString& realArchitecture, const QString& vendor)
{
emit logLine(QString("Java is version %1, using %2 (%3) architecture, from %4.\n\n")
.arg(version, architecture, realArchitecture, vendor), MessageLevel::Launcher);
emit logLine(
QString("Java is version %1, using %2 (%3) architecture, from %4.\n\n").arg(version, architecture, realArchitecture, vendor),
MessageLevel::Launcher);
}

View File

@ -15,30 +15,26 @@
#pragma once
#include <launch/LaunchStep.h>
#include <LoggedProcess.h>
#include <java/JavaChecker.h>
#include <launch/LaunchStep.h>
class CheckJava: public LaunchStep
{
class CheckJava : public LaunchStep {
Q_OBJECT
public:
explicit CheckJava(LaunchTask *parent) :LaunchStep(parent){};
virtual ~CheckJava() {};
public:
explicit CheckJava(LaunchTask* parent) : LaunchStep(parent){};
virtual ~CheckJava(){};
virtual void executeTask();
virtual bool canAbort() const
{
return false;
}
private slots:
virtual bool canAbort() const { return false; }
private slots:
void checkJavaFinished(JavaCheckResult result);
private:
void printJavaInfo(const QString & version, const QString & architecture, const QString & realArchitecture, const QString & vendor);
private:
void printJavaInfo(const QString& version, const QString& architecture, const QString& realArchitecture, const QString& vendor);
void printSystemInfo(bool javaIsKnown, bool javaIs64bit);
private:
private:
QString m_javaPath;
QString m_javaSignature;
JavaCheckerPtr m_JavaChecker;

View File

@ -13,20 +13,18 @@
* limitations under the License.
*/
#include "LookupServerAddress.h"
#include <launch/LaunchTask.h>
LookupServerAddress::LookupServerAddress(LaunchTask *parent) :
LaunchStep(parent), m_dnsLookup(new QDnsLookup(this))
LookupServerAddress::LookupServerAddress(LaunchTask* parent) : LaunchStep(parent), m_dnsLookup(new QDnsLookup(this))
{
connect(m_dnsLookup, &QDnsLookup::finished, this, &LookupServerAddress::on_dnsLookupFinished);
m_dnsLookup->setType(QDnsLookup::SRV);
}
void LookupServerAddress::setLookupAddress(const QString &lookupAddress)
void LookupServerAddress::setLookupAddress(const QString& lookupAddress)
{
m_lookupAddress = lookupAddress;
m_dnsLookup->setName(QString("_minecraft._tcp.%1").arg(lookupAddress));
@ -51,41 +49,40 @@ void LookupServerAddress::executeTask()
void LookupServerAddress::on_dnsLookupFinished()
{
if (isFinished())
{
if (isFinished()) {
// Aborted
return;
}
if (m_dnsLookup->error() != QDnsLookup::NoError)
{
if (m_dnsLookup->error() != QDnsLookup::NoError) {
emit logLine(QString("Failed to resolve server address (this is NOT an error!) %1: %2\n")
.arg(m_dnsLookup->name(), m_dnsLookup->errorString()), MessageLevel::Launcher);
resolve(m_lookupAddress, 25565); // Technically the task failed, however, we don't abort the launch
// and leave it up to minecraft to fail (or maybe not) when connecting
.arg(m_dnsLookup->name(), m_dnsLookup->errorString()),
MessageLevel::Launcher);
resolve(m_lookupAddress, 25565); // Technically the task failed, however, we don't abort the launch
// and leave it up to minecraft to fail (or maybe not) when connecting
return;
}
const auto records = m_dnsLookup->serviceRecords();
if (records.empty())
{
emit logLine(
QString("Failed to resolve server address %1: the DNS lookup succeeded, but no records were returned.\n")
.arg(m_dnsLookup->name()), MessageLevel::Warning);
resolve(m_lookupAddress, 25565); // Technically the task failed, however, we don't abort the launch
// and leave it up to minecraft to fail (or maybe not) when connecting
if (records.empty()) {
emit logLine(QString("Failed to resolve server address %1: the DNS lookup succeeded, but no records were returned.\n")
.arg(m_dnsLookup->name()),
MessageLevel::Warning);
resolve(m_lookupAddress, 25565); // Technically the task failed, however, we don't abort the launch
// and leave it up to minecraft to fail (or maybe not) when connecting
return;
}
const auto &firstRecord = records.at(0);
const auto& firstRecord = records.at(0);
quint16 port = firstRecord.port();
emit logLine(QString("Resolved server address %1 to %2 with port %3\n").arg(
m_dnsLookup->name(), firstRecord.target(), QString::number(port)),MessageLevel::Launcher);
emit logLine(
QString("Resolved server address %1 to %2 with port %3\n").arg(m_dnsLookup->name(), firstRecord.target(), QString::number(port)),
MessageLevel::Launcher);
resolve(firstRecord.target(), port);
}
void LookupServerAddress::resolve(const QString &address, quint16 port)
void LookupServerAddress::resolve(const QString& address, quint16 port)
{
m_output->address = address;
m_output->port = port;

View File

@ -15,35 +15,32 @@
#pragma once
#include <launch/LaunchStep.h>
#include <QObjectPtr.h>
#include <launch/LaunchStep.h>
#include <QDnsLookup>
#include "minecraft/launch/MinecraftServerTarget.h"
class LookupServerAddress: public LaunchStep {
Q_OBJECT
public:
explicit LookupServerAddress(LaunchTask *parent);
virtual ~LookupServerAddress() {};
class LookupServerAddress : public LaunchStep {
Q_OBJECT
public:
explicit LookupServerAddress(LaunchTask* parent);
virtual ~LookupServerAddress(){};
virtual void executeTask();
virtual bool abort();
virtual bool canAbort() const
{
return true;
}
virtual bool canAbort() const { return true; }
void setLookupAddress(const QString &lookupAddress);
void setLookupAddress(const QString& lookupAddress);
void setOutputAddressPtr(MinecraftServerTargetPtr output);
private slots:
private slots:
void on_dnsLookupFinished();
private:
void resolve(const QString &address, quint16 port);
private:
void resolve(const QString& address, quint16 port);
QDnsLookup *m_dnsLookup;
QDnsLookup* m_dnsLookup;
QString m_lookupAddress;
MinecraftServerTargetPtr m_output;
};

View File

@ -36,7 +36,7 @@
#include "PostLaunchCommand.h"
#include <launch/LaunchTask.h>
PostLaunchCommand::PostLaunchCommand(LaunchTask *parent) : LaunchStep(parent)
PostLaunchCommand::PostLaunchCommand(LaunchTask* parent) : LaunchStep(parent)
{
auto instance = m_parent->instance();
m_command = instance->getPostExitCommand();
@ -47,7 +47,7 @@ PostLaunchCommand::PostLaunchCommand(LaunchTask *parent) : LaunchStep(parent)
void PostLaunchCommand::executeTask()
{
//FIXME: where to put this?
// FIXME: where to put this?
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
auto args = QProcess::splitCommand(m_command);
m_parent->substituteVariables(args);
@ -65,31 +65,22 @@ void PostLaunchCommand::executeTask()
void PostLaunchCommand::on_state(LoggedProcess::State state)
{
auto getError = [&]()
{
return tr("Post-Launch command failed with code %1.\n\n").arg(m_process.exitCode());
};
switch(state)
{
auto getError = [&]() { return tr("Post-Launch command failed with code %1.\n\n").arg(m_process.exitCode()); };
switch (state) {
case LoggedProcess::Aborted:
case LoggedProcess::Crashed:
case LoggedProcess::FailedToStart:
{
case LoggedProcess::FailedToStart: {
auto error = getError();
emit logLine(error, MessageLevel::Fatal);
emitFailed(error);
return;
}
case LoggedProcess::Finished:
{
if(m_process.exitCode() != 0)
{
case LoggedProcess::Finished: {
if (m_process.exitCode() != 0) {
auto error = getError();
emit logLine(error, MessageLevel::Fatal);
emitFailed(error);
}
else
{
} else {
emit logLine(tr("Post-Launch command ran successfully.\n\n"), MessageLevel::Launcher);
emitSucceeded();
}
@ -99,7 +90,7 @@ void PostLaunchCommand::on_state(LoggedProcess::State state)
}
}
void PostLaunchCommand::setWorkingDirectory(const QString &wd)
void PostLaunchCommand::setWorkingDirectory(const QString& wd)
{
m_process.setWorkingDirectory(wd);
}
@ -107,8 +98,7 @@ void PostLaunchCommand::setWorkingDirectory(const QString &wd)
bool PostLaunchCommand::abort()
{
auto state = m_process.state();
if (state == LoggedProcess::Running || state == LoggedProcess::Starting)
{
if (state == LoggedProcess::Running || state == LoggedProcess::Starting) {
m_process.kill();
}
return true;

View File

@ -15,27 +15,23 @@
#pragma once
#include <launch/LaunchStep.h>
#include <LoggedProcess.h>
#include <launch/LaunchStep.h>
class PostLaunchCommand: public LaunchStep
{
class PostLaunchCommand : public LaunchStep {
Q_OBJECT
public:
explicit PostLaunchCommand(LaunchTask *parent);
virtual ~PostLaunchCommand() {};
public:
explicit PostLaunchCommand(LaunchTask* parent);
virtual ~PostLaunchCommand(){};
virtual void executeTask();
virtual bool abort();
virtual bool canAbort() const
{
return true;
}
void setWorkingDirectory(const QString &wd);
private slots:
virtual bool canAbort() const { return true; }
void setWorkingDirectory(const QString& wd);
private slots:
void on_state(LoggedProcess::State state);
private:
private:
LoggedProcess m_process;
QString m_command;
};

View File

@ -36,7 +36,7 @@
#include "PreLaunchCommand.h"
#include <launch/LaunchTask.h>
PreLaunchCommand::PreLaunchCommand(LaunchTask *parent) : LaunchStep(parent)
PreLaunchCommand::PreLaunchCommand(LaunchTask* parent) : LaunchStep(parent)
{
auto instance = m_parent->instance();
m_command = instance->getPreLaunchCommand();
@ -47,7 +47,7 @@ PreLaunchCommand::PreLaunchCommand(LaunchTask *parent) : LaunchStep(parent)
void PreLaunchCommand::executeTask()
{
//FIXME: where to put this?
// FIXME: where to put this?
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
auto args = QProcess::splitCommand(m_command);
m_parent->substituteVariables(args);
@ -65,31 +65,22 @@ void PreLaunchCommand::executeTask()
void PreLaunchCommand::on_state(LoggedProcess::State state)
{
auto getError = [&]()
{
return tr("Pre-Launch command failed with code %1.\n\n").arg(m_process.exitCode());
};
switch(state)
{
auto getError = [&]() { return tr("Pre-Launch command failed with code %1.\n\n").arg(m_process.exitCode()); };
switch (state) {
case LoggedProcess::Aborted:
case LoggedProcess::Crashed:
case LoggedProcess::FailedToStart:
{
case LoggedProcess::FailedToStart: {
auto error = getError();
emit logLine(error, MessageLevel::Fatal);
emitFailed(error);
return;
}
case LoggedProcess::Finished:
{
if(m_process.exitCode() != 0)
{
case LoggedProcess::Finished: {
if (m_process.exitCode() != 0) {
auto error = getError();
emit logLine(error, MessageLevel::Fatal);
emitFailed(error);
}
else
{
} else {
emit logLine(tr("Pre-Launch command ran successfully.\n\n"), MessageLevel::Launcher);
emitSucceeded();
}
@ -99,7 +90,7 @@ void PreLaunchCommand::on_state(LoggedProcess::State state)
}
}
void PreLaunchCommand::setWorkingDirectory(const QString &wd)
void PreLaunchCommand::setWorkingDirectory(const QString& wd)
{
m_process.setWorkingDirectory(wd);
}
@ -107,8 +98,7 @@ void PreLaunchCommand::setWorkingDirectory(const QString &wd)
bool PreLaunchCommand::abort()
{
auto state = m_process.state();
if (state == LoggedProcess::Running || state == LoggedProcess::Starting)
{
if (state == LoggedProcess::Running || state == LoggedProcess::Starting) {
m_process.kill();
}
return true;

View File

@ -15,27 +15,23 @@
#pragma once
#include "launch/LaunchStep.h"
#include "LoggedProcess.h"
#include "launch/LaunchStep.h"
class PreLaunchCommand: public LaunchStep
{
class PreLaunchCommand : public LaunchStep {
Q_OBJECT
public:
explicit PreLaunchCommand(LaunchTask *parent);
virtual ~PreLaunchCommand() {};
public:
explicit PreLaunchCommand(LaunchTask* parent);
virtual ~PreLaunchCommand(){};
virtual void executeTask();
virtual bool abort();
virtual bool canAbort() const
{
return true;
}
void setWorkingDirectory(const QString &wd);
private slots:
virtual bool canAbort() const { return true; }
void setWorkingDirectory(const QString& wd);
private slots:
void on_state(LoggedProcess::State state);
private:
private:
LoggedProcess m_process;
QString m_command;
};

View File

@ -20,16 +20,12 @@
#include <launch/LaunchStep.h>
class QuitAfterGameStop: public LaunchStep
{
class QuitAfterGameStop : public LaunchStep {
Q_OBJECT
public:
explicit QuitAfterGameStop(LaunchTask *parent) :LaunchStep(parent){};
virtual ~QuitAfterGameStop() {};
public:
explicit QuitAfterGameStop(LaunchTask* parent) : LaunchStep(parent){};
virtual ~QuitAfterGameStop(){};
virtual void executeTask();
virtual bool canAbort() const
{
return false;
}
virtual bool canAbort() const { return false; }
};

View File

@ -1,11 +1,11 @@
#include "TextPrint.h"
TextPrint::TextPrint(LaunchTask * parent, const QStringList &lines, MessageLevel::Enum level) : LaunchStep(parent)
TextPrint::TextPrint(LaunchTask* parent, const QStringList& lines, MessageLevel::Enum level) : LaunchStep(parent)
{
m_lines = lines;
m_level = level;
}
TextPrint::TextPrint(LaunchTask *parent, const QString &line, MessageLevel::Enum level) : LaunchStep(parent)
TextPrint::TextPrint(LaunchTask* parent, const QString& line, MessageLevel::Enum level) : LaunchStep(parent)
{
m_lines.append(line);
m_level = level;

View File

@ -15,27 +15,26 @@
#pragma once
#include <launch/LaunchStep.h>
#include <LoggedProcess.h>
#include <java/JavaChecker.h>
#include <launch/LaunchStep.h>
/*
* FIXME: maybe do not export
*/
class TextPrint: public LaunchStep
{
class TextPrint : public LaunchStep {
Q_OBJECT
public:
explicit TextPrint(LaunchTask *parent, const QStringList &lines, MessageLevel::Enum level);
explicit TextPrint(LaunchTask *parent, const QString &line, MessageLevel::Enum level);
public:
explicit TextPrint(LaunchTask* parent, const QStringList& lines, MessageLevel::Enum level);
explicit TextPrint(LaunchTask* parent, const QString& line, MessageLevel::Enum level);
virtual ~TextPrint(){};
virtual void executeTask();
virtual bool canAbort() const;
virtual bool abort();
private:
private:
QStringList m_lines;
MessageLevel::Enum m_level;
};

View File

@ -18,14 +18,12 @@
void Update::executeTask()
{
if(m_aborted)
{
if (m_aborted) {
emitFailed(tr("Task aborted."));
return;
}
m_updateTask.reset(m_parent->instance()->createUpdateTask(m_mode));
if(m_updateTask)
{
if (m_updateTask) {
connect(m_updateTask.get(), &Task::finished, this, &Update::updateFinished);
connect(m_updateTask.get(), &Task::progress, this, &Update::setProgress);
connect(m_updateTask.get(), &Task::stepProgress, this, &Update::propagateStepProgress);
@ -44,13 +42,10 @@ void Update::proceed()
void Update::updateFinished()
{
if(m_updateTask->wasSuccessful())
{
if (m_updateTask->wasSuccessful()) {
m_updateTask.reset();
emitSucceeded();
}
else
{
} else {
QString reason = tr("Instance update failed because: %1\n\n").arg(m_updateTask->failReason());
m_updateTask.reset();
emit logLine(reason, MessageLevel::Fatal);
@ -60,21 +55,17 @@ void Update::updateFinished()
bool Update::canAbort() const
{
if(m_updateTask)
{
if (m_updateTask) {
return m_updateTask->canAbort();
}
return true;
}
bool Update::abort()
{
m_aborted = true;
if(m_updateTask)
{
if(m_updateTask->canAbort())
{
if (m_updateTask) {
if (m_updateTask->canAbort()) {
return m_updateTask->abort();
}
}

View File

@ -15,30 +15,29 @@
#pragma once
#include <launch/LaunchStep.h>
#include <QObjectPtr.h>
#include <LoggedProcess.h>
#include <QObjectPtr.h>
#include <java/JavaChecker.h>
#include <launch/LaunchStep.h>
#include <net/Mode.h>
// FIXME: stupid. should be defined by the instance type? or even completely abstracted away...
class Update: public LaunchStep
{
class Update : public LaunchStep {
Q_OBJECT
public:
explicit Update(LaunchTask *parent, Net::Mode mode):LaunchStep(parent), m_mode(mode) {};
virtual ~Update() {};
public:
explicit Update(LaunchTask* parent, Net::Mode mode) : LaunchStep(parent), m_mode(mode){};
virtual ~Update(){};
void executeTask() override;
bool canAbort() const override;
void proceed() override;
public slots:
public slots:
bool abort() override;
private slots:
private slots:
void updateFinished();
private:
private:
Task::Ptr m_updateTask;
bool m_aborted = false;
Net::Mode m_mode = Net::Mode::Offline;