From 1038b00553fa2c438ae3b10321ec7f42e7493b4e Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Tue, 25 Oct 2011 20:56:54 +0300 Subject: [PATCH] Get rid of libboost-filesystem dependency if libtorrent >= v0.16.x is used (cherry picked from commit f6b7b8bd6e9dba86e01c1ea3bffe97b9ae818990) --- INSTALL | 10 +- configure | 111 +++++++++----------- qcm/libboost.qcm | 111 +++++++++----------- src/misc.cpp | 51 ++++++++- src/qtlibtorrent/qbtsession.cpp | 4 + src/qtlibtorrent/qtorrenthandle.cpp | 25 +++-- src/torrentcreator/torrentcreatorthread.cpp | 24 ++++- 7 files changed, 187 insertions(+), 149 deletions(-) diff --git a/INSTALL b/INSTALL index 630242323..db6dc9d99 100644 --- a/INSTALL +++ b/INSTALL @@ -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°) + + °libboost-filesystem is not needed if libtorrent-rasterbar >= v0.16.x is used - - python >= 2.3 && < 3.0 (needed by search engine) + - python >= 2.3 (needed by search engine) * Run time only dependency - geoip-database (optional) diff --git a/configure b/configure index f93ee1d7f..687960c85 100755 --- a/configure +++ b/configure @@ -442,12 +442,15 @@ arg: with-libboost-lib=[path], Path to libboost library files -----END QCMOD----- */ #include +#include + class qc_libboost : public ConfObj { public: - qc_libboost(Conf *c) : ConfObj(c) {} - QString name() const { return "libboost"; } - QString shortname() const { return "libboost"; } + 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,77 +474,61 @@ 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; - sl << "/usr/include"; - sl << "/usr/local/include"; - bool found = false; - foreach(s, sl){ - if(conf->checkHeader(s, "boost/format.hpp")){ - found = true; - break; - } - } - 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"); + + bool exec(){ + 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 LIBTORRENT_VERSION_MAJOR == 0 && LIBTORRENT_VERSION_MINOR < 16 + && conf->checkHeader(s, "boost/filesystem/path.hpp") +#endif + ) { + found = true; + break; + } + } + if (!found) + 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 { + bool found = false; + foreach(const QString& libDir, libDirs) { + QString detected_name = findBoostLib(libDir, lib); + if(!detected_name.isEmpty()) { conf->addLib("-l"+detected_name); - } - } else { - 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; + 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" /* diff --git a/qcm/libboost.qcm b/qcm/libboost.qcm index 788e59c56..4519bffb8 100644 --- a/qcm/libboost.qcm +++ b/qcm/libboost.qcm @@ -6,12 +6,15 @@ arg: with-libboost-lib=[path], Path to libboost library files -----END QCMOD----- */ #include +#include + class qc_libboost : public ConfObj { public: - qc_libboost(Conf *c) : ConfObj(c) {} - QString name() const { return "libboost"; } - QString shortname() const { return "libboost"; } + 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,75 +38,59 @@ 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; - sl << "/usr/include"; - sl << "/usr/local/include"; - bool found = false; - foreach(s, sl){ - if(conf->checkHeader(s, "boost/format.hpp")){ - found = true; - break; - } - } - 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"); + + bool exec(){ + 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 LIBTORRENT_VERSION_MAJOR == 0 && LIBTORRENT_VERSION_MINOR < 16 + && conf->checkHeader(s, "boost/filesystem/path.hpp") +#endif + ) { + found = true; + break; + } + } + if (!found) + 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 { + bool found = false; + foreach(const QString& libDir, libDirs) { + QString detected_name = findBoostLib(libDir, lib); + if(!detected_name.isEmpty()) { conf->addLib("-l"+detected_name); - } - } else { - 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; + found = true; + break; } } + if(!found) { + printf("Could not find boost %s library!\n", qPrintable(lib)); + return false; + } } - return true; - } + return true; + } }; diff --git a/src/misc.cpp b/src/misc.cpp index d87c95b48..60c4b1df4 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -38,7 +38,6 @@ #include #include #include -#include #ifdef DISABLE_GUI #include @@ -63,7 +62,14 @@ const int UNLEN = 256; #include #endif -#ifdef Q_WS_WIN +#ifndef Q_WS_WIN +#if defined(Q_WS_MAC) || defined(Q_OS_FREEBSD) +#include +#include +#else +#include +#endif +#else #include #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 diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index 96b099c5a..2c2df9ff9 100644 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -71,9 +71,11 @@ #include #include #include +#if LIBTORRENT_VERSION_MINOR < 16 #include #include #include +#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 version; version << VERSION_MAJOR; diff --git a/src/qtlibtorrent/qtorrenthandle.cpp b/src/qtlibtorrent/qtorrenthandle.cpp index ce9d2c034..ef739af1e 100644 --- a/src/qtlibtorrent/qtorrenthandle.cpp +++ b/src/qtlibtorrent/qtorrenthandle.cpp @@ -43,7 +43,6 @@ #include #include #include -#include #ifdef Q_WS_WIN #include @@ -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; - 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(out), torrent_file); + + 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); + torrent_entry["info"] = meta; + if(!torrent_handle::trackers().empty()) + torrent_entry["announce"] = torrent_handle::trackers().front().url; + + vector 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; } diff --git a/src/torrentcreator/torrentcreatorthread.cpp b/src/torrentcreator/torrentcreatorthread.cpp index aa6a9da63..ae3b65816 100644 --- a/src/torrentcreator/torrentcreatorthread.cpp +++ b/src/torrentcreator/torrentcreatorthread.cpp @@ -28,11 +28,6 @@ * Contact : chris@qbittorrent.org */ -#include -#include -#include -#include - #include #include #include @@ -47,17 +42,34 @@ #include "torrentcreatorthread.h" #include "misc.h" +#if LIBTORRENT_VERSION_MINOR < 16 +#include +#include +#include +#endif +#include + 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(); }