MCPcopy Create free account
hub / github.com/ModOrganizer2/modorganizer / removeMod

Method removeMod

src/modinfo.cpp:172–209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

170}
171
172bool 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
211unsigned int ModInfo::getIndex(const QString& name)
212{

Callers

nothing calls this directly

Calls 10

removeFunction · 0.85
sizeMethod · 0.45
isRegularMethod · 0.45
absolutePathMethod · 0.45
nameMethod · 0.45
findMethod · 0.45
gameNameMethod · 0.45
nexusIdMethod · 0.45
endMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected