From 5e569d0107aefe292b76ac0458f9420077f350a0 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Sat, 15 Feb 2020 17:22:12 -0500 Subject: re-enabled archive parsing --- src/directoryrefresher.cpp | 126 +++++++++++++++++++++++++++------------------ 1 file changed, 76 insertions(+), 50 deletions(-) (limited to 'src/directoryrefresher.cpp') diff --git a/src/directoryrefresher.cpp b/src/directoryrefresher.cpp index 8a64d4a9..5e1c05a8 100644 --- a/src/directoryrefresher.cpp +++ b/src/directoryrefresher.cpp @@ -210,38 +210,41 @@ void DirectoryRefresher::cleanStructure(DirectoryEntry *structure) } } -void DirectoryRefresher::addModBSAToStructure(DirectoryEntry *directoryStructure, const QString &modName, - int priority, const QString &directory, const QStringList &archives) +void DirectoryRefresher::addModBSAToStructure( + DirectoryEntry* root, const QString& modName, + int priority, const QString& directory, const QStringList& archives) { - std::wstring directoryW = ToWString(QDir::toNativeSeparators(directory)); - IPluginGame *game = qApp->property("managed_game").value(); + const IPluginGame *game = qApp->property("managed_game").value(); GamePlugins *gamePlugins = game->feature(); QStringList loadOrder = QStringList(); gamePlugins->getLoadOrder(loadOrder); - for (const QString &archive : archives) { - QFileInfo fileInfo(archive); - if (m_EnabledArchives.find(fileInfo.fileName()) != m_EnabledArchives.end()) { - - int order = -1; + std::vector lo; + for (auto&& s : loadOrder) { + lo.push_back(s.toStdWString()); + } - for (auto plugin : loadOrder) - { - QString name = plugin.left(plugin.size() - 4); - if (fileInfo.fileName().startsWith(name + " - ", Qt::CaseInsensitive) || fileInfo.fileName().startsWith(name + ".", Qt::CaseInsensitive)) { - order = loadOrder.indexOf(plugin); - } - } + std::vector archivesW; + for (auto&& a : archives) { + archivesW.push_back(a.toStdWString()); + } - try { - IPluginGame *game = qApp->property("managed_game").value(); - directoryStructure->addFromBSA(ToWString(modName), directoryW, ToWString(QDir::toNativeSeparators(fileInfo.absoluteFilePath())), priority, order); - } catch (const std::exception &e) { - throw MyException(tr("failed to parse bsa %1: %2").arg(archive, e.what())); - } - } + std::set enabledArchives; + for (auto&& a : m_EnabledArchives) { + enabledArchives.insert(a.toStdWString()); } + + DirectoryStats dummy; + + root->addFromAllBSAs( + modName.toStdWString(), + QDir::toNativeSeparators(directory).toStdWString(), + priority, + archivesW, + enabledArchives, + lo, + dummy); } void DirectoryRefresher::stealModFilesIntoStructure( @@ -329,6 +332,8 @@ struct ModThread std::wstring modName; std::wstring path; int prio = -1; + std::vector archives; + std::set enabledArchives; DirectoryStats* stats = nullptr; env::DirectoryWalker walker; @@ -354,14 +359,21 @@ struct ModThread SetThisThreadName(QString::fromStdWString(modName + L" refresher")); ds->addFromOrigin(walker, modName, path, prio, *stats); - /*if (Settings::instance().archiveParsing()) { - addModBSAToStructure( - directoryStructure, - entries[i].modName, - prio, - entries[i].absolutePath, - entries[i].archives); - }*/ + if (Settings::instance().archiveParsing()) { + const IPluginGame *game = qApp->property("managed_game").value(); + + GamePlugins *gamePlugins = game->feature(); + QStringList loadOrder = QStringList(); + gamePlugins->getLoadOrder(loadOrder); + + std::vector lo; + for (auto&& s : loadOrder) { + lo.push_back(s.toStdWString()); + } + + ds->addFromAllBSAs( + modName, path, prio, archives, enabledArchives, lo, *stats); + } ready = false; } @@ -377,6 +389,7 @@ void DirectoryRefresher::addMultipleModsFilesToStructure( { std::vector stats(entries.size()); + log::debug("refresher: using {} threads", m_threadCount); g_threads.setMax(m_threadCount); for (std::size_t i=0; igetFileRegister()->reserve(m_lastFileCount); + m_Root.reset(new DirectoryEntry(L"data", nullptr, 0)); + m_Root->getFileRegister()->reserve(m_lastFileCount); - IPluginGame *game = qApp->property("managed_game").value(); + IPluginGame *game = qApp->property("managed_game").value(); - std::wstring dataDirectory = - QDir::toNativeSeparators(game->dataDirectory().absolutePath()).toStdWString(); + std::wstring dataDirectory = + QDir::toNativeSeparators(game->dataDirectory().absolutePath()).toStdWString(); - { - DirectoryStats dummy; - m_Root->addFromOrigin(L"data", dataDirectory, 0, dummy); - } + { + DirectoryStats dummy; + m_Root->addFromOrigin(L"data", dataDirectory, 0, dummy); + } - std::sort(m_Mods.begin(), m_Mods.end(), [](auto lhs, auto rhs) { - return lhs.priority < rhs.priority; - }); + std::sort(m_Mods.begin(), m_Mods.end(), [](auto lhs, auto rhs) { + return lhs.priority < rhs.priority; + }); - addMultipleModsFilesToStructure(m_Root.get(), m_Mods, true); + addMultipleModsFilesToStructure(m_Root.get(), m_Mods, true); - m_Root->getFileRegister()->sortOrigins(); + m_Root->getFileRegister()->sortOrigins(); - cleanStructure(m_Root.get()); + cleanStructure(m_Root.get()); - m_lastFileCount = m_Root->getFileRegister()->highestCount(); - log::debug("refresher saw {} files", m_lastFileCount); + m_lastFileCount = m_Root->getFileRegister()->highestCount(); + log::debug("refresher saw {} files", m_lastFileCount); + } emit progress(100); emit refreshed(); -- cgit v1.3.1