mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-12 13:12:32 +00:00
Loads correctly formated torrents from session dir when starting.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@294 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -53,6 +53,32 @@ DownloadStore::remove(Download* d) {
|
||||
unlink(create_filename(d).c_str());
|
||||
}
|
||||
|
||||
utils::Directory
|
||||
DownloadStore::get_formated_entries() {
|
||||
if (!is_active())
|
||||
return utils::Directory();
|
||||
|
||||
utils::Directory d(m_path);
|
||||
d.update();
|
||||
|
||||
d.erase(std::remove_if(d.begin(), d.end(), std::not1(std::ptr_fun(&DownloadStore::is_correct_format))), d.end());
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
bool
|
||||
DownloadStore::is_correct_format(std::string f) {
|
||||
if (f.size() != 48 || f.substr(40) != ".torrent")
|
||||
return false;
|
||||
|
||||
for (std::string::const_iterator itr = f.begin(); itr != f.end() - 8; ++itr)
|
||||
if (!(*itr >= '0' && *itr <= '9') &&
|
||||
!(*itr >= 'A' && *itr <= 'F'))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string
|
||||
DownloadStore::create_filename(Download* d) {
|
||||
return m_path + utils::string_to_hex(d->get_hash()) + ".torrent";
|
||||
|
||||
@@ -3,25 +3,31 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "utils/directory.h"
|
||||
|
||||
namespace core {
|
||||
|
||||
class Download;
|
||||
|
||||
class DownloadStore {
|
||||
public:
|
||||
|
||||
void activate(const std::string& path);
|
||||
void disable();
|
||||
|
||||
bool is_active() { return !m_path.empty(); }
|
||||
void activate(const std::string& path);
|
||||
void disable();
|
||||
|
||||
void save(Download* d);
|
||||
void remove(Download* d);
|
||||
bool is_active() { return !m_path.empty(); }
|
||||
|
||||
void save(Download* d);
|
||||
void remove(Download* d);
|
||||
|
||||
// Currently shows all entries in the correct format.
|
||||
utils::Directory get_formated_entries();
|
||||
|
||||
private:
|
||||
std::string create_filename(Download* d);
|
||||
static bool is_correct_format(std::string f);
|
||||
std::string create_filename(Download* d);
|
||||
|
||||
std::string m_path;
|
||||
std::string m_path;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ Manager::cleanup() {
|
||||
}
|
||||
|
||||
void
|
||||
Manager::insert(const std::string& uri) {
|
||||
Manager::insert(std::string uri) {
|
||||
if (std::strncmp(uri.c_str(), "http://", 7))
|
||||
create_file(uri);
|
||||
else
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ public:
|
||||
void initialize();
|
||||
void cleanup();
|
||||
|
||||
void insert(const std::string& uri);
|
||||
void insert(std::string uri);
|
||||
iterator erase(DownloadList::iterator itr);
|
||||
|
||||
void start(Download* d);
|
||||
|
||||
Reference in New Issue
Block a user