MCPcopy Create free account
hub / github.com/MultiMC/Launcher / processModrinth

Method processModrinth

launcher/InstanceImportTask.cpp:253–419  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

251}
252
253void InstanceImportTask::processModrinth() {
254 std::vector<Modrinth::File> files;
255 QString minecraftVersion, fabricVersion, quiltVersion, forgeVersion;
256 try
257 {
258 QString indexPath = FS::PathCombine(m_stagingPath, "modrinth.index.json");
259 auto doc = Json::requireDocument(indexPath);
260 auto obj = Json::requireObject(doc, "modrinth.index.json");
261 int formatVersion = Json::requireInteger(obj, "formatVersion", "modrinth.index.json");
262 if (formatVersion == 1)
263 {
264 auto game = Json::requireString(obj, "game", "modrinth.index.json");
265 if (game != "minecraft")
266 {
267 throw JSONValidationError("Unknown game: " + game);
268 }
269
270 auto jsonFiles = Json::requireIsArrayOf<QJsonObject>(obj, "files", "modrinth.index.json");
271 for(auto & obj: jsonFiles) {
272 Modrinth::File file;
273 file.path = Json::requireString(obj, "path");
274
275 // env doesn't have to be present, in that case mod is required
276 auto env = Json::ensureObject(obj, "env");
277 auto clientEnv = Json::ensureString(env, "client", "required");
278
279 if(clientEnv == "required") {
280 // NOOP
281 }
282 else if(clientEnv == "optional") {
283 file.path += ".disabled";
284 }
285 else if(clientEnv == "unsupported") {
286 continue;
287 }
288
289 QJsonObject hashes = Json::requireObject(obj, "hashes");
290 QString hash;
291 QCryptographicHash::Algorithm hashAlgorithm;
292 hash = Json::ensureString(hashes, "sha256");
293 hashAlgorithm = QCryptographicHash::Sha256;
294 if (hash.isEmpty())
295 {
296 hash = Json::ensureString(hashes, "sha512");
297 hashAlgorithm = QCryptographicHash::Sha512;
298 if (hash.isEmpty())
299 {
300 hash = Json::ensureString(hashes, "sha1");
301 hashAlgorithm = QCryptographicHash::Sha1;
302 if (hash.isEmpty())
303 {
304 throw JSONValidationError("No hash found for: " + file.path);
305 }
306 }
307 }
308 file.hash = QByteArray::fromHex(hash.toLatin1());
309 file.hashAlgorithm = hashAlgorithm;
310 // Do not use requireUrl, which uses StrictMode, instead use QUrl's default TolerantMode (as Modrinth seems to incorrectly handle spaces)

Callers

nothing calls this directly

Calls 15

PathCombineFunction · 0.85
requireDocumentFunction · 0.85
requireObjectFunction · 0.85
isEmptyMethod · 0.80
keyMethod · 0.80
causeMethod · 0.80
getPackProfileMethod · 0.80
buildingFromScratchMethod · 0.80
setComponentVersionMethod · 0.80
setIconKeyMethod · 0.80
networkMethod · 0.80
addNetActionMethod · 0.80

Tested by

no test coverage detected