From 386250bc87d150def9a67ae17495c989c42c577c Mon Sep 17 00:00:00 2001 From: rakshasa Date: Thu, 31 Mar 2011 09:35:21 +0000 Subject: [PATCH] * Moved some option string stuff to libtorrent. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1197 e378c898-3ddf-0310-93e7-cc216c733640 --- src/command_download.cc | 55 +++++++++++------------------------------ 1 file changed, 14 insertions(+), 41 deletions(-) diff --git a/src/command_download.cc b/src/command_download.cc index e63f5c3d..6299c799 100644 --- a/src/command_download.cc +++ b/src/command_download.cc @@ -52,6 +52,7 @@ #include #include #include +#include #include "core/download.h" #include "core/download_store.h" @@ -180,66 +181,38 @@ apply_d_directory(core::Download* download, const std::string& name) { torrent::Object apply_d_connection_type(core::Download* download, const std::string& name) { - torrent::Download::ConnectionType connType; + torrent::Download::ConnectionType t = + (torrent::Download::ConnectionType)torrent::option_find_string(torrent::OPTION_CONNECTION_TYPE, name.c_str()); - if (name == "leech") - connType = torrent::Download::CONNECTION_LEECH; - else if (name == "seed") - connType = torrent::Download::CONNECTION_SEED; - else if (name == "initial_seed") - connType = torrent::Download::CONNECTION_INITIAL_SEED; - else - throw torrent::input_error("Unknown peer connection type selected."); - - download->download()->set_connection_type(connType); + download->download()->set_connection_type(t); return torrent::Object(); } const char* retrieve_d_connection_type(core::Download* download) { - switch (download->download()->connection_type()) { - case torrent::Download::CONNECTION_LEECH: - return "leech"; - case torrent::Download::CONNECTION_SEED: - return "seed"; - case torrent::Download::CONNECTION_INITIAL_SEED: - return "initial_seed"; - default: - return "unknown"; - } + return torrent::option_as_string(torrent::OPTION_CONNECTION_TYPE, download->download()->connection_type()); } torrent::Object apply_d_choke_heuristics(core::Download* download, const std::string& name, bool is_down) { - torrent::Download::HeuristicType connType; - - if (name == "upload_leech") - connType = torrent::Download::HEURISTICS_UPLOAD_LEECH; - else if (name == "download_leech") - connType = torrent::Download::HEURISTICS_DOWNLOAD_LEECH; - else - throw torrent::input_error("Unknown peer heuristic selected."); + torrent::Download::HeuristicType t = + (torrent::Download::HeuristicType)torrent::option_find_string(torrent::OPTION_CHOKE_HEURISTICS, name.c_str()); if (is_down) - download->download()->set_download_choke_heuristic(connType); + download->download()->set_download_choke_heuristic(t); else - download->download()->set_upload_choke_heuristic(connType); + download->download()->set_upload_choke_heuristic(t); return torrent::Object(); } const char* retrieve_d_choke_heuristics(core::Download* download, bool is_down) { - switch (is_down ? - download->download()->download_choke_heuristic() : - download->download()->upload_choke_heuristic()) { - case torrent::Download::HEURISTICS_UPLOAD_LEECH: - return "upload_leech"; - case torrent::Download::HEURISTICS_DOWNLOAD_LEECH: - return "download_leech"; - default: - return "unknown"; - } + torrent::Download::HeuristicType t = is_down ? + download->download()->download_choke_heuristic() : + download->download()->upload_choke_heuristic(); + + return torrent::option_as_string(torrent::OPTION_CHOKE_HEURISTICS, t); } const char*