MCPcopy Create free account
hub / github.com/ElyPrismLauncher/Launcher / modrinthVersionsTask

Method modrinthVersionsTask

launcher/modplatform/EnsureMetadataTask.cpp:214–261  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

212// Modrinth
213
214Task::Ptr EnsureMetadataTask::modrinthVersionsTask()
215{
216 auto hash_type = ModPlatform::ProviderCapabilities::hashType(ModPlatform::ResourceProvider::MODRINTH).first();
217
218 auto [ver_task, response] = modrinth_api.currentVersions(m_resources.keys(), hash_type);
219
220 // Prevents unfortunate timings when aborting the task
221 if (!ver_task)
222 return Task::Ptr{ nullptr };
223
224 connect(ver_task.get(), &Task::succeeded, this, [this, response] {
225 QJsonParseError parse_error{};
226 QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
227 if (parse_error.error != QJsonParseError::NoError) {
228 qWarning() << "Error while parsing JSON response from Modrinth::CurrentVersions at" << parse_error.offset
229 << "reason:" << parse_error.errorString();
230 qWarning() << *response;
231
232 failed(parse_error.errorString());
233 return;
234 }
235
236 try {
237 auto entries = Json::requireObject(doc);
238 for (auto& hash : m_resources.keys()) {
239 auto resource = m_resources.find(hash).value();
240 try {
241 auto entry = Json::requireObject(entries, hash);
242
243 setStatus(tr("Parsing API response from Modrinth for '%1'...").arg(resource->name()));
244 qDebug() << "Getting version for" << resource->name() << "from Modrinth";
245
246 m_tempVersions.insert(hash, Modrinth::loadIndexedPackVersion(entry));
247 } catch (Json::JsonException& e) {
248 qDebug() << e.cause();
249 qDebug() << entries;
250
251 emitFail(resource);
252 }
253 }
254 } catch (Json::JsonException& e) {
255 qDebug() << e.cause();
256 qDebug() << doc;
257 }
258 });
259
260 return ver_task;
261}
262
263Task::Ptr EnsureMetadataTask::modrinthProjectsTask()
264{

Callers

nothing calls this directly

Calls 9

requireObjectFunction · 0.85
currentVersionsMethod · 0.80
errorStringMethod · 0.80
valueMethod · 0.80
insertMethod · 0.80
causeMethod · 0.80
getMethod · 0.45
findMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected