summaryrefslogtreecommitdiff
path: root/src/directoryrefresher.cpp
diff options
context:
space:
mode:
authorTannin <devnull@localhost>2014-05-31 13:43:48 +0200
committerTannin <devnull@localhost>2014-05-31 13:43:48 +0200
commit1eb783aae348f906056cee17cb65dfd507429901 (patch)
treed9e5b93c1d528a2182416d971b27e49cb524532b /src/directoryrefresher.cpp
parent93a19799b86dd6e12a186e84eb43699b318b214d (diff)
- 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
Diffstat (limited to 'src/directoryrefresher.cpp')
-rw-r--r--src/directoryrefresher.cpp66
1 files changed, 54 insertions, 12 deletions
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 <http://www.gnu.org/licenses/>.
#include "directoryrefresher.h"
#include "utility.h"
#include "report.h"
+#include "modinfo.h"
#include <gameinfo.h>
#include <QDir>
+#include <QString>
using namespace MOBase;
@@ -50,8 +52,15 @@ void DirectoryRefresher::setMods(const std::vector<std::tuple<QString, QString,
, const std::set<QString> &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));
+ std::wstring modNameW = ToWString(modName);
+
- directoryStructure->addFromOrigin(ToWString(modName), directoryW, priority);
- QDir dir(directory);
+ 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<std::tuple<QString, QString, int> >::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);