* Added torrent::FileList to the API.

git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@659 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2006-03-30 17:57:57 +00:00
parent 8ea6f78e21
commit 59a23ea9ed
9 changed files with 65 additions and 44 deletions
+7 -5
View File
@@ -43,6 +43,7 @@
#include <rak/path.h>
#include <torrent/exceptions.h>
#include <torrent/torrent.h>
#include <torrent/tracker.h>
#include <torrent/tracker_list.h>
#include "utils/variable_generic.h"
@@ -53,6 +54,7 @@ namespace core {
Download::Download(torrent::Download d) :
m_download(d),
m_fileList(d.file_list()),
m_chunksFailed(0) {
@@ -69,8 +71,8 @@ Download::Download(torrent::Download d) :
m_variables.insert("state", new utils::VariableObject(&m_download.bencode(), "rtorrent", "state", torrent::Object::TYPE_STRING));
m_variables.insert("tied_to_file", new utils::VariableObject(&m_download.bencode(), "rtorrent", "tied_to_file", torrent::Object::TYPE_STRING));
m_variables.insert("directory", new utils::VariableSlotString<>(rak::mem_fn(&m_download, &torrent::Download::root_dir),
rak::mem_fn(this, &Download::set_root_directory)));
m_variables.insert("directory", new utils::VariableSlotString<const std::string&>(rak::mem_fn(&m_fileList, &torrent::FileList::root_dir),
rak::mem_fn(this, &Download::set_root_directory)));
m_variables.insert("min_peers", new utils::VariableSlotValue<uint32_t, uint32_t>(rak::mem_fn(&m_download, &torrent::Download::peers_min),
rak::mem_fn(&m_download, &torrent::Download::set_peers_min),
@@ -251,14 +253,14 @@ Download::receive_chunk_failed(__UNUSED uint32_t idx) {
void
Download::set_root_directory(const std::string& path) {
if (path.empty()) {
m_download.set_root_dir("./" + (m_download.size_file_entries() > 1 ? m_download.name() : std::string()));
m_fileList.set_root_dir("./" + (m_fileList.size() > 1 ? m_download.name() : std::string()));
} else {
std::string fullPath = rak::path_expand(path);
m_download.set_root_dir(fullPath +
m_fileList.set_root_dir(fullPath +
(*fullPath.rbegin() != '/' ? "/" : "") +
(m_download.size_file_entries() > 1 ? m_download.name() : ""));
(m_fileList.size() > 1 ? m_download.name() : ""));
}
m_download.bencode().get_key("rtorrent").insert_key("directory", path);
+5
View File
@@ -39,6 +39,7 @@
#include <sigc++/connection.h>
#include <torrent/download.h>
#include <torrent/file_list.h>
#include <torrent/torrent.h>
#include "utils/variable_map.h"
@@ -63,6 +64,8 @@ public:
utils::VariableMap* variables() { return &m_variables; }
std::string variable_string(const std::string& key) { return m_variables.get_string(key); }
torrent::FileList* file_list() { return &m_fileList; }
torrent::Download& get_download() { return m_download; }
const torrent::Download& get_download() const { return m_download; }
std::string get_hash() { return m_download.info_hash(); }
@@ -111,7 +114,9 @@ private:
void set_root_directory(const std::string& path);
// Store the FileList instance so we can use slots etc on it.
torrent::Download m_download;
torrent::FileList m_fileList;
std::string m_message;
uint32_t m_chunksFailed;