mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-10 20:22:31 +00:00
* Set Content::m_chunkSize before adding files.
* Removed the old FileList and replaced it with the cleaned up EntryList code. The API now gives a FileList* instead of FileList. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@810 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -42,6 +42,7 @@
|
||||
#include <sigc++/signal.h>
|
||||
#include <rak/path.h>
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/file_list.h>
|
||||
#include <torrent/rate.h>
|
||||
#include <torrent/torrent.h>
|
||||
#include <torrent/tracker.h>
|
||||
@@ -55,7 +56,6 @@ namespace core {
|
||||
|
||||
Download::Download(download_type d) :
|
||||
m_download(d),
|
||||
m_fileList(d.file_list()),
|
||||
m_trackerList(d.tracker_list()),
|
||||
|
||||
m_hashFailed(false),
|
||||
@@ -90,7 +90,7 @@ Download::Download(download_type d) :
|
||||
// resume/pause.
|
||||
m_variables.insert("state_changed", new utils::VariableObject(bencode(), "rtorrent", "state_changed", torrent::Object::TYPE_VALUE));
|
||||
|
||||
m_variables.insert("directory", new utils::VariableStringSlot(rak::mem_fn(&m_fileList, &torrent::FileList::root_dir), rak::mem_fn(this, &Download::set_root_directory)));
|
||||
m_variables.insert("directory", new utils::VariableStringSlot(rak::mem_fn(m_download.file_list(), &torrent::FileList::root_dir), rak::mem_fn(this, &Download::set_root_directory)));
|
||||
|
||||
// m_variables.insert("info_hash", new utils::VariableStringSlot(rak::mem_fn(&m_download, &torrent::Download::info_hash), NULL));
|
||||
|
||||
@@ -250,15 +250,17 @@ Download::receive_chunk_failed(__UNUSED uint32_t idx) {
|
||||
// Clean up.
|
||||
void
|
||||
Download::set_root_directory(const std::string& path) {
|
||||
torrent::FileList* fileList = m_download.file_list();
|
||||
|
||||
if (path.empty()) {
|
||||
m_fileList.set_root_dir("./" + (m_fileList.size() > 1 ? m_download.name() : std::string()));
|
||||
fileList->set_root_dir("./" + (fileList->size_files() > 1 ? m_download.name() : std::string()));
|
||||
|
||||
} else {
|
||||
std::string fullPath = rak::path_expand(path);
|
||||
|
||||
m_fileList.set_root_dir(fullPath +
|
||||
(*fullPath.rbegin() != '/' ? "/" : "") +
|
||||
(m_fileList.size() > 1 ? m_download.name() : ""));
|
||||
fileList->set_root_dir(fullPath +
|
||||
(*fullPath.rbegin() != '/' ? "/" : "") +
|
||||
(fileList->size_files() > 1 ? m_download.name() : ""));
|
||||
}
|
||||
|
||||
bencode()->get_key("rtorrent").insert_key("directory", path);
|
||||
|
||||
+3
-4
@@ -40,7 +40,6 @@
|
||||
#include <rak/string_manip.h>
|
||||
#include <sigc++/connection.h>
|
||||
#include <torrent/download.h>
|
||||
#include <torrent/file_list.h>
|
||||
#include <torrent/hash_string.h>
|
||||
#include <torrent/tracker_list.h>
|
||||
#include <torrent/torrent.h>
|
||||
@@ -52,7 +51,6 @@ namespace core {
|
||||
class Download {
|
||||
public:
|
||||
typedef torrent::Download download_type;
|
||||
typedef torrent::FileList file_list_type;
|
||||
typedef torrent::TrackerList tracker_list_type;
|
||||
typedef download_type::ConnectionType connection_type;
|
||||
typedef utils::VariableMap variable_map_type;
|
||||
@@ -87,8 +85,10 @@ public:
|
||||
download_type* download() { return &m_download; }
|
||||
const download_type* c_download() const { return &m_download; }
|
||||
|
||||
torrent::FileList* file_list() { return m_download.file_list(); }
|
||||
const torrent::FileList* c_file_list() const { return m_download.file_list(); }
|
||||
|
||||
torrent::Object* bencode() { return m_download.bencode(); }
|
||||
file_list_type* file_list() { return &m_fileList; }
|
||||
tracker_list_type* tracker_list() { return &m_trackerList; }
|
||||
|
||||
const std::string& message() const { return m_message; }
|
||||
@@ -137,7 +137,6 @@ private:
|
||||
|
||||
// Store the FileList instance so we can use slots etc on it.
|
||||
download_type m_download;
|
||||
file_list_type m_fileList;
|
||||
tracker_list_type m_trackerList;
|
||||
|
||||
bool m_hashFailed;
|
||||
|
||||
@@ -95,6 +95,12 @@ te_value(Return (torrent::Download::*fptr)() const, int flags = TextElementValue
|
||||
return display::text_element_value_slot(rak::on(std::mem_fun(&core::Download::c_download), std::mem_fun(fptr)), flags, attributes);
|
||||
}
|
||||
|
||||
template <typename Return>
|
||||
inline TextElementValueBase*
|
||||
te_value(Return (torrent::FileList::*fptr)() const, int flags = TextElementValueBase::flag_normal, int attributes = Attributes::a_invalid) {
|
||||
return display::text_element_value_slot(rak::on(std::mem_fun(&core::Download::c_file_list), std::mem_fun(fptr)), flags, attributes);
|
||||
}
|
||||
|
||||
inline TextElementValueBase*
|
||||
te_variable_value(const std::string& variable, int flags = TextElementValueBase::flag_normal, int attributes = Attributes::a_invalid) {
|
||||
return display::text_element_value_slot(rak::bind2nd(std::mem_fun(&core::Download::variable_value), variable), flags, attributes);
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include <rak/timer.h>
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/connection_manager.h>
|
||||
#include <torrent/file_list.h>
|
||||
#include <torrent/rate.h>
|
||||
#include <torrent/tracker.h>
|
||||
#include <torrent/tracker_list.h>
|
||||
@@ -132,11 +133,11 @@ print_download_info(char* first, char* last, core::Download* d) {
|
||||
first = print_buffer(first, last, " ");
|
||||
|
||||
if (d->is_done())
|
||||
first = print_buffer(first, last, "done %10.1f MB", (double)d->download()->bytes_total() / (double)(1 << 20));
|
||||
first = print_buffer(first, last, "done %10.1f MB", (double)d->download()->file_list()->size_bytes() / (double)(1 << 20));
|
||||
else
|
||||
first = print_buffer(first, last, "%6.1f / %6.1f MB",
|
||||
(double)d->download()->bytes_done() / (double)(1 << 20),
|
||||
(double)d->download()->bytes_total() / (double)(1 << 20));
|
||||
(double)d->download()->file_list()->size_bytes() / (double)(1 << 20));
|
||||
|
||||
first = print_buffer(first, last, " Rate: %5.1f / %5.1f KB Uploaded: %7.1f MB",
|
||||
(double)d->download()->up_rate()->rate() / (1 << 10),
|
||||
@@ -208,7 +209,7 @@ print_download_time_left(char* first, char* last, core::Download* d) {
|
||||
if (rate < 512)
|
||||
return print_buffer(first, last, "--d --:--");
|
||||
|
||||
time_t remaining = (d->download()->bytes_total() - d->download()->bytes_done()) / (rate & ~(uint32_t)(512 - 1));
|
||||
time_t remaining = (d->download()->file_list()->size_bytes() - d->download()->bytes_done()) / (rate & ~(uint32_t)(512 - 1));
|
||||
|
||||
return print_ddhhmm(first, last, remaining);
|
||||
}
|
||||
|
||||
@@ -76,9 +76,9 @@ WindowFileList::redraw() {
|
||||
m_slotSchedule(this, (cachedTime + rak::timer::from_seconds(10)).round_seconds());
|
||||
m_canvas->erase();
|
||||
|
||||
torrent::FileList fl = m_download->download()->file_list();
|
||||
torrent::FileList* fl = m_download->download()->file_list();
|
||||
|
||||
if (fl.size() == 0 || m_canvas->height() < 2)
|
||||
if (fl->size_files() == 0 || m_canvas->height() < 2)
|
||||
return;
|
||||
|
||||
int pos = 0;
|
||||
@@ -92,13 +92,13 @@ WindowFileList::redraw() {
|
||||
|
||||
++pos;
|
||||
|
||||
if (*m_focus >= fl.size())
|
||||
if (*m_focus >= fl->size_files())
|
||||
throw std::logic_error("WindowFileList::redraw() called on an object with a bad focus value");
|
||||
|
||||
Range range = rak::advance_bidirectional<unsigned int>(0, *m_focus, fl.size(), m_canvas->height() - pos);
|
||||
Range range = rak::advance_bidirectional<unsigned int>(0, *m_focus, fl->size_files(), m_canvas->height() - pos);
|
||||
|
||||
while (range.first != range.second) {
|
||||
torrent::File* e = fl.get(range.first);
|
||||
torrent::File* e = fl->at_index(range.first);
|
||||
|
||||
std::string path = e->path()->as_string();
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
#include <torrent/connection_manager.h>
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/file.h>
|
||||
#include <torrent/file_list.h>
|
||||
#include <torrent/path.h>
|
||||
#include <torrent/rate.h>
|
||||
#include <torrent/torrent.h>
|
||||
@@ -175,7 +176,7 @@ apply_close_low_diskspace(Control* m, int64_t arg) {
|
||||
core::Manager::DListItr itr = m->core()->download_list()->begin();
|
||||
|
||||
while ((itr = std::find_if(itr, m->core()->download_list()->end(), std::mem_fun(&core::Download::is_downloading))) != m->core()->download_list()->end()) {
|
||||
if ((*itr)->download()->free_diskspace() < (uint64_t)arg) {
|
||||
if ((*itr)->file_list()->free_diskspace() < (uint64_t)arg) {
|
||||
m->core()->download_list()->close(*itr);
|
||||
|
||||
(*itr)->set_hash_failed(true);
|
||||
|
||||
+2
-1
@@ -42,6 +42,7 @@
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/chunk_manager.h>
|
||||
#include <torrent/connection_manager.h>
|
||||
#include <torrent/file_list.h>
|
||||
#include <torrent/torrent.h>
|
||||
#include <torrent/tracker_list.h>
|
||||
|
||||
@@ -164,7 +165,7 @@ Download::create_info() {
|
||||
element->push_back("");
|
||||
element->push_column("Memory usage:", te_value(&torrent::ChunkManager::memory_usage, value_base::flag_mb), " MB");
|
||||
element->push_column("Max memory usage:", te_value(&torrent::ChunkManager::max_memory_usage, value_base::flag_mb), " MB");
|
||||
element->push_column("Free diskspace:", te_value(&torrent::Download::free_diskspace, value_base::flag_mb), " MB");
|
||||
element->push_column("Free diskspace:", te_value(&torrent::FileList::free_diskspace, value_base::flag_mb), " MB");
|
||||
element->push_column("Safe diskspace:", te_value(&torrent::ChunkManager::safe_free_diskspace, value_base::flag_mb), " MB");
|
||||
|
||||
element->push_back("");
|
||||
|
||||
+19
-18
@@ -106,7 +106,7 @@ ElementFileList::receive_next() {
|
||||
if (m_window == NULL)
|
||||
throw torrent::client_error("ui::ElementFileList::receive_next(...) called on a disabled object");
|
||||
|
||||
if (++m_focus >= m_download->download()->file_list().size())
|
||||
if (++m_focus >= m_download->download()->file_list()->size_files())
|
||||
m_focus = 0;
|
||||
|
||||
m_window->mark_dirty();
|
||||
@@ -117,15 +117,15 @@ ElementFileList::receive_prev() {
|
||||
if (m_window == NULL)
|
||||
throw torrent::client_error("ui::ElementFileList::receive_prev(...) called on a disabled object");
|
||||
|
||||
torrent::FileList fl = m_download->download()->file_list();
|
||||
torrent::FileList* fl = m_download->download()->file_list();
|
||||
|
||||
if (fl.size() == 0)
|
||||
if (fl->size_files() == 0)
|
||||
return;
|
||||
|
||||
if (m_focus != 0)
|
||||
--m_focus;
|
||||
else
|
||||
m_focus = fl.size() - 1;
|
||||
m_focus = fl->size_files() - 1;
|
||||
|
||||
m_window->mark_dirty();
|
||||
}
|
||||
@@ -136,13 +136,14 @@ ElementFileList::receive_pagenext() {
|
||||
throw torrent::client_error("ui::ElementFileList::receive_pagenext(...) called on a disabled object");
|
||||
|
||||
unsigned int count = (m_window->height() - 1) / 2;
|
||||
torrent::FileList* fl = m_download->download()->file_list();
|
||||
|
||||
if (m_focus + count < m_download->download()->file_list().size())
|
||||
if (m_focus + count < fl->size_files())
|
||||
m_focus += count;
|
||||
else if (m_focus == m_download->download()->file_list().size() - 1)
|
||||
else if (m_focus == fl->size_files() - 1)
|
||||
m_focus = 0;
|
||||
else
|
||||
m_focus = m_download->download()->file_list().size() - 1;
|
||||
m_focus = fl->size_files() - 1;
|
||||
|
||||
m_window->mark_dirty();
|
||||
}
|
||||
@@ -152,9 +153,9 @@ ElementFileList::receive_pageprev() {
|
||||
if (m_window == NULL)
|
||||
throw torrent::client_error("ui::ElementFileList::receive_pageprev(...) called on a disabled object");
|
||||
|
||||
torrent::FileList fl = m_download->download()->file_list();
|
||||
torrent::FileList* fl = m_download->download()->file_list();
|
||||
|
||||
if (fl.size() == 0)
|
||||
if (fl->size_files() == 0)
|
||||
return;
|
||||
|
||||
unsigned int count = (m_window->height() - 1) / 2;
|
||||
@@ -162,7 +163,7 @@ ElementFileList::receive_pageprev() {
|
||||
if (m_focus > count)
|
||||
m_focus -= count;
|
||||
else if (m_focus == 0)
|
||||
m_focus = fl.size() - 1;
|
||||
m_focus = fl->size_files() - 1;
|
||||
else
|
||||
m_focus = 0;
|
||||
|
||||
@@ -174,12 +175,12 @@ ElementFileList::receive_priority() {
|
||||
if (m_window == NULL)
|
||||
throw torrent::client_error("ui::ElementFileList::receive_prev(...) called on a disabled object");
|
||||
|
||||
torrent::FileList fl = m_download->download()->file_list();
|
||||
torrent::FileList* fl = m_download->download()->file_list();
|
||||
|
||||
if (m_focus >= fl.size())
|
||||
if (m_focus >= fl->size_files())
|
||||
return;
|
||||
|
||||
torrent::File* file = fl.get(m_focus);
|
||||
torrent::File* file = fl->at_index(m_focus);
|
||||
|
||||
file->set_priority(next_priority(file->priority()));
|
||||
|
||||
@@ -192,15 +193,15 @@ ElementFileList::receive_change_all() {
|
||||
if (m_window == NULL)
|
||||
throw torrent::client_error("ui::ElementFileList::receive_prev(...) called on a disabled object");
|
||||
|
||||
torrent::FileList fl = m_download->download()->file_list();
|
||||
torrent::FileList* fl = m_download->download()->file_list();
|
||||
|
||||
if (m_focus >= fl.size())
|
||||
if (m_focus >= fl->size_files())
|
||||
return;
|
||||
|
||||
Priority p = next_priority(fl.get(m_focus)->priority());
|
||||
Priority p = next_priority(fl->at_index(m_focus)->priority());
|
||||
|
||||
for (int i = 0, last = fl.size(); i != last; ++i)
|
||||
fl.get(i)->set_priority(p);
|
||||
for (int i = 0, last = fl->size_files(); i != last; ++i)
|
||||
fl->at_index(i)->set_priority(p);
|
||||
|
||||
m_download->download()->update_priorities();
|
||||
m_window->mark_dirty();
|
||||
|
||||
Reference in New Issue
Block a user