2015-02-03 03:55:30 +05:30
|
|
|
/* Copyright 2013-2015 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
|
|
|
|
*
|
2013-03-22 19:10:55 +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>
|
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
|
|
|
{
|
2013-03-22 19:10:55 +05:30
|
|
|
Q_OBJECT
|
2015-01-28 03:01:07 +05:30
|
|
|
protected:
|
2015-07-10 04:41:06 +05:30
|
|
|
explicit LaunchTask(InstancePtr instance);
|
2015-01-28 03:01:07 +05:30
|
|
|
void init();
|
2013-03-22 19:10:55 +05:30
|
|
|
|
2015-07-21 06:08:15 +05:30
|
|
|
public:
|
|
|
|
enum State
|
|
|
|
{
|
|
|
|
NotStarted,
|
|
|
|
Running,
|
|
|
|
Waiting,
|
|
|
|
Failed,
|
|
|
|
Aborted,
|
|
|
|
Finished
|
|
|
|
};
|
|
|
|
|
2015-01-28 03:01:07 +05:30
|
|
|
public: /* methods */
|
2015-07-21 06:08:15 +05:30
|
|
|
static std::shared_ptr<LaunchTask> create(InstancePtr inst);
|
2015-07-10 04:41:06 +05:30
|
|
|
virtual ~LaunchTask() {};
|
2014-02-16 04:40:45 +05:30
|
|
|
|
2015-07-21 06:08:15 +05:30
|
|
|
void appendStep(std::shared_ptr<LaunchStep> step);
|
|
|
|
void prependStep(std::shared_ptr<LaunchStep> step);
|
|
|
|
void setCensorFilter(QMap<QString, QString> filter);
|
|
|
|
|
2014-05-18 22:37:01 +05:30
|
|
|
InstancePtr instance()
|
2013-11-23 06:11:28 +05:30
|
|
|
{
|
|
|
|
return m_instance;
|
|
|
|
}
|
|
|
|
|
2015-07-21 06:08:15 +05:30
|
|
|
void setPid(qint64 pid)
|
2015-02-08 22:26:14 +05:30
|
|
|
{
|
2015-07-21 06:08:15 +05:30
|
|
|
m_pid = pid;
|
2015-02-08 22:26:14 +05:30
|
|
|
}
|
|
|
|
|
2015-07-21 06:08:15 +05:30
|
|
|
qint64 pid()
|
|
|
|
{
|
|
|
|
return m_pid;
|
|
|
|
}
|
2015-05-12 01:51:37 +05:30
|
|
|
|
2015-01-28 03:01:07 +05:30
|
|
|
/**
|
|
|
|
* @brief prepare the process for launch (for multi-stage launch)
|
|
|
|
*/
|
2015-07-04 23:32:43 +05:30
|
|
|
virtual void executeTask() override;
|
2013-11-04 07:23:05 +05:30
|
|
|
|
2015-01-28 03:01:07 +05:30
|
|
|
/**
|
|
|
|
* @brief launch the armed instance
|
|
|
|
*/
|
2015-07-21 06:08:15 +05:30
|
|
|
void proceed();
|
2013-11-04 07:23:05 +05:30
|
|
|
|
2015-01-28 03:01:07 +05:30
|
|
|
/**
|
|
|
|
* @brief abort launch
|
|
|
|
*/
|
2015-07-21 06:08:15 +05:30
|
|
|
virtual bool abort() override;
|
2015-06-16 12:49:55 +05:30
|
|
|
|
2015-07-22 12:31:04 +05:30
|
|
|
public:
|
2015-07-21 06:08:15 +05:30
|
|
|
QString substituteVariables(const QString &cmd) const;
|
|
|
|
QString censorPrivateInfo(QString in);
|
2015-01-28 03:01:07 +05:30
|
|
|
|
|
|
|
protected: /* methods */
|
2015-07-05 05:24:30 +05:30
|
|
|
virtual void emitFailed(QString reason);
|
|
|
|
virtual void emitSucceeded();
|
2015-07-10 03:36:05 +05:30
|
|
|
|
2013-02-22 20:47:31 +05:30
|
|
|
signals:
|
2015-07-04 23:32:43 +05:30
|
|
|
/**
|
|
|
|
* @brief emitted when the launch preparations are done
|
|
|
|
*/
|
2015-07-05 05:24:30 +05:30
|
|
|
void readyForLaunch();
|
2015-07-04 23:32:43 +05:30
|
|
|
|
2015-07-26 21:25:29 +05:30
|
|
|
void requestProgress(Task *task);
|
|
|
|
|
|
|
|
void requestLogging();
|
|
|
|
|
2013-03-22 19:10:55 +05:30
|
|
|
/**
|
|
|
|
* @brief emitted when we want to log something
|
|
|
|
* @param text the text to log
|
|
|
|
* @param level the level to log at
|
|
|
|
*/
|
2013-11-04 07:23:05 +05:30
|
|
|
void log(QString text, MessageLevel::Enum level = MessageLevel::MultiMC);
|
2013-02-22 20:47:31 +05:30
|
|
|
|
2015-07-21 06:08:15 +05:30
|
|
|
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();
|
2015-07-26 21:25:29 +05:30
|
|
|
void onProgressReportingRequested();
|
2015-05-12 01:51:37 +05:30
|
|
|
|
2015-07-21 06:08:15 +05:30
|
|
|
protected: /* data */
|
2015-01-28 03:01:07 +05:30
|
|
|
InstancePtr m_instance;
|
2015-07-21 06:08:15 +05:30
|
|
|
QList <std::shared_ptr<LaunchStep>> m_steps;
|
|
|
|
QMap<QString, QString> m_censorFilter;
|
|
|
|
int currentStep = -1;
|
|
|
|
State state = NotStarted;
|
|
|
|
qint64 m_pid = -1;
|
2013-02-22 20:47:31 +05:30
|
|
|
};
|