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

Method chanListDownloadFinished

launcher/updater/UpdateChecker.cpp:227–288  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

225}
226
227void UpdateChecker::chanListDownloadFinished(bool notifyNoUpdate)
228{
229 chanListJob.reset();
230
231 QJsonParseError jsonError;
232 QJsonDocument jsonDoc = QJsonDocument::fromJson(chanlistData, &jsonError);
233 chanlistData.clear();
234 if (jsonError.error != QJsonParseError::NoError)
235 {
236 // TODO: Report errors to the user.
237 qCritical() << "Failed to parse channel list JSON:" << jsonError.errorString() << "at" << jsonError.offset;
238 m_chanListLoading = false;
239 return;
240 }
241
242 QJsonObject object = jsonDoc.object();
243
244 bool success = false;
245 int formatVersion = object.value("format_version").toVariant().toInt(&success);
246 if (formatVersion != CHANLIST_FORMAT || !success)
247 {
248 qCritical()
249 << "Failed to check for updates. Channel list format version mismatch. We're using"
250 << CHANLIST_FORMAT << "server has" << formatVersion;
251 m_chanListLoading = false;
252 return;
253 }
254
255 // Load channels into a temporary array.
256 QList<ChannelListEntry> loadedChannels;
257 QJsonArray channelArray = object.value("channels").toArray();
258 for (QJsonValue chanVal : channelArray)
259 {
260 QJsonObject channelObj = chanVal.toObject();
261 ChannelListEntry entry {
262 channelObj.value("id").toVariant().toString(),
263 channelObj.value("name").toVariant().toString(),
264 channelObj.value("description").toVariant().toString(),
265 channelObj.value("url").toVariant().toString()
266 };
267 if (entry.id.isEmpty() || entry.name.isEmpty() || entry.url.isEmpty())
268 {
269 qCritical() << "Channel list entry with empty ID, name, or URL. Skipping.";
270 continue;
271 }
272 loadedChannels.append(entry);
273 }
274
275 // Swap the channel list we just loaded into the object's channel list.
276 m_channels.swap(loadedChannels);
277
278 m_chanListLoading = false;
279 m_chanListLoaded = true;
280 qDebug() << "Successfully loaded UpdateChecker channel list.";
281
282 // If we're waiting to check for updates, do that now.
283 if (m_checkUpdateWaiting) {
284 checkForUpdate(m_deferredUpdateChannel, notifyNoUpdate);

Callers

nothing calls this directly

Calls 7

fromJsonFunction · 0.85
objectMethod · 0.80
isEmptyMethod · 0.80
appendMethod · 0.80
resetMethod · 0.45
clearMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected