MCPcopy Create free account
hub / github.com/DFHack/dfhack / load_file

Function load_file

library/modules/Persistence.cpp:271–294  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

269}
270
271static bool load_file(const std::filesystem::path & path, int entity_id) {
272 Json::Value json;
273 try {
274 std::ifstream file(path);
275 file >> json;
276 } catch (std::exception &) {
277 // empty file?
278 return false;
279 }
280
281 if (json.isArray()) {
282 auto & entity_store_entry = store[entity_id];
283 for (auto & value : json) {
284 std::shared_ptr<Persistence::DataEntry> entry(new Persistence::DataEntry(entity_id, value));
285 if (entry->key.empty())
286 continue;
287 // ensure fake DF IDs remain globally unique
288 next_fake_df_id = std::min(next_fake_df_id, entry->fake_df_id - 1);
289 add_entry(entity_store_entry, entry);
290 }
291 }
292
293 return true;
294}
295
296void Persistence::Internal::load(color_ostream& out) {
297 CoreSuspender suspend;

Callers 1

loadMethod · 0.70

Calls 2

add_entryFunction · 0.85
emptyMethod · 0.45

Tested by

no test coverage detected