MCPcopy Create free account
hub / github.com/ElyPrismLauncher/Launcher / loadList

Method loadList

launcher/InstanceList.cpp:498–558  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

496}
497
498InstanceList::InstListError InstanceList::loadList()
499{
500 auto existingIds = getIdMapping(m_instances);
501
502 std::vector<std::unique_ptr<BaseInstance>> newList;
503
504 for (auto& id : discoverInstances()) {
505 if (existingIds.contains(id)) {
506 existingIds.remove(id);
507 qInfo() << "Should keep and soft-reload" << id;
508 } else {
509 std::unique_ptr<BaseInstance> instPtr = loadInstance(id);
510 if (instPtr) {
511 newList.push_back(std::move(instPtr));
512 }
513 }
514 }
515
516 // TODO: looks like a general algorithm with a few specifics inserted. Do something about it.
517 if (!existingIds.isEmpty()) {
518 // get the list of removed instances and sort it by their original index, from last to first
519 auto deadList = existingIds.values();
520 auto orderSortPredicate = [](const InstanceLocator& a, const InstanceLocator& b) -> bool { return a.second > b.second; };
521 std::sort(deadList.begin(), deadList.end(), orderSortPredicate);
522 // remove the contiguous ranges of rows
523 int front_bookmark = -1;
524 int back_bookmark = -1;
525 int currentItem = -1;
526 auto removeNow = [this, &front_bookmark, &back_bookmark, &currentItem]() {
527 beginRemoveRows(QModelIndex(), front_bookmark, back_bookmark);
528 m_instances.erase(m_instances.begin() + front_bookmark, m_instances.begin() + back_bookmark + 1);
529 endRemoveRows();
530 front_bookmark = -1;
531 back_bookmark = currentItem;
532 };
533 for (auto& removedItem : deadList) {
534 auto instPtr = removedItem.first;
535 instPtr->invalidate();
536 currentItem = removedItem.second;
537 if (back_bookmark == -1) {
538 // no bookmark yet
539 back_bookmark = currentItem;
540 } else if (currentItem == front_bookmark - 1) {
541 // part of contiguous sequence, continue
542 } else {
543 // seam between previous and current item
544 removeNow();
545 }
546 front_bookmark = currentItem;
547 }
548 if (back_bookmark != -1) {
549 removeNow();
550 }
551 }
552 if (newList.size()) {
553 add(newList);
554 }
555 m_dirty = false;

Callers 1

ApplicationMethod · 0.45

Calls 8

getIdMappingFunction · 0.85
moveFunction · 0.85
QModelIndexClass · 0.85
invalidateMethod · 0.80
containsMethod · 0.45
removeMethod · 0.45
isEmptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected