Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse unmanaged file location when creating ModInfoForeign #2053

Merged
merged 9 commits into from
Jun 22, 2024
17 changes: 9 additions & 8 deletions src/modinfoforeign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<IPluginGame*>();
return game->dataDirectory().absolutePath();
}

std::vector<ModInfo::EFlag> ModInfoForeign::getFlags() const
{
std::vector<ModInfo::EFlag> result = ModInfoWithConflictInfo::getFlags();
Expand Down Expand Up @@ -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<IPluginGame*>();
Silarn marked this conversation as resolved.
Show resolved Hide resolved
QMap<QString, QDir> directories = {{"data", game->dataDirectory()}};
Silarn marked this conversation as resolved.
Show resolved Hide resolved
directories.insert(game->secondaryDataDirectories());
for (QDir directory : directories) {
if (referenceFile.startsWith(directory.absolutePath(), Qt::CaseInsensitive)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe there is a better way in Qt to check if a file is under a directory?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A quick search didn't find anything but there may be a way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still haven't found a better solution for this. It seems to work.

m_BaseDirectory = directory.absolutePath();
}
}
switch (modType) {
case ModInfo::EModType::MOD_DLC:
m_Name = tr("DLC: ") + modName;
Expand Down
3 changes: 2 additions & 1 deletion src/modinfoforeign.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""; }
Expand Down Expand Up @@ -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;
Expand Down
Loading