| 251 | } |
| 252 | |
| 253 | void 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) |
nothing calls this directly
no test coverage detected