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

Method netJobFinished

launcher/modplatform/flame/FileResolvingTask.cpp:113–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111}
112
113void Flame::FileResolvingTask::netJobFinished(QByteArray* response)
114{
115 setProgress(1, 3);
116 // job to check modrinth for blocked projects
117 QJsonDocument doc;
118 QJsonArray array;
119
120 try {
121 doc = Json::requireDocument(*response);
122 array = Json::requireArray(doc.object()["data"]);
123 } catch (Json::JsonException& e) {
124 qCritical() << "Non-JSON data returned from the CF API";
125 qCritical() << e.cause();
126
127 emitFailed(tr("Invalid data returned from the API."));
128
129 return;
130 }
131
132 QStringList hashes;
133 for (QJsonValueRef file : array) {
134 try {
135 auto obj = Json::requireObject(file);
136 auto version = FlameMod::loadIndexedPackVersion(obj);
137 auto fileid = version.fileId.toInt();
138 Q_ASSERT(fileid != 0);
139 Q_ASSERT(m_manifest.files.contains(fileid));
140 m_manifest.files[fileid].version = version;
141 auto url = QUrl(version.downloadUrl, QUrl::TolerantMode);
142 if (!url.isValid() && "sha1" == version.hash_type && !version.hash.isEmpty()) {
143 hashes.push_back(version.hash);
144 }
145 } catch (Json::JsonException& e) {
146 qCritical() << "Non-JSON data returned from the CF API";
147 qCritical() << e.cause();
148
149 emitFailed(tr("Invalid data returned from the API."));
150
151 return;
152 }
153 }
154 if (hashes.isEmpty()) {
155 getFlameProjects();
156 return;
157 }
158 auto [modrinthTask, modrinthResponse] = modrinthAPI.currentVersions(hashes, "sha1");
159 m_task = modrinthTask;
160 (dynamic_cast<NetJob*>(m_task.get()))->setAskRetry(false);
161 auto step_progress = std::make_shared<TaskStepProgress>();
162 connect(m_task.get(), &Task::succeeded, this, [this, modrinthResponse, step_progress]() {
163 step_progress->state = TaskStepState::Succeeded;
164 stepProgress(*step_progress);
165 QJsonParseError parse_error{};
166 QJsonDocument doc = QJsonDocument::fromJson(*modrinthResponse, &parse_error);
167 if (parse_error.error != QJsonParseError::NoError) {
168 qWarning() << "Error while parsing JSON response from Modrinth::CurrentVersions at" << parse_error.offset
169 << "reason:" << parse_error.errorString();
170 qWarning() << *modrinthResponse;

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
isEmptyMethod · 0.45

Tested by

no test coverage detected