Add compile definition to indicate using of libtorrent 2.0 (#15297)

The compile definition is temporary which will be removed when qbt
ditches libtorrent 1.x.
This commit is contained in:
Chocobo1 2021-08-08 13:27:22 +08:00 committed by GitHub
parent bed643e627
commit 138c911ef4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 85 additions and 93 deletions

View file

@ -45,6 +45,9 @@ DEFINES += BOOST_SYSTEM_STATIC_LINK
# Enable if linking dynamically against libtorrent # Enable if linking dynamically against libtorrent
#DEFINES += TORRENT_LINKING_SHARED #DEFINES += TORRENT_LINKING_SHARED
# Enable this if compiling with libtorrent 2.x
#DEFINES += QBT_USES_LIBTORRENT2
# Enable stack trace support # Enable stack trace support
CONFIG += stacktrace CONFIG += stacktrace

2
configure vendored
View file

@ -6279,7 +6279,7 @@ else
libtorrent_LIBS=$pkg_cv_libtorrent_LIBS libtorrent_LIBS=$pkg_cv_libtorrent_LIBS
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
printf "%s\n" "yes" >&6; } printf "%s\n" "yes" >&6; }
CXXFLAGS="$libtorrent_CFLAGS $CXXFLAGS" LIBS="$libtorrent_LIBS $LIBS" CXXFLAGS="$libtorrent_CFLAGS $CXXFLAGS" LIBS="$libtorrent_LIBS $LIBS" QBT_ADD_DEFINES="$QBT_ADD_DEFINES QBT_USES_LIBTORRENT2"
fi fi

View file

@ -178,7 +178,7 @@ AC_COMPILE_IFELSE([DETECT_BOOST_VERSION_PROGRAM(106000)], [],
PKG_CHECK_MODULES(libtorrent, PKG_CHECK_MODULES(libtorrent,
[libtorrent-rasterbar >= 2.0.4], [libtorrent-rasterbar >= 2.0.4],
[CXXFLAGS="$libtorrent_CFLAGS $CXXFLAGS" LIBS="$libtorrent_LIBS $LIBS"], [CXXFLAGS="$libtorrent_CFLAGS $CXXFLAGS" LIBS="$libtorrent_LIBS $LIBS" QBT_ADD_DEFINES="$QBT_ADD_DEFINES QBT_USES_LIBTORRENT2"],
[PKG_CHECK_MODULES(libtorrent, [PKG_CHECK_MODULES(libtorrent,
[libtorrent-rasterbar >= 1.2.14 libtorrent-rasterbar < 2], [libtorrent-rasterbar >= 1.2.14 libtorrent-rasterbar < 2],
[CXXFLAGS="$libtorrent_CFLAGS $CXXFLAGS" LIBS="$libtorrent_LIBS $LIBS"])]) [CXXFLAGS="$libtorrent_CFLAGS $CXXFLAGS" LIBS="$libtorrent_LIBS $LIBS"])])

View file

@ -36,6 +36,7 @@ endmacro()
find_libtorrent(${minLibtorrent1Version}) find_libtorrent(${minLibtorrent1Version})
if (LibtorrentRasterbar_FOUND AND (LibtorrentRasterbar_VERSION VERSION_GREATER_EQUAL 2.0)) if (LibtorrentRasterbar_FOUND AND (LibtorrentRasterbar_VERSION VERSION_GREATER_EQUAL 2.0))
find_libtorrent(${minLibtorrentVersion}) find_libtorrent(${minLibtorrentVersion})
target_compile_definitions(qbt_common_cfg PUBLIC QBT_USES_LIBTORRENT2)
endif() endif()
# force variable type so that it always shows up in ccmake/cmake-gui frontends # force variable type so that it always shows up in ccmake/cmake-gui frontends

View file

@ -35,7 +35,7 @@
#include "base/utils/fs.h" #include "base/utils/fs.h"
#include "common.h" #include "common.h"
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
#include <libtorrent/session.hpp> #include <libtorrent/session.hpp>
std::unique_ptr<lt::disk_interface> customDiskIOConstructor( std::unique_ptr<lt::disk_interface> customDiskIOConstructor(

View file

@ -30,11 +30,10 @@
#include <libtorrent/aux_/vector.hpp> #include <libtorrent/aux_/vector.hpp>
#include <libtorrent/fwd.hpp> #include <libtorrent/fwd.hpp>
#include <libtorrent/version.hpp>
#include <QString> #include <QString>
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
#include <libtorrent/disk_interface.hpp> #include <libtorrent/disk_interface.hpp>
#include <libtorrent/file_storage.hpp> #include <libtorrent/file_storage.hpp>
#include <libtorrent/io_context.hpp> #include <libtorrent/io_context.hpp>
@ -46,7 +45,7 @@
#include <libtorrent/storage.hpp> #include <libtorrent/storage.hpp>
#endif #endif
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
std::unique_ptr<lt::disk_interface> customDiskIOConstructor( std::unique_ptr<lt::disk_interface> customDiskIOConstructor(
lt::io_context &ioContext, lt::settings_interface const &settings, lt::counters &counters); lt::io_context &ioContext, lt::settings_interface const &settings, lt::counters &counters);

View file

@ -43,7 +43,7 @@ bool BitTorrent::InfoHash::isValid() const
SHA1Hash BitTorrent::InfoHash::v1() const SHA1Hash BitTorrent::InfoHash::v1() const
{ {
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
return (m_nativeHash.has_v1() ? SHA1Hash(m_nativeHash.v1) : SHA1Hash()); return (m_nativeHash.has_v1() ? SHA1Hash(m_nativeHash.v1) : SHA1Hash());
#else #else
return {m_nativeHash}; return {m_nativeHash};
@ -52,7 +52,7 @@ SHA1Hash BitTorrent::InfoHash::v1() const
SHA256Hash BitTorrent::InfoHash::v2() const SHA256Hash BitTorrent::InfoHash::v2() const
{ {
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
return (m_nativeHash.has_v2() ? SHA256Hash(m_nativeHash.v2) : SHA256Hash()); return (m_nativeHash.has_v2() ? SHA256Hash(m_nativeHash.v2) : SHA256Hash());
#else #else
return {}; return {};
@ -61,7 +61,7 @@ SHA256Hash BitTorrent::InfoHash::v2() const
BitTorrent::TorrentID BitTorrent::InfoHash::toTorrentID() const BitTorrent::TorrentID BitTorrent::InfoHash::toTorrentID() const
{ {
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
return m_nativeHash.get_best(); return m_nativeHash.get_best();
#else #else
return {m_nativeHash}; return {m_nativeHash};

View file

@ -28,8 +28,7 @@
#pragma once #pragma once
#include <libtorrent/version.hpp> #ifdef QBT_USES_LIBTORRENT2
#if (LIBTORRENT_VERSION_NUM >= 20000)
#include <libtorrent/info_hash.hpp> #include <libtorrent/info_hash.hpp>
#endif #endif
@ -58,7 +57,7 @@ namespace BitTorrent
class InfoHash class InfoHash
{ {
public: public:
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
using WrappedType = lt::info_hash_t; using WrappedType = lt::info_hash_t;
#else #else
using WrappedType = lt::sha1_hash; using WrappedType = lt::sha1_hash;

View file

@ -90,7 +90,7 @@ MagnetUri::MagnetUri(const QString &source)
m_valid = true; m_valid = true;
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
m_infoHash = m_addTorrentParams.info_hashes; m_infoHash = m_addTorrentParams.info_hashes;
#else #else
m_infoHash = m_addTorrentParams.info_hash; m_infoHash = m_addTorrentParams.info_hash;

View file

@ -29,11 +29,10 @@
#pragma once #pragma once
#include <libtorrent/extensions.hpp> #include <libtorrent/extensions.hpp>
#include <libtorrent/version.hpp>
class NativeSessionExtension final : public lt::plugin class NativeSessionExtension final : public lt::plugin
{ {
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
using ClientData = lt::client_data_t; using ClientData = lt::client_data_t;
#else #else
using ClientData = void *; using ClientData = void *;

View file

@ -210,7 +210,7 @@ namespace
{ {
switch (socketType) switch (socketType)
{ {
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
case lt::socket_type_t::http: case lt::socket_type_t::http:
return QLatin1String("HTTP"); return QLatin1String("HTTP");
case lt::socket_type_t::http_ssl: case lt::socket_type_t::http_ssl:
@ -220,7 +220,7 @@ namespace
return QLatin1String("I2P"); return QLatin1String("I2P");
case lt::socket_type_t::socks5: case lt::socket_type_t::socks5:
return QLatin1String("SOCKS5"); return QLatin1String("SOCKS5");
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
case lt::socket_type_t::socks5_ssl: case lt::socket_type_t::socks5_ssl:
return QLatin1String("SOCKS5_SSL"); return QLatin1String("SOCKS5_SSL");
#endif #endif
@ -228,7 +228,7 @@ namespace
return QLatin1String("TCP"); return QLatin1String("TCP");
case lt::socket_type_t::tcp_ssl: case lt::socket_type_t::tcp_ssl:
return QLatin1String("TCP_SSL"); return QLatin1String("TCP_SSL");
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
case lt::socket_type_t::utp: case lt::socket_type_t::utp:
return QLatin1String("UTP"); return QLatin1String("UTP");
#else #else
@ -1077,14 +1077,14 @@ void Session::initializeNativeSession()
pack.set_bool(lt::settings_pack::enable_upnp, false); pack.set_bool(lt::settings_pack::enable_upnp, false);
pack.set_bool(lt::settings_pack::enable_natpmp, false); pack.set_bool(lt::settings_pack::enable_natpmp, false);
#if (LIBTORRENT_VERSION_NUM > 20000) #ifdef QBT_USES_LIBTORRENT2
// preserve the same behavior as in earlier libtorrent versions // preserve the same behavior as in earlier libtorrent versions
pack.set_bool(lt::settings_pack::enable_set_file_valid_data, true); pack.set_bool(lt::settings_pack::enable_set_file_valid_data, true);
#endif #endif
loadLTSettings(pack); loadLTSettings(pack);
lt::session_params sessionParams {pack, {}}; lt::session_params sessionParams {pack, {}};
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
sessionParams.disk_io_constructor = customDiskIOConstructor; sessionParams.disk_io_constructor = customDiskIOConstructor;
#endif #endif
m_nativeSession = new lt::session {sessionParams}; m_nativeSession = new lt::session {sessionParams};
@ -1176,7 +1176,7 @@ void Session::initMetrics()
m_metricIndices.disk.diskBlocksInUse = findMetricIndex("disk.disk_blocks_in_use"); m_metricIndices.disk.diskBlocksInUse = findMetricIndex("disk.disk_blocks_in_use");
m_metricIndices.disk.numBlocksRead = findMetricIndex("disk.num_blocks_read"); m_metricIndices.disk.numBlocksRead = findMetricIndex("disk.num_blocks_read");
#if (LIBTORRENT_VERSION_NUM < 20000) #ifndef QBT_USES_LIBTORRENT2
m_metricIndices.disk.numBlocksCacheHits = findMetricIndex("disk.num_blocks_cache_hits"); m_metricIndices.disk.numBlocksCacheHits = findMetricIndex("disk.num_blocks_cache_hits");
#endif #endif
m_metricIndices.disk.writeJobs = findMetricIndex("disk.num_write_ops"); m_metricIndices.disk.writeJobs = findMetricIndex("disk.num_write_ops");
@ -1263,7 +1263,7 @@ void Session::loadLTSettings(lt::settings_pack &settingsPack)
settingsPack.set_int(lt::settings_pack::peer_turnover_interval, peerTurnoverInterval()); settingsPack.set_int(lt::settings_pack::peer_turnover_interval, peerTurnoverInterval());
settingsPack.set_int(lt::settings_pack::aio_threads, asyncIOThreads()); settingsPack.set_int(lt::settings_pack::aio_threads, asyncIOThreads());
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
settingsPack.set_int(lt::settings_pack::hashing_threads, hashingThreads()); settingsPack.set_int(lt::settings_pack::hashing_threads, hashingThreads());
#endif #endif
settingsPack.set_int(lt::settings_pack::file_pool_size, filePoolSize()); settingsPack.set_int(lt::settings_pack::file_pool_size, filePoolSize());
@ -1271,7 +1271,7 @@ void Session::loadLTSettings(lt::settings_pack &settingsPack)
const int checkingMemUsageSize = checkingMemUsage() * 64; const int checkingMemUsageSize = checkingMemUsage() * 64;
settingsPack.set_int(lt::settings_pack::checking_mem_usage, checkingMemUsageSize); settingsPack.set_int(lt::settings_pack::checking_mem_usage, checkingMemUsageSize);
#if (LIBTORRENT_VERSION_NUM < 20000) #ifndef QBT_USES_LIBTORRENT2
const int cacheSize = (diskCacheSize() > -1) ? (diskCacheSize() * 64) : -1; const int cacheSize = (diskCacheSize() > -1) ? (diskCacheSize() * 64) : -1;
settingsPack.set_int(lt::settings_pack::cache_size, cacheSize); settingsPack.set_int(lt::settings_pack::cache_size, cacheSize);
settingsPack.set_int(lt::settings_pack::cache_expiry, diskCacheTTL()); settingsPack.set_int(lt::settings_pack::cache_expiry, diskCacheTTL());
@ -1282,7 +1282,7 @@ void Session::loadLTSettings(lt::settings_pack &settingsPack)
settingsPack.set_int(lt::settings_pack::disk_io_read_mode, mode); settingsPack.set_int(lt::settings_pack::disk_io_read_mode, mode);
settingsPack.set_int(lt::settings_pack::disk_io_write_mode, mode); settingsPack.set_int(lt::settings_pack::disk_io_write_mode, mode);
#if (LIBTORRENT_VERSION_NUM < 20000) #ifndef QBT_USES_LIBTORRENT2
settingsPack.set_bool(lt::settings_pack::coalesce_reads, isCoalesceReadWriteEnabled()); settingsPack.set_bool(lt::settings_pack::coalesce_reads, isCoalesceReadWriteEnabled());
settingsPack.set_bool(lt::settings_pack::coalesce_writes, isCoalesceReadWriteEnabled()); settingsPack.set_bool(lt::settings_pack::coalesce_writes, isCoalesceReadWriteEnabled());
#endif #endif
@ -2215,7 +2215,7 @@ bool Session::loadTorrent(LoadTorrentParams params)
{ {
lt::add_torrent_params &p = params.ltAddTorrentParams; lt::add_torrent_params &p = params.ltAddTorrentParams;
#if (LIBTORRENT_VERSION_NUM < 20000) #ifndef QBT_USES_LIBTORRENT2
p.storage = customStorageConstructor; p.storage = customStorageConstructor;
#endif #endif
// Limits // Limits
@ -2223,7 +2223,7 @@ bool Session::loadTorrent(LoadTorrentParams params)
p.max_uploads = maxUploadsPerTorrent(); p.max_uploads = maxUploadsPerTorrent();
const bool hasMetadata = (p.ti && p.ti->is_valid()); const bool hasMetadata = (p.ti && p.ti->is_valid());
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
const auto id = TorrentID::fromInfoHash(hasMetadata ? p.ti->info_hashes() : p.info_hashes); const auto id = TorrentID::fromInfoHash(hasMetadata ? p.ti->info_hashes() : p.info_hashes);
#else #else
const auto id = TorrentID::fromInfoHash(hasMetadata ? p.ti->info_hash() : p.info_hash); const auto id = TorrentID::fromInfoHash(hasMetadata ? p.ti->info_hash() : p.info_hash);
@ -2290,7 +2290,7 @@ bool Session::downloadMetadata(const MagnetUri &magnetUri)
// Solution to avoid accidental file writes // Solution to avoid accidental file writes
p.flags |= lt::torrent_flags::upload_mode; p.flags |= lt::torrent_flags::upload_mode;
#if (LIBTORRENT_VERSION_NUM < 20000) #ifndef QBT_USES_LIBTORRENT2
p.storage = customStorageConstructor; p.storage = customStorageConstructor;
#endif #endif
@ -3905,7 +3905,7 @@ void Session::handleTorrentMetadataReceived(TorrentImpl *const torrent)
// Copy the torrent file to the export folder // Copy the torrent file to the export folder
if (!torrentExportDirectory().isEmpty()) if (!torrentExportDirectory().isEmpty())
{ {
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
const TorrentInfo torrentInfo {torrent->nativeHandle().torrent_file_with_hashes()}; const TorrentInfo torrentInfo {torrent->nativeHandle().torrent_file_with_hashes()};
#else #else
const TorrentInfo torrentInfo {torrent->nativeHandle().torrent_file()}; const TorrentInfo torrentInfo {torrent->nativeHandle().torrent_file()};
@ -3963,7 +3963,7 @@ void Session::handleTorrentFinished(TorrentImpl *const torrent)
// Move .torrent file to another folder // Move .torrent file to another folder
if (!finishedTorrentExportDirectory().isEmpty()) if (!finishedTorrentExportDirectory().isEmpty())
{ {
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
const TorrentInfo torrentInfo {torrent->nativeHandle().torrent_file_with_hashes()}; const TorrentInfo torrentInfo {torrent->nativeHandle().torrent_file_with_hashes()};
#else #else
const TorrentInfo torrentInfo {torrent->nativeHandle().torrent_file()}; const TorrentInfo torrentInfo {torrent->nativeHandle().torrent_file()};
@ -4048,7 +4048,7 @@ bool Session::addMoveTorrentStorageJob(TorrentImpl *torrent, const QString &newP
void Session::moveTorrentStorage(const MoveStorageJob &job) const void Session::moveTorrentStorage(const MoveStorageJob &job) const
{ {
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
const auto id = TorrentID::fromInfoHash(job.torrentHandle.info_hashes()); const auto id = TorrentID::fromInfoHash(job.torrentHandle.info_hashes());
#else #else
const auto id = TorrentID::fromInfoHash(job.torrentHandle.info_hash()); const auto id = TorrentID::fromInfoHash(job.torrentHandle.info_hash());
@ -4347,7 +4347,7 @@ void Session::handleAlert(const lt::alert *a)
{ {
switch (a->type()) switch (a->type())
{ {
#if (LIBTORRENT_VERSION_NUM >= 20003) #ifdef QBT_USES_LIBTORRENT2
case lt::file_prio_alert::alert_type: case lt::file_prio_alert::alert_type:
#endif #endif
case lt::file_renamed_alert::alert_type: case lt::file_renamed_alert::alert_type:
@ -4449,7 +4449,7 @@ void Session::dispatchTorrentAlert(const lt::alert *a)
void Session::createTorrent(const lt::torrent_handle &nativeHandle) void Session::createTorrent(const lt::torrent_handle &nativeHandle)
{ {
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
const auto torrentID = TorrentID::fromInfoHash(nativeHandle.info_hashes()); const auto torrentID = TorrentID::fromInfoHash(nativeHandle.info_hashes());
#else #else
const auto torrentID = TorrentID::fromInfoHash(nativeHandle.info_hash()); const auto torrentID = TorrentID::fromInfoHash(nativeHandle.info_hash());
@ -4515,7 +4515,7 @@ void Session::handleAddTorrentAlert(const lt::add_torrent_alert *p)
const lt::add_torrent_params &params = p->params; const lt::add_torrent_params &params = p->params;
const bool hasMetadata = (params.ti && params.ti->is_valid()); const bool hasMetadata = (params.ti && params.ti->is_valid());
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
const auto id = TorrentID::fromInfoHash(hasMetadata ? params.ti->info_hashes() : params.info_hashes); const auto id = TorrentID::fromInfoHash(hasMetadata ? params.ti->info_hashes() : params.info_hashes);
#else #else
const auto id = TorrentID::fromInfoHash(hasMetadata ? params.ti->info_hash() : params.info_hash); const auto id = TorrentID::fromInfoHash(hasMetadata ? params.ti->info_hash() : params.info_hash);
@ -4530,7 +4530,7 @@ void Session::handleAddTorrentAlert(const lt::add_torrent_alert *p)
void Session::handleTorrentRemovedAlert(const lt::torrent_removed_alert *p) void Session::handleTorrentRemovedAlert(const lt::torrent_removed_alert *p)
{ {
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
const auto id = TorrentID::fromInfoHash(p->info_hashes); const auto id = TorrentID::fromInfoHash(p->info_hashes);
#else #else
const auto id = TorrentID::fromInfoHash(p->info_hash); const auto id = TorrentID::fromInfoHash(p->info_hash);
@ -4549,7 +4549,7 @@ void Session::handleTorrentRemovedAlert(const lt::torrent_removed_alert *p)
void Session::handleTorrentDeletedAlert(const lt::torrent_deleted_alert *p) void Session::handleTorrentDeletedAlert(const lt::torrent_deleted_alert *p)
{ {
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
const auto id = TorrentID::fromInfoHash(p->info_hashes); const auto id = TorrentID::fromInfoHash(p->info_hashes);
#else #else
const auto id = TorrentID::fromInfoHash(p->info_hash); const auto id = TorrentID::fromInfoHash(p->info_hash);
@ -4567,7 +4567,7 @@ void Session::handleTorrentDeletedAlert(const lt::torrent_deleted_alert *p)
void Session::handleTorrentDeleteFailedAlert(const lt::torrent_delete_failed_alert *p) void Session::handleTorrentDeleteFailedAlert(const lt::torrent_delete_failed_alert *p)
{ {
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
const auto id = TorrentID::fromInfoHash(p->info_hashes); const auto id = TorrentID::fromInfoHash(p->info_hashes);
#else #else
const auto id = TorrentID::fromInfoHash(p->info_hash); const auto id = TorrentID::fromInfoHash(p->info_hash);
@ -4597,7 +4597,7 @@ void Session::handleTorrentDeleteFailedAlert(const lt::torrent_delete_failed_ale
void Session::handleMetadataReceivedAlert(const lt::metadata_received_alert *p) void Session::handleMetadataReceivedAlert(const lt::metadata_received_alert *p)
{ {
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
const auto id = TorrentID::fromInfoHash(p->handle.info_hashes()); const auto id = TorrentID::fromInfoHash(p->handle.info_hashes());
#else #else
const auto id = TorrentID::fromInfoHash(p->handle.info_hash()); const auto id = TorrentID::fromInfoHash(p->handle.info_hash());
@ -4800,7 +4800,7 @@ void Session::handleSessionStatsAlert(const lt::session_stats_alert *p)
m_cacheStatus.totalUsedBuffers = stats[m_metricIndices.disk.diskBlocksInUse]; m_cacheStatus.totalUsedBuffers = stats[m_metricIndices.disk.diskBlocksInUse];
m_cacheStatus.jobQueueLength = stats[m_metricIndices.disk.queuedDiskJobs]; m_cacheStatus.jobQueueLength = stats[m_metricIndices.disk.queuedDiskJobs];
#if (LIBTORRENT_VERSION_NUM < 20000) #ifndef QBT_USES_LIBTORRENT2
const int64_t numBlocksRead = stats[m_metricIndices.disk.numBlocksRead]; const int64_t numBlocksRead = stats[m_metricIndices.disk.numBlocksRead];
const int64_t numBlocksCacheHits = stats[m_metricIndices.disk.numBlocksCacheHits]; const int64_t numBlocksCacheHits = stats[m_metricIndices.disk.numBlocksCacheHits];
m_cacheStatus.readRatio = static_cast<qreal>(numBlocksCacheHits) / std::max<int64_t>((numBlocksCacheHits + numBlocksRead), 1); m_cacheStatus.readRatio = static_cast<qreal>(numBlocksCacheHits) / std::max<int64_t>((numBlocksCacheHits + numBlocksRead), 1);
@ -4835,7 +4835,7 @@ void Session::handleStorageMovedAlert(const lt::storage_moved_alert *p)
const QString newPath {p->storage_path()}; const QString newPath {p->storage_path()};
Q_ASSERT(newPath == currentJob.path); Q_ASSERT(newPath == currentJob.path);
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
const auto id = TorrentID::fromInfoHash(currentJob.torrentHandle.info_hashes()); const auto id = TorrentID::fromInfoHash(currentJob.torrentHandle.info_hashes());
#else #else
const auto id = TorrentID::fromInfoHash(currentJob.torrentHandle.info_hash()); const auto id = TorrentID::fromInfoHash(currentJob.torrentHandle.info_hash());
@ -4855,7 +4855,7 @@ void Session::handleStorageMovedFailedAlert(const lt::storage_moved_failed_alert
const MoveStorageJob &currentJob = m_moveStorageQueue.first(); const MoveStorageJob &currentJob = m_moveStorageQueue.first();
Q_ASSERT(currentJob.torrentHandle == p->handle); Q_ASSERT(currentJob.torrentHandle == p->handle);
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
const auto id = TorrentID::fromInfoHash(currentJob.torrentHandle.info_hashes()); const auto id = TorrentID::fromInfoHash(currentJob.torrentHandle.info_hashes());
#else #else
const auto id = TorrentID::fromInfoHash(currentJob.torrentHandle.info_hash()); const auto id = TorrentID::fromInfoHash(currentJob.torrentHandle.info_hash());
@ -4878,7 +4878,7 @@ void Session::handleStateUpdateAlert(const lt::state_update_alert *p)
for (const lt::torrent_status &status : p->status) for (const lt::torrent_status &status : p->status)
{ {
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
const auto id = TorrentID::fromInfoHash(status.info_hashes); const auto id = TorrentID::fromInfoHash(status.info_hashes);
#else #else
const auto id = TorrentID::fromInfoHash(status.info_hash); const auto id = TorrentID::fromInfoHash(status.info_hash);

View file

@ -36,7 +36,6 @@
#include <libtorrent/add_torrent_params.hpp> #include <libtorrent/add_torrent_params.hpp>
#include <libtorrent/fwd.hpp> #include <libtorrent/fwd.hpp>
#include <libtorrent/torrent_handle.hpp> #include <libtorrent/torrent_handle.hpp>
#include <libtorrent/version.hpp>
#include <QHash> #include <QHash>
#include <QPointer> #include <QPointer>
@ -191,7 +190,7 @@ namespace BitTorrent
{ {
int diskBlocksInUse = -1; int diskBlocksInUse = -1;
int numBlocksRead = -1; int numBlocksRead = -1;
#if (LIBTORRENT_VERSION_NUM < 20000) #ifndef QBT_USES_LIBTORRENT2
int numBlocksCacheHits = -1; int numBlocksCacheHits = -1;
#endif #endif
int writeJobs = -1; int writeJobs = -1;

View file

@ -57,7 +57,7 @@ namespace
return !Utils::Fs::fileName(QString::fromStdString(f)).startsWith('.'); return !Utils::Fs::fileName(QString::fromStdString(f)).startsWith('.');
} }
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
lt::create_flags_t toNativeTorrentFormatFlag(const BitTorrent::TorrentFormat torrentFormat) lt::create_flags_t toNativeTorrentFormatFlag(const BitTorrent::TorrentFormat torrentFormat)
{ {
switch (torrentFormat) switch (torrentFormat)
@ -159,7 +159,7 @@ void TorrentCreatorThread::run()
checkInterruptionRequested(); checkInterruptionRequested();
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
lt::create_torrent newTorrent {fs, m_params.pieceSize, toNativeTorrentFormatFlag(m_params.torrentFormat)}; lt::create_torrent newTorrent {fs, m_params.pieceSize, toNativeTorrentFormatFlag(m_params.torrentFormat)};
#else #else
lt::create_torrent newTorrent(fs, m_params.pieceSize, m_params.paddedFileSizeLimit lt::create_torrent newTorrent(fs, m_params.pieceSize, m_params.paddedFileSizeLimit
@ -233,7 +233,7 @@ void TorrentCreatorThread::run()
} }
} }
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
int TorrentCreatorThread::calculateTotalPieces(const QString &inputPath, const int pieceSize, const TorrentFormat torrentFormat) int TorrentCreatorThread::calculateTotalPieces(const QString &inputPath, const int pieceSize, const TorrentFormat torrentFormat)
#else #else
int TorrentCreatorThread::calculateTotalPieces(const QString &inputPath, const int pieceSize, const bool isAlignmentOptimized, const int paddedFileSizeLimit) int TorrentCreatorThread::calculateTotalPieces(const QString &inputPath, const int pieceSize, const bool isAlignmentOptimized, const int paddedFileSizeLimit)
@ -245,7 +245,7 @@ int TorrentCreatorThread::calculateTotalPieces(const QString &inputPath, const i
lt::file_storage fs; lt::file_storage fs;
lt::add_files(fs, Utils::Fs::toNativePath(inputPath).toStdString(), fileFilter); lt::add_files(fs, Utils::Fs::toNativePath(inputPath).toStdString(), fileFilter);
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
return lt::create_torrent {fs, pieceSize, toNativeTorrentFormatFlag(torrentFormat)}.num_pieces(); return lt::create_torrent {fs, pieceSize, toNativeTorrentFormatFlag(torrentFormat)}.num_pieces();
#else #else
return lt::create_torrent(fs, pieceSize, paddedFileSizeLimit return lt::create_torrent(fs, pieceSize, paddedFileSizeLimit

View file

@ -28,14 +28,12 @@
#pragma once #pragma once
#include <libtorrent/version.hpp>
#include <QStringList> #include <QStringList>
#include <QThread> #include <QThread>
namespace BitTorrent namespace BitTorrent
{ {
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
enum class TorrentFormat enum class TorrentFormat
{ {
V1, V1,
@ -47,7 +45,7 @@ namespace BitTorrent
struct TorrentCreatorParams struct TorrentCreatorParams
{ {
bool isPrivate; bool isPrivate;
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
TorrentFormat torrentFormat; TorrentFormat torrentFormat;
#else #else
bool isAlignmentOptimized; bool isAlignmentOptimized;
@ -73,7 +71,7 @@ namespace BitTorrent
void create(const TorrentCreatorParams &params); void create(const TorrentCreatorParams &params);
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
static int calculateTotalPieces(const QString &inputPath, const int pieceSize, const TorrentFormat torrentFormat); static int calculateTotalPieces(const QString &inputPath, const int pieceSize, const TorrentFormat torrentFormat);
#else #else
static int calculateTotalPieces(const QString &inputPath static int calculateTotalPieces(const QString &inputPath

View file

@ -43,9 +43,8 @@
#include <libtorrent/session.hpp> #include <libtorrent/session.hpp>
#include <libtorrent/storage_defs.hpp> #include <libtorrent/storage_defs.hpp>
#include <libtorrent/time.hpp> #include <libtorrent/time.hpp>
#include <libtorrent/version.hpp>
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
#include <libtorrent/info_hash.hpp> #include <libtorrent/info_hash.hpp>
#endif #endif
@ -96,7 +95,7 @@ namespace
return entry; return entry;
} }
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
TrackerEntry fromNativeAnnouncerEntry(const lt::announce_entry &nativeEntry TrackerEntry fromNativeAnnouncerEntry(const lt::announce_entry &nativeEntry
, const lt::info_hash_t &hashes, const QMap<lt::tcp::endpoint, int> &trackerPeerCounts) , const lt::info_hash_t &hashes, const QMap<lt::tcp::endpoint, int> &trackerPeerCounts)
#else #else
@ -111,7 +110,7 @@ namespace
int numNotWorking = 0; int numNotWorking = 0;
QString firstTrackerMessage; QString firstTrackerMessage;
QString firstErrorMessage; QString firstErrorMessage;
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
const auto numEndpoints = static_cast<qsizetype>(nativeEntry.endpoints.size() * ((hashes.has_v1() && hashes.has_v2()) ? 2 : 1)); const auto numEndpoints = static_cast<qsizetype>(nativeEntry.endpoints.size() * ((hashes.has_v1() && hashes.has_v2()) ? 2 : 1));
trackerEntry.endpoints.reserve(static_cast<decltype(trackerEntry.endpoints)::size_type>(numEndpoints)); trackerEntry.endpoints.reserve(static_cast<decltype(trackerEntry.endpoints)::size_type>(numEndpoints));
for (const lt::announce_endpoint &endpoint : nativeEntry.endpoints) for (const lt::announce_endpoint &endpoint : nativeEntry.endpoints)
@ -265,7 +264,7 @@ TorrentImpl::TorrentImpl(Session *session, lt::session *nativeSession
, m_session(session) , m_session(session)
, m_nativeSession(nativeSession) , m_nativeSession(nativeSession)
, m_nativeHandle(nativeHandle) , m_nativeHandle(nativeHandle)
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
, m_infoHash(m_nativeHandle.info_hashes()) , m_infoHash(m_nativeHandle.info_hashes())
#else #else
, m_infoHash(m_nativeHandle.info_hash()) , m_infoHash(m_nativeHandle.info_hash())
@ -478,7 +477,7 @@ QVector<TrackerEntry> TorrentImpl::trackers() const
for (const lt::announce_entry &tracker : nativeTrackers) for (const lt::announce_entry &tracker : nativeTrackers)
{ {
const QString trackerURL = QString::fromStdString(tracker.url); const QString trackerURL = QString::fromStdString(tracker.url);
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
entries << fromNativeAnnouncerEntry(tracker, m_nativeHandle.info_hashes(), m_trackerPeerCounts[trackerURL]); entries << fromNativeAnnouncerEntry(tracker, m_nativeHandle.info_hashes(), m_trackerPeerCounts[trackerURL]);
#else #else
entries << fromNativeAnnouncerEntry(tracker, m_trackerPeerCounts[trackerURL]); entries << fromNativeAnnouncerEntry(tracker, m_trackerPeerCounts[trackerURL]);
@ -1942,7 +1941,7 @@ void TorrentImpl::handleFileErrorAlert(const lt::file_error_alert *p)
m_lastFileError = {p->error, p->op}; m_lastFileError = {p->error, p->op};
} }
#if (LIBTORRENT_VERSION_NUM >= 20003) #ifdef QBT_USES_LIBTORRENT2
void TorrentImpl::handleFilePrioAlert(const lt::file_prio_alert *) void TorrentImpl::handleFilePrioAlert(const lt::file_prio_alert *)
{ {
if (m_nativeHandle.need_save_resume_data()) if (m_nativeHandle.need_save_resume_data())
@ -1987,7 +1986,7 @@ void TorrentImpl::handleAlert(const lt::alert *a)
{ {
switch (a->type()) switch (a->type())
{ {
#if (LIBTORRENT_VERSION_NUM >= 20003) #ifdef QBT_USES_LIBTORRENT2
case lt::file_prio_alert::alert_type: case lt::file_prio_alert::alert_type:
handleFilePrioAlert(static_cast<const lt::file_prio_alert*>(a)); handleFilePrioAlert(static_cast<const lt::file_prio_alert*>(a));
break; break;

View file

@ -252,7 +252,7 @@ namespace BitTorrent
void handleFastResumeRejectedAlert(const lt::fastresume_rejected_alert *p); void handleFastResumeRejectedAlert(const lt::fastresume_rejected_alert *p);
void handleFileCompletedAlert(const lt::file_completed_alert *p); void handleFileCompletedAlert(const lt::file_completed_alert *p);
void handleFileErrorAlert(const lt::file_error_alert *p); void handleFileErrorAlert(const lt::file_error_alert *p);
#if (LIBTORRENT_VERSION_NUM >= 20003) #ifdef QBT_USES_LIBTORRENT2
void handleFilePrioAlert(const lt::file_prio_alert *p); void handleFilePrioAlert(const lt::file_prio_alert *p);
#endif #endif
void handleFileRenamedAlert(const lt::file_renamed_alert *p); void handleFileRenamedAlert(const lt::file_renamed_alert *p);

View file

@ -31,7 +31,6 @@
#include <libtorrent/bencode.hpp> #include <libtorrent/bencode.hpp>
#include <libtorrent/create_torrent.hpp> #include <libtorrent/create_torrent.hpp>
#include <libtorrent/error_code.hpp> #include <libtorrent/error_code.hpp>
#include <libtorrent/version.hpp>
#include <QByteArray> #include <QByteArray>
#include <QDateTime> #include <QDateTime>
@ -197,7 +196,7 @@ InfoHash TorrentInfo::infoHash() const
{ {
if (!isValid()) return {}; if (!isValid()) return {};
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
return m_nativeInfo->info_hashes(); return m_nativeInfo->info_hashes();
#else #else
return m_nativeInfo->info_hash(); return m_nativeInfo->info_hash();
@ -342,7 +341,7 @@ QVector<QUrl> TorrentInfo::urlSeeds() const
QByteArray TorrentInfo::metadata() const QByteArray TorrentInfo::metadata() const
{ {
if (!isValid()) return {}; if (!isValid()) return {};
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
const lt::span<const char> infoSection {m_nativeInfo->info_section()}; const lt::span<const char> infoSection {m_nativeInfo->info_section()};
return {infoSection.data(), static_cast<int>(infoSection.size())}; return {infoSection.data(), static_cast<int>(infoSection.size())};
#else #else

View file

@ -96,18 +96,18 @@ namespace
// libtorrent section // libtorrent section
LIBTORRENT_HEADER, LIBTORRENT_HEADER,
ASYNC_IO_THREADS, ASYNC_IO_THREADS,
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
HASHING_THREADS, HASHING_THREADS,
#endif #endif
FILE_POOL_SIZE, FILE_POOL_SIZE,
CHECKING_MEM_USAGE, CHECKING_MEM_USAGE,
#if (LIBTORRENT_VERSION_NUM < 20000) #ifndef QBT_USES_LIBTORRENT2
// cache // cache
DISK_CACHE, DISK_CACHE,
DISK_CACHE_TTL, DISK_CACHE_TTL,
#endif #endif
OS_CACHE, OS_CACHE,
#if (LIBTORRENT_VERSION_NUM < 20000) #ifndef QBT_USES_LIBTORRENT2
COALESCE_RW, COALESCE_RW,
#endif #endif
PIECE_EXTENT_AFFINITY, PIECE_EXTENT_AFFINITY,
@ -199,7 +199,7 @@ void AdvancedSettings::saveAdvancedSettings()
#endif #endif
// Async IO threads // Async IO threads
session->setAsyncIOThreads(m_spinBoxAsyncIOThreads.value()); session->setAsyncIOThreads(m_spinBoxAsyncIOThreads.value());
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
// Hashing threads // Hashing threads
session->setHashingThreads(m_spinBoxHashingThreads.value()); session->setHashingThreads(m_spinBoxHashingThreads.value());
#endif #endif
@ -207,14 +207,14 @@ void AdvancedSettings::saveAdvancedSettings()
session->setFilePoolSize(m_spinBoxFilePoolSize.value()); session->setFilePoolSize(m_spinBoxFilePoolSize.value());
// Checking Memory Usage // Checking Memory Usage
session->setCheckingMemUsage(m_spinBoxCheckingMemUsage.value()); session->setCheckingMemUsage(m_spinBoxCheckingMemUsage.value());
#if (LIBTORRENT_VERSION_NUM < 20000) #ifndef QBT_USES_LIBTORRENT2
// Disk write cache // Disk write cache
session->setDiskCacheSize(m_spinBoxCache.value()); session->setDiskCacheSize(m_spinBoxCache.value());
session->setDiskCacheTTL(m_spinBoxCacheTTL.value()); session->setDiskCacheTTL(m_spinBoxCacheTTL.value());
#endif #endif
// Enable OS cache // Enable OS cache
session->setUseOSCache(m_checkBoxOsCache.isChecked()); session->setUseOSCache(m_checkBoxOsCache.isChecked());
#if (LIBTORRENT_VERSION_NUM < 20000) #ifndef QBT_USES_LIBTORRENT2
// Coalesce reads & writes // Coalesce reads & writes
session->setCoalesceReadWriteEnabled(m_checkBoxCoalesceRW.isChecked()); session->setCoalesceReadWriteEnabled(m_checkBoxCoalesceRW.isChecked());
#endif #endif
@ -321,7 +321,7 @@ void AdvancedSettings::saveAdvancedSettings()
session->setPeerTurnoverInterval(m_spinBoxPeerTurnoverInterval.value()); session->setPeerTurnoverInterval(m_spinBoxPeerTurnoverInterval.value());
} }
#if (LIBTORRENT_VERSION_NUM < 20000) #ifndef QBT_USES_LIBTORRENT2
void AdvancedSettings::updateCacheSpinSuffix(int value) void AdvancedSettings::updateCacheSpinSuffix(int value)
{ {
if (value == 0) if (value == 0)
@ -445,7 +445,7 @@ void AdvancedSettings::loadAdvancedSettings()
addRow(ASYNC_IO_THREADS, (tr("Asynchronous I/O threads") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#aio_threads", "(?)")) addRow(ASYNC_IO_THREADS, (tr("Asynchronous I/O threads") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#aio_threads", "(?)"))
, &m_spinBoxAsyncIOThreads); , &m_spinBoxAsyncIOThreads);
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
// Hashing threads // Hashing threads
m_spinBoxHashingThreads.setMinimum(1); m_spinBoxHashingThreads.setMinimum(1);
m_spinBoxHashingThreads.setMaximum(1024); m_spinBoxHashingThreads.setMaximum(1024);
@ -474,7 +474,7 @@ void AdvancedSettings::loadAdvancedSettings()
m_spinBoxCheckingMemUsage.setSuffix(tr(" MiB")); m_spinBoxCheckingMemUsage.setSuffix(tr(" MiB"));
addRow(CHECKING_MEM_USAGE, (tr("Outstanding memory when checking torrents") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#checking_mem_usage", "(?)")) addRow(CHECKING_MEM_USAGE, (tr("Outstanding memory when checking torrents") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#checking_mem_usage", "(?)"))
, &m_spinBoxCheckingMemUsage); , &m_spinBoxCheckingMemUsage);
#if (LIBTORRENT_VERSION_NUM < 20000) #ifndef QBT_USES_LIBTORRENT2
// Disk write cache // Disk write cache
m_spinBoxCache.setMinimum(-1); m_spinBoxCache.setMinimum(-1);
// When build as 32bit binary, set the maximum at less than 2GB to prevent crashes. // When build as 32bit binary, set the maximum at less than 2GB to prevent crashes.
@ -502,7 +502,7 @@ void AdvancedSettings::loadAdvancedSettings()
m_checkBoxOsCache.setChecked(session->useOSCache()); m_checkBoxOsCache.setChecked(session->useOSCache());
addRow(OS_CACHE, (tr("Enable OS cache") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#disk_io_write_mode", "(?)")) addRow(OS_CACHE, (tr("Enable OS cache") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#disk_io_write_mode", "(?)"))
, &m_checkBoxOsCache); , &m_checkBoxOsCache);
#if (LIBTORRENT_VERSION_NUM < 20000) #ifndef QBT_USES_LIBTORRENT2
// Coalesce reads & writes // Coalesce reads & writes
m_checkBoxCoalesceRW.setChecked(session->isCoalesceReadWriteEnabled()); m_checkBoxCoalesceRW.setChecked(session->isCoalesceReadWriteEnabled());
addRow(COALESCE_RW, (tr("Coalesce reads & writes") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#coalesce_reads", "(?)")) addRow(COALESCE_RW, (tr("Coalesce reads & writes") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#coalesce_reads", "(?)"))

View file

@ -28,8 +28,6 @@
#pragma once #pragma once
#include <libtorrent/version.hpp>
#include <QCheckBox> #include <QCheckBox>
#include <QComboBox> #include <QComboBox>
#include <QLineEdit> #include <QLineEdit>
@ -50,7 +48,7 @@ signals:
void settingsChanged(); void settingsChanged();
private slots: private slots:
#if (LIBTORRENT_VERSION_NUM < 20000) #ifndef QBT_USES_LIBTORRENT2
void updateCacheSpinSuffix(int value); void updateCacheSpinSuffix(int value);
#endif #endif
void updateSaveResumeDataIntervalSuffix(int value); void updateSaveResumeDataIntervalSuffix(int value);
@ -74,7 +72,7 @@ private:
m_comboBoxSeedChokingAlgorithm, m_comboBoxResumeDataStorage; m_comboBoxSeedChokingAlgorithm, m_comboBoxResumeDataStorage;
QLineEdit m_lineEditAnnounceIP; QLineEdit m_lineEditAnnounceIP;
#if (LIBTORRENT_VERSION_NUM < 20000) #ifndef QBT_USES_LIBTORRENT2
QSpinBox m_spinBoxCache, m_spinBoxCacheTTL; QSpinBox m_spinBoxCache, m_spinBoxCacheTTL;
QCheckBox m_checkBoxCoalesceRW; QCheckBox m_checkBoxCoalesceRW;
#else #else

View file

@ -50,7 +50,7 @@ namespace
|| str.startsWith("ftp://", Qt::CaseInsensitive) || str.startsWith("ftp://", Qt::CaseInsensitive)
|| str.startsWith("magnet:", Qt::CaseInsensitive) || str.startsWith("magnet:", Qt::CaseInsensitive)
|| ((str.size() == 40) && !str.contains(QRegularExpression("[^0-9A-Fa-f]"))) // v1 hex-encoded SHA-1 info-hash || ((str.size() == 40) && !str.contains(QRegularExpression("[^0-9A-Fa-f]"))) // v1 hex-encoded SHA-1 info-hash
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
|| ((str.size() == 64) && !str.contains(QRegularExpression("[^0-9A-Fa-f]"))) // v2 hex-encoded SHA-256 info-hash || ((str.size() == 64) && !str.contains(QRegularExpression("[^0-9A-Fa-f]"))) // v2 hex-encoded SHA-256 info-hash
#endif #endif
|| ((str.size() == 32) && !str.contains(QRegularExpression("[^2-7A-Za-z]")))); // v1 Base32 encoded SHA-1 info-hash || ((str.size() == 32) && !str.contains(QRegularExpression("[^2-7A-Za-z]")))); // v1 Base32 encoded SHA-1 info-hash

View file

@ -55,7 +55,7 @@ StatsDialog::StatsDialog(QWidget *parent)
connect(BitTorrent::Session::instance(), &BitTorrent::Session::statsUpdated connect(BitTorrent::Session::instance(), &BitTorrent::Session::statsUpdated
, this, &StatsDialog::update); , this, &StatsDialog::update);
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
m_ui->labelCacheHitsText->hide(); m_ui->labelCacheHitsText->hide();
m_ui->labelCacheHits->hide(); m_ui->labelCacheHits->hide();
#endif #endif
@ -87,7 +87,7 @@ void StatsDialog::update()
((atd > 0) && (atu > 0)) ((atd > 0) && (atu > 0))
? Utils::String::fromDouble(static_cast<qreal>(atu) / atd, 2) ? Utils::String::fromDouble(static_cast<qreal>(atu) / atd, 2)
: "-"); : "-");
#if (LIBTORRENT_VERSION_NUM < 20000) #ifndef QBT_USES_LIBTORRENT2
// Cache hits // Cache hits
const qreal readRatio = cs.readRatio; const qreal readRatio = cs.readRatio;
m_ui->labelCacheHits->setText(QString::fromLatin1("%1%").arg((readRatio > 0) m_ui->labelCacheHits->setText(QString::fromLatin1("%1%").arg((readRatio > 0)

View file

@ -53,7 +53,7 @@ TorrentCreatorDialog::TorrentCreatorDialog(QWidget *parent, const QString &defau
, m_storePrivateTorrent(SETTINGS_KEY("PrivateTorrent")) , m_storePrivateTorrent(SETTINGS_KEY("PrivateTorrent"))
, m_storeStartSeeding(SETTINGS_KEY("StartSeeding")) , m_storeStartSeeding(SETTINGS_KEY("StartSeeding"))
, m_storeIgnoreRatio(SETTINGS_KEY("IgnoreRatio")) , m_storeIgnoreRatio(SETTINGS_KEY("IgnoreRatio"))
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
, m_storeTorrentFormat(SETTINGS_KEY("TorrentFormat")) , m_storeTorrentFormat(SETTINGS_KEY("TorrentFormat"))
#else #else
, m_storeOptimizeAlignment(SETTINGS_KEY("OptimizeAlignment")) , m_storeOptimizeAlignment(SETTINGS_KEY("OptimizeAlignment"))
@ -84,7 +84,7 @@ TorrentCreatorDialog::TorrentCreatorDialog(QWidget *parent, const QString &defau
loadSettings(); loadSettings();
updateInputPath(defaultPath); updateInputPath(defaultPath);
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
m_ui->checkOptimizeAlignment->hide(); m_ui->checkOptimizeAlignment->hide();
#else #else
m_ui->widgetTorrentFormat->hide(); m_ui->widgetTorrentFormat->hide();
@ -127,7 +127,7 @@ int TorrentCreatorDialog::getPieceSize() const
return pieceSizes[m_ui->comboPieceSize->currentIndex()] * 1024; return pieceSizes[m_ui->comboPieceSize->currentIndex()] * 1024;
} }
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
BitTorrent::TorrentFormat TorrentCreatorDialog::getTorrentFormat() const BitTorrent::TorrentFormat TorrentCreatorDialog::getTorrentFormat() const
{ {
switch (m_ui->comboTorrentFormat->currentIndex()) switch (m_ui->comboTorrentFormat->currentIndex())
@ -201,7 +201,7 @@ void TorrentCreatorDialog::onCreateButtonClicked()
const BitTorrent::TorrentCreatorParams params const BitTorrent::TorrentCreatorParams params
{ {
m_ui->checkPrivate->isChecked() m_ui->checkPrivate->isChecked()
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
, getTorrentFormat() , getTorrentFormat()
#else #else
, m_ui->checkOptimizeAlignment->isChecked() , m_ui->checkOptimizeAlignment->isChecked()
@ -266,7 +266,7 @@ void TorrentCreatorDialog::updateProgressBar(int progress)
void TorrentCreatorDialog::updatePiecesCount() void TorrentCreatorDialog::updatePiecesCount()
{ {
const QString path = m_ui->textInputPath->text().trimmed(); const QString path = m_ui->textInputPath->text().trimmed();
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
const int count = BitTorrent::TorrentCreatorThread::calculateTotalPieces( const int count = BitTorrent::TorrentCreatorThread::calculateTotalPieces(
path, getPieceSize(), getTorrentFormat()); path, getPieceSize(), getTorrentFormat());
#else #else
@ -291,7 +291,7 @@ void TorrentCreatorDialog::setInteractionEnabled(const bool enabled) const
m_ui->checkStartSeeding->setEnabled(enabled); m_ui->checkStartSeeding->setEnabled(enabled);
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(enabled); m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(enabled);
m_ui->checkIgnoreShareLimits->setEnabled(enabled && m_ui->checkStartSeeding->isChecked()); m_ui->checkIgnoreShareLimits->setEnabled(enabled && m_ui->checkStartSeeding->isChecked());
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
m_ui->widgetTorrentFormat->setEnabled(enabled); m_ui->widgetTorrentFormat->setEnabled(enabled);
#else #else
m_ui->checkOptimizeAlignment->setEnabled(enabled); m_ui->checkOptimizeAlignment->setEnabled(enabled);
@ -307,7 +307,7 @@ void TorrentCreatorDialog::saveSettings()
m_storePrivateTorrent = m_ui->checkPrivate->isChecked(); m_storePrivateTorrent = m_ui->checkPrivate->isChecked();
m_storeStartSeeding = m_ui->checkStartSeeding->isChecked(); m_storeStartSeeding = m_ui->checkStartSeeding->isChecked();
m_storeIgnoreRatio = m_ui->checkIgnoreShareLimits->isChecked(); m_storeIgnoreRatio = m_ui->checkIgnoreShareLimits->isChecked();
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
m_storeTorrentFormat = m_ui->comboTorrentFormat->currentIndex(); m_storeTorrentFormat = m_ui->comboTorrentFormat->currentIndex();
#else #else
m_storeOptimizeAlignment = m_ui->checkOptimizeAlignment->isChecked(); m_storeOptimizeAlignment = m_ui->checkOptimizeAlignment->isChecked();
@ -331,7 +331,7 @@ void TorrentCreatorDialog::loadSettings()
m_ui->checkStartSeeding->setChecked(m_storeStartSeeding); m_ui->checkStartSeeding->setChecked(m_storeStartSeeding);
m_ui->checkIgnoreShareLimits->setChecked(m_storeIgnoreRatio); m_ui->checkIgnoreShareLimits->setChecked(m_storeIgnoreRatio);
m_ui->checkIgnoreShareLimits->setEnabled(m_ui->checkStartSeeding->isChecked()); m_ui->checkIgnoreShareLimits->setEnabled(m_ui->checkStartSeeding->isChecked());
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
m_ui->comboTorrentFormat->setCurrentIndex(m_storeTorrentFormat.get(1)); m_ui->comboTorrentFormat->setCurrentIndex(m_storeTorrentFormat.get(1));
#else #else
m_ui->checkOptimizeAlignment->setChecked(m_storeOptimizeAlignment.get(true)); m_ui->checkOptimizeAlignment->setChecked(m_storeOptimizeAlignment.get(true));

View file

@ -29,8 +29,6 @@
#pragma once #pragma once
#include <libtorrent/version.hpp>
#include <QDialog> #include <QDialog>
#include "base/bittorrent/torrentcreatorthread.h" #include "base/bittorrent/torrentcreatorthread.h"
@ -68,7 +66,7 @@ private:
void setInteractionEnabled(bool enabled) const; void setInteractionEnabled(bool enabled) const;
int getPieceSize() const; int getPieceSize() const;
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
BitTorrent::TorrentFormat getTorrentFormat() const; BitTorrent::TorrentFormat getTorrentFormat() const;
#else #else
int getPaddedFileSizeLimit() const; int getPaddedFileSizeLimit() const;
@ -83,7 +81,7 @@ private:
SettingValue<bool> m_storePrivateTorrent; SettingValue<bool> m_storePrivateTorrent;
SettingValue<bool> m_storeStartSeeding; SettingValue<bool> m_storeStartSeeding;
SettingValue<bool> m_storeIgnoreRatio; SettingValue<bool> m_storeIgnoreRatio;
#if (LIBTORRENT_VERSION_NUM >= 20000) #ifdef QBT_USES_LIBTORRENT2
SettingValue<int> m_storeTorrentFormat; SettingValue<int> m_storeTorrentFormat;
#else #else
SettingValue<bool> m_storeOptimizeAlignment; SettingValue<bool> m_storeOptimizeAlignment;