diff --git a/src/core/download.cc b/src/core/download.cc index d2a4c6ea..33d380ba 100644 --- a/src/core/download.cc +++ b/src/core/download.cc @@ -129,7 +129,7 @@ Download::enable_udp_trackers(bool state) { uint32_t Download::priority() { - return bencode()->get_key("rtorrent").get_key("priority").as_value(); + return bencode()->get_key("rtorrent").get_key_value("priority"); } void diff --git a/src/core/download.h b/src/core/download.h index 1482d053..3088890f 100644 --- a/src/core/download.h +++ b/src/core/download.h @@ -55,10 +55,10 @@ public: typedef download_type::ConnectionType connection_type; typedef utils::VariableMap variable_map_type; - static const int64_t variable_hashing_stopped = 0; - static const int64_t variable_hashing_initial = 1; - static const int64_t variable_hashing_last = 2; - static const int64_t variable_hashing_rehash = 3; + static const int variable_hashing_stopped = 0; + static const int variable_hashing_initial = 1; + static const int variable_hashing_last = 2; + static const int variable_hashing_rehash = 3; Download(download_type d); ~Download(); diff --git a/src/core/download_factory.cc b/src/core/download_factory.cc index 3a330588..f1476eac 100644 --- a/src/core/download_factory.cc +++ b/src/core/download_factory.cc @@ -232,12 +232,12 @@ DownloadFactory::receive_failed(const std::string& msg) { void DownloadFactory::initialize_rtorrent(Download* download, torrent::Object* rtorrent) { - if (!rtorrent->has_key_value("state") || rtorrent->get_key("state").as_value() > 1) { + if (!rtorrent->has_key_value("state") || rtorrent->get_key_value("state") > 1) { rtorrent->insert_key("state", (int64_t)m_start); rtorrent->insert_key("state_changed", cachedTime.seconds()); } else if (!rtorrent->has_key_value("state_changed") || - rtorrent->get_key("state_changed").as_value() > cachedTime.seconds() || rtorrent->get_key("state_changed").as_value() == 0) { + rtorrent->get_key_value("state_changed") > cachedTime.seconds() || rtorrent->get_key_value("state_changed") == 0) { rtorrent->insert_key("state_changed", cachedTime.seconds()); } @@ -245,18 +245,18 @@ DownloadFactory::initialize_rtorrent(Download* download, torrent::Object* rtorre rtorrent->insert_key("complete", (int64_t)0); if (!rtorrent->has_key_value("hashing")) - rtorrent->insert_key("hashing", Download::variable_hashing_stopped); + rtorrent->insert_key("hashing", (int64_t)Download::variable_hashing_stopped); if (!rtorrent->has_key_string("tied_to_file")) rtorrent->insert_key("tied_to_file", std::string()); if (rtorrent->has_key_value("priority")) - download->variable()->set("priority", rtorrent->get_key("priority").as_value() % 4); + download->variable()->set("priority", rtorrent->get_key_value("priority") % 4); else download->variable()->set("priority", (int64_t)2); if (rtorrent->has_key_value("key")) { - download->tracker_list()->set_key(rtorrent->get_key("key").as_value()); + download->tracker_list()->set_key(rtorrent->get_key_value("key")); } else { download->tracker_list()->set_key(random() % (std::numeric_limits::max() - 1) + 1); @@ -264,7 +264,7 @@ DownloadFactory::initialize_rtorrent(Download* download, torrent::Object* rtorre } if (rtorrent->has_key_value("total_uploaded")) - download->download()->up_rate()->set_total(rtorrent->get_key("total_uploaded").as_value()); + download->download()->up_rate()->set_total(rtorrent->get_key_value("total_uploaded")); if (!rtorrent->has_key_value("ignore_ratio")) rtorrent->insert_key("ignore_ratio", (int64_t)0); diff --git a/src/core/download_list.cc b/src/core/download_list.cc index abcd1cc4..dff39b14 100644 --- a/src/core/download_list.cc +++ b/src/core/download_list.cc @@ -221,9 +221,7 @@ DownloadList::close_throw(Download* download) { download->download()->close(); - if (!download->is_hash_failed() && - download->variable()->get_value("state") != 0 && - download->variable()->get_value("hashing") != Download::variable_hashing_stopped) + if (!download->is_hash_failed() && download->variable()->get_value("hashing") != Download::variable_hashing_stopped) throw torrent::client_error("DownloadList::close_throw(...) called but we're going into a hashing loop."); std::for_each(slot_map_hash_removed().begin(), slot_map_hash_removed().end(), download_list_call(download)); @@ -246,6 +244,12 @@ void DownloadList::start_try(Download* download) { check_contains(download); + // Also don't start if the state is one of those that indicate we + // were manually stopped? + + if (download->is_hash_failed()) + return; + // Don't clear the hash failed as this function is used by scripts, // etc. download->variable()->set("state", (int64_t)1); @@ -321,9 +325,9 @@ DownloadList::pause(Download* download) { try { - // Clear initial hashing, but retain the other types. - if (download->variable()->get_value("hashing") == Download::variable_hashing_initial) - download->variable()->set("hashing", Download::variable_hashing_stopped); + // Always clear hashing on pause. When a hashing request is added, + // it should have cleared the hash resume data. + download->variable()->set_value("hashing", Download::variable_hashing_stopped); if (!download->download()->is_active()) return; @@ -388,7 +392,7 @@ DownloadList::hash_done(Download* download) { // ReiserFS bug with >4GB files. int64_t hashing = download->variable()->get_value("hashing"); - download->variable()->set("hashing", Download::variable_hashing_stopped); + download->variable()->set_value("hashing", Download::variable_hashing_stopped); switch (hashing) { case Download::variable_hashing_initial: @@ -442,6 +446,7 @@ DownloadList::hash_queue(Download* download, int type) { download->download()->hash_resume_clear(); download->set_hash_failed(false); + download->variable()->set_value("hashing", type); if (download->is_open()) throw torrent::internal_error("DownloadList::hash_clear(...) download still open."); diff --git a/src/display/window_download_chunks_seen.cc b/src/display/window_download_chunks_seen.cc index ab240f9e..c3b58a5e 100644 --- a/src/display/window_download_chunks_seen.cc +++ b/src/display/window_download_chunks_seen.cc @@ -99,6 +99,9 @@ WindowDownloadChunksSeen::redraw() { std::vector::const_iterator itrTransfer = transferChunks.begin(); + while (itrTransfer != transferChunks.end() && (uint32_t)(chunk - seen) > (*itrTransfer)->index()) + itrTransfer++; + for (int y = 1; y < m_canvas->get_height() && chunk < last; ++y) { m_canvas->print(0, y, "%5u ", (int)(chunk - seen)); diff --git a/src/utils/variable_map.h b/src/utils/variable_map.h index 4c479936..a3ae905d 100644 --- a/src/utils/variable_map.h +++ b/src/utils/variable_map.h @@ -72,6 +72,7 @@ public: void set(const std::string& key, const mapped_type& arg); void set_string(const std::string& key, const std::string& arg) { set(key, mapped_type(arg)); } + void set_value(const std::string& key, mapped_value_type arg) { set(key, mapped_type(arg)); } // Relocate. void process_command(const std::string& command);