mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-22 00:17:23 -06:00
Get rid of libboost-filesystem dependency if libtorrent >= v0.16.x is used
This commit is contained in:
51
src/misc.cpp
51
src/misc.cpp
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
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);
|
||||
|
||||
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<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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user