mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-22 00:56:18 +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());
|
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
|
std::string
|
||||||
DownloadStore::create_filename(Download* d) {
|
DownloadStore::create_filename(Download* d) {
|
||||||
return m_path + utils::string_to_hex(d->get_hash()) + ".torrent";
|
return m_path + utils::string_to_hex(d->get_hash()) + ".torrent";
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "utils/directory.h"
|
||||||
|
|
||||||
namespace core {
|
namespace core {
|
||||||
|
|
||||||
class Download;
|
class Download;
|
||||||
@@ -18,7 +20,11 @@ public:
|
|||||||
void save(Download* d);
|
void save(Download* d);
|
||||||
void remove(Download* d);
|
void remove(Download* d);
|
||||||
|
|
||||||
|
// Currently shows all entries in the correct format.
|
||||||
|
utils::Directory get_formated_entries();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static bool is_correct_format(std::string f);
|
||||||
std::string create_filename(Download* d);
|
std::string create_filename(Download* d);
|
||||||
|
|
||||||
std::string m_path;
|
std::string m_path;
|
||||||
|
|||||||
+1
-1
@@ -32,7 +32,7 @@ Manager::cleanup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Manager::insert(const std::string& uri) {
|
Manager::insert(std::string uri) {
|
||||||
if (std::strncmp(uri.c_str(), "http://", 7))
|
if (std::strncmp(uri.c_str(), "http://", 7))
|
||||||
create_file(uri);
|
create_file(uri);
|
||||||
else
|
else
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ public:
|
|||||||
void initialize();
|
void initialize();
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
void insert(const std::string& uri);
|
void insert(std::string uri);
|
||||||
iterator erase(DownloadList::iterator itr);
|
iterator erase(DownloadList::iterator itr);
|
||||||
|
|
||||||
void start(Download* d);
|
void start(Download* d);
|
||||||
|
|||||||
+15
-2
@@ -85,6 +85,19 @@ test_dir(const std::string& s) {
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
load_session_torrents(ui::Control* c) {
|
||||||
|
// Load session torrents.
|
||||||
|
std::list<std::string> l = c->get_core().get_download_store().get_formated_entries().make_list();
|
||||||
|
|
||||||
|
std::for_each(l.begin(), l.end(), std::bind1st(std::mem_fun(&core::Manager::insert), &c->get_core()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
load_arg_torrents(ui::Control* c, char** begin, char** end) {
|
||||||
|
std::for_each(begin, end, std::bind1st(std::mem_fun(&core::Manager::insert), &c->get_core()));
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char** argv) {
|
main(int argc, char** argv) {
|
||||||
ui::Control uiControl;
|
ui::Control uiControl;
|
||||||
@@ -122,8 +135,8 @@ main(int argc, char** argv) {
|
|||||||
|
|
||||||
uiControl.get_core().initialize();
|
uiControl.get_core().initialize();
|
||||||
|
|
||||||
while (firstArg < argc)
|
load_session_torrents(&uiControl);
|
||||||
uiControl.get_core().insert(argv[firstArg++]);
|
load_arg_torrents(&uiControl, argv + firstArg, argv + argc);
|
||||||
|
|
||||||
uiControl.get_display().adjust_layout();
|
uiControl.get_display().adjust_layout();
|
||||||
|
|
||||||
|
|||||||
+12
-1
@@ -5,6 +5,7 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
|
||||||
|
#include "functional.h"
|
||||||
#include "directory.h"
|
#include "directory.h"
|
||||||
|
|
||||||
namespace utils {
|
namespace utils {
|
||||||
@@ -28,7 +29,17 @@ Directory::update() {
|
|||||||
Base::push_back(ent->d_name);
|
Base::push_back(ent->d_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::sort(begin(), end(), std::less<std::string>());
|
Base::sort(std::less<std::string>());
|
||||||
|
}
|
||||||
|
|
||||||
|
Directory::Base
|
||||||
|
Directory::make_list() {
|
||||||
|
Base l;
|
||||||
|
|
||||||
|
for (Base::iterator itr = begin(); itr != end(); ++itr)
|
||||||
|
l.push_back(m_path + *itr);
|
||||||
|
|
||||||
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,13 @@
|
|||||||
#define RTORRENT_UTILS_DIRECTORY_H
|
#define RTORRENT_UTILS_DIRECTORY_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <list>
|
||||||
|
|
||||||
namespace utils {
|
namespace utils {
|
||||||
|
|
||||||
class Directory : private std::vector<std::string> {
|
class Directory : private std::list<std::string> {
|
||||||
public:
|
public:
|
||||||
typedef std::vector<std::string> Base;
|
typedef std::list<std::string> Base;
|
||||||
|
|
||||||
using Base::iterator;
|
using Base::iterator;
|
||||||
using Base::const_iterator;
|
using Base::const_iterator;
|
||||||
@@ -23,6 +23,8 @@ public:
|
|||||||
using Base::empty;
|
using Base::empty;
|
||||||
using Base::size;
|
using Base::size;
|
||||||
|
|
||||||
|
using Base::erase;
|
||||||
|
|
||||||
Directory() {}
|
Directory() {}
|
||||||
Directory(const std::string& path) : m_path(path) {}
|
Directory(const std::string& path) : m_path(path) {}
|
||||||
|
|
||||||
@@ -30,6 +32,9 @@ public:
|
|||||||
|
|
||||||
const std::string& get_path() { return m_path; }
|
const std::string& get_path() { return m_path; }
|
||||||
|
|
||||||
|
// Make a list with full path names.
|
||||||
|
Base make_list();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_path;
|
std::string m_path;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -52,9 +52,9 @@ equal(Type t, Ftor f) {
|
|||||||
return _equal<Type, Ftor>(t, f);
|
return _equal<Type, Ftor>(t, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Dest, typename Src>
|
template <typename Src, typename Dest>
|
||||||
struct _on : public std::unary_function<typename Src::argument_type, typename Dest::result_type> {
|
struct _on : public std::unary_function<typename Src::argument_type, typename Dest::result_type> {
|
||||||
_on(Dest d, Src s) : m_dest(d), m_src(s) {}
|
_on(Src s, Dest d) : m_dest(d), m_src(s) {}
|
||||||
|
|
||||||
typename Dest::result_type operator () (typename Src::argument_type arg) {
|
typename Dest::result_type operator () (typename Src::argument_type arg) {
|
||||||
return m_dest(m_src(arg));
|
return m_dest(m_src(arg));
|
||||||
@@ -64,10 +64,10 @@ struct _on : public std::unary_function<typename Src::argument_type, typename De
|
|||||||
Src m_src;
|
Src m_src;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Dest, typename Src>
|
template <typename Src, typename Dest>
|
||||||
inline _on<Dest, Src>
|
inline _on<Src, Dest>
|
||||||
on(Dest d, Src s) {
|
on(Src s, Dest d) {
|
||||||
return _on<Dest, Src>(d, s);
|
return _on<Src, Dest>(s, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Cond, typename Then>
|
template <typename Cond, typename Then>
|
||||||
|
|||||||
Reference in New Issue
Block a user