summaryrefslogtreecommitdiff
path: root/src/modinfo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modinfo.cpp')
-rw-r--r--src/modinfo.cpp46
1 files changed, 32 insertions, 14 deletions
diff --git a/src/modinfo.cpp b/src/modinfo.cpp
index 826aa5c9..bbeefb12 100644
--- a/src/modinfo.cpp
+++ b/src/modinfo.cpp
@@ -180,11 +180,11 @@ bool ModInfo::removeMod(unsigned int index)
ModInfo::Ptr modInfo = s_Collection[index];
s_ModsByName.erase(s_ModsByName.find(modInfo->name()));
- auto iter = s_ModsByModID.find(std::pair<QString, int>(modInfo->getGameName(), modInfo->getNexusID()));
+ auto iter = s_ModsByModID.find(std::pair<QString, int>(modInfo->gameName(), modInfo->nexusId()));
if (iter != s_ModsByModID.end()) {
std::vector<unsigned int> indices = iter->second;
indices.erase(std::remove(indices.begin(), indices.end(), index), indices.end());
- s_ModsByModID[std::pair<QString, int>(modInfo->getGameName(), modInfo->getNexusID())] = indices;
+ s_ModsByModID[std::pair<QString, int>(modInfo->gameName(), modInfo->nexusId())] = indices;
}
// physically remove the mod directory
@@ -281,8 +281,8 @@ void ModInfo::updateIndices()
for (unsigned int i = 0; i < s_Collection.size(); ++i) {
QString modName = s_Collection[i]->internalName();
- QString game = s_Collection[i]->getGameName();
- int modID = s_Collection[i]->getNexusID();
+ QString game = s_Collection[i]->gameName();
+ int modID = s_Collection[i]->nexusId();
s_ModsByName[modName] = i;
s_ModsByModID[std::pair<QString, int>(game, modID)].push_back(i);
}
@@ -308,7 +308,25 @@ bool ModInfo::checkAllForUpdate(PluginContainer *pluginContainer, QObject *recei
earliest = mod->getLastNexusUpdate();
if (mod->getLastNexusUpdate() > latest)
latest = mod->getLastNexusUpdate();
- games.insert(mod->getGameName().toLower());
+ games.insert(mod->gameName().toLower());
+ }
+ }
+
+ // Detect invalid source games
+ for (auto itr = games.begin(); itr != games.end();) {
+ auto gamePlugins = pluginContainer->plugins<IPluginGame>();
+ IPluginGame* gamePlugin = qApp->property("managed_game").value<IPluginGame*>();
+ for (auto plugin : gamePlugins) {
+ if (plugin != nullptr && plugin->gameShortName().compare(*itr, Qt::CaseInsensitive) == 0) {
+ gamePlugin = plugin;
+ break;
+ }
+ }
+ if (gamePlugin != nullptr && gamePlugin->gameNexusName().isEmpty()) {
+ log::warn("{}", tr("The update check has found a mod with a Nexus ID and source game of %1, but this game is not a valid Nexus source.").arg(gamePlugin->gameName()));
+ itr = games.erase(itr);
+ } else {
+ ++itr;
}
}
@@ -316,7 +334,7 @@ bool ModInfo::checkAllForUpdate(PluginContainer *pluginContainer, QObject *recei
std::set<std::pair<QString, int>> organizedGames;
for (auto mod : s_Collection) {
if (mod->canBeUpdated() && mod->getLastNexusUpdate() < QDateTime::currentDateTimeUtc().addMonths(-1)) {
- organizedGames.insert(std::make_pair<QString, int>(mod->getGameName().toLower(), mod->getNexusID()));
+ organizedGames.insert(std::make_pair<QString, int>(mod->gameName().toLower(), mod->nexusId()));
}
}
@@ -354,7 +372,7 @@ std::set<QSharedPointer<ModInfo>> ModInfo::filteredMods(QString gameName, QVaria
for (QVariant result : updateData) {
QVariantMap update = result.toMap();
std::copy_if(s_Collection.begin(), s_Collection.end(), std::inserter(finalMods, finalMods.end()), [=](QSharedPointer<ModInfo> info) -> bool {
- if (info->getNexusID() == update["mod_id"].toInt() && info->getGameName().compare(gameName, Qt::CaseInsensitive) == 0)
+ if (info->nexusId() == update["mod_id"].toInt() && info->gameName().compare(gameName, Qt::CaseInsensitive) == 0)
if (info->getLastNexusUpdate().addSecs(-3600) < QDateTime::fromSecsSinceEpoch(update["latest_file_update"].toInt(), Qt::UTC))
return true;
return false;
@@ -363,13 +381,13 @@ std::set<QSharedPointer<ModInfo>> ModInfo::filteredMods(QString gameName, QVaria
if (addOldMods)
for (auto mod : s_Collection)
- if (mod->getLastNexusUpdate() < QDateTime::currentDateTimeUtc().addMonths(-1) && mod->getGameName().compare(gameName, Qt::CaseInsensitive) == 0)
+ if (mod->getLastNexusUpdate() < QDateTime::currentDateTimeUtc().addMonths(-1) && mod->gameName().compare(gameName, Qt::CaseInsensitive) == 0)
finalMods.insert(mod);
if (markUpdated) {
std::set<QSharedPointer<ModInfo>> updates;
std::copy_if(s_Collection.begin(), s_Collection.end(), std::inserter(updates, updates.end()), [=](QSharedPointer<ModInfo> info) -> bool {
- if (info->getGameName().compare(gameName, Qt::CaseInsensitive) == 0 && info->canBeUpdated())
+ if (info->gameName().compare(gameName, Qt::CaseInsensitive) == 0 && info->canBeUpdated())
return true;
return false;
});
@@ -401,7 +419,7 @@ void ModInfo::manualUpdateCheck(PluginContainer *pluginContainer, QObject *recei
}
}
mods.erase(
- std::remove_if(mods.begin(), mods.end(), [](ModInfo::Ptr mod) -> bool { return mod->getNexusID() <= 0; }),
+ std::remove_if(mods.begin(), mods.end(), [](ModInfo::Ptr mod) -> bool { return mod->nexusId() <= 0; }),
mods.end()
);
for (auto mod : mods) {
@@ -416,7 +434,7 @@ void ModInfo::manualUpdateCheck(PluginContainer *pluginContainer, QObject *recei
log::info("Checking updates for {} mods...", mods.size());
for (auto mod : mods) {
- organizedGames.insert(std::make_pair<QString, int>(mod->getGameName().toLower(), mod->getNexusID()));
+ organizedGames.insert(std::make_pair<QString, int>(mod->gameName().toLower(), mod->nexusId()));
}
for (auto game : organizedGames) {
@@ -508,14 +526,14 @@ bool ModInfo::categorySet(int categoryID) const
QUrl ModInfo::parseCustomURL() const
{
- if (!hasCustomURL() || getCustomURL().isEmpty()) {
+ if (!hasCustomURL() || url().isEmpty()) {
return {};
}
- const auto url = QUrl::fromUserInput(getCustomURL());
+ const auto url = QUrl::fromUserInput(this->url());
if (!url.isValid()) {
- log::error("mod '{}' has an invalid custom url '{}'", name(), getCustomURL());
+ log::error("mod '{}' has an invalid custom url '{}'", name(), this->url());
return {};
}