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

Method Load

launcher/net/HttpMetaCache.cpp:197–244  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

195}
196
197void HttpMetaCache::Load()
198{
199 if (m_index_file.isNull())
200 return;
201
202 QFile index(m_index_file);
203 if (!index.open(QIODevice::ReadOnly))
204 return;
205
206 QJsonDocument json = QJsonDocument::fromJson(index.readAll());
207
208 auto root = Json::requireObject(json, "HttpMetaCache root");
209
210 // check file version first
211 auto version_val = Json::ensureString(root, "version");
212 if (version_val != "1")
213 return;
214
215 // read the entry array
216 auto array = Json::ensureArray(root, "entries");
217 for (auto element : array) {
218 auto element_obj = Json::ensureObject(element);
219 auto base = Json::ensureString(element_obj, "base");
220 if (!m_entries.contains(base))
221 continue;
222
223 auto& entrymap = m_entries[base];
224
225 auto foo = new MetaEntry();
226 foo->baseId = base;
227 foo->relativePath = Json::ensureString(element_obj, "path");
228 foo->md5sum = Json::ensureString(element_obj, "md5sum");
229 foo->etag = Json::ensureString(element_obj, "etag");
230 foo->local_changed_timestamp = Json::ensureDouble(element_obj, "last_changed_timestamp");
231 foo->remote_changed_timestamp = Json::ensureString(element_obj, "remote_changed_timestamp");
232
233 foo->makeEternal(Json::ensureBoolean(element_obj, "eternal", false));
234 if (!foo->isEternal()) {
235 foo->current_age = Json::ensureDouble(element_obj, "current_age");
236 foo->max_age = Json::ensureDouble(element_obj, "max_age");
237 }
238
239 // presumed innocent until closer examination
240 foo->stale = false;
241
242 entrymap.entry_list[foo->relativePath] = MetaEntryPtr(foo);
243 }
244}
245
246void HttpMetaCache::SaveEventually()
247{

Callers 1

ApplicationMethod · 0.80

Calls 6

fromJsonFunction · 0.85
requireObjectFunction · 0.85
openMethod · 0.80
makeEternalMethod · 0.80
isEternalMethod · 0.80
containsMethod · 0.45

Tested by

no test coverage detected