From 3dbee687260a02fa523071ec3f351652cb386144 Mon Sep 17 00:00:00 2001 From: Chris Bessent Date: Sat, 16 Jan 2021 17:59:24 -0700 Subject: Make modlist.txt less case sensitive This should make it so case doesn't matter when it comes to the folder names of mods and what's in modlist.txt. If a mismatch in case is detected, modlist.txt will be flagged dirty to fix it at some point. This handles the foillowing cases: * modlist.txt was modified outside MO * the mod folder was renamed outside MO --- src/profile.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/profile.cpp') diff --git a/src/profile.cpp b/src/profile.cpp index 3cc1a2a3..5a71cacb 100644 --- a/src/profile.cpp +++ b/src/profile.cpp @@ -410,9 +410,18 @@ void Profile::refreshModStatus() } else { namesRead.insert(lookupName); } - unsigned int modIndex = ModInfo::getIndex(lookupName); + unsigned int modIndex = ModInfo::findMod( + [lookupName](ModInfo::Ptr info) { + return info->name().compare(lookupName, Qt::CaseInsensitive) == 0; + } + ); if (modIndex != UINT_MAX) { ModInfo::Ptr info = ModInfo::getByIndex(modIndex); + if (info->name().compare(lookupName) != 0) { + // name in modlist.txt doesn't match case of actual folder + // need to rewrite the modlist to fix this + modStatusModified = true; + } if ((modIndex < m_ModStatus.size()) && (info->getFixedPriority() == INT_MIN)) { m_ModStatus[modIndex].m_Enabled = enabled; -- cgit v1.3.1 From e69cb90dbef5c5c82f9ae860ccbdeb7f034f885e Mon Sep 17 00:00:00 2001 From: Chris Bessent Date: Sat, 16 Jan 2021 20:09:12 -0700 Subject: Improve performance by changing the map to be case insensitive --- src/modinfo.cpp | 2 +- src/modinfo.h | 8 +++++++- src/profile.cpp | 11 +---------- 3 files changed, 9 insertions(+), 12 deletions(-) (limited to 'src/profile.cpp') diff --git a/src/modinfo.cpp b/src/modinfo.cpp index b46a68ab..254fbda3 100644 --- a/src/modinfo.cpp +++ b/src/modinfo.cpp @@ -52,7 +52,7 @@ using namespace MOShared; const std::set ModInfo::s_EmptySet; std::vector ModInfo::s_Collection; ModInfo::Ptr ModInfo::s_Overwrite; -std::map ModInfo::s_ModsByName; +std::map ModInfo::s_ModsByName; std::map, std::vector> ModInfo::s_ModsByModID; int ModInfo::s_NextID; QMutex ModInfo::s_Mutex(QMutex::Recursive); diff --git a/src/modinfo.h b/src/modinfo.h index 634ea900..f18bd347 100644 --- a/src/modinfo.h +++ b/src/modinfo.h @@ -43,6 +43,12 @@ class QDateTime; namespace MOBase { class IPluginGame; } namespace MOShared { class DirectoryEntry; } +struct ModNameCompare { + bool operator()(const QString& lhs, const QString& rhs) const { + return QString::compare(lhs, rhs, Qt::CaseInsensitive) < 0; + } +}; + /** * @brief Represents meta information about a single mod. * @@ -989,7 +995,7 @@ protected: static QMutex s_Mutex; static std::vector s_Collection; static ModInfo::Ptr s_Overwrite; - static std::map s_ModsByName; + static std::map s_ModsByName; static std::map, std::vector> s_ModsByModID; static int s_NextID; diff --git a/src/profile.cpp b/src/profile.cpp index 5a71cacb..3cc1a2a3 100644 --- a/src/profile.cpp +++ b/src/profile.cpp @@ -410,18 +410,9 @@ void Profile::refreshModStatus() } else { namesRead.insert(lookupName); } - unsigned int modIndex = ModInfo::findMod( - [lookupName](ModInfo::Ptr info) { - return info->name().compare(lookupName, Qt::CaseInsensitive) == 0; - } - ); + unsigned int modIndex = ModInfo::getIndex(lookupName); if (modIndex != UINT_MAX) { ModInfo::Ptr info = ModInfo::getByIndex(modIndex); - if (info->name().compare(lookupName) != 0) { - // name in modlist.txt doesn't match case of actual folder - // need to rewrite the modlist to fix this - modStatusModified = true; - } if ((modIndex < m_ModStatus.size()) && (info->getFixedPriority() == INT_MIN)) { m_ModStatus[modIndex].m_Enabled = enabled; -- cgit v1.3.1 From 4c64448947e624fa0a8e7025499cb889d272d232 Mon Sep 17 00:00:00 2001 From: Chris Bessent Date: Mon, 18 Jan 2021 07:55:02 -0700 Subject: Add a warning about overwrite mods being disabled --- src/profile.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/profile.cpp') diff --git a/src/profile.cpp b/src/profile.cpp index 3cc1a2a3..f8fc3eb9 100644 --- a/src/profile.cpp +++ b/src/profile.cpp @@ -382,6 +382,8 @@ void Profile::refreshModStatus() std::set namesRead; + bool warnAboutOverwrite = false; + // load mods from file and update enabled state and priority for them int index = 0; while (!file.atEnd()) { @@ -405,6 +407,9 @@ void Profile::refreshModStatus() } if (modName.size() > 0) { QString lookupName = modName; + if (modName.compare("overwrite", Qt::CaseInsensitive) == 0) { + warnAboutOverwrite = true; + } if (namesRead.find(lookupName) != namesRead.end()) { continue; } else { @@ -486,6 +491,19 @@ void Profile::refreshModStatus() file.close(); updateIndices(); + + // User has a mod named some variation of "overwrite". Tell them about it. + if (warnAboutOverwrite) { + QMessageBox::warning( + nullptr, + tr("Overwrite mod conflict"), + tr("At least one mod named \"overwrite\" was detected, disabled, and moved to the lowest priority on the mod list. " + "You may want to rename this mod and enable it again.") + ); + // also, mark the mod-list as changed + modStatusModified = true; + } + if (modStatusModified) { m_ModListWriter.write(); } -- cgit v1.3.1