mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-15 09:43:07 -07:00
Use libtorrent version.hpp instead of our own DEFINE
This commit is contained in:
parent
2e0c8f848f
commit
5f23cbc470
17 changed files with 79 additions and 62 deletions
|
@ -51,7 +51,8 @@
|
|||
#include "httpserver.h"
|
||||
#include "bandwidthscheduler.h"
|
||||
#include <libtorrent/extensions/ut_metadata.hpp>
|
||||
#ifdef LIBTORRENT_0_15
|
||||
#include <libtorrent/version.hpp>
|
||||
#if LIBTORRENT_VERSION_MINOR > 14
|
||||
#include <libtorrent/extensions/lt_trackers.hpp>
|
||||
#endif
|
||||
#include <libtorrent/extensions/ut_pex.hpp>
|
||||
|
@ -121,7 +122,7 @@ Bittorrent::Bittorrent()
|
|||
// Enabling plugins
|
||||
//s->add_extension(&create_metadata_plugin);
|
||||
s->add_extension(&create_ut_metadata_plugin);
|
||||
#ifdef LIBTORRENT_0_15
|
||||
#if LIBTORRENT_VERSION_MINOR > 14
|
||||
s->add_extension(create_lt_trackers_plugin);
|
||||
#endif
|
||||
if(Preferences::isPeXEnabled()) {
|
||||
|
@ -141,7 +142,7 @@ Bittorrent::Bittorrent()
|
|||
connect(downloader, SIGNAL(downloadFinished(QString, QString)), this, SLOT(processDownloadedFile(QString, QString)));
|
||||
connect(downloader, SIGNAL(downloadFailure(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString)));
|
||||
appendLabelToSavePath = Preferences::appendTorrentLabel();
|
||||
#ifdef LIBTORRENT_0_15
|
||||
#if LIBTORRENT_VERSION_MINOR > 14
|
||||
appendqBExtension = Preferences::useIncompleteFilesExtension();
|
||||
#endif
|
||||
connect(m_scanFolders, SIGNAL(torrentsAdded(QStringList&)), this, SLOT(addTorrentsFromScanFolder(QStringList&)));
|
||||
|
@ -154,7 +155,7 @@ session_proxy Bittorrent::asyncDeletion() {
|
|||
qDebug("Bittorrent session async deletion IN");
|
||||
exiting = true;
|
||||
// Do some BT related saving
|
||||
#ifndef LIBTORRENT_0_15
|
||||
#if LIBTORRENT_VERSION_MINOR < 15
|
||||
saveDHTEntry();
|
||||
#endif
|
||||
saveSessionState();
|
||||
|
@ -171,7 +172,7 @@ Bittorrent::~Bittorrent() {
|
|||
qDebug("BTSession destructor IN");
|
||||
if(!exiting) {
|
||||
// Do some BT related saving
|
||||
#ifndef LIBTORRENT_0_15
|
||||
#if LIBTORRENT_VERSION_MINOR < 15
|
||||
saveDHTEntry();
|
||||
#endif
|
||||
saveSessionState();
|
||||
|
@ -281,7 +282,7 @@ void Bittorrent::configureSession() {
|
|||
setDefaultTempPath(QString::null);
|
||||
}
|
||||
setAppendLabelToSavePath(Preferences::appendTorrentLabel());
|
||||
#ifdef LIBTORRENT_0_15
|
||||
#if LIBTORRENT_VERSION_MINOR > 14
|
||||
setAppendqBExtension(Preferences::useIncompleteFilesExtension());
|
||||
#endif
|
||||
preAllocateAllFiles(Preferences::preAllocateAllFiles());
|
||||
|
@ -423,7 +424,7 @@ void Bittorrent::configureSession() {
|
|||
sessionSettings.stop_tracker_timeout = 1;
|
||||
//sessionSettings.announce_to_all_trackers = true;
|
||||
sessionSettings.auto_scrape_interval = 1200; // 20 minutes
|
||||
#ifdef LIBTORRENT_0_15
|
||||
#if LIBTORRENT_VERSION_MINOR > 14
|
||||
sessionSettings.announce_to_all_trackers = true;
|
||||
sessionSettings.announce_to_all_tiers = true; //uTorrent behavior
|
||||
sessionSettings.auto_scrape_min_interval = 900; // 15 minutes
|
||||
|
@ -858,7 +859,7 @@ QTorrentHandle Bittorrent::addMagnetUri(QString magnet_uri, bool resumed) {
|
|||
qDebug("addMagnetURI: using save_path: %s", qPrintable(savePath));
|
||||
}
|
||||
|
||||
#ifdef LIBTORRENT_0_15
|
||||
#if LIBTORRENT_VERSION_MINOR > 14
|
||||
// Skip checking and directly start seeding (new in libtorrent v0.15)
|
||||
if(TorrentTempData::isSeedingMode(hash)){
|
||||
p.seed_mode=true;
|
||||
|
@ -1082,7 +1083,7 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
|
|||
qDebug("addTorrent: using save_path: %s", qPrintable(savePath));
|
||||
}
|
||||
|
||||
#ifdef LIBTORRENT_0_15
|
||||
#if LIBTORRENT_VERSION_MINOR > 14
|
||||
// Skip checking and directly start seeding (new in libtorrent v0.15)
|
||||
if(TorrentTempData::isSeedingMode(hash)){
|
||||
p.seed_mode=true;
|
||||
|
@ -1173,7 +1174,7 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
|
|||
qDebug("addTorrent: Saving save_path in persistent data: %s", qPrintable(savePath));
|
||||
TorrentPersistentData::saveSavePath(hash, savePath);
|
||||
}
|
||||
#ifdef LIBTORRENT_0_15
|
||||
#if LIBTORRENT_VERSION_MINOR > 14
|
||||
// Append .!qB to incomplete files
|
||||
if(appendqBExtension)
|
||||
appendqBextensionToTorrent(h, true);
|
||||
|
@ -1357,7 +1358,7 @@ void Bittorrent::enableLSD(bool b) {
|
|||
void Bittorrent::loadSessionState() {
|
||||
const QString state_path = misc::cacheLocation()+QDir::separator()+QString::fromUtf8("ses_state");
|
||||
if(!QFile::exists(state_path)) return;
|
||||
#ifdef LIBTORRENT_0_15
|
||||
#if LIBTORRENT_VERSION_MINOR > 14
|
||||
std::vector<char> in;
|
||||
if (load_file(state_path.toLocal8Bit().constData(), in) == 0)
|
||||
{
|
||||
|
@ -1378,7 +1379,7 @@ void Bittorrent::loadSessionState() {
|
|||
void Bittorrent::saveSessionState() {
|
||||
qDebug("Saving session state to disk...");
|
||||
const QString state_path = misc::cacheLocation()+QDir::separator()+QString::fromUtf8("ses_state");
|
||||
#ifdef LIBTORRENT_0_15
|
||||
#if LIBTORRENT_VERSION_MINOR > 14
|
||||
entry session_state;
|
||||
s->save_state(session_state);
|
||||
std::vector<char> out;
|
||||
|
@ -1404,7 +1405,7 @@ void Bittorrent::saveSessionState() {
|
|||
bool Bittorrent::enableDHT(bool b) {
|
||||
if(b) {
|
||||
if(!DHTEnabled) {
|
||||
#ifndef LIBTORRENT_0_15
|
||||
#if LIBTORRENT_VERSION_MINOR < 15
|
||||
entry dht_state;
|
||||
const QString dht_state_path = misc::cacheLocation()+QDir::separator()+QString::fromUtf8("dht_state");
|
||||
if(QFile::exists(dht_state_path)) {
|
||||
|
@ -1416,7 +1417,7 @@ bool Bittorrent::enableDHT(bool b) {
|
|||
}
|
||||
#endif
|
||||
try {
|
||||
#ifdef LIBTORRENT_0_15
|
||||
#if LIBTORRENT_VERSION_MINOR > 14
|
||||
s->start_dht();
|
||||
#else
|
||||
s->start_dht(dht_state);
|
||||
|
@ -1632,7 +1633,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
defaultTempPath = temppath;
|
||||
}
|
||||
|
||||
#ifdef LIBTORRENT_0_15
|
||||
#if LIBTORRENT_VERSION_MINOR > 14
|
||||
void Bittorrent::appendqBextensionToTorrent(QTorrentHandle h, bool append) {
|
||||
if(!h.is_valid() || !h.has_metadata()) return;
|
||||
std::vector<size_type> fp;
|
||||
|
@ -1704,7 +1705,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef LIBTORRENT_0_15
|
||||
#if LIBTORRENT_VERSION_MINOR > 14
|
||||
void Bittorrent::setAppendqBExtension(bool append) {
|
||||
if(appendqBExtension != append) {
|
||||
appendqBExtension = !appendqBExtension;
|
||||
|
@ -1932,7 +1933,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
if(h.is_valid()) {
|
||||
emit finishedTorrent(h);
|
||||
const QString &hash = h.hash();
|
||||
#ifdef LIBTORRENT_0_15
|
||||
#if LIBTORRENT_VERSION_MINOR > 14
|
||||
// Remove .!qB extension if necessary
|
||||
if(appendqBExtension)
|
||||
appendqBextensionToTorrent(h, false);
|
||||
|
@ -2059,7 +2060,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
}
|
||||
}
|
||||
}
|
||||
#ifdef LIBTORRENT_0_15
|
||||
#if LIBTORRENT_VERSION_MINOR > 14
|
||||
// Append .!qB to incomplete files
|
||||
if(appendqBExtension)
|
||||
appendqBextensionToTorrent(h, true);
|
||||
|
@ -2089,7 +2090,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
}
|
||||
}
|
||||
}
|
||||
#ifdef LIBTORRENT_0_15
|
||||
#if LIBTORRENT_VERSION_MINOR > 14
|
||||
else if (file_completed_alert* p = dynamic_cast<file_completed_alert*>(a.get())) {
|
||||
QTorrentHandle h(p->handle);
|
||||
if(appendqBExtension) {
|
||||
|
@ -2119,7 +2120,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
QHash<QString, TrackerInfos> trackers_data = trackersInfos.value(h.hash(), QHash<QString, TrackerInfos>());
|
||||
TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url));
|
||||
data.last_message = misc::toQString(p->msg);
|
||||
#ifndef LIBTORRENT_0_15
|
||||
#if LIBTORRENT_VERSION_MINOR < 15
|
||||
data.verified = false;
|
||||
++data.fail_count;
|
||||
#endif
|
||||
|
@ -2140,7 +2141,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url));
|
||||
data.last_message = ""; // Reset error/warning message
|
||||
data.num_peers = p->num_peers;
|
||||
#ifndef LIBTORRENT_0_15
|
||||
#if LIBTORRENT_VERSION_MINOR < 15
|
||||
data.fail_count = 0;
|
||||
data.verified = true;
|
||||
#endif
|
||||
|
@ -2155,7 +2156,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
const QString &tracker_url = misc::toQString(p->url);
|
||||
TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url));
|
||||
data.last_message = misc::toQString(p->msg); // Store warning message
|
||||
#ifndef LIBTORRENT_0_15
|
||||
#if LIBTORRENT_VERSION_MINOR < 15
|
||||
data.verified = true;
|
||||
data.fail_count = 0;
|
||||
#endif
|
||||
|
@ -2388,7 +2389,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
return sessionStatus.payload_upload_rate;
|
||||
}
|
||||
|
||||
#ifndef LIBTORRENT_0_15
|
||||
#if LIBTORRENT_VERSION_MINOR < 15
|
||||
// Save DHT entry to hard drive
|
||||
void Bittorrent::saveDHTEntry() {
|
||||
// Save DHT entry
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue