diff options
| author | Silarn <jrim@rimpo.org> | 2019-05-09 12:04:03 -0500 |
|---|---|---|
| committer | Silarn <jrim@rimpo.org> | 2019-05-09 12:04:03 -0500 |
| commit | ed4eb2aae8fcf493c07a02cbca3df14f00c5e130 (patch) | |
| tree | df454d19e96d78b8a860d4fcb8f721392fe2c215 /src | |
| parent | 3d2616ea989d728c4b1a1f9a3fc4cb852db50872 (diff) | |
Update NXM link handling to support premium link and validate user info
Diffstat (limited to 'src')
| -rw-r--r-- | src/downloadmanager.cpp | 1 | ||||
| -rw-r--r-- | src/mainwindow.cpp | 12 | ||||
| -rw-r--r-- | src/mainwindow.h | 2 | ||||
| -rw-r--r-- | src/nexusinterface.cpp | 24 | ||||
| -rw-r--r-- | src/nexusinterface.h | 6 | ||||
| -rw-r--r-- | src/nxmaccessmanager.cpp | 3 | ||||
| -rw-r--r-- | src/nxmaccessmanager.h | 2 | ||||
| -rw-r--r-- | src/organizer_en.ts | 124 |
8 files changed, 97 insertions, 77 deletions
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<int, int, int, int>)), - this, SLOT(updateWindowTitle(const QString&, bool))); - connect(NexusInterface::instance(&pluginContainer)->getAccessManager(), SIGNAL(credentialsReceived(const QString&, bool, std::tuple<int, int, int, int>)), - NexusInterface::instance(&m_PluginContainer), SLOT(setRateMax(const QString&, bool, std::tuple<int, int, int, int>))); + connect(NexusInterface::instance(&pluginContainer)->getAccessManager(), SIGNAL(credentialsReceived(const QString&, int, bool, std::tuple<int, int, int, int>)), + this, SLOT(updateWindowTitle(const QString&, int, bool))); + connect(NexusInterface::instance(&pluginContainer)->getAccessManager(), SIGNAL(credentialsReceived(const QString&, int, bool, std::tuple<int, int, int, int>)), + NexusInterface::instance(&m_PluginContainer), SLOT(setRateMax(const QString&, int, bool, std::tuple<int, int, int, int>))); connect(NexusInterface::instance(&pluginContainer), SIGNAL(requestsChanged(int, std::tuple<int, int, int, int>)), this, SLOT(updateAPICounter(int, std::tuple<int, int, int, int>))); 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<int, int, int, int> limits) +void NexusInterface::setRateMax(const QString&, int userId, bool isPremium, std::tuple<int, int, int, int> 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<ModRepositoryFileInfo*>(qvariant_cast<QObject*>(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<int,int,int,int> limits); + void setRateMax(const QString&, int userId, bool isPremium, std::tuple<int,int,int,int> 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<int, int, int, int> limits); + void credentialsReceived(const QString &userName, int userId, bool premium, std::tuple<int, int, int, int> 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</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="643"/> - <location filename="downloadmanager.cpp" line="776"/> + <location filename="downloadmanager.cpp" line="644"/> + <location filename="downloadmanager.cpp" line="777"/> <source>remove: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="662"/> + <location filename="downloadmanager.cpp" line="663"/> <source>failed to delete %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="669"/> + <location filename="downloadmanager.cpp" line="670"/> <source>failed to delete meta file for %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="729"/> + <location filename="downloadmanager.cpp" line="730"/> <source>restore: invalid download index: %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="798"/> + <location filename="downloadmanager.cpp" line="799"/> <source>cancel: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="811"/> + <location filename="downloadmanager.cpp" line="812"/> <source>pause: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="833"/> + <location filename="downloadmanager.cpp" line="834"/> <source>resume: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="844"/> + <location filename="downloadmanager.cpp" line="845"/> <source>resume (int): invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="868"/> + <location filename="downloadmanager.cpp" line="869"/> <source>No known download urls. Sorry, this download can't be resumed.</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="909"/> - <location filename="downloadmanager.cpp" line="961"/> + <location filename="downloadmanager.cpp" line="910"/> + <location filename="downloadmanager.cpp" line="962"/> <source>query: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="931"/> + <location filename="downloadmanager.cpp" line="932"/> <source>Please enter the nexus mod id</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="931"/> + <location filename="downloadmanager.cpp" line="932"/> <source>Mod ID:</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="942"/> + <location filename="downloadmanager.cpp" line="943"/> <source>Please select the source game code for %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1001"/> + <location filename="downloadmanager.cpp" line="1002"/> <source>VisitNexus: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1022"/> + <location filename="downloadmanager.cpp" line="1023"/> <source>Nexus ID for this Mod is unknown</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1029"/> + <location filename="downloadmanager.cpp" line="1030"/> <source>OpenFile: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1046"/> + <location filename="downloadmanager.cpp" line="1047"/> <source>OpenFileInDownloadsFolder: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1082"/> + <location filename="downloadmanager.cpp" line="1083"/> <source>get pending: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1091"/> + <location filename="downloadmanager.cpp" line="1092"/> <source>get path: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1100"/> + <location filename="downloadmanager.cpp" line="1101"/> <source>Main</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1101"/> + <location filename="downloadmanager.cpp" line="1102"/> <source>Update</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1102"/> + <location filename="downloadmanager.cpp" line="1103"/> <source>Optional</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1103"/> + <location filename="downloadmanager.cpp" line="1104"/> <source>Old</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1104"/> + <location filename="downloadmanager.cpp" line="1105"/> <source>Miscellaneous</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1105"/> + <location filename="downloadmanager.cpp" line="1106"/> <source>Deleted</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1106"/> + <location filename="downloadmanager.cpp" line="1107"/> <source>Unknown</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1113"/> + <location filename="downloadmanager.cpp" line="1114"/> <source>display name: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1133"/> + <location filename="downloadmanager.cpp" line="1134"/> <source>file name: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1142"/> + <location filename="downloadmanager.cpp" line="1143"/> <source>file time: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1156"/> + <location filename="downloadmanager.cpp" line="1157"/> <source>file size: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1166"/> + <location filename="downloadmanager.cpp" line="1167"/> <source>progress: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1176"/> + <location filename="downloadmanager.cpp" line="1177"/> <source>state: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1186"/> + <location filename="downloadmanager.cpp" line="1187"/> <source>infocomplete: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1201"/> - <location filename="downloadmanager.cpp" line="1209"/> + <location filename="downloadmanager.cpp" line="1202"/> + <location filename="downloadmanager.cpp" line="1210"/> <source>mod id: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1217"/> + <location filename="downloadmanager.cpp" line="1218"/> <source>ishidden: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1226"/> + <location filename="downloadmanager.cpp" line="1227"/> <source>file info: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1236"/> + <location filename="downloadmanager.cpp" line="1237"/> <source>mark installed: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1281"/> + <location filename="downloadmanager.cpp" line="1282"/> <source>mark uninstalled: invalid download index %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1458"/> + <location filename="downloadmanager.cpp" line="1459"/> <source>Memory allocation error (in processing progress event).</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1468"/> + <location filename="downloadmanager.cpp" line="1469"/> <source>Memory allocation error (in processing downloaded data).</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1584"/> + <location filename="downloadmanager.cpp" line="1585"/> <source>Information updated</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1586"/> - <location filename="downloadmanager.cpp" line="1601"/> + <location filename="downloadmanager.cpp" line="1587"/> + <location filename="downloadmanager.cpp" line="1602"/> <source>No matching file found on Nexus! Maybe this file is no longer available or it was renamed?</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1588"/> + <location filename="downloadmanager.cpp" line="1589"/> <source>No file on Nexus matches the selected file by name. Please manually choose the correct one.</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1716"/> + <location filename="downloadmanager.cpp" line="1717"/> <source>No download server available. Please try again later.</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1881"/> + <location filename="downloadmanager.cpp" line="1882"/> <source>Failed to request file info from nexus: %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1908"/> + <location filename="downloadmanager.cpp" line="1909"/> <source>Warning: Content type is: %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1913"/> + <location filename="downloadmanager.cpp" line="1914"/> <source>Download header content length: %1 downloaded file size: %2</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1915"/> + <location filename="downloadmanager.cpp" line="1916"/> <source>Download failed: %1 (%2)</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="1937"/> + <location filename="downloadmanager.cpp" line="1938"/> <source>We were unable to download the file due to errors after four retries. There may be an issue with the Nexus servers.</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="2020"/> + <location filename="downloadmanager.cpp" line="2021"/> <source>failed to re-open %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="downloadmanager.cpp" line="2061"/> + <location filename="downloadmanager.cpp" line="2062"/> <source>Unable to write download to drive (return %1). Check the drive's available storage. @@ -4459,17 +4459,17 @@ p, li { white-space: pre-wrap; } <translation type="unfinished"></translation> </message> <message> - <location filename="nxmaccessmanager.cpp" line="295"/> + <location filename="nxmaccessmanager.cpp" line="296"/> <source>Validation failed, please reauthenticate in the Settings -> Nexus tab: %1</source> <translation type="unfinished"></translation> </message> <message> - <location filename="nxmaccessmanager.cpp" line="300"/> + <location filename="nxmaccessmanager.cpp" line="301"/> <source>Could not parse response. Invalid JSON.</source> <translation type="unfinished"></translation> </message> <message> - <location filename="nxmaccessmanager.cpp" line="306"/> + <location filename="nxmaccessmanager.cpp" line="307"/> <source>Unknown error.</source> <translation type="unfinished"></translation> </message> @@ -4477,7 +4477,7 @@ p, li { white-space: pre-wrap; } <context> <name>NXMUrl</name> <message> - <location filename="../../uibase/src/nxmurl.cpp" line="33"/> + <location filename="../../uibase/src/nxmurl.cpp" line="34"/> <source>invalid nxm-link: %1</source> <translation type="unfinished"></translation> </message> @@ -4485,17 +4485,17 @@ p, li { white-space: pre-wrap; } <context> <name>NexusInterface</name> <message> - <location filename="nexusinterface.cpp" line="246"/> + <location filename="nexusinterface.cpp" line="254"/> <source>Failed to guess mod id for "%1", please pick the correct one</source> <translation type="unfinished"></translation> </message> <message> - <location filename="nexusinterface.cpp" line="806"/> + <location filename="nexusinterface.cpp" line="820"/> <source>empty response</source> <translation type="unfinished"></translation> </message> <message> - <location filename="nexusinterface.cpp" line="873"/> + <location filename="nexusinterface.cpp" line="887"/> <source>invalid response</source> <translation type="unfinished"></translation> </message> |
