Introduce a 'change listen port' cmd option

Closes #17789.
PR #17862.
This commit is contained in:
BallsOfSpaghetti 2022-10-25 06:43:38 +02:00 committed by GitHub
parent f2dd1e6456
commit fdba525e62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 0 deletions

View file

@ -196,6 +196,12 @@ Application::Application(int &argc, char **argv)
if (m_commandLineArgs.webUiPort > 0) // it will be -1 when user did not set any value
Preferences::instance()->setWebUiPort(m_commandLineArgs.webUiPort);
if (m_commandLineArgs.torrentingPort > 0) // it will be -1 when user did not set any value
{
SettingValue<int> port {u"BitTorrent/Session/Port"_qs};
port = m_commandLineArgs.torrentingPort;
}
}
Application::~Application()

View file

@ -326,6 +326,7 @@ namespace
constexpr const BoolOption NO_SPLASH_OPTION {"no-splash"};
#endif
constexpr const IntOption WEBUI_PORT_OPTION {"webui-port"};
constexpr const IntOption TORRENTING_PORT_OPTION {"torrenting-port"};
constexpr const StringOption PROFILE_OPTION {"profile"};
constexpr const StringOption CONFIGURATION_OPTION {"configuration"};
constexpr const BoolOption RELATIVE_FASTRESUME {"relative-fastresume"};
@ -353,6 +354,7 @@ QBtCommandLineParameters::QBtCommandLineParameters(const QProcessEnvironment &en
, shouldDaemonize(DAEMON_OPTION.value(env))
#endif
, webUiPort(WEBUI_PORT_OPTION.value(env, -1))
, torrentingPort(TORRENTING_PORT_OPTION.value(env, -1))
, addPaused(PAUSED_OPTION.value(env))
, skipDialog(SKIP_DIALOG_OPTION.value(env))
, profileDir(PROFILE_OPTION.value(env))
@ -427,6 +429,15 @@ QBtCommandLineParameters parseCommandLine(const QStringList &args)
throw CommandLineParameterError(QObject::tr("%1 must specify a valid port (1 to 65535).")
.arg(u"--webui-port"_qs));
}
else if (arg == TORRENTING_PORT_OPTION)
{
result.torrentingPort = TORRENTING_PORT_OPTION.value(arg);
if ((result.torrentingPort < 1) || (result.torrentingPort > 65535))
{
throw CommandLineParameterError(QObject::tr("%1 must specify a valid port (1 to 65535).")
.arg(u"--torrenting-port"_qs));
}
}
#ifndef DISABLE_GUI
else if (arg == NO_SPLASH_OPTION)
{
@ -537,6 +548,9 @@ QString makeUsage(const QString &prgName)
+ WEBUI_PORT_OPTION.usage(QObject::tr("port"))
+ wrapText(QObject::tr("Change the Web UI port"))
+ u'\n'
+ TORRENTING_PORT_OPTION.usage(QObject::tr("port"))
+ wrapText(QObject::tr("Change the torrenting port"))
+ u'\n'
#ifndef DISABLE_GUI
+ NO_SPLASH_OPTION.usage() + wrapText(QObject::tr("Disable splash screen")) + u'\n'
#elif !defined(Q_OS_WIN)

View file

@ -56,6 +56,7 @@ struct QBtCommandLineParameters
bool shouldDaemonize;
#endif
int webUiPort;
int torrentingPort;
std::optional<bool> addPaused;
std::optional<bool> skipDialog;
QStringList torrents;