mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-01-24 18:44:52 +08:00
- Optimized a lot torrent real size calculation
This commit is contained in:
parent
cdfaed4fb4
commit
63334ea6fb
@ -95,7 +95,7 @@ void FinishedTorrents::addTorrent(QString hash){
|
||||
// Adding torrent to download list
|
||||
finishedListModel->insertRow(row);
|
||||
finishedListModel->setData(finishedListModel->index(row, F_NAME), QVariant(h.name()));
|
||||
finishedListModel->setData(finishedListModel->index(row, F_SIZE), QVariant((qlonglong)h.total_size()));
|
||||
finishedListModel->setData(finishedListModel->index(row, F_SIZE), QVariant((qlonglong)h.actual_size()));
|
||||
finishedListModel->setData(finishedListModel->index(row, F_UPSPEED), QVariant((double)0.));
|
||||
finishedListModel->setData(finishedListModel->index(row, F_SEEDSLEECH), QVariant("0/0"));
|
||||
finishedListModel->setData(finishedListModel->index(row, F_RATIO), QVariant(QString::fromUtf8(misc::toString(BTSession->getRealRatio(hash)).c_str())));
|
||||
|
@ -72,10 +72,10 @@ bool QTorrentHandle::is_paused() const {
|
||||
return h.is_paused();
|
||||
}
|
||||
|
||||
size_type QTorrentHandle::total_size() const {
|
||||
Q_ASSERT(h.is_valid());
|
||||
return h.get_torrent_info().total_size();
|
||||
}
|
||||
// size_type QTorrentHandle::total_size() const {
|
||||
// Q_ASSERT(h.is_valid());
|
||||
// return h.get_torrent_info().total_size();
|
||||
// }
|
||||
|
||||
size_type QTorrentHandle::total_done() const {
|
||||
Q_ASSERT(h.is_valid());
|
||||
@ -127,34 +127,14 @@ QStringList QTorrentHandle::url_seeds() const {
|
||||
// get the size of the torrent without the filtered files
|
||||
size_type QTorrentHandle::actual_size() const{
|
||||
Q_ASSERT(h.is_valid());
|
||||
unsigned int nbFiles = h.get_torrent_info().num_files();
|
||||
if(!h.is_valid()){
|
||||
qDebug("/!\\ Error: Invalid handle");
|
||||
return h.get_torrent_info().total_size();
|
||||
size_type size = 0;
|
||||
std::vector<int> piece_priorities = h.piece_priorities();
|
||||
for(unsigned int i = 0; i<piece_priorities.size(); ++i){
|
||||
if(piece_priorities[i])
|
||||
size += h.get_torrent_info().piece_size(i);
|
||||
}
|
||||
QString hash = misc::toQString(h.get_torrent_info().info_hash());
|
||||
QFile pieces_file(misc::qBittorrentPath()+QString::fromUtf8("BT_backup")+QDir::separator()+hash+QString::fromUtf8(".priorities"));
|
||||
// Read saved file
|
||||
if(!pieces_file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
||||
return h.get_torrent_info().total_size();
|
||||
}
|
||||
QByteArray pieces_priorities = pieces_file.readAll();
|
||||
pieces_file.close();
|
||||
QList<QByteArray> pieces_priorities_list = pieces_priorities.split('\n');
|
||||
if((unsigned int)pieces_priorities_list.size() != nbFiles+1){
|
||||
std::cerr << "* Error: Corrupted priorities file\n";
|
||||
return h.get_torrent_info().total_size();
|
||||
}
|
||||
size_type effective_size = 0;
|
||||
for(unsigned int i=0; i<nbFiles; ++i){
|
||||
int priority = pieces_priorities_list.at(i).toInt();
|
||||
if( priority < 0 || priority > 7){
|
||||
priority = 1;
|
||||
}
|
||||
if(priority)
|
||||
effective_size += h.get_torrent_info().file_at(i).size;
|
||||
}
|
||||
return effective_size;
|
||||
Q_ASSERT(size >= 0 && size <= h.get_torrent_info().total_size());
|
||||
return size;
|
||||
}
|
||||
|
||||
int QTorrentHandle::download_limit() const {
|
||||
|
@ -56,7 +56,7 @@ class QTorrentHandle {
|
||||
QString current_tracker() const;
|
||||
bool is_valid() const;
|
||||
bool is_paused() const;
|
||||
size_type total_size() const;
|
||||
// size_type total_size() const;
|
||||
size_type total_done() const;
|
||||
float download_payload_rate() const;
|
||||
float upload_payload_rate() const;
|
||||
|
Loading…
Reference in New Issue
Block a user