MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / tryLoadIndex

Function tryLoadIndex

src/OpenLoco/src/Objects/ObjectIndex.cpp:497–541  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

495 }
496
497 static bool tryLoadIndex(const ObjectFoldersState& currentState)
498 {
499 Core::Timer loadTimer;
500
501 const auto indexPath = Environment::getPathNoWarning(Environment::PathId::plugin1);
502 if (!fs::exists(indexPath))
503 {
504 Logging::verbose("Object index does not exist.");
505 return false;
506 }
507 FileStream stream;
508 stream.open(indexPath, StreamMode::read);
509 if (!stream.isOpen())
510 {
511 Logging::error("Unable to load the object index.");
512 return false;
513 }
514
515 try
516 {
517 auto header = deserialiseHeader(stream);
518 if (header.version != kCurrentIndexVersion || header.state != currentState)
519 {
520 return false;
521 }
522 else
523 {
524 _installedObjectList = deserialiseIndex(stream);
525 if (_installedObjectList.empty())
526 {
527 return false;
528 }
529 Logging::verbose("Loaded object index in {} milliseconds.", loadTimer.elapsed());
530 }
531 }
532 catch (const std::runtime_error& ex)
533 {
534 Logging::error("Unable to load the object index: {}", ex.what());
535 return false;
536 }
537
538 reloadAll();
539
540 return true;
541 }
542
543 // 0x00470F3C
544 void loadIndex()

Callers 1

loadIndexFunction · 0.70

Calls 11

getPathNoWarningFunction · 0.85
verboseFunction · 0.85
errorFunction · 0.85
deserialiseHeaderFunction · 0.85
deserialiseIndexFunction · 0.85
reloadAllFunction · 0.85
openMethod · 0.80
isOpenMethod · 0.80
elapsedMethod · 0.80
whatMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected