| 77 | } |
| 78 | |
| 79 | bool LegacyModList::update() |
| 80 | { |
| 81 | if (!m_dir.exists() || !m_dir.isReadable()) |
| 82 | return false; |
| 83 | |
| 84 | QList<Mod> orderedMods; |
| 85 | QList<Mod> newMods; |
| 86 | m_dir.refresh(); |
| 87 | auto folderContents = m_dir.entryInfoList(); |
| 88 | |
| 89 | // first, process the ordered items (if any) |
| 90 | OrderList listOrder = readListFile(m_list_file); |
| 91 | for (auto item : listOrder) |
| 92 | { |
| 93 | QFileInfo infoEnabled(m_dir.filePath(item.id)); |
| 94 | QFileInfo infoDisabled(m_dir.filePath(item.id + ".disabled")); |
| 95 | int idxEnabled = folderContents.indexOf(infoEnabled); |
| 96 | int idxDisabled = folderContents.indexOf(infoDisabled); |
| 97 | bool isEnabled; |
| 98 | // if both enabled and disabled versions are present, it's a special case... |
| 99 | if (idxEnabled >= 0 && idxDisabled >= 0) |
| 100 | { |
| 101 | // we only process the one we actually have in the order file. |
| 102 | // and exactly as we have it. |
| 103 | // THIS IS A CORNER CASE |
| 104 | isEnabled = item.enabled; |
| 105 | } |
| 106 | else |
| 107 | { |
| 108 | // only one is present. |
| 109 | // we pick the one that we found. |
| 110 | // we assume the mod was enabled/disabled by external means |
| 111 | isEnabled = idxEnabled >= 0; |
| 112 | } |
| 113 | int idx = isEnabled ? idxEnabled : idxDisabled; |
| 114 | QFileInfo &info = isEnabled ? infoEnabled : infoDisabled; |
| 115 | // if the file from the index file exists |
| 116 | if (idx != -1) |
| 117 | { |
| 118 | // remove from the actual folder contents list |
| 119 | folderContents.takeAt(idx); |
| 120 | // append the new mod |
| 121 | orderedMods.append(info); |
| 122 | } |
| 123 | } |
| 124 | // if there are any untracked files... append them sorted at the end |
| 125 | if (folderContents.size()) |
| 126 | { |
| 127 | for (auto entry : folderContents) |
| 128 | { |
| 129 | newMods.append(entry); |
| 130 | } |
| 131 | internalSort(newMods); |
| 132 | orderedMods.append(newMods); |
| 133 | } |
| 134 | mods.swap(orderedMods); |
| 135 | return true; |
| 136 | } |
no test coverage detected