Don't use deprecated libtorrent features

This commit is contained in:
Vladimir Golovnev (Glassez)
2019-07-18 19:53:04 +03:00
parent 7f3291c3de
commit 60ffa3030e
16 changed files with 130 additions and 186 deletions

View File

@@ -10,6 +10,7 @@ bittorrent/magneturi.h
bittorrent/peerinfo.h
bittorrent/private/bandwidthscheduler.h
bittorrent/private/filterparserthread.h
bittorrent/private/ltunderlyingtype.h
bittorrent/private/portforwarderimpl.h
bittorrent/private/resumedatasavingmanager.h
bittorrent/private/speedmonitor.h

View File

@@ -9,6 +9,7 @@ HEADERS += \
$$PWD/bittorrent/peerinfo.h \
$$PWD/bittorrent/private/bandwidthscheduler.h \
$$PWD/bittorrent/private/filterparserthread.h \
$$PWD/bittorrent/private/ltunderlyingtype.h \
$$PWD/bittorrent/private/portforwarderimpl.h \
$$PWD/bittorrent/private/resumedatasavingmanager.h \
$$PWD/bittorrent/private/speedmonitor.h \

View File

@@ -0,0 +1,61 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2019 Vladimir Golovnev <glassez@yandex.ru>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*/
#pragma once
#include <type_traits>
template <typename ...>
using void_t = void; // replace this with std::void_t in C++17
template <typename T, typename = void>
struct HasUnderlyingType
: std::false_type
{
};
template <typename T>
struct HasUnderlyingType<T, void_t<typename T::underlying_type>>
: std::true_type
{
};
template <typename T, typename = void>
struct LTUnderlying
{
using type = T;
};
template <typename T>
struct LTUnderlying<T, typename std::enable_if_t<HasUnderlyingType<T>::value>>
{
using type = typename T::underlying_type;
};
template <typename T>
using LTUnderlyingType = typename LTUnderlying<T>::type;

View File

@@ -86,6 +86,7 @@
#include "magneturi.h"
#include "private/bandwidthscheduler.h"
#include "private/filterparserthread.h"
#include "private/ltunderlyingtype.h"
#include "private/portforwarderimpl.h"
#include "private/resumedatasavingmanager.h"
#include "private/statistics.h"
@@ -106,10 +107,16 @@ using namespace BitTorrent;
namespace
{
#if (LIBTORRENT_VERSION_NUM < 10200)
using LTAlertCategory = int;
using LTPeerClass = int;
using LTQueuePosition = int;
using LTSessionFlags = int;
using LTStatusFlags = int;
using LTString = std::string;
#else
using LTAlertCategory = lt::alert_category_t;
using LTPeerClass = lt::peer_class_t;
using LTQueuePosition = lt::queue_position_t;
using LTSessionFlags = lt::session_flags_t;
using LTStatusFlags = lt::status_flags_t;
using LTString = lt::string_view;
@@ -277,7 +284,6 @@ Session::Session(QObject *parent)
, m_diskCacheSize(BITTORRENT_SESSION_KEY("DiskCacheSize"), 64)
, m_diskCacheTTL(BITTORRENT_SESSION_KEY("DiskCacheTTL"), 60)
, m_useOSCache(BITTORRENT_SESSION_KEY("UseOSCache"), true)
, m_guidedReadCacheEnabled(BITTORRENT_SESSION_KEY("GuidedReadCache"), true)
#ifdef Q_OS_WIN
, m_coalesceReadWriteEnabled(BITTORRENT_SESSION_KEY("CoalesceReadWrite"), true)
#else
@@ -338,7 +344,6 @@ Session::Session(QObject *parent)
, m_networkInterfaceAddress(BITTORRENT_SESSION_KEY("InterfaceAddress"))
, m_isIPv6Enabled(BITTORRENT_SESSION_KEY("IPv6Enabled"), false)
, m_encryption(BITTORRENT_SESSION_KEY("Encryption"), 0)
, m_isForceProxyEnabled(BITTORRENT_SESSION_KEY("ForceProxy"), true)
, m_isProxyPeerConnectionsEnabled(BITTORRENT_SESSION_KEY("ProxyPeerConnections"), false)
, m_chokingAlgorithm(BITTORRENT_SESSION_KEY("ChokingAlgorithm"), ChokingAlgorithm::FixedSlots
, clampValue(ChokingAlgorithm::FixedSlots, ChokingAlgorithm::RateBased))
@@ -381,7 +386,7 @@ Session::Session(QObject *parent)
connect(m_seedingLimitTimer, &QTimer::timeout, this, &Session::processShareLimits);
// Set severity level of libtorrent session
const int alertMask = lt::alert::error_notification
const LTAlertCategory alertMask = lt::alert::error_notification
| lt::alert::peer_notification
| lt::alert::port_mapping_notification
| lt::alert::storage_notification
@@ -1252,8 +1257,6 @@ void Session::configure(lt::settings_pack &settingsPack)
settingsPack.set_bool(lt::settings_pack::proxy_peer_connections, isProxyPeerConnectionsEnabled());
}
settingsPack.set_bool(lt::settings_pack::force_proxy
, ((proxyConfig.type == Net::ProxyType::None) ? false : isForceProxyEnabled()));
settingsPack.set_bool(lt::settings_pack::announce_to_all_trackers, announceToAllTrackers());
settingsPack.set_bool(lt::settings_pack::announce_to_all_tiers, announceToAllTiers());
@@ -1274,7 +1277,6 @@ void Session::configure(lt::settings_pack &settingsPack)
: lt::settings_pack::disable_os_cache;
settingsPack.set_int(lt::settings_pack::disk_io_read_mode, mode);
settingsPack.set_int(lt::settings_pack::disk_io_write_mode, mode);
settingsPack.set_bool(lt::settings_pack::guided_read_cache, isGuidedReadCacheEnabled());
settingsPack.set_bool(lt::settings_pack::coalesce_reads, isCoalesceReadWriteEnabled());
settingsPack.set_bool(lt::settings_pack::coalesce_writes, isCoalesceReadWriteEnabled());
@@ -1398,7 +1400,7 @@ void Session::configurePeerClasses()
// Proactively do the same for 0.0.0.0 and address_v4::any()
f.add_rule(lt::address_v4::any()
, lt::address_v4::broadcast()
, 1 << lt::session::global_peer_class_id);
, 1 << static_cast<LTUnderlyingType<LTPeerClass>>(lt::session::global_peer_class_id));
#if (LIBTORRENT_VERSION_NUM >= 10200) || TORRENT_USE_IPV6
// IPv6 may not be available on OS and the parsing
@@ -1407,7 +1409,7 @@ void Session::configurePeerClasses()
try {
f.add_rule(lt::address_v6::any()
, lt::address_v6::from_string("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")
, 1 << lt::session::global_peer_class_id);
, 1 << static_cast<LTUnderlyingType<LTPeerClass>>(lt::session::global_peer_class_id));
}
catch (const std::exception &) {}
#endif
@@ -1416,21 +1418,21 @@ void Session::configurePeerClasses()
// local networks
f.add_rule(lt::address_v4::from_string("10.0.0.0")
, lt::address_v4::from_string("10.255.255.255")
, 1 << lt::session::local_peer_class_id);
, 1 << static_cast<LTUnderlyingType<LTPeerClass>>(lt::session::local_peer_class_id));
f.add_rule(lt::address_v4::from_string("172.16.0.0")
, lt::address_v4::from_string("172.31.255.255")
, 1 << lt::session::local_peer_class_id);
, 1 << static_cast<LTUnderlyingType<LTPeerClass>>(lt::session::local_peer_class_id));
f.add_rule(lt::address_v4::from_string("192.168.0.0")
, lt::address_v4::from_string("192.168.255.255")
, 1 << lt::session::local_peer_class_id);
, 1 << static_cast<LTUnderlyingType<LTPeerClass>>(lt::session::local_peer_class_id));
// link local
f.add_rule(lt::address_v4::from_string("169.254.0.0")
, lt::address_v4::from_string("169.254.255.255")
, 1 << lt::session::local_peer_class_id);
, 1 << static_cast<LTUnderlyingType<LTPeerClass>>(lt::session::local_peer_class_id));
// loopback
f.add_rule(lt::address_v4::from_string("127.0.0.0")
, lt::address_v4::from_string("127.255.255.255")
, 1 << lt::session::local_peer_class_id);
, 1 << static_cast<LTUnderlyingType<LTPeerClass>>(lt::session::local_peer_class_id));
#if (LIBTORRENT_VERSION_NUM >= 10200) || TORRENT_USE_IPV6
// IPv6 may not be available on OS and the parsing
@@ -1440,15 +1442,15 @@ void Session::configurePeerClasses()
// link local
f.add_rule(lt::address_v6::from_string("fe80::")
, lt::address_v6::from_string("febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff")
, 1 << lt::session::local_peer_class_id);
, 1 << static_cast<LTUnderlyingType<LTPeerClass>>(lt::session::local_peer_class_id));
// unique local addresses
f.add_rule(lt::address_v6::from_string("fc00::")
, lt::address_v6::from_string("fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")
, 1 << lt::session::local_peer_class_id);
, 1 << static_cast<LTUnderlyingType<LTPeerClass>>(lt::session::local_peer_class_id));
// loopback
f.add_rule(lt::address_v6::loopback()
, lt::address_v6::loopback()
, 1 << lt::session::local_peer_class_id);
, 1 << static_cast<LTUnderlyingType<LTPeerClass>>(lt::session::local_peer_class_id));
}
catch (const std::exception &) {}
#endif
@@ -2206,7 +2208,7 @@ void Session::saveTorrentsQueue()
QMap<int, QString> queue; // Use QMap since it should be ordered by key
for (const TorrentHandle *torrent : asConst(torrents())) {
// We require actual (non-cached) queue position here!
const int queuePos = torrent->nativeHandle().queue_position();
const int queuePos = LTUnderlyingType<LTQueuePosition> {torrent->nativeHandle().queue_position()};
if (queuePos >= 0)
queue[queuePos] = torrent->hash();
}
@@ -2618,19 +2620,6 @@ void Session::setEncryption(const int state)
}
}
bool Session::isForceProxyEnabled() const
{
return m_isForceProxyEnabled;
}
void Session::setForceProxyEnabled(const bool enabled)
{
if (enabled != isForceProxyEnabled()) {
m_isForceProxyEnabled = enabled;
configureDeferred();
}
}
bool Session::isProxyPeerConnectionsEnabled() const
{
return m_isProxyPeerConnectionsEnabled;
@@ -2925,19 +2914,6 @@ void Session::setUseOSCache(const bool use)
}
}
bool Session::isGuidedReadCacheEnabled() const
{
return m_guidedReadCacheEnabled;
}
void Session::setGuidedReadCacheEnabled(const bool enabled)
{
if (enabled == m_guidedReadCacheEnabled) return;
m_guidedReadCacheEnabled = enabled;
configureDeferred();
}
bool Session::isCoalesceReadWriteEnabled() const
{
return m_coalesceReadWriteEnabled;

View File

@@ -298,8 +298,6 @@ namespace BitTorrent
void setIPv6Enabled(bool enabled);
int encryption() const;
void setEncryption(int state);
bool isForceProxyEnabled() const;
void setForceProxyEnabled(bool enabled);
bool isProxyPeerConnectionsEnabled() const;
void setProxyPeerConnectionsEnabled(bool enabled);
ChokingAlgorithm chokingAlgorithm() const;
@@ -330,8 +328,6 @@ namespace BitTorrent
void setDiskCacheTTL(int ttl);
bool useOSCache() const;
void setUseOSCache(bool use);
bool isGuidedReadCacheEnabled() const;
void setGuidedReadCacheEnabled(bool enabled);
bool isCoalesceReadWriteEnabled() const;
void setCoalesceReadWriteEnabled(bool enabled);
bool isSuggestModeEnabled() const;
@@ -595,7 +591,6 @@ namespace BitTorrent
CachedSettingValue<int> m_diskCacheSize;
CachedSettingValue<int> m_diskCacheTTL;
CachedSettingValue<bool> m_useOSCache;
CachedSettingValue<bool> m_guidedReadCacheEnabled;
CachedSettingValue<bool> m_coalesceReadWriteEnabled;
CachedSettingValue<bool> m_isSuggestMode;
CachedSettingValue<int> m_sendBufferWatermark;
@@ -650,7 +645,6 @@ namespace BitTorrent
CachedSettingValue<QString> m_networkInterfaceAddress;
CachedSettingValue<bool> m_isIPv6Enabled;
CachedSettingValue<int> m_encryption;
CachedSettingValue<bool> m_isForceProxyEnabled;
CachedSettingValue<bool> m_isProxyPeerConnectionsEnabled;
CachedSettingValue<ChokingAlgorithm> m_chokingAlgorithm;
CachedSettingValue<SeedChokingAlgorithm> m_seedChokingAlgorithm;

View File

@@ -44,14 +44,17 @@
#include "base/global.h"
#include "base/utils/fs.h"
#include "base/utils/string.h"
#include "private/ltunderlyingtype.h"
namespace
{
#if (LIBTORRENT_VERSION_NUM < 10200)
using CreateFlags = int;
using LTCreateFlags = int;
using LTPieceIndex = int;
#else
using CreateFlags = lt::create_flags_t;
#endif
using LTCreateFlags = lt::create_flags_t;
using LTPieceIndex = lt::piece_index_t;
#endif
// do not include files and folders whose
// name starts with a .
@@ -136,7 +139,7 @@ void TorrentCreatorThread::run()
if (isInterruptionRequested()) return;
lt::create_torrent newTorrent(fs, m_params.pieceSize, -1
, (m_params.isAlignmentOptimized ? lt::create_torrent::optimize_alignment : CreateFlags {}));
, (m_params.isAlignmentOptimized ? lt::create_torrent::optimize_alignment : LTCreateFlags {}));
// Add url seeds
for (QString seed : asConst(m_params.urlSeeds)) {
@@ -157,7 +160,10 @@ void TorrentCreatorThread::run()
// calculate the hash for all pieces
lt::set_piece_hashes(newTorrent, Utils::Fs::toNativePath(parentPath).toStdString()
, [this, &newTorrent](const int n) { sendProgressSignal(n, newTorrent.num_pieces()); });
, [this, &newTorrent](const LTPieceIndex n)
{
sendProgressSignal(LTUnderlyingType<LTPieceIndex> {n}, newTorrent.num_pieces());
});
// Set qBittorrent as creator and add user comment to
// torrent_info structure
newTorrent.set_creator(creatorStr.toUtf8().constData());
@@ -208,5 +214,5 @@ int TorrentCreatorThread::calculateTotalPieces(const QString &inputPath, const i
lt::add_files(fs, Utils::Fs::toNativePath(inputPath).toStdString(), fileFilter);
return lt::create_torrent(fs, pieceSize, -1
, (isAlignmentOptimized ? lt::create_torrent::optimize_alignment : CreateFlags {})).num_pieces();
, (isAlignmentOptimized ? lt::create_torrent::optimize_alignment : LTCreateFlags {})).num_pieces();
}

View File

@@ -66,6 +66,7 @@
#include "base/utils/string.h"
#include "downloadpriority.h"
#include "peerinfo.h"
#include "private/ltunderlyingtype.h"
#include "session.h"
#include "trackerentry.h"
@@ -77,11 +78,13 @@ namespace
{
#if (LIBTORRENT_VERSION_NUM < 10200)
using LTDownloadPriority = int;
using LTDownloadPriorityUnderlyingType = int;
using LTFileIndex = int;
using LTPieceIndex = int;
using LTQueuePosition = int;
#else
using LTDownloadPriority = lt::download_priority_t;
using LTDownloadPriorityUnderlyingType = lt::download_priority_t::underlying_type;
using LTFileIndex = lt::file_index_t;
using LTPieceIndex = lt::piece_index_t;
using LTQueuePosition = lt::queue_position_t;
#endif
@@ -92,7 +95,7 @@ namespace
, std::back_inserter(out), [](BitTorrent::DownloadPriority priority)
{
return static_cast<LTDownloadPriority>(
static_cast<LTDownloadPriorityUnderlyingType>(priority));
static_cast<LTUnderlyingType<LTDownloadPriority>>(priority));
});
return out;
}
@@ -377,7 +380,7 @@ bool TorrentHandle::isAutoManaged() const
#if (LIBTORRENT_VERSION_NUM < 10200)
return m_nativeStatus.auto_managed;
#else
return (m_nativeStatus.flags & lt::torrent_flags::auto_managed);
return bool {m_nativeStatus.flags & lt::torrent_flags::auto_managed};
#endif
}
@@ -680,7 +683,7 @@ QStringList TorrentHandle::absoluteFilePathsUnwanted() const
QStringList res;
for (int i = 0; i < static_cast<int>(fp.size()); ++i) {
if (fp[i] == 0) {
if (fp[i] == LTDownloadPriority {0}) {
const QString path = Utils::Fs::expandPathAbs(saveDir.absoluteFilePath(filePath(i)));
if (path.contains(".unwanted"))
res << path;
@@ -701,8 +704,7 @@ QVector<DownloadPriority> TorrentHandle::filePriorities() const
QVector<DownloadPriority> ret;
std::transform(fp.cbegin(), fp.cend(), std::back_inserter(ret), [](LTDownloadPriority priority)
{
return static_cast<DownloadPriority>(
static_cast<std::underlying_type<DownloadPriority>::type>(priority));
return static_cast<DownloadPriority>(LTUnderlyingType<LTDownloadPriority> {priority});
});
return ret;
}
@@ -825,7 +827,7 @@ bool TorrentHandle::isSequentialDownload() const
#if (LIBTORRENT_VERSION_NUM < 10200)
return m_nativeStatus.sequential_download;
#else
return (m_nativeStatus.flags & lt::torrent_flags::sequential_download);
return bool {m_nativeStatus.flags & lt::torrent_flags::sequential_download};
#endif
}
@@ -840,13 +842,13 @@ bool TorrentHandle::hasFirstLastPiecePriority() const
const std::vector<LTDownloadPriority> filePriorities = nativeHandle().get_file_priorities();
#endif
for (int i = 0; i < static_cast<int>(filePriorities.size()); ++i) {
if (filePriorities[i] <= 0)
if (filePriorities[i] <= LTDownloadPriority {0})
continue;
const TorrentInfo::PieceRange extremities = info().filePieces(i);
const int firstPiecePrio = nativeHandle().piece_priority(extremities.first());
const int lastPiecePrio = nativeHandle().piece_priority(extremities.last());
return ((firstPiecePrio == 7) && (lastPiecePrio == 7));
const LTDownloadPriority firstPiecePrio = nativeHandle().piece_priority(LTPieceIndex {extremities.first()});
const LTDownloadPriority lastPiecePrio = nativeHandle().piece_priority(LTPieceIndex {extremities.last()});
return ((firstPiecePrio == LTDownloadPriority {7}) && (lastPiecePrio == LTDownloadPriority {7}));
}
return false;
@@ -1149,7 +1151,7 @@ bool TorrentHandle::superSeeding() const
#if (LIBTORRENT_VERSION_NUM < 10200)
return m_nativeStatus.super_seeding;
#else
return (m_nativeStatus.flags & lt::torrent_flags::super_seeding);
return bool {m_nativeStatus.flags & lt::torrent_flags::super_seeding};
#endif
}
@@ -1171,7 +1173,7 @@ QBitArray TorrentHandle::pieces() const
QBitArray result(m_nativeStatus.pieces.size());
for (int i = 0; i < m_nativeStatus.pieces.size(); ++i)
result.setBit(i, m_nativeStatus.pieces.get_bit(i));
result.setBit(i, m_nativeStatus.pieces.get_bit(LTPieceIndex {i}));
return result;
}
@@ -1184,7 +1186,11 @@ QBitArray TorrentHandle::downloadingPieces() const
m_nativeHandle.get_download_queue(queue);
for (const lt::partial_piece_info &info : queue)
#if (LIBTORRENT_VERSION_NUM < 10200)
result.setBit(info.piece_index);
#else
result.setBit(LTUnderlyingType<LTPieceIndex> {info.piece_index});
#endif
return result;
}
@@ -1410,7 +1416,7 @@ void TorrentHandle::setFirstLastPiecePriorityImpl(const bool enabled, const QVec
continue;
// Determine the priority to set
const int newPrio = enabled ? LTDownloadPriority {7} : filePrio;
const LTDownloadPriority newPrio = enabled ? LTDownloadPriority {7} : filePrio;
const TorrentInfo::PieceRange extremities = info().filePieces(index);
// worst case: AVI index = 1% of total file size (at the end of the file)
@@ -1507,9 +1513,9 @@ void TorrentHandle::renameFile(const int index, const QString &name)
{
if (m_startupState != Started) return;
m_oldPath[LTFileIndex {index}].push_back(filePath(index));
m_oldPath[index].push_back(filePath(index));
++m_renameCount;
m_nativeHandle.rename_file(index, Utils::Fs::toNativePath(name).toStdString());
m_nativeHandle.rename_file(LTFileIndex {index}, Utils::Fs::toNativePath(name).toStdString());
}
bool TorrentHandle::saveTorrentFile(const QString &path)
@@ -1807,11 +1813,11 @@ void TorrentHandle::handleFileRenamedAlert(const lt::file_renamed_alert *p)
// remove empty leftover folders
// for example renaming "a/b/c" to "d/b/c", then folders "a/b" and "a" will
// be removed if they are empty
const QString oldFilePath = m_oldPath[LTFileIndex {p->index}].takeFirst();
const QString oldFilePath = m_oldPath[LTUnderlyingType<LTFileIndex> {p->index}].takeFirst();
const QString newFilePath = Utils::Fs::toUniformPath(p->new_name());
if (m_oldPath[LTFileIndex {p->index}].isEmpty())
m_oldPath.remove(LTFileIndex {p->index});
if (m_oldPath[LTUnderlyingType<LTFileIndex> {p->index}].isEmpty())
m_oldPath.remove(LTUnderlyingType<LTFileIndex> {p->index});
QVector<QStringRef> oldPathParts = oldFilePath.splitRef('/', QString::SkipEmptyParts);
oldPathParts.removeLast(); // drop file name part
@@ -1847,12 +1853,12 @@ void TorrentHandle::handleFileRenamedAlert(const lt::file_renamed_alert *p)
void TorrentHandle::handleFileRenameFailedAlert(const lt::file_rename_failed_alert *p)
{
LogMsg(tr("File rename failed. Torrent: \"%1\", file: \"%2\", reason: \"%3\"")
.arg(name(), filePath(p->index)
.arg(name(), filePath(LTUnderlyingType<LTFileIndex> {p->index})
, QString::fromStdString(p->error.message())), Log::WARNING);
m_oldPath[LTFileIndex {p->index}].removeFirst();
if (m_oldPath[LTFileIndex {p->index}].isEmpty())
m_oldPath.remove(LTFileIndex {p->index});
m_oldPath[LTUnderlyingType<LTFileIndex> {p->index}].removeFirst();
if (m_oldPath[LTUnderlyingType<LTFileIndex> {p->index}].isEmpty())
m_oldPath.remove(LTUnderlyingType<LTFileIndex> {p->index});
--m_renameCount;
while (!isMoveInProgress() && (m_renameCount == 0) && !m_moveFinishedTriggers.isEmpty())
@@ -1870,12 +1876,12 @@ void TorrentHandle::handleFileCompletedAlert(const lt::file_completed_alert *p)
qDebug("A file completed download in torrent \"%s\"", qUtf8Printable(name()));
if (m_session->isAppendExtensionEnabled()) {
QString name = filePath(p->index);
QString name = filePath(LTUnderlyingType<LTFileIndex> {p->index});
if (name.endsWith(QB_EXT)) {
const QString oldName = name;
name.chop(QB_EXT.size());
qDebug("Renaming %s to %s", qUtf8Printable(oldName), qUtf8Printable(name));
renameFile(p->index, name);
renameFile(LTUnderlyingType<LTFileIndex> {p->index}, name);
}
}
}

View File

@@ -355,12 +355,6 @@ namespace BitTorrent
private:
typedef std::function<void ()> EventTrigger;
#if (LIBTORRENT_VERSION_NUM < 10200)
using LTFileIndex = int;
#else
using LTFileIndex = lt::file_index_t;
#endif
void updateStatus();
void updateStatus(const lt::torrent_status &nativeStatus);
void updateState();
@@ -425,7 +419,7 @@ namespace BitTorrent
// Until libtorrent provide an "old_name" field in `file_renamed_alert`
// we will rely on this workaround to remove empty leftover folders
QHash<LTFileIndex, QVector<QString>> m_oldPath;
QHash<int, QVector<QString>> m_oldPath;
bool m_useAutoTMM;

View File

@@ -378,7 +378,7 @@ TorrentInfo::PieceRange TorrentInfo::filePieces(const int fileIndex) const
void TorrentInfo::renameFile(const int index, const QString &newPath)
{
if (!isValid()) return;
nativeInfo()->rename_file(index, Utils::Fs::toNativePath(newPath).toStdString());
nativeInfo()->rename_file(LTFileIndex {index}, Utils::Fs::toNativePath(newPath).toStdString());
}
int BitTorrent::TorrentInfo::fileIndex(const QString &fileName) const
@@ -428,7 +428,7 @@ void TorrentInfo::stripRootFolder()
if (files.name() != testName) {
files.set_name(testName);
for (int i = 0; i < files.num_files(); ++i)
files.rename_file(i, files.file_path(i));
files.rename_file(LTFileIndex {i}, files.file_path(LTFileIndex {i}));
}
files.set_name("");