Browse Source

Get rid of libboost-filesystem dependency if libtorrent >= v0.16.x is used

adaptive-webui-19844
Christophe Dumez 13 years ago
parent
commit
f6b7b8bd6e
  1. 10
      INSTALL
  2. 111
      configure
  3. 111
      qcm/libboost.qcm
  4. 51
      src/misc.cpp
  5. 4
      src/qtlibtorrent/qbtsession.cpp
  6. 25
      src/qtlibtorrent/qtorrenthandle.cpp
  7. 24
      src/torrentcreator/torrentcreatorthread.cpp

10
INSTALL

@ -14,15 +14,17 @@ qBittorrent - A BitTorrent client in C++ / Qt4
- pkg-config executable - pkg-config executable
- libtorrent-rasterbar by Arvid Norberg (>= 0.14.4 REQUIRED, compatible with v0.15.x) - libtorrent-rasterbar by Arvid Norberg (>= 0.14.4 REQUIRED, compatible with v0.15.x/v0.16.x)
-> http://www.libtorrent.net -> http://www.libtorrent.net
Be careful: another library (the one used by rTorrent) uses a similar name. Be careful: another library (the one used by rTorrent) uses a similar name.
- libboost 1.34.x (libboost-filesystem, libboost-date-time) + libasio - libboost 1.34.x (libboost-filesystem°) + libasio
or or
- libboost >= 1.35.x (libboost-system, libboost-filesystem, libboost-date-time) - libboost >= 1.35.x (libboost-system, libboost-filesystem°)
- python >= 2.3 && < 3.0 (needed by search engine) °libboost-filesystem is not needed if libtorrent-rasterbar >= v0.16.x is used
- python >= 2.3 (needed by search engine)
* Run time only dependency * Run time only dependency
- geoip-database (optional) - geoip-database (optional)

111
configure vendored

@ -442,12 +442,15 @@ arg: with-libboost-lib=[path], Path to libboost library files
-----END QCMOD----- -----END QCMOD-----
*/ */
#include <boost/version.hpp> #include <boost/version.hpp>
#include <libtorrent/version.hpp>
class qc_libboost : public ConfObj class qc_libboost : public ConfObj
{ {
public: public:
qc_libboost(Conf *c) : ConfObj(c) {} qc_libboost(Conf *c) : ConfObj(c) {}
QString name() const { return "libboost"; } QString name() const { return "libboost"; }
QString shortname() const { return "libboost"; } QString shortname() const { return "libboost"; }
QString findBoostLib(QString path, QString lib) const { QString findBoostLib(QString path, QString lib) const {
QString name; QString name;
QDir libDir(path); QDir libDir(path);
@ -471,77 +474,61 @@ public:
} }
return name; return name;
} }
bool exec(){
QString s; bool exec(){
s = conf->getenv("QC_WITH_LIBBOOST_INC"); QStringList sl;
if(!s.isEmpty()) { QString s = conf->getenv("QC_WITH_LIBBOOST_INC");
if(!conf->checkHeader(s, "boost/format.hpp")) { if (!s.isEmpty())
return false; sl << s;
} sl << "/usr/include";
if(!conf->checkHeader(s, "boost/date_time/posix_time/posix_time.hpp")) { sl << "/usr/local/include";
return false; bool found = false;
} foreach (s, sl) {
if(!conf->checkHeader(s, "boost/filesystem/path.hpp")) { if (conf->checkHeader(s, "boost/format.hpp")
return false; #if LIBTORRENT_VERSION_MAJOR == 0 && LIBTORRENT_VERSION_MINOR < 16
} && conf->checkHeader(s, "boost/filesystem/path.hpp")
}else{ #endif
QStringList sl; ) {
sl << "/usr/include"; found = true;
sl << "/usr/local/include"; break;
bool found = false; }
foreach(s, sl){ }
if(conf->checkHeader(s, "boost/format.hpp")){ if (!found)
found = true; return false;
break;
} conf->addIncludePath(s);
}
if(!found) { // Find library
return false; s = conf->getenv("QC_WITH_LIBBOOST_LIB");
}
if(!conf->checkHeader(s, "boost/date_time/posix_time/posix_time.hpp")) {
return false;
}
if(!conf->checkHeader(s, "boost/filesystem/path.hpp")) {
return false;
}
}
conf->addIncludePath(s);
// Find library
s = conf->getenv("QC_WITH_LIBBOOST_LIB");
QStringList required_libs; QStringList required_libs;
#if BOOST_VERSION >= 103500 #if BOOST_VERSION >= 103500
required_libs << "system"; required_libs << "system";
#endif #endif
#if LIBTORRENT_VERSION_MAJOR == 0 && LIBTORRENT_VERSION_MINOR < 16
required_libs << "filesystem" ; required_libs << "filesystem" ;
#endif
QStringList libDirs; QStringList libDirs;
if (!s.isEmpty())
libDirs << s;
libDirs << "/usr/lib/" << "/usr/lib64/" << "/usr/local/lib/" << "/usr/local/lib64/"; libDirs << "/usr/lib/" << "/usr/lib64/" << "/usr/local/lib/" << "/usr/local/lib64/";
foreach(const QString& lib, required_libs) { foreach(const QString& lib, required_libs) {
if(!s.isEmpty()) { bool found = false;
QString detected_name = findBoostLib(s, lib); foreach(const QString& libDir, libDirs) {
if(detected_name.isEmpty()) { QString detected_name = findBoostLib(libDir, lib);
printf("Could not find boost %s library!\n", qPrintable(lib)); if(!detected_name.isEmpty()) {
return false;
} else {
conf->addLib("-l"+detected_name); conf->addLib("-l"+detected_name);
found = true;
break;
} }
} else { }
bool found = false; if(!found) {
foreach(const QString& libDir, libDirs) { printf("Could not find boost %s library!\n", qPrintable(lib));
QString detected_name = findBoostLib(libDir, lib); return false;
if(!detected_name.isEmpty()) {
conf->addLib("-l"+detected_name);
found = true;
break;
}
}
if(!found) {
printf("Could not find boost %s library!\n", qPrintable(lib));
return false;
}
} }
} }
return true; return true;
} }
}; };
#line 1 "geoip-database.qcm" #line 1 "geoip-database.qcm"
/* /*

111
qcm/libboost.qcm

@ -6,12 +6,15 @@ arg: with-libboost-lib=[path], Path to libboost library files
-----END QCMOD----- -----END QCMOD-----
*/ */
#include <boost/version.hpp> #include <boost/version.hpp>
#include <libtorrent/version.hpp>
class qc_libboost : public ConfObj class qc_libboost : public ConfObj
{ {
public: public:
qc_libboost(Conf *c) : ConfObj(c) {} qc_libboost(Conf *c) : ConfObj(c) {}
QString name() const { return "libboost"; } QString name() const { return "libboost"; }
QString shortname() const { return "libboost"; } QString shortname() const { return "libboost"; }
QString findBoostLib(QString path, QString lib) const { QString findBoostLib(QString path, QString lib) const {
QString name; QString name;
QDir libDir(path); QDir libDir(path);
@ -35,75 +38,59 @@ public:
} }
return name; return name;
} }
bool exec(){
QString s; bool exec(){
s = conf->getenv("QC_WITH_LIBBOOST_INC"); QStringList sl;
if(!s.isEmpty()) { QString s = conf->getenv("QC_WITH_LIBBOOST_INC");
if(!conf->checkHeader(s, "boost/format.hpp")) { if (!s.isEmpty())
return false; sl << s;
} sl << "/usr/include";
if(!conf->checkHeader(s, "boost/date_time/posix_time/posix_time.hpp")) { sl << "/usr/local/include";
return false; bool found = false;
} foreach (s, sl) {
if(!conf->checkHeader(s, "boost/filesystem/path.hpp")) { if (conf->checkHeader(s, "boost/format.hpp")
return false; #if LIBTORRENT_VERSION_MAJOR == 0 && LIBTORRENT_VERSION_MINOR < 16
} && conf->checkHeader(s, "boost/filesystem/path.hpp")
}else{ #endif
QStringList sl; ) {
sl << "/usr/include"; found = true;
sl << "/usr/local/include"; break;
bool found = false; }
foreach(s, sl){ }
if(conf->checkHeader(s, "boost/format.hpp")){ if (!found)
found = true; return false;
break;
} conf->addIncludePath(s);
}
if(!found) { // Find library
return false; s = conf->getenv("QC_WITH_LIBBOOST_LIB");
}
if(!conf->checkHeader(s, "boost/date_time/posix_time/posix_time.hpp")) {
return false;
}
if(!conf->checkHeader(s, "boost/filesystem/path.hpp")) {
return false;
}
}
conf->addIncludePath(s);
// Find library
s = conf->getenv("QC_WITH_LIBBOOST_LIB");
QStringList required_libs; QStringList required_libs;
#if BOOST_VERSION >= 103500 #if BOOST_VERSION >= 103500
required_libs << "system"; required_libs << "system";
#endif #endif
#if LIBTORRENT_VERSION_MAJOR == 0 && LIBTORRENT_VERSION_MINOR < 16
required_libs << "filesystem" ; required_libs << "filesystem" ;
#endif
QStringList libDirs; QStringList libDirs;
if (!s.isEmpty())
libDirs << s;
libDirs << "/usr/lib/" << "/usr/lib64/" << "/usr/local/lib/" << "/usr/local/lib64/"; libDirs << "/usr/lib/" << "/usr/lib64/" << "/usr/local/lib/" << "/usr/local/lib64/";
foreach(const QString& lib, required_libs) { foreach(const QString& lib, required_libs) {
if(!s.isEmpty()) { bool found = false;
QString detected_name = findBoostLib(s, lib); foreach(const QString& libDir, libDirs) {
if(detected_name.isEmpty()) { QString detected_name = findBoostLib(libDir, lib);
printf("Could not find boost %s library!\n", qPrintable(lib)); if(!detected_name.isEmpty()) {
return false;
} else {
conf->addLib("-l"+detected_name); conf->addLib("-l"+detected_name);
} found = true;
} else { break;
bool found = false;
foreach(const QString& libDir, libDirs) {
QString detected_name = findBoostLib(libDir, lib);
if(!detected_name.isEmpty()) {
conf->addLib("-l"+detected_name);
found = true;
break;
}
}
if(!found) {
printf("Could not find boost %s library!\n", qPrintable(lib));
return false;
} }
} }
if(!found) {
printf("Could not find boost %s library!\n", qPrintable(lib));
return false;
}
} }
return true; return true;
} }
}; };

51
src/misc.cpp

@ -38,7 +38,6 @@
#include <QDebug> #include <QDebug>
#include <QProcess> #include <QProcess>
#include <QSettings> #include <QSettings>
#include <boost/filesystem/operations.hpp>
#ifdef DISABLE_GUI #ifdef DISABLE_GUI
#include <QCoreApplication> #include <QCoreApplication>
@ -63,7 +62,14 @@ const int UNLEN = 256;
#include <Cocoa/Cocoa.h> #include <Cocoa/Cocoa.h>
#endif #endif
#ifdef Q_WS_WIN #ifndef Q_WS_WIN
#if defined(Q_WS_MAC) || defined(Q_OS_FREEBSD)
#include <sys/param.h>
#include <sys/mount.h>
#else
#include <sys/vfs.h>
#endif
#else
#include <winbase.h> #include <winbase.h>
#endif #endif
@ -230,9 +236,44 @@ long long misc::freeDiskSpaceOnPath(QString path) {
if(!dir_path.exists()) return -1; if(!dir_path.exists()) return -1;
} }
Q_ASSERT(dir_path.exists()); Q_ASSERT(dir_path.exists());
namespace fs = boost::filesystem;
fs::space_info sp_in = fs::space(fs::path(dir_path.path().toLocal8Bit())); #ifndef Q_WS_WIN
return sp_in.available; unsigned long long available;
struct statfs stats;
const QString statfs_path = dir_path.path()+"/.";
const int ret = statfs (qPrintable(statfs_path), &stats) ;
if(ret == 0) {
available = ((unsigned long long)stats.f_bavail) *
((unsigned long long)stats.f_bsize) ;
return available;
} else {
return -1;
}
#else
typedef BOOL (WINAPI *GetDiskFreeSpaceEx_t)(LPCTSTR,
PULARGE_INTEGER,
PULARGE_INTEGER,
PULARGE_INTEGER);
GetDiskFreeSpaceEx_t
pGetDiskFreeSpaceEx = (GetDiskFreeSpaceEx_t)::GetProcAddress
(
::GetModuleHandle(TEXT("kernel32.dll")),
"GetDiskFreeSpaceExW"
);
if ( pGetDiskFreeSpaceEx )
{
ULARGE_INTEGER bytesFree, bytesTotal;
unsigned long long *ret;
if (pGetDiskFreeSpaceEx((LPCTSTR)(QDir::toNativeSeparators(dir_path.path())).utf16(), &bytesFree, &bytesTotal, NULL)) {
ret = (unsigned long long*)&bytesFree;
return *ret;
} else {
return -1;
}
} else {
return -1;
}
#endif
} }
#ifndef DISABLE_GUI #ifndef DISABLE_GUI

4
src/qtlibtorrent/qbtsession.cpp

@ -71,9 +71,11 @@
#include <libtorrent/torrent_info.hpp> #include <libtorrent/torrent_info.hpp>
#include <libtorrent/upnp.hpp> #include <libtorrent/upnp.hpp>
#include <libtorrent/natpmp.hpp> #include <libtorrent/natpmp.hpp>
#if LIBTORRENT_VERSION_MINOR < 16
#include <boost/filesystem/exception.hpp> #include <boost/filesystem/exception.hpp>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
#endif
#if LIBTORRENT_VERSION_MINOR > 15 #if LIBTORRENT_VERSION_MINOR > 15
#include "libtorrent/error_code.hpp" #include "libtorrent/error_code.hpp"
#endif #endif
@ -105,8 +107,10 @@ QBtSession::QBtSession()
BigRatioTimer->setInterval(10000); BigRatioTimer->setInterval(10000);
connect(BigRatioTimer, SIGNAL(timeout()), SLOT(processBigRatios())); connect(BigRatioTimer, SIGNAL(timeout()), SLOT(processBigRatios()));
Preferences pref; Preferences pref;
#if LIBTORRENT_VERSION_MINOR < 16
// To avoid some exceptions // To avoid some exceptions
boost::filesystem::path::default_name_check(boost::filesystem::no_check); boost::filesystem::path::default_name_check(boost::filesystem::no_check);
#endif
// Creating Bittorrent session // Creating Bittorrent session
QList<int> version; QList<int> version;
version << VERSION_MAJOR; version << VERSION_MAJOR;

25
src/qtlibtorrent/qtorrenthandle.cpp

@ -43,7 +43,6 @@
#include <libtorrent/torrent_info.hpp> #include <libtorrent/torrent_info.hpp>
#include <libtorrent/bencode.hpp> #include <libtorrent/bencode.hpp>
#include <libtorrent/entry.hpp> #include <libtorrent/entry.hpp>
#include <boost/filesystem/fstream.hpp>
#ifdef Q_WS_WIN #ifdef Q_WS_WIN
#include <Windows.h> #include <Windows.h>
@ -638,18 +637,22 @@ void QTorrentHandle::move_storage(QString new_path) const {
bool QTorrentHandle::save_torrent_file(QString path) const { bool QTorrentHandle::save_torrent_file(QString path) const {
if(!has_metadata()) return false; if(!has_metadata()) return false;
QFile met_file(path);
if(met_file.open(QIODevice::WriteOnly)) { entry meta = bdecode(torrent_handle::get_torrent_info().metadata().get(), torrent_handle::get_torrent_info().metadata().get()+torrent_handle::get_torrent_info().metadata_size());
entry meta = bdecode(torrent_handle::get_torrent_info().metadata().get(), torrent_handle::get_torrent_info().metadata().get()+torrent_handle::get_torrent_info().metadata_size()); entry torrent_entry(entry::dictionary_t);
entry torrent_file(entry::dictionary_t); torrent_entry["info"] = meta;
torrent_file["info"] = meta; if(!torrent_handle::trackers().empty())
if(!torrent_handle::trackers().empty()) torrent_entry["announce"] = torrent_handle::trackers().front().url;
torrent_file["announce"] = torrent_handle::trackers().front().url;
boost::filesystem::ofstream out(path.toLocal8Bit().constData(), std::ios_base::binary); vector<char> out;
out.unsetf(std::ios_base::skipws); bencode(back_inserter(out), torrent_entry);
bencode(std::ostream_iterator<char>(out), torrent_file); QFile torrent_file(path);
if (!out.empty() && torrent_file.open(QIODevice::WriteOnly)) {
torrent_file.write(&out[0], out.size());
torrent_file.close();
return true; return true;
} }
return false; return false;
} }

24
src/torrentcreator/torrentcreatorthread.cpp

@ -28,11 +28,6 @@
* Contact : chris@qbittorrent.org * Contact : chris@qbittorrent.org
*/ */
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/bind.hpp>
#include <libtorrent/version.hpp> #include <libtorrent/version.hpp>
#include <libtorrent/entry.hpp> #include <libtorrent/entry.hpp>
#include <libtorrent/bencode.hpp> #include <libtorrent/bencode.hpp>
@ -47,17 +42,34 @@
#include "torrentcreatorthread.h" #include "torrentcreatorthread.h"
#include "misc.h" #include "misc.h"
#if LIBTORRENT_VERSION_MINOR < 16
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/fstream.hpp>
#endif
#include <boost/bind.hpp>
using namespace libtorrent; using namespace libtorrent;
#if LIBTORRENT_VERSION_MINOR < 16
using namespace boost::filesystem; using namespace boost::filesystem;
#endif
// do not include files and folders whose // do not include files and folders whose
// name starts with a . // name starts with a .
#if LIBTORRENT_VERSION_MINOR >= 16
bool file_filter(std::string const& f)
{
if (filename(f)[0] == '.') return false;
return true;
}
#else
bool file_filter(boost::filesystem::path const& filename) bool file_filter(boost::filesystem::path const& filename)
{ {
if (filename.leaf()[0] == '.') return false; if (filename.leaf()[0] == '.') return false;
std::cerr << filename << std::endl; std::cerr << filename << std::endl;
return true; return true;
} }
#endif
void TorrentCreatorThread::create(QString _input_path, QString _save_path, QStringList _trackers, QStringList _url_seeds, QString _comment, bool _is_private, int _piece_size) void TorrentCreatorThread::create(QString _input_path, QString _save_path, QStringList _trackers, QStringList _url_seeds, QString _comment, bool _is_private, int _piece_size)
{ {
@ -70,7 +82,9 @@ void TorrentCreatorThread::create(QString _input_path, QString _save_path, QStri
comment = _comment; comment = _comment;
is_private = _is_private; is_private = _is_private;
piece_size = _piece_size; piece_size = _piece_size;
#if LIBTORRENT_VERSION_MINOR < 16
path::default_name_check(no_check); path::default_name_check(no_check);
#endif
abort = false; abort = false;
start(); start();
} }

Loading…
Cancel
Save