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
This commit is contained in:
Jeremy Rimpo
2026-05-04 16:40:32 -05:00
committed by GitHub
parent ca7a149874
commit f5d89ad625
3 changed files with 52 additions and 7 deletions
+9 -2
View File
@@ -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 {};
}
+40 -2
View File
@@ -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;
+3 -3
View File
@@ -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);