don't use deprecated libtorrent functions

This commit is contained in:
arvidn
2013-12-31 16:49:16 -08:00
parent 3b4f9d2eeb
commit c1c824bcf7
8 changed files with 161 additions and 53 deletions

View File

@@ -72,7 +72,7 @@
#include <string.h>
#include "dnsupdater.h"
#if LIBTORRENT_VERSION_MAJOR < 1
#if LIBTORRENT_VERSION_NUM < 10000
#include <libtorrent/upnp.hpp>
#include <libtorrent/natpmp.hpp>
#endif
@@ -110,7 +110,7 @@ QBtSession::QBtSession()
, geoipDBLoaded(false), resolve_countries(false)
#endif
, m_tracker(0), m_shutdownAct(NO_SHUTDOWN)
#if LIBTORRENT_VERSION_MAJOR < 1
#if LIBTORRENT_VERSION_NUM < 10000
, m_upnp(0), m_natpmp(0)
#endif
, m_dynDNSUpdater(0)
@@ -476,12 +476,12 @@ void QBtSession::configureSession() {
if (pref.isDHTEnabled()) {
// Set DHT Port
if (enableDHT(true)) {
int dht_port;
if (pref.isDHTPortSameAsBT())
dht_port = 0;
else
int dht_port = 0;
#if LIBTORRENT_VERSION_NUM < 10000
if (!pref.isDHTPortSameAsBT())
dht_port = pref.getDHTPort();
setDHTPort(dht_port);
#endif
if (dht_port == 0) dht_port = new_listenPort;
addConsoleMessage(tr("DHT support [ON], port: UDP/%1").arg(dht_port), QString::fromUtf8("blue"));
} else {
@@ -491,6 +491,7 @@ void QBtSession::configureSession() {
enableDHT(false);
addConsoleMessage(tr("DHT support [OFF]"), QString::fromUtf8("blue"));
}
// * PeX
if (PeXEnabled) {
addConsoleMessage(tr("PeX support [ON]"), QString::fromUtf8("blue"));
@@ -1112,7 +1113,7 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr
if (resumed) {
if (loadFastResumeData(hash, buf)) {
fastResume = true;
#if LIBTORRENT_VERSION_MAJOR < 1
#if LIBTORRENT_VERSION_NUM < 10000
p.resume_data = &buf;
#else
p.resume_data = buf;
@@ -1228,9 +1229,9 @@ void QBtSession::initializeAddTorrentParams(const QString &hash, add_torrent_par
// Seeding mode
// Skip checking and directly start seeding (new in libtorrent v0.15)
if (TorrentTempData::isSeedingMode(hash))
p.seed_mode=true;
p.flags |= add_torrent_params::flag_seed_mode;
else
p.seed_mode=false;
p.flags &= ~add_torrent_params::flag_seed_mode;
// Preallocation mode
if (preAllocateAll)
@@ -1252,9 +1253,9 @@ void QBtSession::initializeAddTorrentParams(const QString &hash, add_torrent_par
}*/
// Start in pause
p.paused = true;
p.duplicate_is_error = false; // Already checked
p.auto_managed = false; // Because it is added in paused state
p.flags |= add_torrent_params::flag_paused;
p.flags &= ~add_torrent_params::flag_duplicate_is_error; // Already checked
p.flags &= ~add_torrent_params::flag_auto_managed; // Because it is added in paused state
}
void QBtSession::loadTorrentTempData(QTorrentHandle &h, QString savePath, bool magnet) {
@@ -1442,7 +1443,7 @@ void QBtSession::enableUPnP(bool b) {
Preferences pref;
if (b) {
qDebug("Enabling UPnP / NAT-PMP");
#if LIBTORRENT_VERSION_MAJOR < 1
#if LIBTORRENT_VERSION_NUM < 10000
m_upnp = s->start_upnp();
m_natpmp = s->start_natpmp();
#else
@@ -1452,7 +1453,7 @@ void QBtSession::enableUPnP(bool b) {
// Use UPnP/NAT-PMP for Web UI too
if (pref.isWebUiEnabled() && pref.useUPnPForWebUIPort()) {
const qint16 port = pref.getWebUiPort();
#if LIBTORRENT_VERSION_MAJOR < 1
#if LIBTORRENT_VERSION_NUM < 10000
m_upnp->add_mapping(upnp::tcp, port, port);
m_natpmp->add_mapping(natpmp::tcp, port, port);
#else
@@ -1464,7 +1465,7 @@ void QBtSession::enableUPnP(bool b) {
s->stop_upnp();
s->stop_natpmp();
#if LIBTORRENT_VERSION_MAJOR < 1
#if LIBTORRENT_VERSION_NUM < 10000
m_upnp = 0;
m_natpmp = 0;
#endif
@@ -1981,6 +1982,7 @@ void QBtSession::updateRatioTimer()
}
}
#if LIBTORRENT_VERSION_NUM < 10000
// Set DHT port (>= 1 or 0 if same as BT)
void QBtSession::setDHTPort(int dht_port) {
if (dht_port >= 0) {
@@ -1992,6 +1994,7 @@ void QBtSession::setDHTPort(int dht_port) {
qDebug("Set DHT Port to %d", dht_port);
}
}
#endif
// Enable IP Filtering
void QBtSession::enableIPFilter(const QString &filter_path, bool force) {

View File

@@ -145,7 +145,9 @@ public slots:
void setMaxRatioPerTorrent(const QString &hash, qreal ratio);
qreal getMaxRatioPerTorrent(const QString &hash, bool *usesGlobalRatio) const;
void removeRatioPerTorrent(const QString &hash);
#if LIBTORRENT_VERSION_NUM < 10000
void setDHTPort(int dht_port);
#endif
void setProxySettings(libtorrent::proxy_settings proxySettings);
void setSessionSettings(const libtorrent::session_settings &sessionSettings);
void setDefaultSavePath(const QString &savepath);
@@ -279,7 +281,7 @@ private:
TorrentSpeedMonitor *m_speedMonitor;
shutDownAction m_shutdownAct;
// Port forwarding
#if LIBTORRENT_VERSION_MAJOR < 1
#if LIBTORRENT_VERSION_NUM < 10000
libtorrent::upnp *m_upnp;
libtorrent::natpmp *m_natpmp;
#endif

View File

@@ -84,13 +84,21 @@ QString QTorrentHandle::hash() const {
QString QTorrentHandle::name() const {
QString name = TorrentPersistentData::getName(hash());
if (name.isEmpty()) {
#if LIBTORRENT_VERSION_NUM < 10000
name = misc::toQStringU(torrent_handle::name());
#else
name = misc::toQStringU(torrent_handle::status(torrent_handle::query_name).name);
#endif
}
return name;
}
QString QTorrentHandle::creation_date() const {
#if LIBTORRENT_VERSION_NUM < 10000
boost::optional<time_t> t = torrent_handle::get_torrent_info().creation_date();
#else
boost::optional<time_t> t = torrent_handle::torrent_file()->creation_date();
#endif
return t ? misc::toQString(*t) : "";
}
@@ -132,34 +140,50 @@ bool QTorrentHandle::is_queued() const {
}
size_type QTorrentHandle::total_size() const {
#if LIBTORRENT_VERSION_NUM < 10000
return torrent_handle::get_torrent_info().total_size();
#else
return torrent_handle::torrent_file()->total_size();
#endif
}
size_type QTorrentHandle::piece_length() const {
#if LIBTORRENT_VERSION_NUM < 10000
return torrent_handle::get_torrent_info().piece_length();
#else
return torrent_handle::torrent_file()->piece_length();
#endif
}
int QTorrentHandle::num_pieces() const {
#if LIBTORRENT_VERSION_NUM < 10000
return torrent_handle::get_torrent_info().num_pieces();
#else
return torrent_handle::torrent_file()->num_pieces();
#endif
}
bool QTorrentHandle::first_last_piece_first() const {
const torrent_info& t = get_torrent_info();
#if LIBTORRENT_VERSION_NUM < 10000
torrent_info const* t = &get_torrent_info();
#else
boost::intrusive_ptr<torrent_info const> t = torrent_file();
#endif
// Get int first media file
int index = 0;
for (index = 0; index < t.num_files(); ++index) {
QString path = misc::toQStringU(t.file_at(index).path);
for (index = 0; index < t->num_files(); ++index) {
QString path = misc::toQStringU(t->file_at(index).path);
const QString ext = fsutils::fileExtension(path);
if (misc::isPreviewable(ext) && torrent_handle::file_priority(index) > 0)
break;
}
if (index >= t.num_files()) // No media file
if (index >= t->num_files()) // No media file
return false;
QPair<int, int> extremities = get_file_extremity_pieces (t, index);
QPair<int, int> extremities = get_file_extremity_pieces(*t, index);
return (torrent_handle::piece_priority(extremities.first) == 7)
&& (torrent_handle::piece_priority(extremities.second) == 7);
@@ -198,7 +222,13 @@ int QTorrentHandle::num_incomplete() const {
}
QString QTorrentHandle::save_path() const {
return misc::toQStringU(torrent_handle::save_path()).replace("\\", "/");
#if LIBTORRENT_VERSION_NUM < 10000
return misc::toQStringU(torrent_handle::save_path())
.replace("\\", "/");
#else
return misc::toQStringU(status(torrent_handle::query_save_path).save_path)
.replace("\\", "/");
#endif
}
QString QTorrentHandle::save_path_parsed() const {
@@ -248,25 +278,46 @@ bool QTorrentHandle::has_filtered_pieces() const {
}
int QTorrentHandle::num_files() const {
#if LIBTORRENT_VERSION_NUM < 10000
return torrent_handle::get_torrent_info().num_files();
#else
return torrent_handle::torrent_file()->num_files();
#endif
}
QString QTorrentHandle::filename_at(unsigned int index) const {
#if LIBTORRENT_VERSION_NUM < 10000
Q_ASSERT(index < (unsigned int)torrent_handle::get_torrent_info().num_files());
#else
Q_ASSERT(index < (unsigned int)torrent_handle::torrent_file()->num_files());
#endif
return fsutils::fileName(filepath_at(index));
}
size_type QTorrentHandle::filesize_at(unsigned int index) const {
#if LIBTORRENT_VERSION_NUM < 10000
Q_ASSERT(index < (unsigned int)torrent_handle::get_torrent_info().num_files());
return torrent_handle::get_torrent_info().file_at(index).size;
return torrent_handle::get_torrent_info().files().file_size(index);
#else
Q_ASSERT(index < (unsigned int)torrent_handle::torrent_file()->num_files());
return torrent_handle::torrent_file()->files().file_size(index);
#endif
}
QString QTorrentHandle::filepath_at(unsigned int index) const {
return misc::toQStringU(torrent_handle::get_torrent_info().file_at(index).path);
#if LIBTORRENT_VERSION_NUM < 10000
return misc::toQStringU(torrent_handle::get_torrent_info().files().file_path(index));
#else
return misc::toQStringU(torrent_handle::torrent_file()->files().file_path(index));
#endif
}
QString QTorrentHandle::orig_filepath_at(unsigned int index) const {
return misc::toQStringU(torrent_handle::get_torrent_info().orig_files().at(index).path);
#if LIBTORRENT_VERSION_NUM < 10000
return misc::toQStringU(torrent_handle::get_torrent_info().orig_files().file_path(index));
#else
return misc::toQStringU(torrent_handle::torrent_file()->orig_files().file_path(index));
#endif
}
torrent_status::state_t QTorrentHandle::state() const {
@@ -274,11 +325,19 @@ torrent_status::state_t QTorrentHandle::state() const {
}
QString QTorrentHandle::creator() const {
#if LIBTORRENT_VERSION_NUM < 10000
return misc::toQStringU(torrent_handle::get_torrent_info().creator());
#else
return misc::toQStringU(torrent_handle::torrent_file()->creator());
#endif
}
QString QTorrentHandle::comment() const {
#if LIBTORRENT_VERSION_NUM < 10000
return misc::toQStringU(torrent_handle::get_torrent_info().comment());
#else
return misc::toQStringU(torrent_handle::torrent_file()->comment());
#endif
}
size_type QTorrentHandle::total_failed_bytes() const {
@@ -394,7 +453,11 @@ int QTorrentHandle::connections_limit() const {
}
bool QTorrentHandle::priv() const {
#if LIBTORRENT_VERSION_NUM < 10000
return torrent_handle::get_torrent_info().priv();
#else
return torrent_handle::torrent_file()->priv();
#endif
}
QString QTorrentHandle::firstFileSavePath() const {
@@ -416,11 +479,11 @@ QString QTorrentHandle::root_path() const
{
if (num_files() < 2)
return save_path();
QString first_filepath = filepath_at(0);
const int slashIndex = first_filepath.indexOf(QRegExp("[/\\\\]"));
if (slashIndex >= 0)
return QDir(save_path()).absoluteFilePath(first_filepath.left(slashIndex));
return save_path();
QString first_filepath = filepath_at(0);
const int slashIndex = first_filepath.indexOf(QRegExp("[/\\\\]"));
if (slashIndex >= 0)
return QDir(save_path()).absoluteFilePath(first_filepath.left(slashIndex));
return save_path();
}
bool QTorrentHandle::has_error() const {
@@ -519,10 +582,14 @@ void QTorrentHandle::move_storage(const QString& new_path) const {
bool QTorrentHandle::save_torrent_file(const QString& path) const {
if (!has_metadata()) return false;
const torrent_info& t = torrent_handle::get_torrent_info();
#if LIBTORRENT_VERSION_NUM < 10000
torrent_info const* t = &get_torrent_info();
#else
boost::intrusive_ptr<torrent_info const> t = torrent_file();
#endif
entry meta = bdecode(t.metadata().get(),
t.metadata().get() + t.metadata_size());
entry meta = bdecode(t->metadata().get(),
t->metadata().get() + t->metadata_size());
entry torrent_entry(entry::dictionary_t);
torrent_entry["info"] = meta;
if (!torrent_handle::trackers().empty())
@@ -549,7 +616,11 @@ void QTorrentHandle::file_priority(int index, int priority) const {
}
void QTorrentHandle::prioritize_files(const vector<int> &files) const {
#if LIBTORRENT_VERSION_NUM < 10000
if ((int)files.size() != torrent_handle::get_torrent_info().num_files()) return;
#else
if ((int)files.size() != torrent_handle::torrent_file()->num_files()) return;
#endif
qDebug() << Q_FUNC_INFO;
bool was_seed = is_seed();
vector<size_type> progress;
@@ -557,10 +628,13 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const {
qDebug() << Q_FUNC_INFO << "Changing files priorities...";
torrent_handle::prioritize_files(files);
qDebug() << Q_FUNC_INFO << "Moving unwanted files to .unwanted folder and conversely...";
QString spath = save_path();
for (uint i = 0; i < files.size(); ++i) {
// Move unwanted files to a .unwanted subfolder
if (files[i] == 0) {
QString old_abspath = QDir(save_path()).absoluteFilePath(filepath_at(i));
QString old_abspath = QDir(spath).absoluteFilePath(filepath_at(i));
QString parent_abspath = fsutils::branchPath(old_abspath);
// Make sure the file does not already exists
if (QDir(parent_abspath).dirName() != ".unwanted") {
@@ -602,8 +676,8 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const {
else
rename_file(i, QDir(new_relpath).filePath(old_name));
// Remove .unwanted directory if empty
qDebug() << "Attempting to remove .unwanted folder at " << QDir(save_path() + QDir::separator() + new_relpath).absoluteFilePath(".unwanted");
QDir(save_path() + QDir::separator() + new_relpath).rmdir(".unwanted");
qDebug() << "Attempting to remove .unwanted folder at " << QDir(spath + QDir::separator() + new_relpath).absoluteFilePath(".unwanted");
QDir(spath + QDir::separator() + new_relpath).rmdir(".unwanted");
}
}
}
@@ -616,7 +690,7 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const {
const Preferences pref;
if (pref.isTempPathEnabled()) {
QString tmp_path = pref.getTempPath();
qDebug() << "tmp folder is enabled, move torrent to " << tmp_path << " from " << save_path();
qDebug() << "tmp folder is enabled, move torrent to " << tmp_path << " from " << spath;
move_storage(tmp_path);
}
}
@@ -626,7 +700,13 @@ void QTorrentHandle::prioritize_first_last_piece(int file_index, bool b) const {
// Determine the priority to set
int prio = b ? 7 : torrent_handle::file_priority(file_index);
QPair<int, int> extremities = get_file_extremity_pieces (get_torrent_info(), file_index);
#if LIBTORRENT_VERSION_NUM < 10000
torrent_info const* tf = &get_torrent_info();
#else
boost::intrusive_ptr<torrent_info const> tf = torrent_file();
#endif
QPair<int, int> extremities = get_file_extremity_pieces(*tf, file_index);
piece_priority(extremities.first, prio);
piece_priority(extremities.second, prio);
}