summaryrefslogtreecommitdiff
path: root/archived/projt-launcher/launcher/modplatform/ModIndex.cpp
blob: 7499b81720308429a9b55f4cc2b142944dbc6b07 (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
// 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.
 *
 * === Upstream License Block (Do Not Modify) ==============================
 *
 *
 *
 *  Prism Launcher - Minecraft Launcher
 *  Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
 *  Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
 *
 *  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.
 *
 * ======================================================================== */

#include "modplatform/ModIndex.h"

#include <QCryptographicHash>
#include <QDebug>
#include <QIODevice>

namespace ModPlatform
{

	static const QMap<QString, IndexedVersionType::VersionType> s_indexed_version_type_names = {
		{ "release", IndexedVersionType::VersionType::Release },
		{ "beta", IndexedVersionType::VersionType::Beta },
		{ "alpha", IndexedVersionType::VersionType::Alpha }
	};

	static const QList<ModLoaderType> loaderList = { NeoForge, Forge,	 Cauldron,		LiteLoader,	  Quilt,
													 Fabric,   Babric,	 BTA,			LegacyFabric, Ornithe,
													 Rift,	   Risugami, StationLoader, ModLoaderMP,  Optifine };

	QList<ModLoaderType> modLoaderTypesToList(ModLoaderTypes flags)
	{
		QList<ModLoaderType> flagList;
		for (auto flag : loaderList)
		{
			if (flags.testFlag(flag))
			{
				flagList.append(flag);
			}
		}
		return flagList;
	}

	IndexedVersionType::IndexedVersionType(const QString& type) : IndexedVersionType(enumFromString(type))
	{}

	IndexedVersionType::IndexedVersionType(const IndexedVersionType::VersionType& type)
	{
		m_type = type;
	}

	IndexedVersionType::IndexedVersionType(const IndexedVersionType& other)
	{
		m_type = other.m_type;
	}

	IndexedVersionType& IndexedVersionType::operator=(const IndexedVersionType& other)
	{
		m_type = other.m_type;
		return *this;
	}

	const QString IndexedVersionType::toString(const IndexedVersionType::VersionType& type)
	{
		return s_indexed_version_type_names.key(type, "unknown");
	}

	IndexedVersionType::VersionType IndexedVersionType::enumFromString(const QString& type)
	{
		return s_indexed_version_type_names.value(type, IndexedVersionType::VersionType::Unknown);
	}

	const char* ProviderCapabilities::name(ResourceProvider p)
	{
		switch (p)
		{
			case ResourceProvider::MODRINTH: return "modrinth";
			case ResourceProvider::FLAME: return "curseforge";
		}
		return {};
	}

	QString ProviderCapabilities::readableName(ResourceProvider p)
	{
		switch (p)
		{
			case ResourceProvider::MODRINTH: return "Modrinth";
			case ResourceProvider::FLAME: return "CurseForge";
		}
		return {};
	}

	QStringList ProviderCapabilities::hashType(ResourceProvider p)
	{
		switch (p)
		{
			case ResourceProvider::MODRINTH: return { "sha512", "sha1" };
			case ResourceProvider::FLAME:
				// Try newer formats first, fall back to old format
				return { "sha1", "md5", "murmur2" };
		}
		return {};
	}

	QString getMetaURL(ResourceProvider provider, QVariant projectID)
	{
		return ((provider == ModPlatform::ResourceProvider::FLAME) ? "https://www.curseforge.com/projects/"
																   : "https://modrinth.com/mod/")
			 + projectID.toString();
	}

	auto getModLoaderAsString(ModLoaderType type) -> const QString
	{
		switch (type)
		{
			case NeoForge: return "neoforge";
			case Forge: return "forge";
			case Cauldron: return "cauldron";
			case LiteLoader: return "liteloader";
			case Fabric: return "fabric";
			case Quilt: return "quilt";
			case DataPack: return "datapack";
			case Babric: return "babric";
			case BTA: return "bta-babric";
			case LegacyFabric: return "legacy-fabric";
			case Ornithe: return "ornithe";
			case Rift: return "rift";
			case Risugami: return "risugami";
			case StationLoader: return "station-loader";
			case ModLoaderMP: return "modloadermp";
			case Optifine: return "optifine";
			default: break;
		}
		return "";
	}

	auto getModLoaderFromString(QString type) -> ModLoaderType
	{
		if (type == "neoforge")
			return NeoForge;
		if (type == "forge")
			return Forge;
		if (type == "cauldron")
			return Cauldron;
		if (type == "liteloader")
			return LiteLoader;
		if (type == "fabric")
			return Fabric;
		if (type == "quilt")
			return Quilt;
		if (type == "babric")
			return Babric;
		if (type == "bta-babric")
			return BTA;
		if (type == "legacy-fabric")
			return LegacyFabric;
		if (type == "ornithe")
			return Ornithe;
		if (type == "rift")
			return Rift;
		if (type == "risugami")
			return Risugami;
		if (type == "station-loader")
			return StationLoader;
		if (type == "modloadermp")
			return ModLoaderMP;
		if (type == "optifine")
			return Optifine;
		return {};
	}

	QString SideUtils::toString(Side side)
	{
		switch (side)
		{
			case Side::ClientSide: return "client";
			case Side::ServerSide: return "server";
			case Side::UniversalSide: return "both";
			case Side::NoSide: break;
		}
		return {};
	}

	Side SideUtils::fromString(QString side)
	{
		if (side == "client")
			return Side::ClientSide;
		if (side == "server")
			return Side::ServerSide;
		if (side == "both")
			return Side::UniversalSide;
		return Side::UniversalSide;
	}
} // namespace ModPlatform