diff options
| -rw-r--r-- | src/commandline.cpp | 11 | ||||
| -rw-r--r-- | src/downloadmanager.cpp | 42 | ||||
| -rw-r--r-- | src/downloadmanager.h | 6 |
3 files changed, 52 insertions, 7 deletions
diff --git a/src/commandline.cpp b/src/commandline.cpp index 3aa4b1ca..769403c4 100644 --- a/src/commandline.cpp +++ b/src/commandline.cpp @@ -857,7 +857,8 @@ po::options_description DownloadFileCommand::getVisibleOptions() const { po::options_description d; - d.add_options()("name,n", po::value<std::string>(), "(optional) the download name")( + d.add_options()("game,g", po::value<std::string>(), "managed game")( + "name,n", po::value<std::string>(), "(optional) the download name")( "modname,m", po::value<std::string>(), "(optional) the mod name")( "version,v", po::value<std::string>(), "(optional) the download / mod version")( "source,s", po::value<std::string>(), "(optional) the download source"); @@ -891,6 +892,7 @@ bool DownloadFileCommand::canForwardToPrimary() const std::optional<int> DownloadFileCommand::runPostOrganizer(OrganizerCore& core) { const QString url = QString::fromStdString(vm()["URL"].as<std::string>()); + QString game(""); QString name, modName, version, source; if (!url.startsWith("https://")) { @@ -898,6 +900,10 @@ std::optional<int> DownloadFileCommand::runPostOrganizer(OrganizerCore& core) return 1; } + if (vm().count("game")) { + game = QString::fromStdString(vm()["game"].as<std::string>()); + } + if (vm().count("name")) { name = QString::fromStdString(vm()["name"].as<std::string>()); } @@ -917,7 +923,8 @@ std::optional<int> DownloadFileCommand::runPostOrganizer(OrganizerCore& core) log::debug("starting direct download from command line: {}", url.toStdString()); MessageDialog::showMessage(QObject::tr("Download started"), qApp->activeWindow(), false); - core.downloadManager()->startDownloadURLWithMeta(url, name, modName, version, source); + core.downloadManager()->startDownloadURLWithMeta(url, game, name, modName, version, + source); return {}; } 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; diff --git a/src/downloadmanager.h b/src/downloadmanager.h index ad93b87d..a65d4fcb 100644 --- a/src/downloadmanager.h +++ b/src/downloadmanager.h @@ -410,9 +410,9 @@ public: public: // IDownloadManager interface: int startDownloadURLs(const QStringList& urls); - int startDownloadURLWithMeta(const QString& url, const QString& name, - const QString& modName, const QString& version, - const QString& source); + int startDownloadURLWithMeta(const QString& url, const QString& game, + const QString& name, const QString& modName, + const QString& version, const QString& source); int startDownloadNexusFile(const QString& gameName, int modID, int fileID); QString downloadPath(int id); |
