diff --git a/src/pluginlist.cpp b/src/pluginlist.cpp index 748ffbada..5b056f83c 100644 --- a/src/pluginlist.cpp +++ b/src/pluginlist.cpp @@ -182,82 +182,81 @@ void PluginList::refresh(const QString& profileName, gamePlugins ? gamePlugins->lightPluginsAreSupported() : false; const bool overridePluginsAreSupported = gamePlugins ? gamePlugins->overridePluginsAreSupported() : false; + const bool loadOrderMechanismNone = + m_GamePlugin->loadOrderMechanism() == IPluginGame::LoadOrderMechanism::None; m_CurrentProfile = profileName; - QStringList availablePlugins; + std::unordered_map availablePlugins; + QStringList archiveCandidates; - std::vector files = baseDirectory.getFiles(); - for (FileEntryPtr current : files) { + for (FileEntryPtr current : baseDirectory.getFiles()) { if (current.get() == nullptr) { continue; } - QString filename = ToQString(current->getName()); + const QString& filename = ToQString(current->getName()); if (filename.endsWith(".esp", Qt::CaseInsensitive) || filename.endsWith(".esm", Qt::CaseInsensitive) || filename.endsWith(".esl", Qt::CaseInsensitive)) { + availablePlugins.insert(std::make_pair(filename, current)); + } else if (filename.endsWith(".bsa", Qt::CaseInsensitive) || + filename.endsWith("ba2", Qt::CaseInsensitive)) { + archiveCandidates.append(filename); + } + } - availablePlugins.append(filename); + for (const auto& [filename, current] : availablePlugins) { + if (m_ESPsByName.contains(filename)) { + continue; + } - if (m_ESPsByName.find(filename) != m_ESPsByName.end()) { - continue; - } + bool forceLoaded = Settings::instance().game().forceEnableCoreFiles() && + primaryPlugins.contains(filename, Qt::CaseInsensitive); + bool forceEnabled = enabledPlugins.contains(filename, Qt::CaseInsensitive); + bool forceDisabled = loadOrderMechanismNone && !forceLoaded && !forceEnabled; + if (!lightPluginsAreSupported && filename.endsWith(".esl")) { + forceDisabled = true; + } - bool forceLoaded = Settings::instance().game().forceEnableCoreFiles() && - primaryPlugins.contains(filename, Qt::CaseInsensitive); - bool forceEnabled = enabledPlugins.contains(filename, Qt::CaseInsensitive); - bool forceDisabled = - m_GamePlugin->loadOrderMechanism() == IPluginGame::LoadOrderMechanism::None && - !forceLoaded && !forceEnabled; - if (!lightPluginsAreSupported && filename.endsWith(".esl")) { - forceDisabled = true; - } + bool archive = false; + try { + FilesOrigin& origin = baseDirectory.getOriginByID(current->getOrigin(archive)); - bool archive = false; - try { - FilesOrigin& origin = baseDirectory.getOriginByID(current->getOrigin(archive)); - - // name without extension - QString baseName = QFileInfo(filename).completeBaseName(); - - QString iniPath = baseName + ".ini"; - bool hasIni = baseDirectory.findFile(ToWString(iniPath)).get() != nullptr; - std::set loadedArchives; - QString candidateName; - for (FileEntryPtr archiveCandidate : files) { - candidateName = ToQString(archiveCandidate->getName()); - if (candidateName.startsWith(baseName, Qt::CaseInsensitive) && - (candidateName.endsWith(".bsa", Qt::CaseInsensitive) || - candidateName.endsWith(".ba2", Qt::CaseInsensitive))) { - loadedArchives.insert(candidateName); - } - } + // name without extension + QString baseName = QFileInfo(filename).completeBaseName(); - QString originName = ToQString(origin.getName()); - unsigned int modIndex = ModInfo::getIndex(originName); - if (modIndex != UINT_MAX) { - ModInfo::Ptr modInfo = ModInfo::getByIndex(modIndex); - originName = modInfo->name(); + QString iniPath = baseName + ".ini"; + bool hasIni = baseDirectory.findFile(ToWString(iniPath)).get() != nullptr; + std::set loadedArchives; + for (const auto& archiveName : archiveCandidates) { + if (archiveName.startsWith(baseName, Qt::CaseInsensitive)) { + loadedArchives.insert(archiveName); } + } - m_ESPs.push_back(ESPInfo(filename, forceLoaded, forceEnabled, forceDisabled, - originName, ToQString(current->getFullPath()), hasIni, - loadedArchives, lightPluginsAreSupported, - overridePluginsAreSupported)); - m_ESPs.rbegin()->priority = -1; - } catch (const std::exception& e) { - reportError( - tr("failed to update esp info for file %1 (source id: %2), error: %3") - .arg(filename) - .arg(current->getOrigin(archive)) - .arg(e.what())); + QString originName = ToQString(origin.getName()); + unsigned int modIndex = ModInfo::getIndex(originName); + if (modIndex != UINT_MAX) { + ModInfo::Ptr modInfo = ModInfo::getByIndex(modIndex); + originName = modInfo->name(); } + + m_ESPs.emplace_back(filename, forceLoaded, forceEnabled, forceDisabled, + originName, ToQString(current->getFullPath()), hasIni, + loadedArchives, lightPluginsAreSupported, + overridePluginsAreSupported); + m_ESPs.rbegin()->priority = -1; + } catch (const std::exception& e) { + reportError(tr("failed to update esp info for file %1 (source id: %2), error: %3") + .arg(filename) + .arg(current->getOrigin(archive)) + .arg(e.what())); } } for (const auto& espName : m_ESPsByName) { - if (!availablePlugins.contains(espName.first, Qt::CaseInsensitive)) { + if (!availablePlugins.contains(espName.first)) { m_ESPs[espName.second].name = ""; } } diff --git a/src/shared/directoryentry.cpp b/src/shared/directoryentry.cpp index 5468beea4..01c325ef1 100644 --- a/src/shared/directoryentry.cpp +++ b/src/shared/directoryentry.cpp @@ -299,6 +299,7 @@ int DirectoryEntry::anyOrigin() const std::vector DirectoryEntry::getFiles() const { std::vector result; + result.reserve(m_Files.size()); for (auto iter = m_Files.begin(); iter != m_Files.end(); ++iter) { result.push_back(m_FileRegister->getFile(iter->second));