From 1e11ce050a0b9ed2e638fbf3fc114c14e601855a Mon Sep 17 00:00:00 2001 From: Jeremy Rimpo Date: Sun, 16 Jun 2024 03:38:24 -0500 Subject: [PATCH] Parse unmanaged file location when creating ModInfoForeign - Fixes issues with secondaryDataDirectories --- src/modinfoforeign.cpp | 17 +++++++++-------- src/modinfoforeign.h | 3 ++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/modinfoforeign.cpp b/src/modinfoforeign.cpp index db90aa416..880051f43 100644 --- a/src/modinfoforeign.cpp +++ b/src/modinfoforeign.cpp @@ -13,13 +13,6 @@ QDateTime ModInfoForeign::creationTime() const return m_CreationTime; } -QString ModInfoForeign::absolutePath() const -{ - // I ought to store this, it's used elsewhere - IPluginGame const* game = qApp->property("managed_game").value(); - return game->dataDirectory().absolutePath(); -} - std::vector ModInfoForeign::getFlags() const { std::vector result = ModInfoWithConflictInfo::getFlags(); @@ -49,7 +42,15 @@ ModInfoForeign::ModInfoForeign(const QString& modName, const QString& referenceF : ModInfoWithConflictInfo(core), m_ReferenceFile(referenceFile), m_Archives(archives), m_ModType(modType) { - m_CreationTime = QFileInfo(referenceFile).birthTime(); + m_CreationTime = QFileInfo(referenceFile).birthTime(); + IPluginGame const* game = qApp->property("managed_game").value(); + QMap directories = {{"data", game->dataDirectory()}}; + directories.insert(game->secondaryDataDirectories()); + for (QDir directory : directories) { + if (referenceFile.startsWith(directory.absolutePath(), Qt::CaseInsensitive)) { + m_BaseDirectory = directory.absolutePath(); + } + } switch (modType) { case ModInfo::EModType::MOD_DLC: m_Name = tr("DLC: ") + modName; diff --git a/src/modinfoforeign.h b/src/modinfoforeign.h index dc66e1b04..fa57e3780 100644 --- a/src/modinfoforeign.h +++ b/src/modinfoforeign.h @@ -39,7 +39,7 @@ class ModInfoForeign : public ModInfoWithConflictInfo virtual QString comments() const override { return ""; } virtual QString notes() const override { return ""; } virtual QDateTime creationTime() const override; - virtual QString absolutePath() const override; + virtual QString absolutePath() const override { return m_BaseDirectory; } virtual MOBase::VersionInfo newestVersion() const override { return QString(); } virtual MOBase::VersionInfo ignoredVersion() const override { return QString(); } virtual QString installationFile() const override { return ""; } @@ -108,6 +108,7 @@ class ModInfoForeign : public ModInfoWithConflictInfo QString m_Name; QString m_InternalName; QString m_ReferenceFile; + QString m_BaseDirectory; QStringList m_Archives; QDateTime m_CreationTime; int m_Priority;