From 1eb783aae348f906056cee17cb65dfd507429901 Mon Sep 17 00:00:00 2001 From: Tannin Date: Sat, 31 May 2014 13:43:48 +0200 Subject: - added a new mod type that represents files handled externally (i.e. DLCs) as mods in MO - hashes of file names in bsa files are no longer checked all the time - author and description is now read from esp files - rewrote the code that fixes modlists after a rename, should be a bit more robust - fixes to qt 5 and msvc 2013 compatibility - started to update the tutorial (not done yet!) - bugfix: counter for the problems badge wasn't calculated correctly --- src/directoryrefresher.cpp | 68 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 13 deletions(-) (limited to 'src/directoryrefresher.cpp') diff --git a/src/directoryrefresher.cpp b/src/directoryrefresher.cpp index 21d1f811..52e16be4 100644 --- a/src/directoryrefresher.cpp +++ b/src/directoryrefresher.cpp @@ -20,8 +20,10 @@ along with Mod Organizer. If not, see . #include "directoryrefresher.h" #include "utility.h" #include "report.h" +#include "modinfo.h" #include #include +#include using namespace MOBase; @@ -50,8 +52,15 @@ void DirectoryRefresher::setMods(const std::vector &managedArchives) { QMutexLocker locker(&m_RefreshLock); - m_Mods = mods; - m_ManagedArchives = managedArchives; + + m_Mods.clear(); + for (auto mod = mods.begin(); mod != mods.end(); ++mod) { + QString name = std::get<0>(*mod); + ModInfo::Ptr info = ModInfo::getByIndex(ModInfo::getIndex(name)); + m_Mods.push_back(EntryInfo(name, std::get<1>(*mod), info->stealFiles(), info->archives(), std::get<2>(*mod))); + } + + m_EnabledArchives = managedArchives; } @@ -68,18 +77,51 @@ void DirectoryRefresher::cleanStructure(DirectoryEntry *structure) } } -void DirectoryRefresher::addModToStructure(DirectoryEntry *directoryStructure, const QString &modName, int priority, const QString &directory) +void DirectoryRefresher::addModToStructure(DirectoryEntry *directoryStructure + , const QString &modName + , int priority + , const QString &directory + , const QStringList &stealFiles + , const QStringList &archives) { std::wstring directoryW = ToWString(QDir::toNativeSeparators(directory)); - - directoryStructure->addFromOrigin(ToWString(modName), directoryW, priority); - QDir dir(directory); + std::wstring modNameW = ToWString(modName); + + + if (stealFiles.length() > 0) { + // instead of adding all the files of the target directory, we just change the root of the specified + // files to this mod + directoryStructure->createOrigin(modNameW, directoryW, priority); + foreach (const QString &filename, stealFiles) { + QFileInfo fileInfo(filename); + FileEntry::Ptr file = directoryStructure->findFile(ToWString(fileInfo.fileName())); + if (file.get() != NULL) { + if (file->getOrigin() == 0) { + // replace data as the origin on this bsa + file->removeOrigin(0); + file->addOrigin(directoryStructure->getOriginByName(modNameW).getID(), + file->getFileTime(), L""); + } + } + } + } else { + directoryStructure->addFromOrigin(modNameW, directoryW, priority); + } +/* QDir dir(directory); QFileInfoList bsaFiles = dir.entryInfoList(QStringList("*.bsa"), QDir::Files); foreach (QFileInfo file, bsaFiles) { - if (m_ManagedArchives.find(file.fileName()) != m_ManagedArchives.end()) { + if (m_EnabledArchives.find(file.fileName()) != m_EnabledArchives.end()) { directoryStructure->addFromBSA(ToWString(modName), directoryW, ToWString(QDir::toNativeSeparators(file.absoluteFilePath())), priority); } + }*/ + + foreach (const QString &archive, archives) { + QFileInfo fileInfo(archive); + if (m_EnabledArchives.find(fileInfo.fileName()) != m_EnabledArchives.end()) { + directoryStructure->addFromBSA(modNameW, directoryW, + ToWString(QDir::toNativeSeparators(fileInfo.absoluteFilePath())), priority); + } } } @@ -91,23 +133,23 @@ void DirectoryRefresher::refresh() m_DirectoryStructure = new DirectoryEntry(L"data", NULL, 0); + std::wstring dataDirectory = GameInfo::instance().getGameDirectory() + L"\\data"; + m_DirectoryStructure->addFromOrigin(L"data", dataDirectory, 0); + // TODO what was the point of having the priority in this tuple? the list is already sorted by priority - std::vector >::const_iterator iter = m_Mods.begin(); + auto iter = m_Mods.begin(); //TODO i is the priority here, where higher = more important. the input vector is also sorted by priority but inverted! for (int i = 1; iter != m_Mods.end(); ++iter, ++i) { - QString modName = std::get<0>(*iter); +qDebug("%s - %d", qPrintable(iter->modName), i); try { - addModToStructure(m_DirectoryStructure, modName, i, std::get<1>(*iter)); + addModToStructure(m_DirectoryStructure, iter->modName, i, iter->absolutePath, iter->stealFiles, iter->archives); } catch (const std::exception &e) { emit error(tr("failed to read bsa: %1").arg(e.what())); } emit progress((i * 100) / m_Mods.size() + 1); } - std::wstring dataDirectory = GameInfo::instance().getGameDirectory() + L"\\data"; - m_DirectoryStructure->addFromOrigin(L"data", dataDirectory, 0); - emit progress(100); cleanStructure(m_DirectoryStructure); -- cgit v1.3.1