mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-23 08:48:07 -06:00
Merge pull request #10950 from glassez/drop-deprecated
Don't use deprecated libtorrent features
This commit is contained in:
@@ -67,6 +67,7 @@
|
||||
#include "downloadpriority.h"
|
||||
#include "peeraddress.h"
|
||||
#include "peerinfo.h"
|
||||
#include "private/ltunderlyingtype.h"
|
||||
#include "session.h"
|
||||
#include "trackerentry.h"
|
||||
|
||||
@@ -74,15 +75,29 @@ const QString QB_EXT {QStringLiteral(".!qB")};
|
||||
|
||||
using namespace BitTorrent;
|
||||
|
||||
#if (LIBTORRENT_VERSION_NUM >= 10200)
|
||||
namespace libtorrent
|
||||
{
|
||||
namespace aux
|
||||
{
|
||||
template <typename T, typename Tag>
|
||||
uint qHash(const strong_typedef<T, Tag> &key, const uint seed)
|
||||
{
|
||||
return static_cast<uint>((std::hash<strong_typedef<T, Tag>> {})(key) ^ seed);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace
|
||||
{
|
||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
||||
using LTDownloadPriority = int;
|
||||
using LTDownloadPriorityUnderlyingType = int;
|
||||
using LTPieceIndex = int;
|
||||
using LTQueuePosition = int;
|
||||
#else
|
||||
using LTDownloadPriority = lt::download_priority_t;
|
||||
using LTDownloadPriorityUnderlyingType = lt::download_priority_t::underlying_type;
|
||||
using LTPieceIndex = lt::piece_index_t;
|
||||
using LTQueuePosition = lt::queue_position_t;
|
||||
#endif
|
||||
|
||||
@@ -93,7 +108,7 @@ namespace
|
||||
, std::back_inserter(out), [](BitTorrent::DownloadPriority priority)
|
||||
{
|
||||
return static_cast<LTDownloadPriority>(
|
||||
static_cast<LTDownloadPriorityUnderlyingType>(priority));
|
||||
static_cast<LTUnderlyingType<LTDownloadPriority>>(priority));
|
||||
});
|
||||
return out;
|
||||
}
|
||||
@@ -378,7 +393,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
|
||||
}
|
||||
|
||||
@@ -681,7 +696,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;
|
||||
@@ -702,8 +717,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;
|
||||
}
|
||||
@@ -826,7 +840,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
|
||||
}
|
||||
|
||||
@@ -841,13 +855,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;
|
||||
@@ -1150,7 +1164,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
|
||||
}
|
||||
|
||||
@@ -1172,7 +1186,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;
|
||||
}
|
||||
@@ -1185,7 +1199,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;
|
||||
}
|
||||
@@ -1411,7 +1429,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)
|
||||
@@ -1510,7 +1528,7 @@ void TorrentHandle::renameFile(const int index, const QString &name)
|
||||
|
||||
m_oldPath[LTFileIndex {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)
|
||||
@@ -1808,11 +1826,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[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[p->index].isEmpty())
|
||||
m_oldPath.remove(p->index);
|
||||
|
||||
QVector<QStringRef> oldPathParts = oldFilePath.splitRef('/', QString::SkipEmptyParts);
|
||||
oldPathParts.removeLast(); // drop file name part
|
||||
@@ -1848,12 +1866,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[p->index].removeFirst();
|
||||
if (m_oldPath[p->index].isEmpty())
|
||||
m_oldPath.remove(p->index);
|
||||
|
||||
--m_renameCount;
|
||||
while (!isMoveInProgress() && (m_renameCount == 0) && !m_moveFinishedTriggers.isEmpty())
|
||||
@@ -1871,12 +1889,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user