From 86e904d1a25cec42176421c7ed08bd9ce464861b Mon Sep 17 00:00:00 2001 From: Yat Ho Date: Tue, 11 Mar 2025 05:16:25 +0800 Subject: [PATCH] feat: sequential download cmdline options in remote and daemon (#7048) * feat: add seq option in remote * feat: print session sequential download setting in remote * refactor: assert options torrent size in daemon * feat: add seq option in daemon --- daemon/daemon.cc | 13 ++++++++++++- utils/remote.cc | 43 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/daemon/daemon.cc b/daemon/daemon.cc index 6a94b8ab8..09410ce5a 100644 --- a/daemon/daemon.cc +++ b/daemon/daemon.cc @@ -77,7 +77,7 @@ char constexpr Usage[] = "Transmission " LONG_VERSION_STRING // --- Config File -auto constexpr Options = std::array{ +auto constexpr Options = std::array{ { { 'a', "allowed", "Allowed IP addresses. (Default: " TR_DEFAULT_RPC_WHITELIST ")", "a", true, "" }, { 'b', "blocklist", "Enable peer blocklists", "b", false, nullptr }, { 'B', "no-blocklist", "Disable peer blocklists", "B", false, nullptr }, @@ -141,9 +141,12 @@ auto constexpr Options = std::array{ "GSR", false, nullptr }, + { 994, "sequential-download", "Enable sequential download by default", "seq", false, nullptr }, + { 995, "no-sequential-download", "Disable sequential download by default", "SEQ", false, nullptr }, { 'x', "pid-file", "Enable PID file", "x", true, "" }, { 0, nullptr, nullptr, nullptr, false, nullptr } } }; +static_assert(Options[std::size(Options) - 2].val != 0); [[nodiscard]] std::string getConfigDir(int argc, char const* const* argv) { @@ -487,6 +490,14 @@ bool tr_daemon::parse_args(int argc, char const* const* argv, bool* dump_setting tr_variantDictAddStr(&settings_, TR_KEY_default_trackers, optstr); break; + case 994: + tr_variantDictAddBool(&settings_, TR_KEY_sequentialDownload, true); + break; + + case 995: + tr_variantDictAddBool(&settings_, TR_KEY_sequentialDownload, false); + break; + case 'd': *dump_settings = true; break; diff --git a/utils/remote.cc b/utils/remote.cc index 5f1b2273c..259ea1706 100644 --- a/utils/remote.cc +++ b/utils/remote.cc @@ -210,7 +210,7 @@ enum // --- Command-Line Arguments -auto constexpr Options = std::array{ +auto constexpr Options = std::array{ { { 'a', "add", "Add torrent files by filename or URL", "a", false, nullptr }, { 970, "alt-speed", "Use the alternate Limits", "as", false, nullptr }, { 971, "no-alt-speed", "Don't use the alternate Limits", "AS", false, nullptr }, @@ -339,6 +339,8 @@ auto constexpr Options = std::array{ { 991, "no-start-paused", "Start added torrents unpaused", nullptr, false, nullptr }, { 992, "trash-torrent", "Delete torrents after adding", nullptr, false, nullptr }, { 993, "no-trash-torrent", "Do not delete torrents after adding", nullptr, false, nullptr }, + { 994, "sequential-download", "Download the torrent sequentially", "seq", false, nullptr }, + { 995, "no-sequential-download", "Download the torrent sequentially", "SEQ", false, nullptr }, { 984, "honor-session", "Make the current torrent(s) honor the session limits", "hl", false, nullptr }, { 985, "no-honor-session", "Make the current torrent(s) not honor the session limits", "HL", false, nullptr }, { 'u', @@ -500,6 +502,10 @@ enum case 930: /* peers */ return MODE_SESSION_SET | MODE_TORRENT_SET; + case 994: /* sequential-download */ + case 995: /* no-sequential-download */ + return MODE_SESSION_SET | MODE_TORRENT_SET | MODE_TORRENT_ADD; + case 'r': /* remove */ case 840: /* remove and delete */ return MODE_TORRENT_REMOVE; @@ -1831,6 +1837,11 @@ void print_session(tr_variant::Map const& map) fmt::print(" Maximum memory cache size: {:s}\n", Memory{ *i, Memory::Units::MBytes }.to_string()); } + if (auto b = args->value_if(TR_KEY_sequentialDownload); b) + { + fmt::print(" Sequential download: {:s}\n", *b ? "Yes" : "No"); + } + auto const alt_enabled = args->value_if(TR_KEY_alt_speed_enabled); auto const alt_time_enabled = args->value_if(TR_KEY_alt_speed_time_enabled); auto const up_enabled = args->value_if(TR_KEY_speed_limit_up_enabled); @@ -3111,6 +3122,36 @@ int process_args(char const* rpcurl, int argc, char const* const* argv, RemoteCo break; } } + else if (step_mode == (MODE_SESSION_SET | MODE_TORRENT_SET | MODE_TORRENT_ADD)) + { + tr_variant::Map& args = [&]() -> tr_variant::Map& + { + if (tadd.has_value()) + { + return ensure_tadd(tadd); + } + if (!std::empty(config.torrent_ids)) + { + return ensure_tset(tset); + } + return ensure_sset(sset); + }(); + + switch (c) + { + case 994: + args.insert_or_assign(TR_KEY_sequentialDownload, true); + break; + + case 995: + args.insert_or_assign(TR_KEY_sequentialDownload, false); + break; + + default: + TR_ASSERT_MSG(false, "unhandled value"); + break; + } + } else if (step_mode == MODE_TORRENT_REMOVE) { auto map = tr_variant::Map{ 2 };