summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSilarn <jrim@rimpo.org>2018-05-02 12:38:23 -0500
committerSilarn <jrim@rimpo.org>2018-05-02 12:38:23 -0500
commit168da18aa51868ad3ac908affb55a8aabdba1aed (patch)
tree7ebd21b8936f27b620a6eab72a4eeb19789bed20 /src
parentd62ec9c867b448276ab9873ddd3f320487ab5572 (diff)
Fix MO endorsement check and add game to ModInfo s_ModsByModID
Diffstat (limited to 'src')
-rw-r--r--src/downloadmanager.cpp8
-rw-r--r--src/downloadmanager.h8
-rw-r--r--src/mainwindow.cpp12
-rw-r--r--src/modinfo.cpp14
-rw-r--r--src/modinfo.h4
-rw-r--r--src/organizercore.cpp3
6 files changed, 38 insertions, 11 deletions
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp
index 097a1168..d9e86544 100644
--- a/src/downloadmanager.cpp
+++ b/src/downloadmanager.cpp
@@ -895,6 +895,14 @@ int DownloadManager::getModID(int index) const
return m_ActiveDownloads.at(index)->m_FileInfo->modID;
}
+QString DownloadManager::getGameName(int index) const
+{
+ if ((index < 0) || (index >= m_ActiveDownloads.size())) {
+ throw MyException(tr("mod id: invalid download index %1").arg(index));
+ }
+ return m_ActiveDownloads.at(index)->m_FileInfo->gameName;
+}
+
bool DownloadManager::isHidden(int index) const
{
if ((index < 0) || (index >= m_ActiveDownloads.size())) {
diff --git a/src/downloadmanager.h b/src/downloadmanager.h
index 0ff77011..e1925040 100644
--- a/src/downloadmanager.h
+++ b/src/downloadmanager.h
@@ -289,6 +289,14 @@ public:
int getModID(int index) const;
/**
+ * @brief retrieve the game name of the downlaod specified by the index
+ *
+ * @param index index of the file to look up
+ * @return the game name
+ **/
+ QString getGameName(int index) const;
+
+ /**
* @brief determine if the specified file is supposed to be hidden
* @param index index of the file to look up
* @return true if the specified file is supposed to be hidden
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 3933987e..a95b7b70 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -4231,12 +4231,20 @@ void MainWindow::nxmUpdatesAvailable(const std::vector<int> &modIDs, QVariant us
QVariantList resultList = resultData.toList();
for (auto iter = resultList.begin(); iter != resultList.end(); ++iter) {
QVariantMap result = iter->toMap();
- if (result["id"].toInt() == m_OrganizerCore.managedGame()->nexusModOrganizerID()) {
+ if (result["id"].toInt() == m_OrganizerCore.managedGame()->nexusModOrganizerID()
+ && result["game_id"].toInt() == m_OrganizerCore.managedGame()->nexusGameID()) {
if (!result["voted_by_user"].toBool()) {
ui->actionEndorseMO->setVisible(true);
}
} else {
- std::vector<ModInfo::Ptr> info = ModInfo::getByModID(result["id"].toInt());
+ QString gameName = m_OrganizerCore.managedGame()->gameShortName();
+ for (IPluginGame *game : m_PluginContainer.plugins<IPluginGame>()) {
+ if (game->nexusGameID() == result["game_id"].toInt()) {
+ gameName = game->gameShortName();
+ break;
+ }
+ }
+ std::vector<ModInfo::Ptr> info = ModInfo::getByModID(gameName, result["id"].toInt());
for (auto iter = info.begin(); iter != info.end(); ++iter) {
(*iter)->setNewestVersion(result["version"].toString());
(*iter)->setNexusDescription(result["description"].toString());
diff --git a/src/modinfo.cpp b/src/modinfo.cpp
index d916d982..6b3fd528 100644
--- a/src/modinfo.cpp
+++ b/src/modinfo.cpp
@@ -48,7 +48,7 @@ using namespace MOShared;
std::vector<ModInfo::Ptr> ModInfo::s_Collection;
std::map<QString, unsigned int> ModInfo::s_ModsByName;
-std::map<int, std::vector<unsigned int> > ModInfo::s_ModsByModID;
+std::map<std::pair<QString, int>, std::vector<unsigned int>> ModInfo::s_ModsByModID;
int ModInfo::s_NextID;
QMutex ModInfo::s_Mutex(QMutex::Recursive);
@@ -132,11 +132,11 @@ ModInfo::Ptr ModInfo::getByIndex(unsigned int index)
}
-std::vector<ModInfo::Ptr> ModInfo::getByModID(int modID)
+std::vector<ModInfo::Ptr> ModInfo::getByModID(QString game, int modID)
{
QMutexLocker locker(&s_Mutex);
- auto iter = s_ModsByModID.find(modID);
+ auto iter = s_ModsByModID.find(std::pair<QString, int>(game, modID));
if (iter == s_ModsByModID.end()) {
return std::vector<ModInfo::Ptr>();
}
@@ -161,11 +161,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(modInfo->getNexusID());
+ auto iter = s_ModsByModID.find(std::pair<QString, int>(modInfo->getGameName(), modInfo->getNexusID()));
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[modInfo->getNexusID()] = indices;
+ s_ModsByModID[std::pair<QString, int>(modInfo->getGameName(), modInfo->getNexusID())] = indices;
}
// physically remove the mod directory
@@ -255,9 +255,10 @@ 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();
s_ModsByName[modName] = i;
- s_ModsByModID[modID].push_back(i);
+ s_ModsByModID[std::pair<QString, int>(game, modID)].push_back(i);
}
}
@@ -289,6 +290,7 @@ int ModInfo::checkAllForUpdate(PluginContainer *pluginContainer, QObject *receiv
IPluginGame const *game = qApp->property("managed_game").value<IPluginGame *>();
modIDs.push_back(game->nexusModOrganizerID());
checkChunkForUpdate(pluginContainer, modIDs, receiver, game->gameShortName());
+ modIDs.clear();
std::multimap<QString, QSharedPointer<ModInfo>> organizedGames;
for (auto mod : s_Collection) {
diff --git a/src/modinfo.h b/src/modinfo.h
index 19be2ca2..7bb2bdad 100644
--- a/src/modinfo.h
+++ b/src/modinfo.h
@@ -148,7 +148,7 @@ public:
* @todo in its current form, this function is broken! There may be multiple mods with the same nexus id,
* this function will return only one of them
**/
- static std::vector<ModInfo::Ptr> getByModID(int modID);
+ static std::vector<ModInfo::Ptr> getByModID(QString game, int modID);
/**
* @brief remove a mod by index
@@ -638,7 +638,7 @@ protected:
private:
static QMutex s_Mutex;
- static std::map<int, std::vector<unsigned int> > s_ModsByModID;
+ static std::map<std::pair<QString, int>, std::vector<unsigned int> > s_ModsByModID;
static int s_NextID;
bool m_Valid;
diff --git a/src/organizercore.cpp b/src/organizercore.cpp
index 69c28c5c..4739021a 100644
--- a/src/organizercore.cpp
+++ b/src/organizercore.cpp
@@ -919,13 +919,14 @@ void OrganizerCore::installDownload(int index)
{
try {
QString fileName = m_DownloadManager.getFilePath(index);
+ QString gameName = m_DownloadManager.getGameName(index);
int modID = m_DownloadManager.getModID(index);
int fileID = m_DownloadManager.getFileInfo(index)->fileID;
GuessedValue<QString> modName;
// see if there already are mods with the specified mod id
if (modID != 0) {
- std::vector<ModInfo::Ptr> modInfo = ModInfo::getByModID(modID);
+ std::vector<ModInfo::Ptr> modInfo = ModInfo::getByModID(gameName, modID);
for (auto iter = modInfo.begin(); iter != modInfo.end(); ++iter) {
std::vector<ModInfo::EFlag> flags = (*iter)->getFlags();
if (std::find(flags.begin(), flags.end(), ModInfo::FLAG_BACKUP)