From 67d5651278d5194811942e4e2b699617ed9cb700 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Mon, 2 Sep 2024 09:34:27 +0200 Subject: [PATCH] SPE-2451: Fix of faulty manifest file Decision tree on (un)selected repo / installed printers --- src/slic3r/GUI/PresetArchiveDatabase.cpp | 41 ++++++++++++++++++------ 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/src/slic3r/GUI/PresetArchiveDatabase.cpp b/src/slic3r/GUI/PresetArchiveDatabase.cpp index 93922abc1a..f011b91d53 100644 --- a/src/slic3r/GUI/PresetArchiveDatabase.cpp +++ b/src/slic3r/GUI/PresetArchiveDatabase.cpp @@ -409,21 +409,44 @@ void PresetArchiveDatabase::set_installed_printer_repositories(const std::vector // set correct repos as having installed printer for (const std::string &used_id : used_ids) { // find archive with id and is used + std::vector selected_uuid; + std::vector unselected_uuid; for (const auto &archive : m_archive_repositories) { if (archive->get_manifest().id != used_id) { continue; } const std::string uuid = archive->get_uuid(); - - const auto& it = m_selected_repositories_uuid.find(uuid); - assert(it != m_selected_repositories_uuid.end()); - if (it->second == false) { - continue; - } - - // set archive as has installed printer - m_has_installed_printer_repositories_uuid[uuid] = true; + if (m_selected_repositories_uuid[uuid]) { + selected_uuid.emplace_back(uuid); + } else { + unselected_uuid.emplace_back(uuid); + } } + + if (selected_uuid.empty() && unselected_uuid.empty()) { + // there is id in used_ids that is not in m_archive_repositories - BAD + assert(true); + continue; + } else if (selected_uuid.size() == 1){ + // regular case + m_has_installed_printer_repositories_uuid[selected_uuid.front()] = true; + } else if (selected_uuid.size() > 1) { + // this should not happen, only one repo of same id should be selected (online / local conflict) + assert(true); + // select first one to solve the conflict + m_has_installed_printer_repositories_uuid[selected_uuid.front()] = true; + // unselect the rest + for (size_t i = 1; i < selected_uuid.size(); i++) { + m_selected_repositories_uuid[selected_uuid[i]] = false; + } + } else if (selected_uuid.empty()) { + // This is a rare case, where there are no selected repos with matching id but id has installed printers + // Repro: install printer, unselect repo in the next run of wizard, next, cancel wizard, run wizard again and press finish. + // Solution: Select the first unselected + m_has_installed_printer_repositories_uuid[unselected_uuid.front()] = true; + m_selected_repositories_uuid[unselected_uuid.front()] = true; + } + } save_app_manifest_json(); }