| 35 | } |
| 36 | |
| 37 | void Flame::FileResolvingTask::netJobFinished() |
| 38 | { |
| 39 | setProgress(1, 3); |
| 40 | // job to check modrinth for blocked projects |
| 41 | auto job = new NetJob("Modrinth check", m_network); |
| 42 | blockedProjects = QMap<File *,QByteArray *>(); |
| 43 | QJsonDocument doc; |
| 44 | |
| 45 | try { |
| 46 | doc = Json::requireDocument(*result); |
| 47 | } |
| 48 | catch (const JSONValidationError &e) { |
| 49 | qDebug() << "Flame::FileResolvingTask: Json Validation error: " << e.what(); |
| 50 | emitFailed(e.what()); |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | auto array = Json::requireArray(doc.object()["data"]); |
| 55 | for (QJsonValueRef file : array) { |
| 56 | auto fileid = Json::requireInteger(Json::requireObject(file)["id"]); |
| 57 | auto& out = m_toProcess.files[fileid]; |
| 58 | try { |
| 59 | out.parseFromObject(Json::requireObject(file)); |
| 60 | } catch (const JSONValidationError& e) { |
| 61 | qDebug() << "Blocked mod on curseforge" << out.fileName; |
| 62 | auto hash = out.hash; |
| 63 | if(!hash.isEmpty()) { |
| 64 | auto url = QString("https://api.modrinth.com/v2/version_file/%1?algorithm=sha1").arg(hash); |
| 65 | auto output = new QByteArray(); |
| 66 | auto dl = Net::Download::makeByteArray(QUrl(url), output); |
| 67 | QObject::connect(dl.get(), &Net::Download::succeeded, [&out]() { |
| 68 | out.resolved = true; |
| 69 | }); |
| 70 | |
| 71 | job->addNetAction(dl); |
| 72 | blockedProjects.insert(&out, output); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | connect(job, &NetJob::finished, this, &Flame::FileResolvingTask::modrinthCheckFinished); |
| 77 | |
| 78 | job->start(); |
| 79 | } |
| 80 | |
| 81 | void Flame::FileResolvingTask::modrinthCheckFinished() { |
| 82 | setProgress(2, 3); |
nothing calls this directly
no test coverage detected