| 42 | } |
| 43 | |
| 44 | bool FlameCreationTask::updateInstance() |
| 45 | { |
| 46 | auto instance_list = APPLICATION->instances(); |
| 47 | |
| 48 | // FIXME: How to handle situations when there's more than one install already for a given modpack? |
| 49 | auto inst = instance_list->getInstanceByManagedName(originalName()); |
| 50 | |
| 51 | if (!inst) { |
| 52 | inst = instance_list->getInstanceById(originalName()); |
| 53 | |
| 54 | if (!inst) |
| 55 | return false; |
| 56 | } |
| 57 | |
| 58 | QString index_path(FS::PathCombine(m_stagingPath, "manifest.json")); |
| 59 | |
| 60 | try { |
| 61 | Flame::loadManifest(m_pack, index_path); |
| 62 | } catch (const JSONValidationError& e) { |
| 63 | setError(tr("Could not understand pack manifest:\n") + e.cause()); |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | auto version_id = inst->getManagedPackVersionName(); |
| 68 | auto version_str = !version_id.isEmpty() ? tr(" (version %1)").arg(version_id) : ""; |
| 69 | |
| 70 | auto info = CustomMessageBox::selectable( |
| 71 | m_parent, tr("Similar modpack was found!"), |
| 72 | tr("One or more of your instances are from this same modpack%1. Do you want to create a " |
| 73 | "separate instance, or update the existing one?\n\nNOTE: Make sure you made a backup of your important instance data before " |
| 74 | "updating, as worlds can be corrupted and some configuration may be lost (due to pack overrides).") |
| 75 | .arg(version_str), QMessageBox::Information, QMessageBox::Ok | QMessageBox::Reset | QMessageBox::Abort); |
| 76 | info->setButtonText(QMessageBox::Ok, tr("Update existing instance")); |
| 77 | info->setButtonText(QMessageBox::Abort, tr("Create new instance")); |
| 78 | info->setButtonText(QMessageBox::Reset, tr("Cancel")); |
| 79 | |
| 80 | info->exec(); |
| 81 | |
| 82 | if (info->clickedButton() == info->button(QMessageBox::Abort)) |
| 83 | return false; |
| 84 | |
| 85 | if (info->clickedButton() == info->button(QMessageBox::Reset)) { |
| 86 | m_abort = true; |
| 87 | return false; |
| 88 | } |
| 89 | |
| 90 | QDir old_inst_dir(inst->instanceRoot()); |
| 91 | |
| 92 | QString old_index_folder(FS::PathCombine(old_inst_dir.absolutePath(), "flame")); |
| 93 | QString old_index_path(FS::PathCombine(old_index_folder, "manifest.json")); |
| 94 | |
| 95 | QFileInfo old_index_file(old_index_path); |
| 96 | if (old_index_file.exists()) { |
| 97 | Flame::Manifest old_pack; |
| 98 | Flame::loadManifest(old_pack, old_index_path); |
| 99 | |
| 100 | auto& old_files = old_pack.files; |
| 101 |
nothing calls this directly
no test coverage detected