2019-01-17 01:44:24 +05:30
|
|
|
/* Copyright 2013-2019 MultiMC Contributors
|
2013-02-22 20:47:31 +05:30
|
|
|
*
|
|
|
|
* Authors: Orochimarufan <orochimarufan.x3@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
2018-07-15 18:21:05 +05:30
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-02-22 20:47:31 +05:30
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2013-11-04 07:23:05 +05:30
|
|
|
|
2013-07-29 04:29:35 +05:30
|
|
|
#pragma once
|
2013-02-22 20:47:31 +05:30
|
|
|
#include <QProcess>
|
2016-08-19 01:01:37 +05:30
|
|
|
#include <QObjectPtr.h>
|
|
|
|
#include "LogModel.h"
|
2013-07-29 04:29:35 +05:30
|
|
|
#include "BaseInstance.h"
|
2015-05-12 01:51:37 +05:30
|
|
|
#include "MessageLevel.h"
|
|
|
|
#include "LoggedProcess.h"
|
2015-07-21 06:08:15 +05:30
|
|
|
#include "LaunchStep.h"
|
2013-02-22 20:47:31 +05:30
|
|
|
|
2015-09-05 22:16:57 +05:30
|
|
|
#include "multimc_logic_export.h"
|
|
|
|
|
|
|
|
class MULTIMC_LOGIC_EXPORT LaunchTask: public Task
|
2013-02-22 20:47:31 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
Q_OBJECT
|
2015-01-28 03:01:07 +05:30
|
|
|
protected:
|
2018-07-15 18:21:05 +05:30
|
|
|
explicit LaunchTask(InstancePtr instance);
|
|
|
|
void init();
|
2013-03-22 19:10:55 +05:30
|
|
|
|
2015-07-21 06:08:15 +05:30
|
|
|
public:
|
2018-07-15 18:21:05 +05:30
|
|
|
enum State
|
|
|
|
{
|
|
|
|
NotStarted,
|
|
|
|
Running,
|
|
|
|
Waiting,
|
|
|
|
Failed,
|
|
|
|
Aborted,
|
|
|
|
Finished
|
|
|
|
};
|
2015-07-21 06:08:15 +05:30
|
|
|
|
2015-01-28 03:01:07 +05:30
|
|
|
public: /* methods */
|
2019-04-08 03:29:04 +05:30
|
|
|
static shared_qobject_ptr<LaunchTask> create(InstancePtr inst);
|
2018-07-15 18:21:05 +05:30
|
|
|
virtual ~LaunchTask() {};
|
2014-02-16 04:40:45 +05:30
|
|
|
|
2019-04-08 03:29:04 +05:30
|
|
|
void appendStep(shared_qobject_ptr<LaunchStep> step);
|
|
|
|
void prependStep(shared_qobject_ptr<LaunchStep> step);
|
2018-07-15 18:21:05 +05:30
|
|
|
void setCensorFilter(QMap<QString, QString> filter);
|
2015-07-21 06:08:15 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
InstancePtr instance()
|
|
|
|
{
|
|
|
|
return m_instance;
|
|
|
|
}
|
2013-11-23 06:11:28 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
void setPid(qint64 pid)
|
|
|
|
{
|
|
|
|
m_pid = pid;
|
|
|
|
}
|
2015-02-08 22:26:14 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
qint64 pid()
|
|
|
|
{
|
|
|
|
return m_pid;
|
|
|
|
}
|
2015-05-12 01:51:37 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
/**
|
|
|
|
* @brief prepare the process for launch (for multi-stage launch)
|
|
|
|
*/
|
|
|
|
virtual void executeTask() override;
|
2013-11-04 07:23:05 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
/**
|
|
|
|
* @brief launch the armed instance
|
|
|
|
*/
|
|
|
|
void proceed();
|
2013-11-04 07:23:05 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
/**
|
|
|
|
* @brief abort launch
|
|
|
|
*/
|
|
|
|
bool abort() override;
|
2016-11-26 22:36:08 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
bool canAbort() const override;
|
2015-06-16 12:49:55 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
shared_qobject_ptr<LogModel> getLogModel();
|
2016-08-19 01:01:37 +05:30
|
|
|
|
2015-07-22 12:31:04 +05:30
|
|
|
public:
|
2018-07-15 18:21:05 +05:30
|
|
|
QString substituteVariables(const QString &cmd) const;
|
|
|
|
QString censorPrivateInfo(QString in);
|
2015-01-28 03:01:07 +05:30
|
|
|
|
|
|
|
protected: /* methods */
|
2018-07-15 18:21:05 +05:30
|
|
|
virtual void emitFailed(QString reason) override;
|
|
|
|
virtual void emitSucceeded() override;
|
2015-07-10 03:36:05 +05:30
|
|
|
|
2013-02-22 20:47:31 +05:30
|
|
|
signals:
|
2018-07-15 18:21:05 +05:30
|
|
|
/**
|
|
|
|
* @brief emitted when the launch preparations are done
|
|
|
|
*/
|
|
|
|
void readyForLaunch();
|
2015-07-04 23:32:43 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
void requestProgress(Task *task);
|
2015-07-26 21:25:29 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
void requestLogging();
|
2015-07-26 21:25:29 +05:30
|
|
|
|
2015-07-21 06:08:15 +05:30
|
|
|
public slots:
|
2018-07-15 18:21:05 +05:30
|
|
|
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();
|
2015-05-12 01:51:37 +05:30
|
|
|
|
2016-11-15 07:21:22 +05:30
|
|
|
private: /*methods */
|
2018-07-15 18:21:05 +05:30
|
|
|
void finalizeSteps(bool successful, const QString & error);
|
2016-11-15 07:21:22 +05:30
|
|
|
|
2015-07-21 06:08:15 +05:30
|
|
|
protected: /* data */
|
2018-07-15 18:21:05 +05:30
|
|
|
InstancePtr m_instance;
|
|
|
|
shared_qobject_ptr<LogModel> m_logModel;
|
2019-04-08 03:29:04 +05:30
|
|
|
QList <shared_qobject_ptr<LaunchStep>> m_steps;
|
2018-07-15 18:21:05 +05:30
|
|
|
QMap<QString, QString> m_censorFilter;
|
|
|
|
int currentStep = -1;
|
|
|
|
State state = NotStarted;
|
|
|
|
qint64 m_pid = -1;
|
2013-02-22 20:47:31 +05:30
|
|
|
};
|