diff options
| author | Tannin <devnull@localhost> | 2013-05-19 11:36:36 +0200 |
|---|---|---|
| committer | Tannin <devnull@localhost> | 2013-05-19 11:36:36 +0200 |
| commit | 0beb88760b4c258b89daf5791069dc885c0c27aa (patch) | |
| tree | e86596d032ef4bc6ba7f2ce5823becd42adcbaca /src/downloadmanager.cpp | |
| parent | 4fbfc9aa54ed4499f54eb7b3cd942337f6b49e58 (diff) | |
- added hook for GetModuleFileName
- downloads are now identifiable by ID
- fixed a bug with the multi-select categories list
- fixed a problem with the nexus-login code breaking support for certain passwords
- fixed a bug where detection of archive invalidation didn't work correctly
- fixed ncc plugin trying to handle archives that aren't actually fomods
Diffstat (limited to 'src/downloadmanager.cpp')
| -rw-r--r-- | src/downloadmanager.cpp | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 69edc625..0ec8536b 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -42,11 +42,13 @@ using namespace MOBase; static const char UNFINISHED[] = ".unfinished"; +unsigned int DownloadManager::DownloadInfo::s_NextDownloadID = 1U; + DownloadManager::DownloadInfo *DownloadManager::DownloadInfo::createNew(const NexusInfo &nexusInfo, int modID, int fileID, const QStringList &URLs) { DownloadInfo *info = new DownloadInfo; - + info->m_DownloadID = s_NextDownloadID++; info->m_StartTime.start(); info->m_Progress = 0; info->m_ResumePos = 0; @@ -88,6 +90,7 @@ DownloadManager::DownloadInfo *DownloadManager::DownloadInfo::createFromMeta(con } } + info->m_DownloadID = s_NextDownloadID++; info->m_Output.setFileName(filePath); info->m_ModID = metaFile.value("modID", 0).toInt(); info->m_FileID = metaFile.value("fileID", 0).toInt(); @@ -461,6 +464,18 @@ void DownloadManager::resumeDownload(int index) } +DownloadManager::DownloadInfo *DownloadManager::downloadInfoByID(unsigned int id) +{ + auto iter = std::find_if(m_ActiveDownloads.begin(), m_ActiveDownloads.end(), + [id](DownloadInfo *info) { return info->m_DownloadID == id; }); + if (iter != m_ActiveDownloads.end()) { + return *iter; + } else { + return NULL; + } +} + + void DownloadManager::queryInfo(int index) { if ((index < 0) || (index >= m_ActiveDownloads.size())) { @@ -622,7 +637,6 @@ QString DownloadManager::getFileNameFromNetworkReply(QNetworkReply *reply) void DownloadManager::setState(DownloadManager::DownloadInfo *info, DownloadManager::DownloadState state) { - qDebug("change state of %s %d -> %d", qPrintable(info->m_FileName), info->m_State, state); info->m_State = state; switch (state) { case STATE_PAUSED: @@ -633,10 +647,10 @@ void DownloadManager::setState(DownloadManager::DownloadInfo *info, DownloadMana info->m_Reply->abort(); } break; case STATE_FETCHINGMODINFO: { - m_RequestIDs.insert(m_NexusInterface->requestDescription(info->m_ModID, this, qVariantFromValue(static_cast<void*>(info)))); + m_RequestIDs.insert(m_NexusInterface->requestDescription(info->m_ModID, this, info->m_DownloadID)); } break; case STATE_FETCHINGFILEINFO: { - m_RequestIDs.insert(m_NexusInterface->requestFiles(info->m_ModID, this, qVariantFromValue(static_cast<void*>(info)))); + m_RequestIDs.insert(m_NexusInterface->requestFiles(info->m_ModID, this, info->m_DownloadID)); } break; case STATE_READY: { createMetaFile(info); @@ -729,7 +743,10 @@ void DownloadManager::nxmDescriptionAvailable(int, QVariant userData, QVariant r QVariantMap result = resultData.toMap(); - DownloadInfo *info = static_cast<DownloadInfo*>(userData.value<void*>()); +// DownloadInfo *info = static_cast<DownloadInfo*>(userData.value<void*>()); + DownloadInfo *info = downloadInfoByID(userData.toInt()); + if (info == NULL) return; + info->m_NexusInfo.m_Category = result["category_id"].toInt(); info->m_NexusInfo.m_ModName = result["name"].toString().trimmed(); info->m_NexusInfo.m_NewestVersion = result["version"].toString(); @@ -751,7 +768,8 @@ void DownloadManager::nxmFilesAvailable(int, QVariant userData, QVariant resultD m_RequestIDs.erase(idIter); } - DownloadInfo *info = static_cast<DownloadInfo*>(userData.value<void*>()); + DownloadInfo *info = downloadInfoByID(userData.toInt()); + if (info == NULL) return; QVariantList result = resultData.toList(); |
