MCPcopy Create free account
hub / github.com/PolyMC/PolyMC / modrinthCheckFinished

Method modrinthCheckFinished

launcher/modplatform/flame/FileResolvingTask.cpp:81–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79}
80
81void Flame::FileResolvingTask::modrinthCheckFinished() {
82 setProgress(2, 3);
83 qDebug() << "Finished with blocked mods : " << blockedProjects.size();
84
85 for (auto it = blockedProjects.keyBegin(); it != blockedProjects.keyEnd(); it++) {
86 auto &out = *it;
87 auto bytes = blockedProjects[out];
88 if (!out->resolved) {
89 delete bytes;
90 continue;
91 }
92 QJsonDocument doc = QJsonDocument::fromJson(*bytes);
93 auto obj = doc.object();
94 auto array = Json::requireArray(obj,"files");
95 for (auto file: array) {
96 auto fileObj = Json::requireObject(file);
97 auto primary = Json::requireBoolean(fileObj,"primary");
98 if (primary) {
99 out->url = Json::requireUrl(fileObj,"url");
100 qDebug() << "Found alternative on modrinth " << out->fileName;
101 break;
102 }
103 }
104 delete bytes;
105 }
106 //copy to an output list and filter out projects found on modrinth
107 auto block = new QList<File *>();
108 auto it = blockedProjects.keys();
109 std::copy_if(it.begin(), it.end(), std::back_inserter(*block), [](File *f) {
110 return !f->resolved;
111 });
112 //Display not found mods early
113 if (!block->empty()) {
114 //blocked mods found, we need the slug for displaying.... we need another job :D !
115 auto slugJob = new NetJob("Slug Job", m_network);
116 auto slugs = QVector<QByteArray>(block->size());
117 auto index = 0;
118 for (auto fileInfo: *block) {
119 auto projectId = fileInfo->projectId;
120 slugs[index] = QByteArray();
121 auto url = QString("https://api.curseforge.com/v1/mods/%1").arg(projectId);
122 auto dl = Net::Download::makeByteArray(url, &slugs[index]);
123 slugJob->addNetAction(dl);
124 index++;
125 }
126 connect(slugJob, &NetJob::succeeded, this, [slugs, this, slugJob, block]() {
127 slugJob->deleteLater();
128 auto index = 0;
129 for (const auto &slugResult: slugs) {
130 auto json = QJsonDocument::fromJson(slugResult);
131 auto base = Json::requireString(Json::requireObject(Json::requireObject(Json::requireObject(json),"data"),"links"),
132 "websiteUrl");
133 auto mod = block->at(index);
134 auto link = QString("%1/download/%2").arg(base, QString::number(mod->fileId));
135 mod->websiteUrl = link;
136 index++;
137 }
138 emitSucceeded();

Callers

nothing calls this directly

Calls 13

fromJsonFunction · 0.85
requireArrayFunction · 0.85
requireObjectFunction · 0.85
QByteArrayClass · 0.85
QStringClass · 0.85
objectMethod · 0.80
beginMethod · 0.80
endMethod · 0.80
addNetActionMethod · 0.80
sizeMethod · 0.45
emptyMethod · 0.45
atMethod · 0.45

Tested by

no test coverage detected