From fdba525e6287ca72cafaac6871fc137d43d79e93 Mon Sep 17 00:00:00 2001 From: BallsOfSpaghetti <115404710+OpenSpaghettiSauce@users.noreply.github.com> Date: Tue, 25 Oct 2022 06:43:38 +0200 Subject: [PATCH] Introduce a 'change listen port' cmd option Closes #17789. PR #17862. --- src/app/application.cpp | 6 ++++++ src/app/cmdoptions.cpp | 14 ++++++++++++++ src/app/cmdoptions.h | 1 + 3 files changed, 21 insertions(+) diff --git a/src/app/application.cpp b/src/app/application.cpp index 587f30a47..4af731821 100644 --- a/src/app/application.cpp +++ b/src/app/application.cpp @@ -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 port {u"BitTorrent/Session/Port"_qs}; + port = m_commandLineArgs.torrentingPort; + } } Application::~Application() diff --git a/src/app/cmdoptions.cpp b/src/app/cmdoptions.cpp index de17bdc97..23ec754ad 100644 --- a/src/app/cmdoptions.cpp +++ b/src/app/cmdoptions.cpp @@ -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) diff --git a/src/app/cmdoptions.h b/src/app/cmdoptions.h index 77fb67b77..c15915fd8 100644 --- a/src/app/cmdoptions.h +++ b/src/app/cmdoptions.h @@ -56,6 +56,7 @@ struct QBtCommandLineParameters bool shouldDaemonize; #endif int webUiPort; + int torrentingPort; std::optional addPaused; std::optional skipDialog; QStringList torrents;