| 170 | } |
| 171 | |
| 172 | bool ModInfo::removeMod(unsigned int index) |
| 173 | { |
| 174 | QMutexLocker locker(&s_Mutex); |
| 175 | |
| 176 | if (index >= s_Collection.size()) { |
| 177 | throw Exception(tr("remove: invalid mod index %1").arg(index)); |
| 178 | } |
| 179 | |
| 180 | ModInfo::Ptr modInfo = s_Collection[index]; |
| 181 | |
| 182 | // remove the actual mod (this is the most likely to fail so we do this first) |
| 183 | if (modInfo->isRegular()) { |
| 184 | if (!shellDelete(QStringList(modInfo->absolutePath()), true)) { |
| 185 | reportError( |
| 186 | tr("remove: failed to delete mod '%1' directory").arg(modInfo->name())); |
| 187 | return false; |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | // update the indices |
| 192 | s_ModsByName.erase(s_ModsByName.find(modInfo->name())); |
| 193 | |
| 194 | auto iter = s_ModsByModID.find( |
| 195 | std::pair<QString, int>(modInfo->gameName(), modInfo->nexusId())); |
| 196 | if (iter != s_ModsByModID.end()) { |
| 197 | std::vector<unsigned int> indices = iter->second; |
| 198 | indices.erase(std::remove(indices.begin(), indices.end(), index), indices.end()); |
| 199 | s_ModsByModID[std::pair<QString, int>(modInfo->gameName(), modInfo->nexusId())] = |
| 200 | indices; |
| 201 | } |
| 202 | |
| 203 | // finally, remove the mod from the collection |
| 204 | s_Collection.erase(s_Collection.begin() + index); |
| 205 | |
| 206 | // and update the indices |
| 207 | updateIndices(); |
| 208 | return true; |
| 209 | } |
| 210 | |
| 211 | unsigned int ModInfo::getIndex(const QString& name) |
| 212 | { |