MCPcopy Create free account
hub / github.com/PrismLauncher/PrismLauncher / Load

Method Load

launcher/net/HttpMetaCache.cpp:222–284  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

220}
221
222void HttpMetaCache::Load()
223{
224 if (m_index_file.isNull())
225 return;
226
227 QFile index(m_index_file);
228 if (!index.open(QIODevice::ReadOnly))
229 return;
230
231 QJsonParseError parseError;
232 QJsonDocument json = QJsonDocument::fromJson(index.readAll(), &parseError);
233
234 // Fail if the JSON is invalid.
235 if (parseError.error != QJsonParseError::NoError) {
236 qCritical() << QString("Failed to parse HttpMetaCache file: %1 at offset %2")
237 .arg(parseError.errorString(), QString::number(parseError.offset))
238 .toUtf8();
239 return;
240 }
241
242 // Make sure the root is an object.
243 if (!json.isObject()) {
244 qCritical() << "HttpMetaCache root should be an object.";
245 return;
246 }
247
248 auto root = json.object();
249
250 // check file version first
251 auto version_val = root["version"].toString();
252 if (version_val != "1")
253 return;
254
255 // read the entry array
256 auto array = root["entries"].toArray();
257 for (auto element : array) {
258 auto element_obj = element.toObject();
259 auto base = element_obj["base"].toString();
260 if (!m_entries.contains(base))
261 continue;
262
263 auto& entrymap = m_entries[base];
264
265 auto foo = new MetaEntry();
266 foo->m_baseId = base;
267 foo->m_relativePath = element_obj["path"].toString();
268 foo->m_md5sum = element_obj["md5sum"].toString();
269 foo->m_etag = element_obj["etag"].toString();
270 foo->m_local_changed_timestamp = element_obj["last_changed_timestamp"].toDouble();
271 foo->m_remote_changed_timestamp = element_obj["remote_changed_timestamp"].toString();
272
273 foo->makeEternal(element_obj[QStringLiteral("eternal")].toBool());
274 if (!foo->isEternal()) {
275 foo->m_current_age = element_obj["current_age"].toDouble();
276 foo->m_max_age = element_obj["max_age"].toDouble();
277 }
278
279 // presumed innocent until closer examination

Callers 1

ApplicationMethod · 0.80

Calls 9

readAllMethod · 0.80
errorStringMethod · 0.80
objectMethod · 0.80
makeEternalMethod · 0.80
isEternalMethod · 0.80
QStringClass · 0.50
openMethod · 0.45
toStringMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected