mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-14 06:02:31 +00:00
Saves to a session directory, but does not delete.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@292 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -13,6 +13,8 @@ libsub_core_a_SOURCES = \
|
||||
download.h \
|
||||
download_list.cc \
|
||||
download_list.h \
|
||||
download_store.cc \
|
||||
download_store.h \
|
||||
manager.cc \
|
||||
manager.h \
|
||||
poll.cc \
|
||||
|
||||
+3
-3
@@ -16,12 +16,12 @@ public:
|
||||
|
||||
const std::string& get_tracker_msg() { return m_trackerMsg; }
|
||||
|
||||
void open() { m_download.open(); }
|
||||
void close() { m_download.close(); }
|
||||
|
||||
void start() { m_download.start(); }
|
||||
void stop() { m_download.stop(); }
|
||||
|
||||
void open() { m_download.open(); }
|
||||
void close() { m_download.close(); }
|
||||
|
||||
bool operator == (const std::string& str) { return str == m_download.get_hash(); }
|
||||
|
||||
private:
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
#include <sigc++/bind.h>
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/torrent.h>
|
||||
|
||||
#include "utils/functional.h"
|
||||
|
||||
#include "download.h"
|
||||
#include "download_list.h"
|
||||
|
||||
namespace core {
|
||||
@@ -14,18 +14,26 @@ DownloadList::iterator
|
||||
DownloadList::insert(std::istream* str) {
|
||||
torrent::Download d = torrent::download_create(str);
|
||||
|
||||
iterator itr = Base::insert(end(), Download());
|
||||
itr->set_download(d);
|
||||
iterator itr = Base::insert(end(), new Download);
|
||||
(*itr)->set_download(d);
|
||||
|
||||
return itr;
|
||||
}
|
||||
|
||||
void
|
||||
DownloadList::erase(iterator itr) {
|
||||
itr->release_download();
|
||||
(*itr)->release_download();
|
||||
|
||||
torrent::download_remove(itr->get_hash());
|
||||
torrent::download_remove((*itr)->get_hash());
|
||||
delete *itr;
|
||||
Base::erase(itr);
|
||||
}
|
||||
|
||||
void
|
||||
DownloadList::clear() {
|
||||
std::for_each(begin(), end(), func::call_delete());
|
||||
|
||||
Base::clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
#define RTORRENT_CORE_DOWNLOAD_LIST_H
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
#include "download.h"
|
||||
#include <list>
|
||||
|
||||
namespace core {
|
||||
|
||||
class DownloadList : private std::list<Download> {
|
||||
class Download;
|
||||
|
||||
class DownloadList : private std::list<Download*> {
|
||||
public:
|
||||
typedef std::list<Download> Base;
|
||||
typedef std::list<Download*> Base;
|
||||
|
||||
using Base::iterator;
|
||||
using Base::const_iterator;
|
||||
@@ -24,8 +25,13 @@ public:
|
||||
using Base::empty;
|
||||
using Base::size;
|
||||
|
||||
~DownloadList() { clear(); }
|
||||
|
||||
iterator insert(std::istream* str);
|
||||
void erase(iterator itr);
|
||||
|
||||
private:
|
||||
void clear();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <stdexcept>
|
||||
#include <torrent/bencode.h>
|
||||
#include <torrent/torrent.h>
|
||||
|
||||
#include "utils/parse.h"
|
||||
|
||||
#include "download.h"
|
||||
#include "download_store.h"
|
||||
|
||||
namespace core {
|
||||
|
||||
void
|
||||
DownloadStore::activate(const std::string& path) {
|
||||
m_path = path;
|
||||
|
||||
if (m_path.empty())
|
||||
throw std::logic_error("core::DownloadStore::activate(...) received an empty path");
|
||||
|
||||
if (*m_path.rbegin() != '/')
|
||||
m_path += '/';
|
||||
}
|
||||
|
||||
void
|
||||
DownloadStore::disable() {
|
||||
m_path = "";
|
||||
}
|
||||
|
||||
void
|
||||
DownloadStore::save(Download* d) {
|
||||
std::fstream f(create_filename(d).c_str(), std::ios::out | std::ios::trunc);
|
||||
|
||||
if (!f.is_open())
|
||||
throw std::runtime_error("core::DownloadStore::save(...) could not open file");
|
||||
|
||||
f << torrent::download_bencode(d->get_hash());
|
||||
|
||||
if (f.fail())
|
||||
throw std::runtime_error("core::DownloadStore::save(...) could not write torrent");
|
||||
}
|
||||
|
||||
void
|
||||
DownloadStore::remove(Download* d) {
|
||||
}
|
||||
|
||||
std::string
|
||||
DownloadStore::create_filename(Download* d) {
|
||||
return m_path + utils::string_to_hex(d->get_hash()) + ".torrent";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef RTORRENT_CORE_SESSION_MANAGER_H
|
||||
#define RTORRENT_CORE_SESSION_MANAGER_H
|
||||
#ifndef RTORRENT_CORE_DOWNLOAD_STORE_H
|
||||
#define RTORRENT_CORE_DOWNLOAD_STORE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace core {
|
||||
|
||||
class Download;
|
||||
|
||||
class SessionManager {
|
||||
class DownloadStore {
|
||||
public:
|
||||
|
||||
void activate(const std::string& path);
|
||||
@@ -19,6 +19,8 @@ public:
|
||||
void remove(Download* d);
|
||||
|
||||
private:
|
||||
std::string create_filename(Download* d);
|
||||
|
||||
std::string m_path;
|
||||
};
|
||||
|
||||
+12
-6
@@ -8,6 +8,7 @@
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/torrent.h>
|
||||
|
||||
#include "download.h"
|
||||
#include "manager.h"
|
||||
#include "curl_get.h"
|
||||
|
||||
@@ -40,11 +41,11 @@ Manager::insert(const std::string& uri) {
|
||||
|
||||
void
|
||||
Manager::erase(DownloadList::iterator itr) {
|
||||
if (itr->get_download().is_active())
|
||||
if ((*itr)->get_download().is_active())
|
||||
throw std::logic_error("core::Manager::erase(...) called on an active download");
|
||||
|
||||
if (itr->get_download().is_open())
|
||||
itr->close();
|
||||
if ((*itr)->get_download().is_open())
|
||||
(*itr)->close();
|
||||
|
||||
m_downloadList.erase(itr);
|
||||
}
|
||||
@@ -60,7 +61,7 @@ Manager::start(Download* d) {
|
||||
if (d->get_download().is_hash_checked())
|
||||
d->start();
|
||||
else
|
||||
m_hashQueue.insert(d, sigc::mem_fun(*d, &Download::start));
|
||||
m_hashQueue.insert(d, sigc::mem_fun(d, &Download::start));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -68,6 +69,9 @@ Manager::stop(Download* d) {
|
||||
m_hashQueue.remove(d);
|
||||
|
||||
d->stop();
|
||||
|
||||
d->get_download().hash_save();
|
||||
m_downloadStore.save(d);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -79,7 +83,8 @@ Manager::create_file(const std::string& uri) {
|
||||
|
||||
itr = m_downloadList.insert(&f);
|
||||
|
||||
start(&*itr);
|
||||
start(*itr);
|
||||
m_downloadStore.save(*itr);
|
||||
|
||||
} catch (torrent::local_error& e) {
|
||||
// What to do? Keep in list for now.
|
||||
@@ -101,7 +106,8 @@ Manager::receive_http_done(CurlGet* http) {
|
||||
try {
|
||||
itr = m_downloadList.insert(http->get_stream());
|
||||
|
||||
start(&*itr);
|
||||
start(*itr);
|
||||
m_downloadStore.save(*itr);
|
||||
|
||||
} catch (torrent::local_error& e) {
|
||||
// What to do? Keep in list for now.
|
||||
|
||||
+23
-20
@@ -2,6 +2,7 @@
|
||||
#define RTORRENT_CORE_MANAGER_H
|
||||
|
||||
#include "download_list.h"
|
||||
#include "download_store.h"
|
||||
#include "hash_queue.h"
|
||||
#include "http_queue.h"
|
||||
#include "poll.h"
|
||||
@@ -15,36 +16,38 @@ public:
|
||||
|
||||
Manager() : m_portFirst(6890), m_portLast(6999) {}
|
||||
|
||||
DownloadList& get_download_list() { return m_downloadList; }
|
||||
HashQueue& get_hash_queue() { return m_hashQueue; }
|
||||
HttpQueue& get_http_queue() { return m_httpQueue; }
|
||||
DownloadList& get_download_list() { return m_downloadList; }
|
||||
DownloadStore& get_download_store() { return m_downloadStore; }
|
||||
HashQueue& get_hash_queue() { return m_hashQueue; }
|
||||
HttpQueue& get_http_queue() { return m_httpQueue; }
|
||||
|
||||
Poll& get_poll() { return m_poll; }
|
||||
Poll& get_poll() { return m_poll; }
|
||||
|
||||
void initialize();
|
||||
void cleanup();
|
||||
void initialize();
|
||||
void cleanup();
|
||||
|
||||
void insert(const std::string& uri);
|
||||
void erase(DownloadList::iterator itr);
|
||||
void insert(const std::string& uri);
|
||||
void erase(DownloadList::iterator itr);
|
||||
|
||||
void start(Download* d);
|
||||
void stop(Download* d);
|
||||
void start(Download* d);
|
||||
void stop(Download* d);
|
||||
|
||||
void set_port_range(int a, int b) { m_portFirst = a; m_portLast = b; }
|
||||
void set_port_range(int a, int b) { m_portFirst = a; m_portLast = b; }
|
||||
|
||||
private:
|
||||
void receive_http_done(CurlGet* http);
|
||||
void receive_http_done(CurlGet* http);
|
||||
|
||||
void create_file(const std::string& uri);
|
||||
void create_http(const std::string& uri);
|
||||
void create_file(const std::string& uri);
|
||||
void create_http(const std::string& uri);
|
||||
|
||||
DownloadList m_downloadList;
|
||||
HashQueue m_hashQueue;
|
||||
HttpQueue m_httpQueue;
|
||||
Poll m_poll;
|
||||
DownloadList m_downloadList;
|
||||
DownloadStore m_downloadStore;
|
||||
HashQueue m_hashQueue;
|
||||
HttpQueue m_httpQueue;
|
||||
Poll m_poll;
|
||||
|
||||
int m_portFirst;
|
||||
int m_portLast;
|
||||
int m_portFirst;
|
||||
int m_portLast;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "download.h"
|
||||
#include "session_manager.h"
|
||||
|
||||
namespace core {
|
||||
|
||||
void
|
||||
SessionManager::activate(const std::string& path) {
|
||||
m_path = path;
|
||||
|
||||
if (m_path.empty())
|
||||
throw std::logic_error("core::SessionManager::activate(...) received an empty path");
|
||||
|
||||
if (m_path.rbegin() != '/')
|
||||
m_path += '/';
|
||||
}
|
||||
|
||||
void
|
||||
SessionManager::disable() {
|
||||
m_path = "";
|
||||
}
|
||||
|
||||
void
|
||||
SessionManager::save(Download* d) {
|
||||
std::fstream f(
|
||||
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
SessionManager::remove(Download* d) {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user