| 294 | } |
| 295 | |
| 296 | void Persistence::Internal::load(color_ostream& out) { |
| 297 | CoreSuspender suspend; |
| 298 | LastLoadSaveTickCountUpdater tickCountUpdater; |
| 299 | |
| 300 | clear(out); |
| 301 | |
| 302 | std::string world_name = World::ReadWorldFolder(); |
| 303 | std::filesystem::path save_path = getSavePath(world_name); |
| 304 | std::vector<std::filesystem::path> files; |
| 305 | if (0 != Filesystem::listdir(save_path, files)) { |
| 306 | DEBUG(persistence,out).print("not loading state; save directory doesn't exist: '{}'\n", save_path); |
| 307 | return; |
| 308 | } |
| 309 | |
| 310 | bool found = false; |
| 311 | for (auto & fname : files) { |
| 312 | int entity_id = Persistence::WORLD_ENTITY_ID; |
| 313 | if (fname != "dfhack-world.dat" && !get_entity_id(fname.string(), entity_id)) |
| 314 | continue; |
| 315 | |
| 316 | found = true; |
| 317 | std::filesystem::path path = save_path / fname; |
| 318 | if (!load_file(path, entity_id)) |
| 319 | out.printerr("Cannot load data from: '{}'\n", path); |
| 320 | } |
| 321 | |
| 322 | if (found) |
| 323 | return; |
| 324 | |
| 325 | // new file formats not found; attempt to load legacy file |
| 326 | const std::filesystem::path legacy_fname = getSaveFilePath(world_name, "legacy-data"); |
| 327 | if (Filesystem::exists(legacy_fname)) { |
| 328 | int synthesized_entity_id = Persistence::WORLD_ENTITY_ID; |
| 329 | if (World::IsSiteLoaded()) |
| 330 | synthesized_entity_id = World::GetCurrentSiteId(); |
| 331 | load_file(legacy_fname, synthesized_entity_id); |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | static bool is_good_entity_id(int entity_id) { |
| 336 | return entity_id == Persistence::WORLD_ENTITY_ID || entity_id >= 0; |
nothing calls this directly
no test coverage detected