summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTannin <devnull@localhost>2013-12-07 12:48:18 +0100
committerTannin <devnull@localhost>2013-12-07 12:48:18 +0100
commit469cc2d945afebb1291a825339642b5e95f0e223 (patch)
treeff1300a0aa0fb093c64a69babcebf78f5ac9aa2a /src
parent0e90b9d233eb3ae8276f6f8bfc4612c117544404 (diff)
- download manager now saves the file times on nexus, for potential later use in version check
- nexus interface now supports 301 redirects - now using the new nexus url format - bugfix: "visit on nexus" used an outdated url scheme and thus caused unnecessary redirection
Diffstat (limited to 'src')
-rw-r--r--src/downloadmanager.cpp26
-rw-r--r--src/downloadmanager.h5
-rw-r--r--src/mainwindow.cpp2
-rw-r--r--src/nexusinterface.cpp59
-rw-r--r--src/nexusinterface.h7
-rw-r--r--src/shared/fallout3info.cpp4
-rw-r--r--src/shared/fallout3info.h1
-rw-r--r--src/shared/falloutnvinfo.cpp4
-rw-r--r--src/shared/falloutnvinfo.h1
-rw-r--r--src/shared/gameinfo.h1
-rw-r--r--src/shared/oblivioninfo.cpp4
-rw-r--r--src/shared/oblivioninfo.h1
-rw-r--r--src/shared/skyriminfo.cpp4
-rw-r--r--src/shared/skyriminfo.h1
14 files changed, 80 insertions, 40 deletions
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp
index 779b052c..48484d24 100644
--- a/src/downloadmanager.cpp
+++ b/src/downloadmanager.cpp
@@ -153,7 +153,8 @@ QString DownloadManager::DownloadInfo::currentURL()
DownloadManager::DownloadManager(NexusInterface *nexusInterface, QObject *parent)
- : IDownloadManager(parent), m_NexusInterface(nexusInterface), m_DirWatcher(), m_ShowHidden(false)
+ : IDownloadManager(parent), m_NexusInterface(nexusInterface), m_DirWatcher(), m_ShowHidden(false),
+ m_DateExpression("/Date\\((\\d+)\\)/")
{
connect(&m_DirWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(directoryChanged(QString)));
}
@@ -851,7 +852,6 @@ void DownloadManager::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
setState(info, STATE_PAUSED);
} else {
if (bytesTotal > info->m_TotalSize) {
- qDebug("file size %s: %lld", qPrintable(info->m_FileName), bytesTotal);
info->m_TotalSize = bytesTotal;
}
int oldProgress = info->m_Progress;
@@ -883,6 +883,7 @@ void DownloadManager::createMetaFile(DownloadInfo *info)
metaFile.setValue("name", info->m_NexusInfo.m_Name);
metaFile.setValue("modName", info->m_NexusInfo.m_ModName);
metaFile.setValue("version", info->m_NexusInfo.m_Version);
+ metaFile.setValue("fileTime", info->m_NexusInfo.m_FileTime);
metaFile.setValue("fileCategory", info->m_NexusInfo.m_FileCategory);
metaFile.setValue("newestVersion", info->m_NexusInfo.m_NewestVersion);
metaFile.setValue("category", info->m_NexusInfo.m_Category);
@@ -914,11 +915,9 @@ void DownloadManager::nxmDescriptionAvailable(int, QVariant userData, QVariant r
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();
-
if (info->m_FileID != 0) {
setState(info, STATE_READY);
} else {
@@ -927,6 +926,17 @@ void DownloadManager::nxmDescriptionAvailable(int, QVariant userData, QVariant r
}
+QDateTime DownloadManager::matchDate(const QString &timeString)
+{
+ if (m_DateExpression.exactMatch(timeString)) {
+ return QDateTime::fromMSecsSinceEpoch(m_DateExpression.cap(1).toLongLong());
+ } else {
+ qWarning("date not matched: %s", qPrintable(timeString));
+ return QDateTime::currentDateTime();
+ }
+}
+
+
void DownloadManager::nxmFilesAvailable(int, QVariant userData, QVariant resultData, int requestID)
{
std::set<int>::iterator idIter = m_RequestIDs.find(requestID);
@@ -960,7 +970,11 @@ void DownloadManager::nxmFilesAvailable(int, QVariant userData, QVariant resultD
(fileNameVariant == info->m_FileName) || (fileNameVariant == alternativeLocalName)) {
info->m_NexusInfo.m_Name = fileInfo["name"].toString();
info->m_NexusInfo.m_Version = fileInfo["version"].toString();
+ if (info->m_NexusInfo.m_Version.isEmpty()) {
+ info->m_NexusInfo.m_Version = info->m_NexusInfo.m_NewestVersion;
+ }
info->m_NexusInfo.m_FileCategory = fileInfo["category_id"].toInt();
+ info->m_NexusInfo.m_FileTime = matchDate(fileInfo["date"].toString());
info->m_FileID = fileInfo["id"].toInt();
found = true;
break;
@@ -1014,7 +1028,11 @@ void DownloadManager::nxmFileInfoAvailable(int modID, int fileID, QVariant userD
info.m_Name = result["name"].toString();
info.m_Version = result["version"].toString();
+ if (info.m_Version.isEmpty()) {
+ info.m_Version = info.m_NewestVersion;
+ }
info.m_FileName = result["uri"].toString();
+ info.m_FileTime = matchDate(result["date"].toString());
if (userData.isValid()) {
m_RequestIDs.insert(m_NexusInterface->requestDownloadURL(modID, fileID, this, qVariantFromValue(info), userData.toString()));
diff --git a/src/downloadmanager.h b/src/downloadmanager.h
index e82ea064..099e6084 100644
--- a/src/downloadmanager.h
+++ b/src/downloadmanager.h
@@ -46,6 +46,7 @@ struct NexusInfo {
QString m_NewestVersion;
QString m_FileName;
QVariantList m_DownloadMap;
+ QDateTime m_FileTime;
bool m_Set;
};
Q_DECLARE_METATYPE(NexusInfo)
@@ -437,6 +438,8 @@ private:
DownloadInfo *downloadInfoByID(unsigned int id);
+ QDateTime matchDate(const QString &timeString);
+
private:
static const int AUTOMATIC_RETRIES = 3;
@@ -458,6 +461,8 @@ private:
bool m_ShowHidden;
+ QRegExp m_DateExpression;
+
};
#endif // DOWNLOADMANAGER_H
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index d5330017..cca10279 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -3214,7 +3214,7 @@ void MainWindow::visitOnNexus_clicked()
{
int modID = m_ModList.data(m_ModList.index(m_ContextRow, 0), Qt::UserRole).toInt();
if (modID > 0) {
- nexusLinkActivated(QString("%1/downloads/file.php?id=%2").arg(ToQString(GameInfo::instance().getNexusPage())).arg(modID));
+ nexusLinkActivated(QString("%1/mods/%2").arg(ToQString(GameInfo::instance().getNexusPage())).arg(modID));
} else {
MessageDialog::showMessage(tr("Nexus ID for this Mod is unknown"), this);
}
diff --git a/src/nexusinterface.cpp b/src/nexusinterface.cpp
index 6a4ae046..6b5cf19c 100644
--- a/src/nexusinterface.cpp
+++ b/src/nexusinterface.cpp
@@ -380,29 +380,33 @@ void NexusInterface::nextRequest()
info.m_Timeout->setInterval(60000);
QString url;
- switch (info.m_Type) {
- case NXMRequestInfo::TYPE_DESCRIPTION: {
- url = QString("%1/Mods/%2/").arg(info.m_URL).arg(info.m_ModID);
- } break;
- case NXMRequestInfo::TYPE_FILES: {
- url = QString("%1/Files/indexfrommod/%2/").arg(info.m_URL).arg(info.m_ModID);
- } break;
- case NXMRequestInfo::TYPE_FILEINFO: {
- url = QString("%1/Files/%2/").arg(info.m_URL).arg(info.m_FileID);
- } break;
- case NXMRequestInfo::TYPE_DOWNLOADURL: {
- url = QString("%1/Files/download/%2").arg(info.m_URL).arg(info.m_FileID);
- } break;
- case NXMRequestInfo::TYPE_TOGGLEENDORSEMENT: {
- url = QString("%1/Mods/toggleendorsement/%2?lvote=%3").arg(info.m_URL).arg(info.m_ModID).arg(!info.m_Endorse);
- } break;
- case NXMRequestInfo::TYPE_GETUPDATES: {
- QString modIDList = VectorJoin<int>(info.m_ModIDList, ",");
- modIDList = "[" + modIDList + "]";
- url = QString("%1/Mods/GetUpdates?ModList=%2").arg(info.m_URL).arg(modIDList);
- } break;
+ if (!info.m_Reroute) {
+ switch (info.m_Type) {
+ case NXMRequestInfo::TYPE_DESCRIPTION: {
+ url = QString("%1/Mods/%2/").arg(info.m_URL).arg(info.m_ModID);
+ } break;
+ case NXMRequestInfo::TYPE_FILES: {
+ url = QString("%1/Files/indexfrommod/%2/").arg(info.m_URL).arg(info.m_ModID);
+ } break;
+ case NXMRequestInfo::TYPE_FILEINFO: {
+ url = QString("%1/Files/%2/").arg(info.m_URL).arg(info.m_FileID);
+ } break;
+ case NXMRequestInfo::TYPE_DOWNLOADURL: {
+ url = QString("%1/Files/download/%2").arg(info.m_URL).arg(info.m_FileID);
+ } break;
+ case NXMRequestInfo::TYPE_TOGGLEENDORSEMENT: {
+ url = QString("%1/Mods/toggleendorsement/%2?lvote=%3").arg(info.m_URL).arg(info.m_ModID).arg(!info.m_Endorse);
+ } break;
+ case NXMRequestInfo::TYPE_GETUPDATES: {
+ QString modIDList = VectorJoin<int>(info.m_ModIDList, ",");
+ modIDList = "[" + modIDList + "]";
+ url = QString("%1/Mods/GetUpdates?ModList=%2").arg(info.m_URL).arg(modIDList);
+ } break;
+ }
+ url.append(QString("?game_id=%1").arg(GameInfo::instance().getNexusGameID()));
+ } else {
+ url = info.m_URL;
}
-
QNetworkRequest request(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/xml");
request.setRawHeader("User-Agent",
@@ -433,13 +437,21 @@ void NexusInterface::requestFinished(std::list<NXMRequestInfo>::iterator iter)
qWarning("request failed: %s", reply->errorString().toUtf8().constData());
emit nxmRequestFailed(iter->m_ModID, iter->m_UserData, iter->m_ID, reply->errorString());
} else {
+ int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
+ if (statusCode == 301) {
+ // redirect request, return request to queue
+ iter->m_URL = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString();
+ iter->m_Reroute = true;
+ m_RequestQueue.enqueue(*iter);
+ nextRequest();
+ return;
+ }
QByteArray data = reply->readAll();
if (data.isNull() || data.isEmpty() || (strcmp(data.constData(), "null") == 0)) {
QString nexusError(reply->rawHeader("NexusErrorInfo"));
if (nexusError.length() == 0) {
nexusError = tr("empty response");
}
-
emit nxmRequestFailed(iter->m_ModID, iter->m_UserData, iter->m_ID, nexusError);
} else {
bool ok;
@@ -509,7 +521,6 @@ void NexusInterface::requestTimeout()
qWarning("invalid sender type");
return;
}
- qWarning("request timeout");
for (std::list<NXMRequestInfo>::iterator iter = m_ActiveRequest.begin(); iter != m_ActiveRequest.end(); ++iter) {
if (iter->m_Timeout == timer) {
// this abort causes a "request failed" which cleans up the rest
diff --git a/src/nexusinterface.h b/src/nexusinterface.h
index da5fe02a..e7a01b0f 100644
--- a/src/nexusinterface.h
+++ b/src/nexusinterface.h
@@ -270,18 +270,19 @@ private:
QVariant m_UserData;
QTimer *m_Timeout;
QString m_URL;
+ bool m_Reroute;
int m_ID;
int m_Endorse;
NXMRequestInfo(int modID, Type type, QVariant userData, const QString &url)
: m_ModID(modID), m_FileID(0), m_Reply(NULL), m_Type(type), m_UserData(userData),
- m_Timeout(NULL), m_ID(s_NextID.fetchAndAddAcquire(1)), m_URL(url) {}
+ m_Timeout(NULL), m_Reroute(false), m_ID(s_NextID.fetchAndAddAcquire(1)), m_URL(url) {}
NXMRequestInfo(std::vector<int> modIDList, Type type, QVariant userData, const QString &url)
: m_ModID(-1), m_ModIDList(modIDList), m_FileID(0), m_Reply(NULL), m_Type(type), m_UserData(userData),
- m_Timeout(NULL), m_ID(s_NextID.fetchAndAddAcquire(1)), m_URL(url) {}
+ m_Timeout(NULL), m_Reroute(false), m_ID(s_NextID.fetchAndAddAcquire(1)), m_URL(url) {}
NXMRequestInfo(int modID, int fileID, Type type, QVariant userData, const QString &url)
: m_ModID(modID), m_FileID(fileID), m_Reply(NULL), m_Type(type), m_UserData(userData),
- m_Timeout(NULL), m_ID(s_NextID.fetchAndAddAcquire(1)), m_URL(url) {}
+ m_Timeout(NULL), m_Reroute(false), m_ID(s_NextID.fetchAndAddAcquire(1)), m_URL(url) {}
private:
static QAtomicInt s_NextID;
diff --git a/src/shared/fallout3info.cpp b/src/shared/fallout3info.cpp
index c673fa1b..864a67be 100644
--- a/src/shared/fallout3info.cpp
+++ b/src/shared/fallout3info.cpp
@@ -155,13 +155,13 @@ std::wstring Fallout3Info::getSEName()
std::wstring Fallout3Info::getNexusPage()
{
- return L"http://fallout3.nexusmods.com";
+ return L"http://www.nexusmods.com/fallout3";
}
std::wstring Fallout3Info::getNexusInfoUrlStatic()
{
- return L"http://fallout3.nexusmods.com";
+ return L"http://www.nexusmods.com/fallout3";
}
diff --git a/src/shared/fallout3info.h b/src/shared/fallout3info.h
index 0fa97d41..4bcb9d37 100644
--- a/src/shared/fallout3info.h
+++ b/src/shared/fallout3info.h
@@ -76,6 +76,7 @@ public:
virtual std::wstring getNexusInfoUrl() { return Fallout3Info::getNexusInfoUrlStatic(); }
static int getNexusModIDStatic();
virtual int getNexusModID() { return Fallout3Info::getNexusModIDStatic(); }
+ virtual int getNexusGameID() { return 120; }
virtual void createProfile(const std::wstring &directory, bool useDefaults);
virtual void repairProfile(const std::wstring &directory);
diff --git a/src/shared/falloutnvinfo.cpp b/src/shared/falloutnvinfo.cpp
index 7d7f0098..8df9607d 100644
--- a/src/shared/falloutnvinfo.cpp
+++ b/src/shared/falloutnvinfo.cpp
@@ -209,13 +209,13 @@ std::wstring FalloutNVInfo::getSEName()
std::wstring FalloutNVInfo::getNexusPage()
{
- return L"http://newvegas.nexusmods.com";
+ return L"http://www.nexusmods.com/newvegas";
}
std::wstring FalloutNVInfo::getNexusInfoUrlStatic()
{
- return L"http://newvegas.nexusmods.com";
+ return L"http://www.nexusmods.com/newvegas";
}
diff --git a/src/shared/falloutnvinfo.h b/src/shared/falloutnvinfo.h
index 3960c951..e25d2e02 100644
--- a/src/shared/falloutnvinfo.h
+++ b/src/shared/falloutnvinfo.h
@@ -77,6 +77,7 @@ public:
virtual std::wstring getNexusInfoUrl() { return FalloutNVInfo::getNexusInfoUrlStatic(); }
static int getNexusModIDStatic();
virtual int getNexusModID() { return FalloutNVInfo::getNexusModIDStatic(); }
+ virtual int getNexusGameID() { return 130; }
virtual void createProfile(const std::wstring &directory, bool useDefaults);
virtual void repairProfile(const std::wstring &directory);
diff --git a/src/shared/gameinfo.h b/src/shared/gameinfo.h
index 0221dd1b..d517fc1b 100644
--- a/src/shared/gameinfo.h
+++ b/src/shared/gameinfo.h
@@ -145,6 +145,7 @@ public:
virtual std::wstring getNexusPage() = 0;
virtual std::wstring getNexusInfoUrl() = 0;
virtual int getNexusModID() = 0;
+ virtual int getNexusGameID() = 0;
// clone relevant files to the specified directory
virtual void createProfile(const std::wstring &directory, bool useDefaults) = 0;
diff --git a/src/shared/oblivioninfo.cpp b/src/shared/oblivioninfo.cpp
index b3e65e59..1438de0a 100644
--- a/src/shared/oblivioninfo.cpp
+++ b/src/shared/oblivioninfo.cpp
@@ -191,13 +191,13 @@ std::wstring OblivionInfo::getSEName()
std::wstring OblivionInfo::getNexusPage()
{
- return L"http://oblivion.nexusmods.com";
+ return L"http://www.nexusmods.com/oblivion";
}
std::wstring OblivionInfo::getNexusInfoUrlStatic()
{
- return L"http://oblivion.nexusmods.com";
+ return L"http://www.nexusmods.com/oblivion";
}
diff --git a/src/shared/oblivioninfo.h b/src/shared/oblivioninfo.h
index 6a9f56ca..dfa53575 100644
--- a/src/shared/oblivioninfo.h
+++ b/src/shared/oblivioninfo.h
@@ -73,6 +73,7 @@ public:
virtual std::wstring getNexusInfoUrl() { return OblivionInfo::getNexusInfoUrlStatic(); }
static int getNexusModIDStatic();
virtual int getNexusModID() { return OblivionInfo::getNexusModIDStatic(); }
+ virtual int getNexusGameID() { return 101; }
virtual void createProfile(const std::wstring &directory, bool useDefaults);
virtual void repairProfile(const std::wstring &directory);
diff --git a/src/shared/skyriminfo.cpp b/src/shared/skyriminfo.cpp
index 0a0dd98d..a8b9a433 100644
--- a/src/shared/skyriminfo.cpp
+++ b/src/shared/skyriminfo.cpp
@@ -183,13 +183,13 @@ std::wstring SkyrimInfo::getSEName()
std::wstring SkyrimInfo::getNexusPage()
{
- return L"http://skyrim.nexusmods.com";
+ return L"http://www.nexusmods.com/skyrim";
}
std::wstring SkyrimInfo::getNexusInfoUrlStatic()
{
- return L"http://skyrim.nexusmods.com";
+ return L"http://www.nexusmods.com/skyrim";
}
diff --git a/src/shared/skyriminfo.h b/src/shared/skyriminfo.h
index ae5ab81f..7da523a1 100644
--- a/src/shared/skyriminfo.h
+++ b/src/shared/skyriminfo.h
@@ -81,6 +81,7 @@ public:
virtual std::wstring getNexusInfoUrl() { return SkyrimInfo::getNexusInfoUrlStatic(); }
static int getNexusModIDStatic();
virtual int getNexusModID() { return SkyrimInfo::getNexusModIDStatic(); }
+ virtual int getNexusGameID() { return 110; }
virtual void createProfile(const std::wstring &directory, bool useDefaults);
virtual void repairProfile(const std::wstring &directory);