Adds a new object to the index by: 1. creating a partial index, 2. validating, 3. creating a full index entry
| 390 | |
| 391 | // Adds a new object to the index by: 1. creating a partial index, 2. validating, 3. creating a full index entry |
| 392 | static void addObjectToIndex(const fs::path filepath) |
| 393 | { |
| 394 | ObjectHeader objHeader{}; |
| 395 | try |
| 396 | { |
| 397 | FileStream stream; |
| 398 | stream.open(filepath, StreamMode::read); |
| 399 | if (!stream.isOpen()) |
| 400 | { |
| 401 | Logging::error("Unable to open object index file."); |
| 402 | return; |
| 403 | } |
| 404 | objHeader = stream.readValue<ObjectHeader>(); |
| 405 | } |
| 406 | catch (const std::runtime_error& ex) |
| 407 | { |
| 408 | Logging::error("Unable to read object index header: {}", ex.what()); |
| 409 | return; |
| 410 | } |
| 411 | |
| 412 | const auto partialNewEntry = createPartialNewEntry(objHeader, filepath); |
| 413 | _installedObjectList.push_back(partialNewEntry); |
| 414 | |
| 415 | const auto loadResult = loadTemporaryObject(objHeader); |
| 416 | _installedObjectList.pop_back(); |
| 417 | |
| 418 | if (!loadResult.has_value()) |
| 419 | { |
| 420 | Logging::error("Unable to load the object '{}', can't add to index", objHeader.getName()); |
| 421 | return; |
| 422 | } |
| 423 | |
| 424 | // Load full entry into temp buffer. |
| 425 | // 0x009D1CC8 |
| 426 | const auto newEntry = createNewEntry(objHeader, filepath, loadResult.value()); |
| 427 | |
| 428 | freeTemporaryObject(); |
| 429 | |
| 430 | auto duplicate = std::ranges::find(_installedObjectList, objHeader, &ObjectIndexEntry::_header); |
| 431 | if (duplicate != _installedObjectList.end()) |
| 432 | { |
| 433 | Logging::error("Duplicate object found {}, {} won't be added to index", duplicate->_filepath, newEntry._filepath); |
| 434 | return; |
| 435 | } |
| 436 | _installedObjectList.push_back(newEntry); // Previously ordered by name... |
| 437 | } |
| 438 | |
| 439 | static void addObjectsInFolder(fs::path path, bool shouldRecurse, uint32_t numObjects) |
| 440 | { |
no test coverage detected