summaryrefslogtreecommitdiff
path: root/archived/projt-launcher/launcher/launch/LaunchPipeline.hpp
blob: 53e9ec3bfe533b42e51ae1d79321bb803f764602 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: 2026 Project Tick
// SPDX-FileContributor: Project Tick Team
/*
 *  ProjT Launcher - Minecraft Launcher
 *  Copyright (C) 2026 Project Tick
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, version 3.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, write to the Free Software Foundation,
 *  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#pragma once

#include <QObjectPtr.h>
#include <minecraft/MinecraftInstance.h>
#include <QList>
#include <QMap>
#include <QProcessEnvironment>

#include "LaunchLineRouter.hpp"
#include "LaunchLogModel.hpp"
#include "LaunchStage.hpp"
#include "LaunchVariableExpander.hpp"
#include "MessageLevel.h"

class BaseInstance;

namespace projt::launch
{
	class LaunchPipeline : public Task
	{
		Q_OBJECT
	  public:
		using Ptr	   = shared_qobject_ptr<LaunchPipeline>;
		using StagePtr = shared_qobject_ptr<LaunchStage>;

		enum class State
		{
			Idle,
			Running,
			Waiting,
			Failed,
			Aborted,
			Finished
		};

		static Ptr create(MinecraftInstancePtr instance);
		explicit LaunchPipeline(MinecraftInstancePtr instance);
		~LaunchPipeline() override = default;

		void appendStage(StagePtr stage);
		void prependStage(StagePtr stage);
		void setCensorFilter(QMap<QString, QString> filter);

		MinecraftInstancePtr instance() const
		{
			return m_instanceRef;
		}

		void setPid(qint64 pid)
		{
			m_processId = pid;
		}

		qint64 pid() const
		{
			return m_processId;
		}

		void executeTask() override;
		void proceed();
		bool abort() override;
		bool canAbort() const override;

		shared_qobject_ptr<LaunchLogModel> logModel();

		QString substituteVariables(const QString& cmd, bool isLaunch = false) const;
		QString censorPrivateInfo(QString input) const;

	  signals:
		void readyForLaunch();
		void requestProgress(Task* task);

	  public slots:
		void onLogLines(const QStringList& lines, MessageLevel::Enum defaultLevel = MessageLevel::Launcher);
		void onLogLine(QString line, MessageLevel::Enum defaultLevel = MessageLevel::Launcher);
		void onReadyForLaunch();
		void onStageFinished();
		void onProgressReportingRequested();

	  protected:
		void emitFailed(QString reason) override;
		void emitSucceeded() override;

	  private:
		void advanceStage();
		void closeStages(bool successful, const QString& error);

		MinecraftInstancePtr m_instanceRef;
		shared_qobject_ptr<LaunchLogModel> m_logStore;
		QList<StagePtr> m_stageQueue;
		QList<StagePtr> m_stageHistory;
		StagePtr m_activeStage;
		QMap<QString, QString> m_redactions;
		State m_state	   = State::Idle;
		qint64 m_processId = -1;
		LaunchLineRouter m_lineRouter;
		LaunchVariableExpander m_expander;
	};
} // namespace projt::launch