diff --git a/src/base/bittorrent/peerinfo.cpp b/src/base/bittorrent/peerinfo.cpp index 857424aee..4ea3f9f10 100644 --- a/src/base/bittorrent/peerinfo.cpp +++ b/src/base/bittorrent/peerinfo.cpp @@ -408,3 +408,8 @@ QString PeerInfo::flagsDescription() const { return m_flagsDescription; } + +int PeerInfo::downloadingPieceIndex() const +{ + return m_nativeInfo.downloading_piece_index; +} diff --git a/src/base/bittorrent/peerinfo.h b/src/base/bittorrent/peerinfo.h index ae63e2d54..0c7a06570 100644 --- a/src/base/bittorrent/peerinfo.h +++ b/src/base/bittorrent/peerinfo.h @@ -100,6 +100,7 @@ namespace BitTorrent #ifndef DISABLE_COUNTRIES_RESOLUTION QString country() const; #endif + int downloadingPieceIndex() const; private: void calcRelevance(const TorrentHandle *torrent); diff --git a/src/base/bittorrent/torrentinfo.cpp b/src/base/bittorrent/torrentinfo.cpp index d7da2f517..3eea6ab03 100644 --- a/src/base/bittorrent/torrentinfo.cpp +++ b/src/base/bittorrent/torrentinfo.cpp @@ -211,6 +211,20 @@ QByteArray TorrentInfo::metadata() const return QByteArray(m_nativeInfo->metadata().get(), m_nativeInfo->metadata_size()); } +QStringList TorrentInfo::filesForPiece(int pieceIndex) const +{ + if (pieceIndex < 0) + return QStringList(); + + std::vector files( + nativeInfo()->map_block(pieceIndex, 0, nativeInfo()->piece_length())); + QStringList res; + for (const libtorrent::file_slice& s: files) { + res.append(filePath(s.file_index)); + } + return res; +} + void TorrentInfo::renameFile(uint index, const QString &newPath) { if (!isValid()) return; diff --git a/src/base/bittorrent/torrentinfo.h b/src/base/bittorrent/torrentinfo.h index 392fa8b46..802e9882d 100644 --- a/src/base/bittorrent/torrentinfo.h +++ b/src/base/bittorrent/torrentinfo.h @@ -75,6 +75,7 @@ namespace BitTorrent QList trackers() const; QList urlSeeds() const; QByteArray metadata() const; + QStringList filesForPiece(int pieceIndex) const; void renameFile(uint index, const QString &newPath); boost::intrusive_ptr nativeInfo() const;