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

Method netJobFinished

launcher/modplatform/flame/FileResolvingTask.cpp:90–198  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88}
89
90void Flame::FileResolvingTask::netJobFinished()
91{
92 setProgress(1, 3);
93 // job to check modrinth for blocked projects
94 QJsonDocument doc;
95 QJsonArray array;
96
97 try {
98 doc = Json::requireDocument(*m_result);
99 array = Json::requireArray(doc.object()["data"]);
100 } catch (Json::JsonException& e) {
101 qCritical() << "Non-JSON data returned from the CF API";
102 qCritical() << e.cause();
103
104 emitFailed(tr("Invalid data returned from the API."));
105
106 return;
107 }
108
109 QStringList hashes;
110 for (QJsonValueRef file : array) {
111 try {
112 auto obj = Json::requireObject(file);
113 auto version = FlameMod::loadIndexedPackVersion(obj);
114 auto fileid = version.fileId.toInt();
115 Q_ASSERT(fileid != 0);
116 Q_ASSERT(m_manifest.files.contains(fileid));
117 m_manifest.files[fileid].version = version;
118 auto url = QUrl(version.downloadUrl, QUrl::TolerantMode);
119 if (!url.isValid() && "sha1" == version.hash_type && !version.hash.isEmpty()) {
120 hashes.push_back(version.hash);
121 }
122 } catch (Json::JsonException& e) {
123 qCritical() << "Non-JSON data returned from the CF API";
124 qCritical() << e.cause();
125
126 emitFailed(tr("Invalid data returned from the API."));
127
128 return;
129 }
130 }
131 if (hashes.isEmpty()) {
132 getFlameProjects();
133 return;
134 }
135 m_result.reset(new QByteArray());
136 m_task = modrinthAPI.currentVersions(hashes, "sha1", m_result);
137 (dynamic_cast<NetJob*>(m_task.get()))->setAskRetry(false);
138 auto step_progress = std::make_shared<TaskStepProgress>();
139 connect(m_task.get(), &Task::finished, this, [this, step_progress]() {
140 step_progress->state = TaskStepState::Succeeded;
141 stepProgress(*step_progress);
142 QJsonParseError parse_error{};
143 QJsonDocument doc = QJsonDocument::fromJson(*m_result, &parse_error);
144 if (parse_error.error != QJsonParseError::NoError) {
145 qWarning() << "Error while parsing JSON response from Modrinth::CurrentVersions at " << parse_error.offset
146 << " reason: " << parse_error.errorString();
147 qWarning() << *m_result;

Callers

nothing calls this directly

Calls 15

requireDocumentFunction · 0.85
requireArrayFunction · 0.85
requireObjectFunction · 0.85
QUrlClass · 0.85
objectMethod · 0.80
causeMethod · 0.80
currentVersionsMethod · 0.80
setAskRetryMethod · 0.80
errorStringMethod · 0.80
containsMethod · 0.45
isValidMethod · 0.45

Tested by

no test coverage detected