From 0a19f0433992be5f9791c8869380d09cd06b66b8 Mon Sep 17 00:00:00 2001 From: Tannin Date: Fri, 22 Mar 2013 18:46:40 +0100 Subject: - support for grouping filters for mod list (incomplete) - offering multiple options for mod names during installation - support for renaming profiles - updated installer plugins - minor bugfixes --- src/modinfo.cpp | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) (limited to 'src/modinfo.cpp') diff --git a/src/modinfo.cpp b/src/modinfo.cpp index b8ef834f..28bdf789 100644 --- a/src/modinfo.cpp +++ b/src/modinfo.cpp @@ -44,7 +44,7 @@ using namespace MOShared; std::vector ModInfo::s_Collection; std::map ModInfo::s_ModsByName; -std::map ModInfo::s_ModsByModID; +std::map > ModInfo::s_ModsByModID; int ModInfo::s_NextID; QMutex ModInfo::s_Mutex(QMutex::Recursive); @@ -128,20 +128,21 @@ ModInfo::Ptr ModInfo::getByIndex(unsigned int index) } -ModInfo::Ptr ModInfo::getByModID(int modID, bool missingAcceptable) +std::vector ModInfo::getByModID(int modID) { QMutexLocker locker(&s_Mutex); - std::map::iterator iter = s_ModsByModID.find(modID); + auto iter = s_ModsByModID.find(modID); if (iter == s_ModsByModID.end()) { - if (missingAcceptable) { - return ModInfo::Ptr(); - } else { - throw MyException(tr("invalid mod id %1").arg(modID)); - } + return std::vector(); + } + + std::vector result; + for (auto idxIter = iter->second.begin(); idxIter != iter->second.end(); ++idxIter) { + result.push_back(getByIndex(*idxIter)); } - return getByIndex(iter->second); + return result; } @@ -157,12 +158,11 @@ bool ModInfo::removeMod(unsigned int index) ModInfo::Ptr modInfo = s_Collection[index]; s_ModsByName.erase(s_ModsByName.find(modInfo->name())); - //TODO this is a bit more complicated since multiple mods may have the - // same mod id but only one appears in the index - std::map::iterator iter = s_ModsByModID.find(modInfo->getNexusID()) ; - if ((iter != s_ModsByModID.end()) && - (iter->second == index)) { - s_ModsByModID.erase(iter); + auto iter = s_ModsByModID.find(modInfo->getNexusID()); + if (iter != s_ModsByModID.end()) { + std::vector indices = iter->second; + std::remove(indices.begin(), indices.end(), index); + s_ModsByModID[modInfo->getNexusID()] = indices; } // physically remove the mod directory @@ -234,12 +234,7 @@ void ModInfo::updateIndices() QString modName = s_Collection[i]->name(); int modID = s_Collection[i]->getNexusID(); s_ModsByName[modName] = i; - - // don't overwrite a modid-entry with a backup entry. This is a bit of a workaround - if ((s_ModsByModID.find(modID) == s_ModsByModID.end()) || - !backupRegEx.exactMatch(modName)) { - s_ModsByModID[modID] = i; - } + s_ModsByModID[modID].push_back(i); } } -- cgit v1.3.1