replaced boost.filesystem with custom functions (improves efficiency and drops unnecessary dependencies and improves libtorrent portability)
This commit is contained in:
@@ -38,8 +38,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#pragma warning(push, 1)
|
||||
#endif
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/filesystem/convenience.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
@@ -502,11 +500,6 @@ void print_peer_info(std::string& out, std::vector<libtorrent::peer_info> const&
|
||||
typedef std::multimap<std::string, libtorrent::torrent_handle> handles_t;
|
||||
|
||||
using boost::bind;
|
||||
using boost::filesystem::path;
|
||||
using boost::filesystem::exists;
|
||||
using boost::filesystem::directory_iterator;
|
||||
using boost::filesystem::extension;
|
||||
|
||||
|
||||
// monitored_dir is true if this torrent is added because
|
||||
// it was found in the directory that is monitored. If it
|
||||
@@ -517,7 +510,7 @@ void add_torrent(libtorrent::session& ses
|
||||
, std::string const& torrent
|
||||
, float preferred_ratio
|
||||
, bool compact_mode
|
||||
, path const& save_path
|
||||
, std::string const& save_path
|
||||
, bool monitored_dir
|
||||
, int torrent_upload_limit
|
||||
, int torrent_download_limit)
|
||||
@@ -538,7 +531,7 @@ void add_torrent(libtorrent::session& ses
|
||||
add_torrent_params p;
|
||||
lazy_entry resume_data;
|
||||
|
||||
std::string filename = (save_path / (t->name() + ".resume")).string();
|
||||
std::string filename = combine_path(save_path, t->name() + ".resume");
|
||||
|
||||
std::vector<char> buf;
|
||||
if (load_file(filename.c_str(), buf) == 0)
|
||||
@@ -565,12 +558,12 @@ void add_torrent(libtorrent::session& ses
|
||||
#endif
|
||||
}
|
||||
|
||||
void scan_dir(path const& dir_path
|
||||
void scan_dir(std::string const& dir_path
|
||||
, libtorrent::session& ses
|
||||
, handles_t& handles
|
||||
, float preferred_ratio
|
||||
, bool compact_mode
|
||||
, path const& save_path
|
||||
, std::string const& save_path
|
||||
, int torrent_upload_limit
|
||||
, int torrent_download_limit)
|
||||
{
|
||||
@@ -578,10 +571,11 @@ void scan_dir(path const& dir_path
|
||||
|
||||
using namespace libtorrent;
|
||||
|
||||
for (directory_iterator i(dir_path), end; i != end; ++i)
|
||||
error_code ec;
|
||||
for (directory i(dir_path, ec); !i.done(); i.next(ec))
|
||||
{
|
||||
if (extension(*i) != ".torrent") continue;
|
||||
std::string file = i->path().string();
|
||||
std::string file = i.file();
|
||||
if (extension(file) != ".torrent") continue;
|
||||
|
||||
handles_t::iterator k = handles.find(file);
|
||||
if (k != handles.end())
|
||||
@@ -659,7 +653,7 @@ void print_alert(libtorrent::alert const* a, std::string& str)
|
||||
fprintf(g_log_file, "[%s] %s\n", time_now_string(), a->message().c_str());
|
||||
}
|
||||
|
||||
int save_file(boost::filesystem::path const& filename, std::vector<char>& v)
|
||||
int save_file(std::string const& filename, std::vector<char>& v)
|
||||
{
|
||||
using namespace libtorrent;
|
||||
|
||||
@@ -697,7 +691,7 @@ void handle_alert(libtorrent::session& ses, libtorrent::alert* a
|
||||
{
|
||||
std::vector<char> out;
|
||||
bencode(std::back_inserter(out), *p->resume_data);
|
||||
save_file(h.save_path() / (h.name() + ".resume"), out);
|
||||
save_file(combine_path(h.save_path(), h.name() + ".resume"), out);
|
||||
if (std::find_if(handles.begin(), handles.end()
|
||||
, bind(&handles_t::value_type::second, _1) == h) == handles.end())
|
||||
ses.remove_torrent(h);
|
||||
@@ -718,11 +712,6 @@ static char const* state_str[] =
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
#if BOOST_VERSION < 103400
|
||||
using boost::filesystem::no_check;
|
||||
path::default_name_check(no_check);
|
||||
#endif
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
fprintf(stderr, "usage: client_test [OPTIONS] [TORRENT|MAGNETURL]\n\n"
|
||||
@@ -818,10 +807,10 @@ int main(int argc, char* argv[])
|
||||
int listen_port = 6881;
|
||||
float preferred_ratio = 0.f;
|
||||
std::string allocation_mode = "sparse";
|
||||
boost::filesystem::path save_path(".");
|
||||
std::string save_path(".");
|
||||
int torrent_upload_limit = 0;
|
||||
int torrent_download_limit = 0;
|
||||
boost::filesystem::path monitor_dir;
|
||||
std::string monitor_dir;
|
||||
std::string bind_to_interface = "";
|
||||
int poll_interval = 5;
|
||||
|
||||
@@ -1097,7 +1086,7 @@ int main(int argc, char* argv[])
|
||||
torrent_handle h = rd->handle;
|
||||
std::vector<char> out;
|
||||
bencode(std::back_inserter(out), *rd->resume_data);
|
||||
save_file(h.save_path() / (h.name() + ".resume"), out);
|
||||
save_file(combine_path(h.save_path(), h.name() + ".resume"), out);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1554,7 +1543,7 @@ int main(int argc, char* argv[])
|
||||
, pad_file?esc("34"):""
|
||||
, progress / 10.f
|
||||
, add_suffix(file_progress[i]).c_str()
|
||||
, info.file_at(i).path.leaf().c_str()
|
||||
, filename(info.file_at(i).path).c_str()
|
||||
, pad_file?esc("0"):"");
|
||||
out += str;
|
||||
}
|
||||
|
@@ -40,22 +40,17 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libtorrent/torrent_info.hpp"
|
||||
#include "libtorrent/lazy_entry.hpp"
|
||||
#include "libtorrent/magnet_uri.hpp"
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
using namespace libtorrent;
|
||||
using namespace boost::filesystem;
|
||||
|
||||
if (argc != 2)
|
||||
{
|
||||
std::cerr << "usage: dump_torrent torrent-file\n";
|
||||
return 1;
|
||||
}
|
||||
#if BOOST_VERSION < 103400
|
||||
boost::filesystem::path::default_name_check(boost::filesystem::no_check);
|
||||
#endif
|
||||
|
||||
int size = file_size(argv[1]);
|
||||
if (size > 10 * 1000000)
|
||||
@@ -126,9 +121,9 @@ int main(int argc, char* argv[])
|
||||
<< (i->symlink_attribute?'l':'-')
|
||||
<< " "
|
||||
<< "[ " << std::setw(4) << first << ", " << std::setw(4) << last << " ]\t"
|
||||
<< i->path.string() ;
|
||||
<< i->path;
|
||||
if (i->symlink_attribute)
|
||||
std::cout << " -> " << i->symlink_path.string();
|
||||
std::cout << " -> " << i->symlink_path;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
|
@@ -37,20 +37,18 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libtorrent/storage.hpp"
|
||||
#include "libtorrent/hasher.hpp"
|
||||
#include "libtorrent/create_torrent.hpp"
|
||||
#include "libtorrent/file.hpp"
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
using namespace boost::filesystem;
|
||||
using namespace libtorrent;
|
||||
|
||||
// do not include files and folders whose
|
||||
// name starts with a .
|
||||
bool file_filter(boost::filesystem::path const& filename)
|
||||
bool file_filter(std::string const& f)
|
||||
{
|
||||
if (filename.leaf()[0] == '.') return false;
|
||||
fprintf(stderr, "%s\n", filename.string().c_str());
|
||||
if (filename(f)[0] == '.') return false;
|
||||
fprintf(stderr, "%s\n", f.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -82,7 +80,6 @@ void print_usage()
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
using namespace libtorrent;
|
||||
using namespace boost::filesystem;
|
||||
|
||||
char const* creator_str = "libtorrent";
|
||||
|
||||
@@ -140,7 +137,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
file_storage fs;
|
||||
file_pool fp;
|
||||
path full_path = complete(path(argv[1]));
|
||||
std::string full_path = libtorrent::complete(argv[1]);
|
||||
|
||||
add_files(fs, full_path, file_filter);
|
||||
|
||||
@@ -154,7 +151,7 @@ int main(int argc, char* argv[])
|
||||
t.add_url_seed(*i);
|
||||
|
||||
error_code ec;
|
||||
set_piece_hashes(t, full_path.branch_path()
|
||||
set_piece_hashes(t, parent_path(full_path)
|
||||
, boost::bind(&print_progress, _1, t.num_pieces()), ec);
|
||||
if (ec)
|
||||
{
|
||||
|
@@ -42,10 +42,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
using namespace libtorrent;
|
||||
#if BOOST_VERSION < 103400
|
||||
namespace fs = boost::filesystem;
|
||||
fs::path::default_name_check(fs::no_check);
|
||||
#endif
|
||||
|
||||
if (argc != 2)
|
||||
{
|
||||
|
Reference in New Issue
Block a user