MCPcopy Create free account
hub / github.com/FreesmTeam/FreesmLauncher / modrinthVersionsTask

Method modrinthVersionsTask

launcher/modplatform/EnsureMetadataTask.cpp:218–266  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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