summaryrefslogtreecommitdiffstats
path: root/api/logic/launch
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2018-07-15 14:51:05 +0200
committerPetr Mrázek <peterix@gmail.com>2018-07-15 14:51:05 +0200
commitbbb3b3e6f6e3c0f95873f22e6d0a4aaf350f49d9 (patch)
treee6497e304b7b9368367565fbc7c06efab1124b1c /api/logic/launch
parent03280cc62e75f8073f8d3d9e9e3952acf21fa77d (diff)
downloadMultiMC-bbb3b3e6f6e3c0f95873f22e6d0a4aaf350f49d9.tar
MultiMC-bbb3b3e6f6e3c0f95873f22e6d0a4aaf350f49d9.tar.gz
MultiMC-bbb3b3e6f6e3c0f95873f22e6d0a4aaf350f49d9.tar.lz
MultiMC-bbb3b3e6f6e3c0f95873f22e6d0a4aaf350f49d9.tar.xz
MultiMC-bbb3b3e6f6e3c0f95873f22e6d0a4aaf350f49d9.zip
NOISSUE tabs -> spaces
Diffstat (limited to 'api/logic/launch')
-rw-r--r--api/logic/launch/LaunchStep.cpp12
-rw-r--r--api/logic/launch/LaunchStep.h30
-rw-r--r--api/logic/launch/LaunchTask.cpp324
-rw-r--r--api/logic/launch/LaunchTask.h134
-rw-r--r--api/logic/launch/LogModel.cpp218
-rw-r--r--api/logic/launch/LogModel.h70
-rw-r--r--api/logic/launch/steps/PostLaunchCommand.cpp94
-rw-r--r--api/logic/launch/steps/PostLaunchCommand.h26
-rw-r--r--api/logic/launch/steps/PreLaunchCommand.cpp96
-rw-r--r--api/logic/launch/steps/PreLaunchCommand.h26
-rw-r--r--api/logic/launch/steps/TextPrint.cpp18
-rw-r--r--api/logic/launch/steps/TextPrint.h18
-rw-r--r--api/logic/launch/steps/Update.cpp84
-rw-r--r--api/logic/launch/steps/Update.h22
14 files changed, 586 insertions, 586 deletions
diff --git a/api/logic/launch/LaunchStep.cpp b/api/logic/launch/LaunchStep.cpp
index 01f72a0a..e2327712 100644
--- a/api/logic/launch/LaunchStep.cpp
+++ b/api/logic/launch/LaunchStep.cpp
@@ -18,10 +18,10 @@
void LaunchStep::bind(LaunchTask *parent)
{
- m_parent = parent;
- connect(this, &LaunchStep::readyForLaunch, parent, &LaunchTask::onReadyForLaunch);
- connect(this, &LaunchStep::logLine, parent, &LaunchTask::onLogLine);
- connect(this, &LaunchStep::logLines, parent, &LaunchTask::onLogLines);
- connect(this, &LaunchStep::finished, parent, &LaunchTask::onStepFinished);
- connect(this, &LaunchStep::progressReportingRequest, parent, &LaunchTask::onProgressReportingRequested);
+ m_parent = parent;
+ connect(this, &LaunchStep::readyForLaunch, parent, &LaunchTask::onReadyForLaunch);
+ connect(this, &LaunchStep::logLine, parent, &LaunchTask::onLogLine);
+ connect(this, &LaunchStep::logLines, parent, &LaunchTask::onLogLines);
+ connect(this, &LaunchStep::finished, parent, &LaunchTask::onStepFinished);
+ connect(this, &LaunchStep::progressReportingRequest, parent, &LaunchTask::onProgressReportingRequested);
}
diff --git a/api/logic/launch/LaunchStep.h b/api/logic/launch/LaunchStep.h
index 80778e34..0abe456a 100644
--- a/api/logic/launch/LaunchStep.h
+++ b/api/logic/launch/LaunchStep.h
@@ -23,28 +23,28 @@
class LaunchTask;
class LaunchStep: public Task
{
- Q_OBJECT
+ Q_OBJECT
public: /* methods */
- explicit LaunchStep(LaunchTask *parent):Task(nullptr), m_parent(parent)
- {
- bind(parent);
- };
- virtual ~LaunchStep() {};
+ explicit LaunchStep(LaunchTask *parent):Task(nullptr), m_parent(parent)
+ {
+ bind(parent);
+ };
+ virtual ~LaunchStep() {};
protected: /* methods */
- virtual void bind(LaunchTask *parent);
+ virtual void bind(LaunchTask *parent);
signals:
- void logLines(QStringList lines, MessageLevel::Enum level);
- void logLine(QString line, MessageLevel::Enum level);
- void readyForLaunch();
- void progressReportingRequest();
+ void logLines(QStringList lines, MessageLevel::Enum level);
+ void logLine(QString line, MessageLevel::Enum level);
+ void readyForLaunch();
+ void progressReportingRequest();
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 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() {};
protected: /* data */
- LaunchTask *m_parent;
+ LaunchTask *m_parent;
}; \ No newline at end of file
diff --git a/api/logic/launch/LaunchTask.cpp b/api/logic/launch/LaunchTask.cpp
index 99c16721..c00fa32a 100644
--- a/api/logic/launch/LaunchTask.cpp
+++ b/api/logic/launch/LaunchTask.cpp
@@ -30,14 +30,14 @@
void LaunchTask::init()
{
- m_instance->setRunning(true);
+ m_instance->setRunning(true);
}
std::shared_ptr<LaunchTask> LaunchTask::create(InstancePtr inst)
{
- std::shared_ptr<LaunchTask> proc(new LaunchTask(inst));
- proc->init();
- return proc;
+ std::shared_ptr<LaunchTask> proc(new LaunchTask(inst));
+ proc->init();
+ return proc;
}
LaunchTask::LaunchTask(InstancePtr instance): m_instance(instance)
@@ -46,235 +46,235 @@ LaunchTask::LaunchTask(InstancePtr instance): m_instance(instance)
void LaunchTask::appendStep(std::shared_ptr<LaunchStep> step)
{
- m_steps.append(step);
+ m_steps.append(step);
}
void LaunchTask::prependStep(std::shared_ptr<LaunchStep> step)
{
- m_steps.prepend(step);
+ m_steps.prepend(step);
}
void LaunchTask::executeTask()
{
- m_instance->setCrashed(false);
- if(!m_steps.size())
- {
- state = LaunchTask::Finished;
- emitSucceeded();
- }
- state = LaunchTask::Running;
- onStepFinished();
+ m_instance->setCrashed(false);
+ if(!m_steps.size())
+ {
+ state = LaunchTask::Finished;
+ emitSucceeded();
+ }
+ state = LaunchTask::Running;
+ onStepFinished();
}
void LaunchTask::onReadyForLaunch()
{
- state = LaunchTask::Waiting;
- emit readyForLaunch();
+ state = LaunchTask::Waiting;
+ emit readyForLaunch();
}
void LaunchTask::onStepFinished()
{
- // initial -> just start the first step
- if(currentStep == -1)
- {
- currentStep ++;
- m_steps[currentStep]->start();
- return;
- }
+ // initial -> just start the first step
+ if(currentStep == -1)
+ {
+ currentStep ++;
+ m_steps[currentStep]->start();
+ return;
+ }
- auto step = m_steps[currentStep];
- if(step->wasSuccessful())
- {
- // end?
- if(currentStep == m_steps.size() - 1)
- {
- finalizeSteps(true, QString());
- }
- else
- {
- currentStep ++;
- step = m_steps[currentStep];
- step->start();
- }
- }
- else
- {
- finalizeSteps(false, step->failReason());
- }
+ auto step = m_steps[currentStep];
+ if(step->wasSuccessful())
+ {
+ // end?
+ if(currentStep == m_steps.size() - 1)
+ {
+ finalizeSteps(true, QString());
+ }
+ else
+ {
+ currentStep ++;
+ step = m_steps[currentStep];
+ step->start();
+ }
+ }
+ else
+ {
+ finalizeSteps(false, step->failReason());
+ }
}
void LaunchTask::finalizeSteps(bool successful, const QString& error)
{
- for(auto step = currentStep; step >= 0; step--)
- {
- m_steps[step]->finalize();
- }
- if(successful)
- {
- emitSucceeded();
- }
- else
- {
- emitFailed(error);
- }
+ for(auto step = currentStep; step >= 0; step--)
+ {
+ m_steps[step]->finalize();
+ }
+ if(successful)
+ {
+ emitSucceeded();
+ }
+ else
+ {
+ emitFailed(error);
+ }
}
void LaunchTask::onProgressReportingRequested()
{
- state = LaunchTask::Waiting;
- emit requestProgress(m_steps[currentStep].get());
+ state = LaunchTask::Waiting;
+ emit requestProgress(m_steps[currentStep].get());
}
void LaunchTask::setCensorFilter(QMap<QString, QString> filter)
{
- m_censorFilter = filter;
+ m_censorFilter = filter;
}
QString LaunchTask::censorPrivateInfo(QString in)
{
- auto iter = m_censorFilter.begin();
- while (iter != m_censorFilter.end())
- {
- in.replace(iter.key(), iter.value());
- iter++;
- }
- return in;
+ auto iter = m_censorFilter.begin();
+ while (iter != m_censorFilter.end())
+ {
+ in.replace(iter.key(), iter.value());
+ iter++;
+ }
+ return in;
}
void LaunchTask::proceed()
{
- if(state != LaunchTask::Waiting)
- {
- return;
- }
- m_steps[currentStep]->proceed();
+ if(state != LaunchTask::Waiting)
+ {
+ return;
+ }
+ m_steps[currentStep]->proceed();
}
bool LaunchTask::canAbort() const
{
- switch(state)
- {
- case LaunchTask::Aborted:
- case LaunchTask::Failed:
- case LaunchTask::Finished:
- return false;
- case LaunchTask::NotStarted:
- return true;
- case LaunchTask::Running:
- case LaunchTask::Waiting:
- {
- auto step = m_steps[currentStep];
- return step->canAbort();
- }
- }
- return false;
+ switch(state)
+ {
+ case LaunchTask::Aborted:
+ case LaunchTask::Failed:
+ case LaunchTask::Finished:
+ return false;
+ case LaunchTask::NotStarted:
+ return true;
+ case LaunchTask::Running:
+ case LaunchTask::Waiting:
+ {
+ auto step = m_steps[currentStep];
+ return step->canAbort();
+ }
+ }
+ return false;
}
bool LaunchTask::abort()
{
- switch(state)
- {
- case LaunchTask::Aborted:
- case LaunchTask::Failed:
- case LaunchTask::Finished:
- return true;
- case LaunchTask::NotStarted:
- {
- state = LaunchTask::Aborted;
- emitFailed("Aborted");
- return true;
- }
- case LaunchTask::Running:
- case LaunchTask::Waiting:
- {
- auto step = m_steps[currentStep];
- if(!step->canAbort())
- {
- return false;
- }
- if(step->abort())
- {
- state = LaunchTask::Aborted;
- return true;
- }
- }
- default:
- break;
- }
- return false;
+ switch(state)
+ {
+ case LaunchTask::Aborted:
+ case LaunchTask::Failed:
+ case LaunchTask::Finished:
+ return true;
+ case LaunchTask::NotStarted:
+ {
+ state = LaunchTask::Aborted;
+ emitFailed("Aborted");
+ return true;
+ }
+ case LaunchTask::Running:
+ case LaunchTask::Waiting:
+ {
+ auto step = m_steps[currentStep];
+ if(!step->canAbort())
+ {
+ return false;
+ }
+ if(step->abort())
+ {
+ state = LaunchTask::Aborted;
+ return true;
+ }
+ }
+ default:
+ break;
+ }
+ return false;
}
shared_qobject_ptr<LogModel> LaunchTask::getLogModel()
{
- 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("MultiMC 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()));
- }
- return 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("MultiMC 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()));
+ }
+ return m_logModel;
}
void LaunchTask::onLogLines(const QStringList &lines, MessageLevel::Enum defaultLevel)
{
- for (auto & line: lines)
- {
- onLogLine(line, defaultLevel);
- }
+ for (auto & line: lines)
+ {
+ onLogLine(line, defaultLevel);
+ }
}
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)
- {
- level = innerLevel;
- }
+ // if the launcher part set a log level, use it
+ auto innerLevel = MessageLevel::fromLine(line);
+ if(innerLevel != MessageLevel::Unknown)
+ {
+ level = innerLevel;
+ }
- // If the level is still undetermined, guess level
- if (level == MessageLevel::StdErr || level == MessageLevel::StdOut || level == MessageLevel::Unknown)
- {
- level = m_instance->guessLevel(line, level);
- }
+ // If the level is still undetermined, guess level
+ if (level == MessageLevel::StdErr || level == MessageLevel::StdOut || level == MessageLevel::Unknown)
+ {
+ level = m_instance->guessLevel(line, level);
+ }
- // censor private user info
- line = censorPrivateInfo(line);
+ // censor private user info
+ line = censorPrivateInfo(line);
- auto &model = *getLogModel();
- model.append(level, line);
+ auto &model = *getLogModel();
+ model.append(level, line);
}
void LaunchTask::emitSucceeded()
{
- m_instance->setRunning(false);
- Task::emitSucceeded();
+ m_instance->setRunning(false);
+ Task::emitSucceeded();
}
void LaunchTask::emitFailed(QString reason)
{
- m_instance->setRunning(false);
- m_instance->setCrashed(true);
- Task::emitFailed(reason);
+ m_instance->setRunning(false);
+ m_instance->setCrashed(true);
+ Task::emitFailed(reason);
}
QString LaunchTask::substituteVariables(const QString &cmd) const
{
- QString out = cmd;
- auto variables = m_instance->getVariables();
- for (auto it = variables.begin(); it != variables.end(); ++it)
- {
- out.replace("$" + it.key(), it.value());
- }
- auto env = QProcessEnvironment::systemEnvironment();
- for (auto var : env.keys())
- {
- out.replace("$" + var, env.value(var));
- }
- return out;
+ QString out = cmd;
+ auto variables = m_instance->getVariables();
+ for (auto it = variables.begin(); it != variables.end(); ++it)
+ {
+ out.replace("$" + it.key(), it.value());
+ }
+ auto env = QProcessEnvironment::systemEnvironment();
+ for (auto var : env.keys())
+ {
+ out.replace("$" + var, env.value(var));
+ }
+ return out;
}
diff --git a/api/logic/launch/LaunchTask.h b/api/logic/launch/LaunchTask.h
index 746d6d19..f5e226b5 100644
--- a/api/logic/launch/LaunchTask.h
+++ b/api/logic/launch/LaunchTask.h
@@ -6,7 +6,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -28,98 +28,98 @@
class MULTIMC_LOGIC_EXPORT LaunchTask: public Task
{
- Q_OBJECT
+ Q_OBJECT
protected:
- explicit LaunchTask(InstancePtr instance);
- void init();
+ explicit LaunchTask(InstancePtr instance);
+ void init();
public:
- enum State
- {
- NotStarted,
- Running,
- Waiting,
- Failed,
- Aborted,
- Finished
- };
+ enum State
+ {
+ NotStarted,
+ Running,
+ Waiting,
+ Failed,
+ Aborted,
+ Finished
+ };
public: /* methods */
- static std::shared_ptr<LaunchTask> create(InstancePtr inst);
- virtual ~LaunchTask() {};
+ static std::shared_ptr<LaunchTask> create(InstancePtr inst);
+ virtual ~LaunchTask() {};
- void appendStep(std::shared_ptr<LaunchStep> step);
- void prependStep(std::shared_ptr<LaunchStep> step);
- void setCensorFilter(QMap<QString, QString> filter);
+ void appendStep(std::shared_ptr<LaunchStep> step);
+ void prependStep(std::shared_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)
- */
- virtual void executeTask() override;
+ /**
+ * @brief prepare the process for launch (for multi-stage launch)
+ */
+ virtual void executeTask() override;
- /**
- * @brief launch the armed instance
- */
- void proceed();
+ /**
+ * @brief launch the armed instance
+ */
+ void proceed();
- /**
- * @brief abort launch
- */
- bool abort() override;
+ /**
+ * @brief abort launch
+ */
+ bool abort() override;
- bool canAbort() const override;
+ bool canAbort() const override;
- shared_qobject_ptr<LogModel> getLogModel();
+ shared_qobject_ptr<LogModel> getLogModel();
public:
- QString substituteVariables(const QString &cmd) const;
- QString censorPrivateInfo(QString in);
+ QString substituteVariables(const QString &cmd) const;
+ QString censorPrivateInfo(QString in);
protected: /* methods */
- virtual void emitFailed(QString reason) override;
- virtual void emitSucceeded() override;
+ virtual void emitFailed(QString reason) override;
+ virtual void emitSucceeded() override;
signals:
- /**
- * @brief emitted when the launch preparations are done
- */
- void readyForLaunch();
+ /**
+ * @brief emitted when the launch preparations are done
+ */
+ void readyForLaunch();
- void requestProgress(Task *task);
+ void requestProgress(Task *task);
- void requestLogging();
+ void requestLogging();
public slots:
- void onLogLines(const QStringList& lines, MessageLevel::Enum defaultLevel = MessageLevel::MultiMC);
- void onLogLine(QString line, MessageLevel::Enum defaultLevel = MessageLevel::MultiMC);
- void onReadyForLaunch();
- void onStepFinished();
- void onProgressReportingRequested();
+ void onLogLines(const QStringList& lines, MessageLevel::Enum defaultLevel = MessageLevel::MultiMC);
+ void onLogLine(QString line, MessageLevel::Enum defaultLevel = MessageLevel::MultiMC);
+ void onReadyForLaunch();
+ void onStepFinished();
+ void onProgressReportingRequested();
private: /*methods */
- void finalizeSteps(bool successful, const QString & error);
+ void finalizeSteps(bool successful, const QString & error);
protected: /* data */
- InstancePtr m_instance;
- shared_qobject_ptr<LogModel> m_logModel;
- QList <std::shared_ptr<LaunchStep>> m_steps;
- QMap<QString, QString> m_censorFilter;
- int currentStep = -1;
- State state = NotStarted;
- qint64 m_pid = -1;
+ InstancePtr m_instance;
+ shared_qobject_ptr<LogModel> m_logModel;
+ QList <std::shared_ptr<LaunchStep>> m_steps;
+ QMap<QString, QString> m_censorFilter;
+ int currentStep = -1;
+ State state = NotStarted;
+ qint64 m_pid = -1;
};
diff --git a/api/logic/launch/LogModel.cpp b/api/logic/launch/LogModel.cpp
index 72b076e9..92f9487a 100644
--- a/api/logic/launch/LogModel.cpp
+++ b/api/logic/launch/LogModel.cpp
@@ -2,166 +2,166 @@
LogModel::LogModel(QObject *parent):QAbstractListModel(parent)
{
- m_content.resize(m_maxLines);
+ m_content.resize(m_maxLines);
}
int LogModel::rowCount(const QModelIndex &parent) const
{
- if (parent.isValid())
- return 0;
+ if (parent.isValid())
+ return 0;
- return m_numLines;
+ return m_numLines;
}
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)
- {
- return m_content[realRow].line;
- }
- if(role == LevelRole)
- {
- return m_content[realRow].level;
- }
-
- return QVariant();
+ 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)
+ {
+ return m_content[realRow].line;
+ }
+ if(role == LevelRole)
+ {
+ return m_content[realRow].level;
+ }
+
+ return QVariant();
}
void LogModel::append(MessageLevel::Enum level, QString line)
{
- if(m_suspended)
- {
- return;
- }
- int lineNum = (m_firstLine + m_numLines) % m_maxLines;
- // overflow
- 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 --;
- endRemoveRows();
- }
- else if (m_numLines == m_maxLines - 1 && m_stopOnOverflow)
- {
- level = MessageLevel::Fatal;
- line = m_overflowMessage;
- }
- beginInsertRows(QModelIndex(), m_numLines, m_numLines);
- m_numLines ++;
- m_content[lineNum].level = level;
- m_content[lineNum].line = line;
- endInsertRows();
+ if(m_suspended)
+ {
+ return;
+ }
+ int lineNum = (m_firstLine + m_numLines) % m_maxLines;
+ // overflow
+ 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 --;
+ endRemoveRows();
+ }
+ else if (m_numLines == m_maxLines - 1 && m_stopOnOverflow)
+ {
+ level = MessageLevel::Fatal;
+ line = m_overflowMessage;
+ }
+ beginInsertRows(QModelIndex(), m_numLines, m_numLines);
+ m_numLines ++;
+ m_content[lineNum].level = level;
+ m_content[lineNum].line = line;
+ endInsertRows();
}
void LogModel::suspend(bool suspend)
{
- m_suspended = suspend;
+ m_suspended = suspend;
}
bool LogModel::suspended()
{
- return m_suspended;
+ return m_suspended;
}
void LogModel::clear()
{
- beginResetModel();
- m_firstLine = 0;
- m_numLines = 0;
- endResetModel();
+ beginResetModel();
+ m_firstLine = 0;
+ m_numLines = 0;
+ endResetModel();
}
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;
- out.append(line + '\n');
- }
- out.squeeze();
- return out;
+ 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;
+ out.append(line + '\n');
+ }
+ out.squeeze();
+ return out;
}
void LogModel::setMaxLines(int maxLines)
{
- // no-op
- if(maxLines == m_maxLines)
- {
- return;
- }
- // if it all still fits in the buffer, just resize it
- if(m_firstLine + m_numLines < m_maxLines)
- {
- m_maxLines = maxLines;
- m_content.resize(maxLines);
- return;
- }
- // otherwise, we need to reorganize the data because it crosses the wrap boundary
- QVector<entry> newContent;
- newContent.resize(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++)
- {
- newContent[i] = m_content[(m_firstLine + i) % m_maxLines];
- }
- m_content.swap(newContent);
- }
- 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++)
- {
- newContent[i] = m_content[(m_firstLine + lead + i) % m_maxLines];
- }
- m_numLines = m_maxLines;
- m_content.swap(newContent);
- endRemoveRows();
- }
- m_firstLine = 0;
- m_maxLines = maxLines;
+ // no-op
+ if(maxLines == m_maxLines)
+ {
+ return;
+ }
+ // if it all still fits in the buffer, just resize it
+ if(m_firstLine + m_numLines < m_maxLines)
+ {
+ m_maxLines = maxLines;
+ m_content.resize(maxLines);
+ return;
+ }
+ // otherwise, we need to reorganize the data because it crosses the wrap boundary
+ QVector<entry> newContent;
+ newContent.resize(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++)
+ {
+ newContent[i] = m_content[(m_firstLine + i) % m_maxLines];
+ }
+ m_content.swap(newContent);
+ }
+ 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++)
+ {
+ newContent[i] = m_content[(m_firstLine + lead + i) % m_maxLines];
+ }
+ m_numLines = m_maxLines;
+ m_content.swap(newContent);
+ endRemoveRows();
+ }
+ m_firstLine = 0;
+ m_maxLines = maxLines;
}
int LogModel::getMaxLines()
{
- return m_maxLines;
+ return m_maxLines;
}
void LogModel::setStopOnOverflow(bool stop)
{
- m_stopOnOverflow = stop;
+ m_stopOnOverflow = stop;
}
void LogModel::setOverflowMessage(const QString& overflowMessage)
{
- m_overflowMessage = overflowMessage;
+ m_overflowMessage = overflowMessage;
}
void LogModel::setLineWrap(bool state)
{
- if(m_lineWrap != state)
- {
- m_lineWrap = state;
- }
+ if(m_lineWrap != state)
+ {
+ m_lineWrap = state;
+ }
}
bool LogModel::wrapLines() const
{
- return m_lineWrap;
+ return m_lineWrap;
}
diff --git a/api/logic/launch/LogModel.h b/api/logic/launch/LogModel.h
index e6deac89..bccceaef 100644
--- a/api/logic/launch/LogModel.h
+++ b/api/logic/launch/LogModel.h
@@ -8,53 +8,53 @@
class MULTIMC_LOGIC_EXPORT LogModel : public QAbstractListModel
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit LogModel(QObject *parent = 0);
+ 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();
+ void append(MessageLevel::Enum, QString line);
+ void clear();
- void suspend(bool suspend);
- bool suspended();
+ void suspend(bool suspend);
+ bool suspended();
- QString toPlainText();
+ QString toPlainText();
- int getMaxLines();
- void setMaxLines(int maxLines);
- void setStopOnOverflow(bool stop);
- void setOverflowMessage(const QString & overflowMessage);
+ int getMaxLines();
+ void setMaxLines(int maxLines);
+ void setStopOnOverflow(bool stop);
+ void setOverflowMessage(const QString & overflowMessage);
- void setLineWrap(bool state);
- bool wrapLines() const;
+ void setLineWrap(bool state);
+ bool wrapLines() const;
- enum Roles
- {
- LevelRole = Qt::UserRole
- };
+ enum Roles
+ {
+ LevelRole = Qt::UserRole
+ };
private /* types */:
- struct entry
- {
- MessageLevel::Enum level;
- QString line;
- };
+ struct entry
+ {
+ MessageLevel::Enum level;
+ QString line;
+ };
private: /* data */
- QVector <entry> m_content;
- int m_maxLines = 1000;
- // first line in the circular buffer
- int m_firstLine = 0;
- // number of lines occupied in the circular buffer
- int m_numLines = 0;
- bool m_stopOnOverflow = false;
- QString m_overflowMessage = "OVERFLOW";
- bool m_suspended = false;
- bool m_lineWrap = true;
+ QVector <entry> m_content;
+ int m_maxLines = 1000;
+ // first line in the circular buffer
+ int m_firstLine = 0;
+ // number of lines occupied in the circular buffer
+ int m_numLines = 0;
+ bool m_stopOnOverflow = false;
+ QString m_overflowMessage = "OVERFLOW";
+ bool m_suspended = false;
+ bool m_lineWrap = true;
private:
- Q_DISABLE_COPY(LogModel)
+ Q_DISABLE_COPY(LogModel)
};
diff --git a/api/logic/launch/steps/PostLaunchCommand.cpp b/api/logic/launch/steps/PostLaunchCommand.cpp
index bc3b3ffe..3730f71c 100644
--- a/api/logic/launch/steps/PostLaunchCommand.cpp
+++ b/api/logic/launch/steps/PostLaunchCommand.cpp
@@ -18,67 +18,67 @@
PostLaunchCommand::PostLaunchCommand(LaunchTask *parent) : LaunchStep(parent)
{
- auto instance = m_parent->instance();
- m_command = instance->getPostExitCommand();
- m_process.setProcessEnvironment(instance->createEnvironment());
- connect(&m_process, &LoggedProcess::log, this, &PostLaunchCommand::logLines);
- connect(&m_process, &LoggedProcess::stateChanged, this, &PostLaunchCommand::on_state);
+ auto instance = m_parent->instance();
+ m_command = instance->getPostExitCommand();
+ m_process.setProcessEnvironment(instance->createEnvironment());
+ connect(&m_process, &LoggedProcess::log, this, &PostLaunchCommand::logLines);
+ connect(&m_process, &LoggedProcess::stateChanged, this, &PostLaunchCommand::on_state);
}
void PostLaunchCommand::executeTask()
{
- QString postlaunch_cmd = m_parent->substituteVariables(m_command);
- emit logLine(tr("Running Post-Launch command: %1").arg(postlaunch_cmd), MessageLevel::MultiMC);
- m_process.start(postlaunch_cmd);
+ QString postlaunch_cmd = m_parent->substituteVariables(m_command);
+ emit logLine(tr("Running Post-Launch command: %1").arg(postlaunch_cmd), MessageLevel::MultiMC);
+ m_process.start(postlaunch_cmd);
}
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)
- {
- case LoggedProcess::Aborted:
- case LoggedProcess::Crashed:
- case LoggedProcess::FailedToStart:
- {
- auto error = getError();
- emit logLine(error, MessageLevel::Fatal);
- emitFailed(error);
- return;
- }
- case LoggedProcess::Finished:
- {
- if(m_process.exitCode() != 0)
- {
- auto error = getError();
- emit logLine(error, MessageLevel::Fatal);
- emitFailed(error);
- }
- else
- {
- emit logLine(tr("Post-Launch command ran successfully.\n\n"), MessageLevel::MultiMC);
- emitSucceeded();
- }
- }
- default:
- break;
- }
+ 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:
+ {
+ auto error = getError();
+ emit logLine(error, MessageLevel::Fatal);
+ emitFailed(error);
+ return;
+ }
+ case LoggedProcess::Finished:
+ {
+ if(m_process.exitCode() != 0)
+ {
+ auto error = getError();
+ emit logLine(error, MessageLevel::Fatal);
+ emitFailed(error);
+ }
+ else
+ {
+ emit logLine(tr("Post-Launch command ran successfully.\n\n"), MessageLevel::MultiMC);
+ emitSucceeded();
+ }
+ }
+ default:
+ break;
+ }
}
void PostLaunchCommand::setWorkingDirectory(const QString &wd)
{
- m_process.setWorkingDirectory(wd);
+ m_process.setWorkingDirectory(wd);
}
bool PostLaunchCommand::abort()
{
- auto state = m_process.state();
- if (state == LoggedProcess::Running || state == LoggedProcess::Starting)
- {
- m_process.kill();
- }
- return true;
+ auto state = m_process.state();
+ if (state == LoggedProcess::Running || state == LoggedProcess::Starting)
+ {
+ m_process.kill();
+ }
+ return true;
}
diff --git a/api/logic/launch/steps/PostLaunchCommand.h b/api/logic/launch/steps/PostLaunchCommand.h
index 88681cbc..efba62d9 100644
--- a/api/logic/launch/steps/PostLaunchCommand.h
+++ b/api/logic/launch/steps/PostLaunchCommand.h
@@ -20,22 +20,22 @@
class PostLaunchCommand: public LaunchStep
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit PostLaunchCommand(LaunchTask *parent);
- virtual ~PostLaunchCommand() {};
+ explicit PostLaunchCommand(LaunchTask *parent);
+ virtual ~PostLaunchCommand() {};
- virtual void executeTask();
- virtual bool abort();
- virtual bool canAbort() const
- {
- return true;
- }
- void setWorkingDirectory(const QString &wd);
+ virtual void executeTask();
+ virtual bool abort();
+ virtual bool canAbort() const
+ {
+ return true;
+ }
+ void setWorkingDirectory(const QString &wd);
private slots:
- void on_state(LoggedProcess::State state);
+ void on_state(LoggedProcess::State state);
private:
- LoggedProcess m_process;
- QString m_command;
+ LoggedProcess m_process;
+ QString m_command;
};
diff --git a/api/logic/launch/steps/PreLaunchCommand.cpp b/api/logic/launch/steps/PreLaunchCommand.cpp
index 7c37d5cb..c5e1e373 100644
--- a/api/logic/launch/steps/PreLaunchCommand.cpp
+++ b/api/logic/launch/steps/PreLaunchCommand.cpp
@@ -18,68 +18,68 @@
PreLaunchCommand::PreLaunchCommand(LaunchTask *parent) : LaunchStep(parent)
{
- auto instance = m_parent->instance();
- m_command = instance->getPreLaunchCommand();
- m_process.setProcessEnvironment(instance->createEnvironment());
- connect(&m_process, &LoggedProcess::log, this, &PreLaunchCommand::logLines);
- connect(&m_process, &LoggedProcess::stateChanged, this, &PreLaunchCommand::on_state);
+ auto instance = m_parent->instance();
+ m_command = instance->getPreLaunchCommand();
+ m_process.setProcessEnvironment(instance->createEnvironment());
+ connect(&m_process, &LoggedProcess::log, this, &PreLaunchCommand::logLines);
+ connect(&m_process, &LoggedProcess::stateChanged, this, &PreLaunchCommand::on_state);
}
void PreLaunchCommand::executeTask()
{
- //FIXME: where to put this?
- QString prelaunch_cmd = m_parent->substituteVariables(m_command);
- emit logLine(tr("Running Pre-Launch command: %1").arg(prelaunch_cmd), MessageLevel::MultiMC);
- m_process.start(prelaunch_cmd);
+ //FIXME: where to put this?
+ QString prelaunch_cmd = m_parent->substituteVariables(m_command);
+ emit logLine(tr("Running Pre-Launch command: %1").arg(prelaunch_cmd), MessageLevel::MultiMC);
+ m_process.start(prelaunch_cmd);
}
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)
- {
- case LoggedProcess::Aborted:
- case LoggedProcess::Crashed:
- case LoggedProcess::FailedToStart:
- {
- auto error = getError();
- emit logLine(error, MessageLevel::Fatal);
- emitFailed(error);
- return;
- }
- case LoggedProcess::Finished:
- {
- if(m_process.exitCode() != 0)
- {
- auto error = getError();
- emit logLine(error, MessageLevel::Fatal);
- emitFailed(error);
- }
- else
- {
- emit logLine(tr("Pre-Launch command ran successfully.\n\n"), MessageLevel::MultiMC);
- emitSucceeded();
- }
- }
- default:
- break;
- }
+ 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:
+ {
+ auto error = getError();
+ emit logLine(error, MessageLevel::Fatal);
+ emitFailed(error);
+ return;
+ }
+ case LoggedProcess::Finished:
+ {
+ if(m_process.exitCode() != 0)
+ {
+ auto error = getError();
+ emit logLine(error, MessageLevel::Fatal);
+ emitFailed(error);
+ }
+ else
+ {
+ emit logLine(tr("Pre-Launch command ran successfully.\n\n"), MessageLevel::MultiMC);
+ emitSucceeded();
+ }
+ }
+ default:
+ break;
+ }
}
void PreLaunchCommand::setWorkingDirectory(const QString &wd)
{
- m_process.setWorkingDirectory(wd);
+ m_process.setWorkingDirectory(wd);
}
bool PreLaunchCommand::abort()
{
- auto state = m_process.state();
- if (state == LoggedProcess::Running || state == LoggedProcess::Starting)
- {
- m_process.kill();
- }
- return true;
+ auto state = m_process.state();
+ if (state == LoggedProcess::Running || state == LoggedProcess::Starting)
+ {
+ m_process.kill();
+ }
+ return true;
}
diff --git a/api/logic/launch/steps/PreLaunchCommand.h b/api/logic/launch/steps/PreLaunchCommand.h
index 5c955923..861e5be7 100644
--- a/api/logic/launch/steps/PreLaunchCommand.h
+++ b/api/logic/launch/steps/PreLaunchCommand.h
@@ -20,22 +20,22 @@
class PreLaunchCommand: public LaunchStep
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit PreLaunchCommand(LaunchTask *parent);
- virtual ~PreLaunchCommand() {};
+ explicit PreLaunchCommand(LaunchTask *parent);
+ virtual ~PreLaunchCommand() {};
- virtual void executeTask();
- virtual bool abort();
- virtual bool canAbort() const
- {
- return true;
- }
- void setWorkingDirectory(const QString &wd);
+ virtual void executeTask();
+ virtual bool abort();
+ virtual bool canAbort() const
+ {
+ return true;
+ }
+ void setWorkingDirectory(const QString &wd);
private slots:
- void on_state(LoggedProcess::State state);
+ void on_state(LoggedProcess::State state);
private:
- LoggedProcess m_process;
- QString m_command;
+ LoggedProcess m_process;
+ QString m_command;
};
diff --git a/api/logic/launch/steps/TextPrint.cpp b/api/logic/launch/steps/TextPrint.cpp
index f307b1fd..0c1f320c 100644
--- a/api/logic/launch/steps/TextPrint.cpp
+++ b/api/logic/launch/steps/TextPrint.cpp
@@ -2,28 +2,28 @@
TextPrint::TextPrint(LaunchTask * parent, const QStringList &lines, MessageLevel::Enum level) : LaunchStep(parent)
{
- m_lines = lines;
- m_level = level;
+ m_lines = lines;
+ m_level = level;
}
TextPrint::TextPrint(LaunchTask *parent, const QString &line, MessageLevel::Enum level) : LaunchStep(parent)
{
- m_lines.append(line);
- m_level = level;
+ m_lines.append(line);
+ m_level = level;
}
void TextPrint::executeTask()
{
- emit logLines(m_lines, m_level);
- emitSucceeded();
+ emit logLines(m_lines, m_level);
+ emitSucceeded();
}
bool TextPrint::canAbort() const
{
- return true;
+ return true;
}
bool TextPrint::abort()
{
- emitFailed("Aborted.");
- return true;
+ emitFailed("Aborted.");
+ return true;
}
diff --git a/api/logic/launch/steps/TextPrint.h b/api/logic/launch/steps/TextPrint.h
index 3e3e06cb..48b8cf6f 100644
--- a/api/logic/launch/steps/TextPrint.h
+++ b/api/logic/launch/steps/TextPrint.h
@@ -27,17 +27,17 @@
class MULTIMC_LOGIC_EXPORT TextPrint: public LaunchStep
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit TextPrint(LaunchTask *parent, const QStringList &lines, MessageLevel::Enum level);
- explicit TextPrint(LaunchTask *parent, const QString &line, MessageLevel::Enum level);
- virtual ~TextPrint(){};
+ 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();
+ virtual void executeTask();
+ virtual bool canAbort() const;
+ virtual bool abort();
private:
- QStringList m_lines;
- MessageLevel::Enum m_level;
+ QStringList m_lines;
+ MessageLevel::Enum m_level;
};
diff --git a/api/logic/launch/steps/Update.cpp b/api/logic/launch/steps/Update.cpp
index d057febb..65f24391 100644
--- a/api/logic/launch/steps/Update.cpp
+++ b/api/logic/launch/steps/Update.cpp
@@ -18,63 +18,63 @@
void Update::executeTask()
{
- if(m_aborted)
- {
- emitFailed(tr("Task aborted."));
- return;
- }
- m_updateTask.reset(m_parent->instance()->createUpdateTask(m_mode));
- if(m_updateTask)
- {
- connect(m_updateTask.get(), SIGNAL(finished()), this, SLOT(updateFinished()));
- connect(m_updateTask.get(), &Task::progress, this, &Task::setProgress);
- connect(m_updateTask.get(), &Task::status, this, &Task::setStatus);
- emit progressReportingRequest();
- return;
- }
- emitSucceeded();
+ if(m_aborted)
+ {
+ emitFailed(tr("Task aborted."));
+ return;
+ }
+ m_updateTask.reset(m_parent->instance()->createUpdateTask(m_mode));
+ if(m_updateTask)
+ {
+ connect(m_updateTask.get(), SIGNAL(finished()), this, SLOT(updateFinished()));
+ connect(m_updateTask.get(), &Task::progress, this, &Task::setProgress);
+ connect(m_updateTask.get(), &Task::status, this, &Task::setStatus);
+ emit progressReportingRequest();
+ return;
+ }
+ emitSucceeded();
}
void Update::proceed()
{
- m_updateTask->start();
+ m_updateTask->start();
}
void Update::updateFinished()
{
- if(m_updateTask->wasSuccessful())
- {
- m_updateTask.reset();
- emitSucceeded();
- }
- else
- {
- QString reason = tr("Instance update failed because: %1.\n\n").arg(m_updateTask->failReason());
- m_updateTask.reset();
- emit logLine(reason, MessageLevel::Fatal);
- emitFailed(reason);
- }
+ if(m_updateTask->wasSuccessful())
+ {
+ m_updateTask.reset();
+ emitSucceeded();
+ }
+ else
+ {
+ QString reason = tr("Instance update failed because: %1.\n\n").arg(m_updateTask->failReason());
+ m_updateTask.reset();
+ emit logLine(reason, MessageLevel::Fatal);
+ emitFailed(reason);
+ }
}
bool Update::canAbort() const
{
- if(m_updateTask)
- {
- return m_updateTask->canAbort();
- }
- return true;
+ if(m_updateTask)
+ {
+ return m_updateTask->canAbort();
+ }
+ return true;
}
bool Update::abort()
{
- m_aborted = true;
- if(m_updateTask)
- {
- if(m_updateTask->canAbort())
- {
- return m_updateTask->abort();
- }
- }
- return true;
+ m_aborted = true;
+ if(m_updateTask)
+ {
+ if(m_updateTask->canAbort())
+ {
+ return m_updateTask->abort();
+ }
+ }
+ return true;
}
diff --git a/api/logic/launch/steps/Update.h b/api/logic/launch/steps/Update.h
index 7a14011a..baa0b80e 100644
--- a/api/logic/launch/steps/Update.h
+++ b/api/logic/launch/steps/Update.h
@@ -24,22 +24,22 @@
// FIXME: stupid. should be defined by the instance type? or even completely abstracted away...
class Update: public LaunchStep
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit Update(LaunchTask *parent, Net::Mode mode):LaunchStep(parent), m_mode(mode) {};
- virtual ~Update() {};
+ explicit Update(LaunchTask *parent, Net::Mode mode):LaunchStep(parent), m_mode(mode) {};
+ virtual ~Update() {};
- void executeTask() override;
- bool canAbort() const override;
- void proceed() override;
+ void executeTask() override;
+ bool canAbort() const override;
+ void proceed() override;
public slots:
- bool abort() override;
+ bool abort() override;
private slots:
- void updateFinished();
+ void updateFinished();
private:
- shared_qobject_ptr<Task> m_updateTask;
- bool m_aborted = false;
- Net::Mode m_mode = Net::Mode::Offline;
+ shared_qobject_ptr<Task> m_updateTask;
+ bool m_aborted = false;
+ Net::Mode m_mode = Net::Mode::Offline;
};