mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-01-06 15:04:34 +08:00
Merge pull request #12692 from Chocobo1/cleanup
Handle empty piece range properly
This commit is contained in:
commit
93e1e063b2
@ -2120,11 +2120,11 @@ void TorrentHandleImpl::prioritizeFiles(const QVector<DownloadPriority> &priorit
|
|||||||
QVector<qreal> TorrentHandleImpl::availableFileFractions() const
|
QVector<qreal> TorrentHandleImpl::availableFileFractions() const
|
||||||
{
|
{
|
||||||
const int filesCount = this->filesCount();
|
const int filesCount = this->filesCount();
|
||||||
if (filesCount < 0) return {};
|
if (filesCount <= 0) return {};
|
||||||
|
|
||||||
const QVector<int> piecesAvailability = pieceAvailability();
|
const QVector<int> piecesAvailability = pieceAvailability();
|
||||||
// libtorrent returns empty array for seeding only torrents
|
// libtorrent returns empty array for seeding only torrents
|
||||||
if (piecesAvailability.empty()) return QVector<qreal>(filesCount, -1.);
|
if (piecesAvailability.empty()) return QVector<qreal>(filesCount, -1);
|
||||||
|
|
||||||
QVector<qreal> res;
|
QVector<qreal> res;
|
||||||
res.reserve(filesCount);
|
res.reserve(filesCount);
|
||||||
@ -2136,7 +2136,10 @@ QVector<qreal> TorrentHandleImpl::availableFileFractions() const
|
|||||||
for (const int piece : filePieces)
|
for (const int piece : filePieces)
|
||||||
availablePieces += (piecesAvailability[piece] > 0) ? 1 : 0;
|
availablePieces += (piecesAvailability[piece] > 0) ? 1 : 0;
|
||||||
|
|
||||||
res.push_back(static_cast<qreal>(availablePieces) / filePieces.size());
|
const qreal availability = filePieces.isEmpty()
|
||||||
|
? 1 // the file has no pieces, so it is available by default
|
||||||
|
: static_cast<qreal>(availablePieces) / filePieces.size();
|
||||||
|
res.push_back(availability);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -233,7 +233,7 @@ void TorrentContentModel::updateFilesAvailability(const QVector<qreal> &fa)
|
|||||||
if (m_filesIndex.size() != fa.size()) return;
|
if (m_filesIndex.size() != fa.size()) return;
|
||||||
|
|
||||||
emit layoutAboutToBeChanged();
|
emit layoutAboutToBeChanged();
|
||||||
for (int i = 0; i < fa.size(); ++i)
|
for (int i = 0; i < m_filesIndex.size(); ++i)
|
||||||
m_filesIndex[i]->setAvailability(fa[i]);
|
m_filesIndex[i]->setAvailability(fa[i]);
|
||||||
// Update folders progress in the tree
|
// Update folders progress in the tree
|
||||||
m_rootItem->recalculateProgress();
|
m_rootItem->recalculateProgress();
|
||||||
|
@ -73,7 +73,7 @@ void TorrentContentModelFile::setProgress(qreal progress)
|
|||||||
Q_ASSERT(m_progress <= 1.);
|
Q_ASSERT(m_progress <= 1.);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentContentModelFile::setAvailability(qreal availability)
|
void TorrentContentModelFile::setAvailability(const qreal availability)
|
||||||
{
|
{
|
||||||
m_availability = availability;
|
m_availability = availability;
|
||||||
Q_ASSERT(m_availability <= 1.);
|
Q_ASSERT(m_availability <= 1.);
|
||||||
|
Loading…
Reference in New Issue
Block a user