| 51 | {} |
| 52 | |
| 53 | void ModFolderLoadTask::executeTask() |
| 54 | { |
| 55 | if (thread() != m_thread_to_spawn_into) |
| 56 | connect(this, &Task::finished, this->thread(), &QThread::quit); |
| 57 | |
| 58 | if (m_is_indexed) { |
| 59 | // Read metadata first |
| 60 | getFromMetadata(); |
| 61 | } |
| 62 | |
| 63 | // Read JAR files that don't have metadata |
| 64 | m_mods_dir.refresh(); |
| 65 | for (auto entry : m_mods_dir.entryInfoList()) { |
| 66 | Mod* mod(new Mod(entry)); |
| 67 | |
| 68 | if (mod->enabled()) { |
| 69 | if (m_result->mods.contains(mod->internal_id())) { |
| 70 | m_result->mods[mod->internal_id()]->setStatus(ModStatus::Installed); |
| 71 | // Delete the object we just created, since a valid one is already in the mods list. |
| 72 | delete mod; |
| 73 | } |
| 74 | else { |
| 75 | m_result->mods[mod->internal_id()] = mod; |
| 76 | m_result->mods[mod->internal_id()]->setStatus(ModStatus::NoMetadata); |
| 77 | } |
| 78 | } |
| 79 | else { |
| 80 | QString chopped_id = mod->internal_id().chopped(9); |
| 81 | if (m_result->mods.contains(chopped_id)) { |
| 82 | m_result->mods[mod->internal_id()] = mod; |
| 83 | |
| 84 | auto metadata = m_result->mods[chopped_id]->metadata(); |
| 85 | if (metadata) { |
| 86 | mod->setMetadata(*metadata); |
| 87 | |
| 88 | m_result->mods[mod->internal_id()]->setStatus(ModStatus::Installed); |
| 89 | m_result->mods.remove(chopped_id); |
| 90 | } |
| 91 | } |
| 92 | else { |
| 93 | m_result->mods[mod->internal_id()] = mod; |
| 94 | m_result->mods[mod->internal_id()]->setStatus(ModStatus::NoMetadata); |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | // Remove orphan metadata to prevent issues |
| 100 | // See https://github.com/PolyMC/PolyMC/issues/996 |
| 101 | if (m_clean_orphan) { |
| 102 | QMutableMapIterator iter(m_result->mods); |
| 103 | while (iter.hasNext()) { |
| 104 | auto mod = iter.next().value(); |
| 105 | if (mod->status() == ModStatus::NotInstalled) { |
| 106 | mod->destroy(m_index_dir, false); |
| 107 | iter.remove(); |
| 108 | } |
| 109 | } |
| 110 | } |
nothing calls this directly
no test coverage detected