From ed4eb2aae8fcf493c07a02cbca3df14f00c5e130 Mon Sep 17 00:00:00 2001 From: Silarn Date: Thu, 9 May 2019 12:04:03 -0500 Subject: Update NXM link handling to support premium link and validate user info --- src/downloadmanager.cpp | 1 + src/mainwindow.cpp | 12 ++--- src/mainwindow.h | 2 +- src/nexusinterface.cpp | 24 +++++++-- src/nexusinterface.h | 6 ++- src/nxmaccessmanager.cpp | 3 +- src/nxmaccessmanager.h | 2 +- src/organizer_en.ts | 124 +++++++++++++++++++++++------------------------ 8 files changed, 97 insertions(+), 77 deletions(-) (limited to 'src') diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 25542ef3..78162f11 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -628,6 +628,7 @@ void DownloadManager::addNXMDownload(const QString &url) info->nexusKey = nxmInfo.key(); info->nexusExpires = nxmInfo.expires(); + info->nexusDownloadUser = nxmInfo.userId(); QObject *test = info; m_RequestIDs.insert(m_NexusInterface->requestFileInfo(nxmInfo.game(), nxmInfo.modId(), nxmInfo.fileId(), this, qVariantFromValue(test), "")); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 389e65ca..02c65266 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -217,7 +217,7 @@ MainWindow::MainWindow(QSettings &initSettings QWebEngineProfile::defaultProfile()->setCachePath(m_OrganizerCore.settings().getCacheDirectory()); QWebEngineProfile::defaultProfile()->setPersistentStoragePath(m_OrganizerCore.settings().getCacheDirectory()); ui->setupUi(this); - updateWindowTitle(QString(), false); + updateWindowTitle(QString(), 0, false); languageChange(m_OrganizerCore.settings().language()); @@ -403,10 +403,10 @@ MainWindow::MainWindow(QSettings &initSettings connect(NexusInterface::instance(&pluginContainer), SIGNAL(nxmDownloadURLsAvailable(QString,int,int,QVariant,QVariant,int)), this, SLOT(nxmDownloadURLs(QString,int,int,QVariant,QVariant,int))); connect(NexusInterface::instance(&pluginContainer), SIGNAL(needLogin()), &m_OrganizerCore, SLOT(nexusApi())); connect(NexusInterface::instance(&pluginContainer)->getAccessManager(), SIGNAL(validateFailed(QString)), this, SLOT(validationFailed(QString))); - connect(NexusInterface::instance(&pluginContainer)->getAccessManager(), SIGNAL(credentialsReceived(const QString&, bool, std::tuple)), - this, SLOT(updateWindowTitle(const QString&, bool))); - connect(NexusInterface::instance(&pluginContainer)->getAccessManager(), SIGNAL(credentialsReceived(const QString&, bool, std::tuple)), - NexusInterface::instance(&m_PluginContainer), SLOT(setRateMax(const QString&, bool, std::tuple))); + connect(NexusInterface::instance(&pluginContainer)->getAccessManager(), SIGNAL(credentialsReceived(const QString&, int, bool, std::tuple)), + this, SLOT(updateWindowTitle(const QString&, int, bool))); + connect(NexusInterface::instance(&pluginContainer)->getAccessManager(), SIGNAL(credentialsReceived(const QString&, int, bool, std::tuple)), + NexusInterface::instance(&m_PluginContainer), SLOT(setRateMax(const QString&, int, bool, std::tuple))); connect(NexusInterface::instance(&pluginContainer), SIGNAL(requestsChanged(int, std::tuple)), this, SLOT(updateAPICounter(int, std::tuple))); connect(&TutorialManager::instance(), SIGNAL(windowTutorialFinished(QString)), this, SLOT(windowTutorialFinished(QString))); @@ -514,7 +514,7 @@ MainWindow::~MainWindow() } -void MainWindow::updateWindowTitle(const QString &accountName, bool premium) +void MainWindow::updateWindowTitle(const QString &accountName, int, bool premium) { QString title = QString("%1 Mod Organizer v%2").arg( m_OrganizerCore.managedGame()->gameName(), diff --git a/src/mainwindow.h b/src/mainwindow.h index d119f49c..727dd165 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -396,7 +396,7 @@ private: private slots: - void updateWindowTitle(const QString &accountName, bool premium); + void updateWindowTitle(const QString &accountName, int, bool premium); void showMessage(const QString &message); void showError(const QString &message); diff --git a/src/nexusinterface.cpp b/src/nexusinterface.cpp index 9db0d54e..a4c08f53 100644 --- a/src/nexusinterface.cpp +++ b/src/nexusinterface.cpp @@ -180,7 +180,13 @@ QAtomicInt NexusInterface::NXMRequestInfo::s_NextID(0); NexusInterface::NexusInterface(PluginContainer *pluginContainer) - : m_PluginContainer(pluginContainer), m_RemainingDailyRequests(2500), m_RemainingHourlyRequests(100), m_MaxDailyRequests(2500), m_MaxHourlyRequests(100) + : m_PluginContainer(pluginContainer) + , m_RemainingDailyRequests(2500) + , m_RemainingHourlyRequests(100) + , m_MaxDailyRequests(2500) + , m_MaxHourlyRequests(100) + , m_IsPremium(false) + , m_UserID(0) { m_MOVersion = createVersionInfo(); @@ -216,12 +222,14 @@ void NexusInterface::loginCompleted() nextRequest(); } -void NexusInterface::setRateMax(const QString&, bool, std::tuple limits) +void NexusInterface::setRateMax(const QString&, int userId, bool isPremium, std::tuple limits) { m_RemainingDailyRequests = std::get<0>(limits); m_MaxDailyRequests = std::get<1>(limits); m_RemainingHourlyRequests = std::get<2>(limits); m_MaxHourlyRequests = std::get<3>(limits); + m_IsPremium = isPremium; + m_UserID = userId; emit requestsChanged(m_RequestQueue.size(), limits); } @@ -688,11 +696,17 @@ void NexusInterface::nextRequest() } break; case NXMRequestInfo::TYPE_DOWNLOADURL: { ModRepositoryFileInfo *fileInfo = qobject_cast(qvariant_cast(info.m_UserData)); - if (!fileInfo->nexusKey.isEmpty() && fileInfo->nexusExpires) + if (m_IsPremium) { + url = QString("%1/games/%2/mods/%3/files/%4/download_link").arg(info.m_URL).arg(info.m_GameName).arg(info.m_ModID).arg(info.m_FileID); + } else if (!fileInfo->nexusKey.isEmpty() && fileInfo->nexusExpires && fileInfo->nexusDownloadUser == m_UserID) { url = QString("%1/games/%2/mods/%3/files/%4/download_link?key=%5&expires=%6") .arg(info.m_URL).arg(info.m_GameName).arg(info.m_ModID).arg(info.m_FileID).arg(fileInfo->nexusKey).arg(fileInfo->nexusExpires); - else - url = QString("%1/games/%2/mods/%3/files/%4/download_link").arg(info.m_URL).arg(info.m_GameName).arg(info.m_ModID).arg(info.m_FileID); + } else { + QString warning("Aborting download: Either you clicked on a premium-only link and your account is not premium, " + "or the download link was generated by a different account than the one stored in Mod Organizer."); + qWarning() << warning; + return; + } } break; case NXMRequestInfo::TYPE_ENDORSEMENTS: { url = QString("%1/user/endorsements").arg(info.m_URL); diff --git a/src/nexusinterface.h b/src/nexusinterface.h index ac7f61c5..70c1c9c9 100644 --- a/src/nexusinterface.h +++ b/src/nexusinterface.h @@ -463,7 +463,7 @@ signals: public slots: - void setRateMax(const QString&, bool, std::tuple limits); + void setRateMax(const QString&, int userId, bool isPremium, std::tuple limits); private slots: @@ -551,6 +551,10 @@ private: int m_MaxDailyRequests; int m_MaxHourlyRequests; + int m_UserID; + + bool m_IsPremium; + }; #endif // NEXUSINTERFACE_H diff --git a/src/nxmaccessmanager.cpp b/src/nxmaccessmanager.cpp index b1e1ad89..00bb2a91 100644 --- a/src/nxmaccessmanager.cpp +++ b/src/nxmaccessmanager.cpp @@ -272,6 +272,7 @@ void NXMAccessManager::validateFinished() if (!jdoc.isNull()) { QJsonObject credentialsData = jdoc.object(); if (credentialsData.contains("user_id")) { + int id = credentialsData.value("user_id").toInt(); QString name = credentialsData.value("name").toString(); bool premium = credentialsData.value("is_premium").toBool(); @@ -282,7 +283,7 @@ void NXMAccessManager::validateFinished() m_ValidateReply->rawHeader("x-rl-hourly-limit").toInt() )); - emit credentialsReceived(name, premium, limits); + emit credentialsReceived(name, id, premium, limits); m_ValidateReply->deleteLater(); m_ValidateReply = nullptr; diff --git a/src/nxmaccessmanager.h b/src/nxmaccessmanager.h index da7736cc..54ae14fb 100644 --- a/src/nxmaccessmanager.h +++ b/src/nxmaccessmanager.h @@ -78,7 +78,7 @@ signals: void validateFailed(const QString &message); - void credentialsReceived(const QString &userName, bool premium, std::tuple limits); + void credentialsReceived(const QString &userName, int userId, bool premium, std::tuple limits); private slots: diff --git a/src/organizer_en.ts b/src/organizer_en.ts index 28ddc09c..b8f4914f 100644 --- a/src/organizer_en.ts +++ b/src/organizer_en.ts @@ -624,261 +624,261 @@ File %3: %4 - - + + remove: invalid download index %1 - + failed to delete %1 - + failed to delete meta file for %1 - + restore: invalid download index: %1 - + cancel: invalid download index %1 - + pause: invalid download index %1 - + resume: invalid download index %1 - + resume (int): invalid download index %1 - + No known download urls. Sorry, this download can't be resumed. - - + + query: invalid download index %1 - + Please enter the nexus mod id - + Mod ID: - + Please select the source game code for %1 - + VisitNexus: invalid download index %1 - + Nexus ID for this Mod is unknown - + OpenFile: invalid download index %1 - + OpenFileInDownloadsFolder: invalid download index %1 - + get pending: invalid download index %1 - + get path: invalid download index %1 - + Main - + Update - + Optional - + Old - + Miscellaneous - + Deleted - + Unknown - + display name: invalid download index %1 - + file name: invalid download index %1 - + file time: invalid download index %1 - + file size: invalid download index %1 - + progress: invalid download index %1 - + state: invalid download index %1 - + infocomplete: invalid download index %1 - - + + mod id: invalid download index %1 - + ishidden: invalid download index %1 - + file info: invalid download index %1 - + mark installed: invalid download index %1 - + mark uninstalled: invalid download index %1 - + Memory allocation error (in processing progress event). - + Memory allocation error (in processing downloaded data). - + Information updated - - + + No matching file found on Nexus! Maybe this file is no longer available or it was renamed? - + No file on Nexus matches the selected file by name. Please manually choose the correct one. - + No download server available. Please try again later. - + Failed to request file info from nexus: %1 - + Warning: Content type is: %1 - + Download header content length: %1 downloaded file size: %2 - + Download failed: %1 (%2) - + We were unable to download the file due to errors after four retries. There may be an issue with the Nexus servers. - + failed to re-open %1 - + Unable to write download to drive (return %1). Check the drive's available storage. @@ -4459,17 +4459,17 @@ p, li { white-space: pre-wrap; } - + Validation failed, please reauthenticate in the Settings -> Nexus tab: %1 - + Could not parse response. Invalid JSON. - + Unknown error. @@ -4477,7 +4477,7 @@ p, li { white-space: pre-wrap; } NXMUrl - + invalid nxm-link: %1 @@ -4485,17 +4485,17 @@ p, li { white-space: pre-wrap; } NexusInterface - + Failed to guess mod id for "%1", please pick the correct one - + empty response - + invalid response -- cgit v1.3.1