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 | |
| 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
| -rw-r--r-- | src/downloadmanager.cpp | 30 | ||||
| -rw-r--r-- | src/downloadmanager.h | 6 | ||||
| -rw-r--r-- | src/logbuffer.cpp | 3 | ||||
| -rw-r--r-- | src/mainwindow.cpp | 22 | ||||
| -rw-r--r-- | src/nxmaccessmanager.cpp | 9 | ||||
| -rw-r--r-- | src/profile.cpp | 15 |
6 files changed, 64 insertions, 21 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(); diff --git a/src/downloadmanager.h b/src/downloadmanager.h index 407acd3c..b2fee921 100644 --- a/src/downloadmanager.h +++ b/src/downloadmanager.h @@ -75,6 +75,7 @@ public: private: struct DownloadInfo { + unsigned int m_DownloadID; QString m_FileName; QFile m_Output; QNetworkReply *m_Reply; @@ -108,7 +109,8 @@ private: bool isPausedState(); QString currentURL(); - + private: + static unsigned int s_NextDownloadID; private: DownloadInfo() : m_TotalSize(0), m_ReQueried(false) {} }; @@ -343,6 +345,8 @@ private: void setState(DownloadInfo *info, DownloadManager::DownloadState state); + DownloadInfo *downloadInfoByID(unsigned int id); + private: static const int AUTOMATIC_RETRIES = 3; diff --git a/src/logbuffer.cpp b/src/logbuffer.cpp index c891f4c5..d563f796 100644 --- a/src/logbuffer.cpp +++ b/src/logbuffer.cpp @@ -65,6 +65,8 @@ void LogBuffer::write() const return; } + DWORD lastError = ::GetLastError(); + QFile file(m_OutFileName); if (!file.open(QIODevice::WriteOnly)) { reportError(tr("failed to write log to %1: %2").arg(m_OutFileName).arg(file.errorString())); @@ -77,6 +79,7 @@ void LogBuffer::write() const file.write(m_Messages.at(i % m_Messages.size()).toUtf8()); file.write("\r\n"); } + ::SetLastError(lastError); } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 65633ab1..cecf3d7d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2290,8 +2290,15 @@ void MainWindow::refreshFilters() ui->modList->setCurrentIndex(QModelIndex()); // save previous filter text so we can restore it later, in case the filter still exists then - QTreeWidgetItem *currentItem = ui->categoriesList->currentItem(); - QString previousFilter = currentItem != NULL ? currentItem->text(0) : tr("<All>"); +// QTreeWidgetItem *currentItem = ui->categoriesList->currentItem(); +// QString previousFilter = currentItem != NULL ? currentItem->text(0) : tr("<All>"); + + + QStringList selectedItems; + foreach (QTreeWidgetItem *item, ui->categoriesList->selectedItems()) { + selectedItems.append(item->text(0)); + } + ui->categoriesList->clear(); addFilterItem(NULL, tr("<Checked>"), CategoryFactory::CATEGORY_SPECIAL_CHECKED); @@ -2315,13 +2322,10 @@ void MainWindow::refreshFilters() addCategoryFilters(NULL, categoriesUsed, 0); - QList<QTreeWidgetItem*> matches = ui->categoriesList->findItems(previousFilter, Qt::MatchFixedString | Qt::MatchRecursive); - if (matches.size() > 0) { - QTreeWidgetItem *currentItem = matches.at(0); - ui->categoriesList->setCurrentItem(currentItem); - while (currentItem != NULL) { - currentItem->setExpanded(true); - currentItem = currentItem->parent(); + foreach (const QString &item, selectedItems) { + QList<QTreeWidgetItem*> matches = ui->categoriesList->findItems(item, Qt::MatchFixedString | Qt::MatchRecursive); + if (matches.size() > 0) { + matches.at(0)->setSelected(true); } } diff --git a/src/nxmaccessmanager.cpp b/src/nxmaccessmanager.cpp index 0f9f0209..dd05116d 100644 --- a/src/nxmaccessmanager.cpp +++ b/src/nxmaccessmanager.cpp @@ -95,10 +95,15 @@ void NXMAccessManager::login(const QString &username, const QString &password) void NXMAccessManager::pageLogin() { - QString requestString = QString("http://gatekeeper.nexusmods.com/Sessions/?Login&username=%2&password=%3").arg(m_Username).arg(m_Password); + QString requestString = QString("http://gatekeeper.nexusmods.com/Sessions/?Login"); + QUrl postData; + postData.addQueryItem("username", m_Username); + postData.addQueryItem("password", m_Password); QNetworkRequest request(requestString); - m_LoginReply = get(request); + request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); + + m_LoginReply = post(request, postData.encodedQuery()); m_LoginTimeout.start(); connect(m_LoginReply, SIGNAL(finished()), this, SLOT(loginFinished())); diff --git a/src/profile.cpp b/src/profile.cpp index 24c6d943..38899cba 100644 --- a/src/profile.cpp +++ b/src/profile.cpp @@ -547,6 +547,9 @@ bool Profile::invalidationActive(bool *supported) const *supported = true; wchar_t buffer[1024]; std::wstring iniFileName = ToWString(QDir::toNativeSeparators(getIniFileName())); + // epic ms fail: GetPrivateProfileString uses errno (for whatever reason) to signal a fail since the return value + // has a different meaning (number of bytes copied). HOWEVER, it will not set errno to 0 if NO error occured + errno = 0; if (::GetPrivateProfileStringW(L"Archive", GameInfo::instance().archiveListKey().c_str(), L"", buffer, 1024, iniFileName.c_str()) == 0) { if (errno != 0x02) { @@ -555,8 +558,7 @@ bool Profile::invalidationActive(bool *supported) const } return false; } else { - qCritical("failed to parse \"%ls\"", iniFileName.c_str()); - QString errorMessage = tr("failed to parse ini file (%1): %2").arg(QDir::toNativeSeparators(getIniFileName())).arg(::GetLastError()); + QString errorMessage = tr("failed to parse ini file (%1)").arg(ToQString(iniFileName)); throw windows_error(errorMessage.toUtf8().constData()); } } @@ -580,6 +582,7 @@ void Profile::deactivateInvalidation() const if (GameInfo::instance().requiresBSAInvalidation()) { wchar_t buffer[1024]; std::wstring iniFileName = ToWString(QDir::toNativeSeparators(getIniFileName())); + errno = 0; if (::GetPrivateProfileStringW(L"Archive", GameInfo::instance().archiveListKey().c_str(), L"", buffer, 1024, iniFileName.c_str()) == 0) { if (errno == 0x02) { @@ -619,9 +622,15 @@ void Profile::activateInvalidation(const QString& dataDirectory) const if (GameInfo::instance().requiresBSAInvalidation()) { wchar_t buffer[1024]; std::wstring iniFileName = ToWString(QDir::toNativeSeparators(getIniFileName())); + errno = 0; if (::GetPrivateProfileStringW(L"Archive", GameInfo::instance().archiveListKey().c_str(), L"", buffer, 1024, iniFileName.c_str()) == 0) { - throw windows_error("failed to parse ini file"); + if (errno == 0x02) { + throw windows_error("failed to parse ini file"); + } else { + // ignore. shouldn't have gotten here anyway + return; + } } QStringList archives = ToQString(buffer).split(", "); |
