summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/downloadlistwidget.cpp4
-rw-r--r--src/downloadlistwidgetcompact.cpp3
-rw-r--r--src/downloadmanager.cpp38
-rw-r--r--src/downloadmanager.h12
-rw-r--r--src/mainwindow.cpp12
-rw-r--r--src/modinfo.cpp20
-rw-r--r--src/modinfo.h4
-rw-r--r--src/nexusinterface.cpp61
-rw-r--r--src/nexusinterface.h6
-rw-r--r--src/organizercore.cpp6
10 files changed, 96 insertions, 70 deletions
diff --git a/src/downloadlistwidget.cpp b/src/downloadlistwidget.cpp
index cb7a49c3..2af74cc2 100644
--- a/src/downloadlistwidget.cpp
+++ b/src/downloadlistwidget.cpp
@@ -53,6 +53,7 @@ DownloadListWidgetDelegate::DownloadListWidgetDelegate(DownloadManager *manager,
m_InstallLabel = m_ItemWidget->findChild<QLabel*>("installLabel");
m_InstallLabel->setVisible(false);
+ m_Progress->setTextVisible(true);
connect(manager, SIGNAL(stateChanged(int,DownloadManager::DownloadState)), this, SLOT(stateChanged(int,DownloadManager::DownloadState)));
connect(manager, SIGNAL(downloadRemoved(int)), this, SLOT(resetCache(int)));
@@ -159,7 +160,8 @@ void DownloadListWidgetDelegate::paintRegularDownload(int downloadIndex) const
} else {
m_InstallLabel->setVisible(false);
m_Progress->setVisible(true);
- m_Progress->setValue(m_Manager->getProgress(downloadIndex));
+ m_Progress->setValue(m_Manager->getProgress(downloadIndex).first);
+ m_Progress->setFormat(m_Manager->getProgress(downloadIndex).second);
}
}
diff --git a/src/downloadlistwidgetcompact.cpp b/src/downloadlistwidgetcompact.cpp
index b390bff4..898d400a 100644
--- a/src/downloadlistwidgetcompact.cpp
+++ b/src/downloadlistwidgetcompact.cpp
@@ -138,7 +138,8 @@ void DownloadListWidgetCompactDelegate::paintRegularDownload(int downloadIndex)
} else {
m_DoneLabel->setVisible(false);
m_Progress->setVisible(true);
- m_Progress->setValue(m_Manager->getProgress(downloadIndex));
+ m_Progress->setValue(m_Manager->getProgress(downloadIndex).first);
+ m_Progress->setFormat(m_Manager->getProgress(downloadIndex).second);
}
}
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp
index 77a4cf98..d9e86544 100644
--- a/src/downloadmanager.cpp
+++ b/src/downloadmanager.cpp
@@ -62,7 +62,7 @@ DownloadManager::DownloadInfo *DownloadManager::DownloadInfo::createNew(const Mo
info->m_DownloadID = s_NextDownloadID++;
info->m_StartTime.start();
info->m_PreResumeSize = 0LL;
- info->m_Progress = 0;
+ info->m_Progress = std::make_pair<int, QString>(0, "0 bytes/sec");
info->m_ResumePos = 0;
info->m_FileInfo = new ModRepositoryFileInfo(*fileInfo);
info->m_Urls = URLs;
@@ -852,7 +852,7 @@ qint64 DownloadManager::getFileSize(int index) const
}
-int DownloadManager::getProgress(int index) const
+std::pair<int, QString> DownloadManager::getProgress(int index) const
{
if ((index < 0) || (index >= m_ActiveDownloads.size())) {
throw MyException(tr("progress: invalid download index %1").arg(index));
@@ -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())) {
@@ -1076,12 +1084,28 @@ void DownloadManager::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
if (bytesTotal > info->m_TotalSize) {
info->m_TotalSize = bytesTotal;
}
- int oldProgress = info->m_Progress;
- info->m_Progress = ((info->m_ResumePos + bytesReceived) * 100) / (info->m_ResumePos + bytesTotal);
- TaskProgressManager::instance().updateProgress(info->m_TaskProgressId, bytesReceived, bytesTotal);
- if (oldProgress != info->m_Progress) {
- emit update(index);
+ int oldProgress = info->m_Progress.first;
+ info->m_Progress.first = ((info->m_ResumePos + bytesReceived) * 100) / (info->m_ResumePos + bytesTotal);
+
+ // calculate the download speed
+ double speed = bytesReceived * 1000.0 / info->m_StartTime.elapsed();
+ QString unit;
+ if (speed < 1024) {
+ unit = "bytes/sec";
+ }
+ else if (speed < 1024 * 1024) {
+ speed /= 1024;
+ unit = "kB/s";
+ }
+ else {
+ speed /= 1024 * 1024;
+ unit = "MB/s";
}
+
+ info->m_Progress.second = QString::fromLatin1("%1% - %2 %3").arg(info->m_Progress.first).arg(speed, 3, 'f', 1).arg(unit);
+
+ TaskProgressManager::instance().updateProgress(info->m_TaskProgressId, bytesReceived, bytesTotal);
+ emit update(index);
}
}
} catch (const std::bad_alloc&) {
diff --git a/src/downloadmanager.h b/src/downloadmanager.h
index 308d365b..e1925040 100644
--- a/src/downloadmanager.h
+++ b/src/downloadmanager.h
@@ -75,7 +75,7 @@ private:
QNetworkReply *m_Reply;
QTime m_StartTime;
qint64 m_PreResumeSize;
- int m_Progress;
+ std::pair<int, QString> m_Progress;
DownloadState m_State;
int m_CurrentUrl;
QStringList m_Urls;
@@ -259,7 +259,7 @@ public:
* @param index index of the file to look up
* @return progress of the download in percent (integer)
**/
- int getProgress(int index) const;
+ std::pair<int, QString> getProgress(int index) const;
/**
* @brief retrieve the current state of the download
@@ -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..e505bacc 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);
}
}
@@ -287,8 +288,11 @@ int ModInfo::checkAllForUpdate(PluginContainer *pluginContainer, QObject *receiv
//I ought to store this, it's used elsewhere
IPluginGame const *game = qApp->property("managed_game").value<IPluginGame *>();
- modIDs.push_back(game->nexusModOrganizerID());
- checkChunkForUpdate(pluginContainer, modIDs, receiver, game->gameShortName());
+ if (game->nexusModOrganizerID()) {
+ 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/nexusinterface.cpp b/src/nexusinterface.cpp
index 8bf0de6e..d2a52c7b 100644
--- a/src/nexusinterface.cpp
+++ b/src/nexusinterface.cpp
@@ -247,21 +247,19 @@ bool NexusInterface::isURLGameRelated(const QUrl &url) const
{
QString const name(url.toString());
return name.startsWith(getGameURL("") + "/") ||
- name.startsWith(getOldModsURL() + "/");
+ name.startsWith(getOldModsURL("") + "/");
}
QString NexusInterface::getGameURL(QString gameName) const
{
IPluginGame *game = getGame(gameName);
- if (game != nullptr) {
- return "https://www.nexusmods.com/" + game->gameNexusName().toLower();
- }
- return "https://www.nexusmods.com/" + m_Game->gameNexusName().toLower();
+ return "https://www.nexusmods.com/" + game->gameNexusName().toLower();
}
-QString NexusInterface::getOldModsURL() const
+QString NexusInterface::getOldModsURL(QString gameName) const
{
- return "https://" + m_Game->gameNexusName().toLower() + ".nexusmods.com/mods";
+ IPluginGame *game = getGame(gameName);
+ return "https://" + game->gameNexusName().toLower() + ".nexusmods.com/mods";
}
@@ -291,7 +289,7 @@ bool NexusInterface::isModURL(int modID, const QString &url) const
return true;
}
//Try the alternate (old style) mod name
- QString alt = QString("%1/%2").arg(getOldModsURL()).arg(modID);
+ QString alt = QString("%1/%2").arg(getOldModsURL("")).arg(modID);
return QUrl(alt) == QUrl(url);
}
@@ -321,22 +319,17 @@ int NexusInterface::requestUpdates(const std::vector<int> &modIDs, QObject *rece
QString gameName, const QString &subModule)
{
IPluginGame *game = getGame(gameName);
+ NXMRequestInfo requestInfo(modIDs, NXMRequestInfo::TYPE_GETUPDATES, userData, subModule, game);
+ m_RequestQueue.enqueue(requestInfo);
- if (game != nullptr) {
- NXMRequestInfo requestInfo(modIDs, NXMRequestInfo::TYPE_GETUPDATES, userData, subModule, game);
- m_RequestQueue.enqueue(requestInfo);
-
- connect(this, SIGNAL(nxmUpdatesAvailable(std::vector<int>, QVariant, QVariant, int)),
- receiver, SLOT(nxmUpdatesAvailable(std::vector<int>, QVariant, QVariant, int)), Qt::UniqueConnection);
-
- connect(this, SIGNAL(nxmRequestFailed(QString, int, int, QVariant, int, QString)),
- receiver, SLOT(nxmRequestFailed(QString, int, int, QVariant, int, QString)), Qt::UniqueConnection);
+ connect(this, SIGNAL(nxmUpdatesAvailable(std::vector<int>, QVariant, QVariant, int)),
+ receiver, SLOT(nxmUpdatesAvailable(std::vector<int>, QVariant, QVariant, int)), Qt::UniqueConnection);
- nextRequest();
- return requestInfo.m_ID;
- }
+ connect(this, SIGNAL(nxmRequestFailed(QString, int, int, QVariant, int, QString)),
+ receiver, SLOT(nxmRequestFailed(QString, int, int, QVariant, int, QString)), Qt::UniqueConnection);
- return -1;
+ nextRequest();
+ return requestInfo.m_ID;
}
@@ -378,20 +371,17 @@ int NexusInterface::requestFiles(QString gameName, int modID, QObject *receiver,
int NexusInterface::requestFileInfo(QString gameName, int modID, int fileID, QObject *receiver, QVariant userData, const QString &subModule)
{
IPluginGame *gamePlugin = getGame(gameName);
- if (gamePlugin != nullptr) {
- NXMRequestInfo requestInfo(modID, fileID, NXMRequestInfo::TYPE_FILEINFO, userData, subModule, gamePlugin);
- m_RequestQueue.enqueue(requestInfo);
+ NXMRequestInfo requestInfo(modID, fileID, NXMRequestInfo::TYPE_FILEINFO, userData, subModule, gamePlugin);
+ m_RequestQueue.enqueue(requestInfo);
- connect(this, SIGNAL(nxmFileInfoAvailable(QString, int, int, QVariant, QVariant, int)),
- receiver, SLOT(nxmFileInfoAvailable(QString, int, int, QVariant, QVariant, int)), Qt::UniqueConnection);
+ connect(this, SIGNAL(nxmFileInfoAvailable(QString, int, int, QVariant, QVariant, int)),
+ receiver, SLOT(nxmFileInfoAvailable(QString, int, int, QVariant, QVariant, int)), Qt::UniqueConnection);
- connect(this, SIGNAL(nxmRequestFailed(QString, int, int, QVariant, int, QString)),
- receiver, SLOT(nxmRequestFailed(QString, int, int, QVariant, int, QString)), Qt::UniqueConnection);
+ connect(this, SIGNAL(nxmRequestFailed(QString, int, int, QVariant, int, QString)),
+ receiver, SLOT(nxmRequestFailed(QString, int, int, QVariant, int, QString)), Qt::UniqueConnection);
- nextRequest();
- return requestInfo.m_ID;
- }
- return -1;
+ nextRequest();
+ return requestInfo.m_ID;
}
@@ -438,7 +428,7 @@ bool NexusInterface::requiresLogin(const NXMRequestInfo &info)
IPluginGame* NexusInterface::getGame(QString gameName) const
{
auto gamePlugins = m_PluginContainer->plugins<IPluginGame>();
- IPluginGame *gamePlugin = nullptr;
+ IPluginGame *gamePlugin = qApp->property("managed_game").value<IPluginGame*>();
for (auto plugin : gamePlugins) {
if (plugin->gameShortName().compare(gameName, Qt::CaseInsensitive) == 0) {
gamePlugin = plugin;
@@ -637,11 +627,6 @@ void NexusInterface::requestTimeout()
}
}
-void NexusInterface::managedGameChanged(IPluginGame const *game)
-{
- m_Game = game;
-}
-
namespace {
QString get_management_url(MOBase::IPluginGame const *game)
{
diff --git a/src/nexusinterface.h b/src/nexusinterface.h
index 4a5ac0dd..defb370f 100644
--- a/src/nexusinterface.h
+++ b/src/nexusinterface.h
@@ -349,9 +349,6 @@ signals:
void nxmEndorsementToggled(QString gameName, int modID, QVariant userData, QVariant resultData, int requestID);
void nxmRequestFailed(QString gameName, int modID, int fileID, QVariant userData, int requestID, const QString &errorString);
-public slots:
- void managedGameChanged(MOBase::IPluginGame const *game);
-
private slots:
void requestFinished();
@@ -404,7 +401,7 @@ private:
void requestFinished(std::list<NXMRequestInfo>::iterator iter);
bool requiresLogin(const NXMRequestInfo &info);
MOBase::IPluginGame *getGame(QString gameName) const;
- QString getOldModsURL() const;
+ QString getOldModsURL(QString gameName) const;
private:
@@ -418,7 +415,6 @@ private:
MOBase::VersionInfo m_MOVersion;
QString m_NMMVersion;
- MOBase::IPluginGame const *m_Game;
PluginContainer *m_PluginContainer;
};
diff --git a/src/organizercore.cpp b/src/organizercore.cpp
index 69c28c5c..d1b1fcd7 100644
--- a/src/organizercore.cpp
+++ b/src/organizercore.cpp
@@ -240,9 +240,6 @@ OrganizerCore::OrganizerCore(const QSettings &initSettings)
SLOT(managedGameChanged(MOBase::IPluginGame const *)));
connect(this, SIGNAL(managedGameChanged(MOBase::IPluginGame const *)),
&m_PluginList, SLOT(managedGameChanged(MOBase::IPluginGame const *)));
- connect(this, SIGNAL(managedGameChanged(MOBase::IPluginGame const *)),
- NexusInterface::instance(m_PluginContainer),
- SLOT(managedGameChanged(MOBase::IPluginGame const *)));
connect(&m_PluginList, &PluginList::writePluginsList, &m_PluginListsWriter,
&DelayedFileWriterBase::write);
@@ -919,13 +916,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)