MCPcopy Create free account
hub / github.com/MultiMC/Launcher / Load

Method Load

launcher/net/HttpMetaCache.cpp:177–223  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

175}
176
177void HttpMetaCache::Load()
178{
179 if(m_index_file.isNull())
180 return;
181
182 QFile index(m_index_file);
183 if (!index.open(QIODevice::ReadOnly))
184 return;
185
186 QJsonDocument json = QJsonDocument::fromJson(index.readAll());
187 if (!json.isObject())
188 return;
189 auto root = json.object();
190 // check file version first
191 auto version_val = root.value("version");
192 if (!version_val.isString())
193 return;
194 if (version_val.toString() != "1")
195 return;
196
197 // read the entry array
198 auto entries_val = root.value("entries");
199 if (!entries_val.isArray())
200 return;
201 QJsonArray array = entries_val.toArray();
202 for (auto element : array)
203 {
204 if (!element.isObject())
205 return;
206 auto element_obj = element.toObject();
207 QString base = element_obj.value("base").toString();
208 if (!m_entries.contains(base))
209 continue;
210 auto &entrymap = m_entries[base];
211 auto foo = new MetaEntry();
212 foo->baseId = base;
213 QString path = foo->relativePath = element_obj.value("path").toString();
214 foo->md5sum = element_obj.value("md5sum").toString();
215 foo->etag = element_obj.value("etag").toString();
216 foo->local_changed_timestamp = element_obj.value("last_changed_timestamp").toDouble();
217 foo->remote_changed_timestamp =
218 element_obj.value("remote_changed_timestamp").toString();
219 // presumed innocent until closer examination
220 foo->stale = false;
221 entrymap.entry_list[path] = MetaEntryPtr(foo);
222 }
223}
224
225void HttpMetaCache::SaveEventually()
226{

Callers 1

ApplicationMethod · 0.80

Calls 5

fromJsonFunction · 0.85
openMethod · 0.80
objectMethod · 0.80
toStringMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected