diff options
| author | Jeremy Rimpo <jeremy.rimpo@servermonkey.com> | 2026-05-04 16:40:32 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-05-04 16:40:32 -0500 |
| commit | f5d89ad6250343acddbcd5541fb6e7b7df4f27d2 (patch) | |
| tree | f3274f5c5b597d34fa367a73833f8e0b1aa9e94e /src/downloadmanager.cpp | |
| parent | ca7a149874e99a8f401cb30c430f58a48be4c642 (diff) | |
Download command: Add game instance check (#2388)
* Add game instance check
- Should be ignored if not passed to command
- Functions much like NXM game check
Diffstat (limited to 'src/downloadmanager.cpp')
| -rw-r--r-- | src/downloadmanager.cpp | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index c5d4c13e..170e38f2 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -1986,17 +1986,55 @@ int DownloadManager::startDownloadURLs(const QStringList& urls) return m_ActiveDownloads.size() - 1; } -int DownloadManager::startDownloadURLWithMeta(const QString& url, const QString& name, +int DownloadManager::startDownloadURLWithMeta(const QString& url, const QString& game, + const QString& name, const QString& modName, const QString& version, const QString& source) { ModRepositoryFileInfo info; + MOBase::IPluginGame* requestedGame = m_OrganizerCore->getGame(game); + if (requestedGame) { + MOBase::IPluginGame* foundGame = nullptr; + QStringList validGames; + validGames.append(m_ManagedGame->gameShortName()); + validGames.append(m_ManagedGame->validShortNames()); + for (auto validGame : validGames) { + MOBase::IPluginGame* gamePlugin = m_OrganizerCore->getGame(validGame); + + // some game plugins give names in validShortNames() that may refer to other + // plugins, like ttw returning "FalloutNV" and "Fallout3"; if these plugins + // are not loaded, getGame() might return null + if (!gamePlugin) { + // log an error, it's most probably not normal + log::error("no plugin for game '{}', an antivirus might have deleted it", game); + continue; + } + + if (game.compare(gamePlugin->gameShortName(), Qt::CaseInsensitive) == 0) { + foundGame = gamePlugin; + break; + } + } + if (foundGame == nullptr) { + log::debug("download requested for wrong game (current game: {}, url: {})", + m_ManagedGame->gameShortName(), game); + QMessageBox::information( + m_ParentWidget, tr("Wrong Game"), + tr("The download link is for a mod for \"%1\" but this instance of MO " + "has been set up for \"%2\".") + .arg(requestedGame->displayGameName()) + .arg(m_ManagedGame->displayGameName()), + QMessageBox::Ok); + return 0; + } + info.gameName = game; + } info.name = name; info.modName = modName; info.version = version; info.repository = source; - if (!addDownload(QStringList(url), "", -1, -1, &info)) { + if (!addDownload(QStringList(url), game, -1, -1, &info)) { return 0; } return m_ActiveDownloads.size() - 1; |
