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

This commit is contained in:
Christophe Dumez 2011-10-25 20:56:54 +03:00
parent 1b8a2bf7c1
commit f6b7b8bd6e
7 changed files with 187 additions and 149 deletions

10
INSTALL
View file

@ -14,15 +14,17 @@ qBittorrent - A BitTorrent client in C++ / Qt4
- 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
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
- 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
- geoip-database (optional)

53
configure vendored
View file

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

View file

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

View file

@ -38,7 +38,6 @@
#include <QDebug>
#include <QProcess>
#include <QSettings>
#include <boost/filesystem/operations.hpp>
#ifdef DISABLE_GUI
#include <QCoreApplication>
@ -63,7 +62,14 @@ const int UNLEN = 256;
#include <Cocoa/Cocoa.h>
#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>
#endif
@ -230,9 +236,44 @@ long long misc::freeDiskSpaceOnPath(QString path) {
if(!dir_path.exists()) return -1;
}
Q_ASSERT(dir_path.exists());
namespace fs = boost::filesystem;
fs::space_info sp_in = fs::space(fs::path(dir_path.path().toLocal8Bit()));
return sp_in.available;
#ifndef Q_WS_WIN
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

View file

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

View file

@ -43,7 +43,6 @@
#include <libtorrent/torrent_info.hpp>
#include <libtorrent/bencode.hpp>
#include <libtorrent/entry.hpp>
#include <boost/filesystem/fstream.hpp>
#ifdef Q_WS_WIN
#include <Windows.h>
@ -638,18 +637,22 @@ void QTorrentHandle::move_storage(QString new_path) const {
bool QTorrentHandle::save_torrent_file(QString path) const {
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 torrent_file(entry::dictionary_t);
torrent_file["info"] = meta;
entry torrent_entry(entry::dictionary_t);
torrent_entry["info"] = meta;
if(!torrent_handle::trackers().empty())
torrent_file["announce"] = torrent_handle::trackers().front().url;
boost::filesystem::ofstream out(path.toLocal8Bit().constData(), std::ios_base::binary);
out.unsetf(std::ios_base::skipws);
bencode(std::ostream_iterator<char>(out), torrent_file);
torrent_entry["announce"] = torrent_handle::trackers().front().url;
vector<char> out;
bencode(back_inserter(out), torrent_entry);
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 false;
}

View file

@ -28,11 +28,6 @@
* 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/entry.hpp>
#include <libtorrent/bencode.hpp>
@ -47,17 +42,34 @@
#include "torrentcreatorthread.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;
#if LIBTORRENT_VERSION_MINOR < 16
using namespace boost::filesystem;
#endif
// do not include files and folders whose
// 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)
{
if (filename.leaf()[0] == '.') return false;
std::cerr << filename << std::endl;
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)
{
@ -70,7 +82,9 @@ void TorrentCreatorThread::create(QString _input_path, QString _save_path, QStri
comment = _comment;
is_private = _is_private;
piece_size = _piece_size;
#if LIBTORRENT_VERSION_MINOR < 16
path::default_name_check(no_check);
#endif
abort = false;
start();
}