|
|
@ -72,10 +72,10 @@ bool QTorrentHandle::is_paused() const { |
|
|
|
return h.is_paused(); |
|
|
|
return h.is_paused(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
size_type QTorrentHandle::total_size() const { |
|
|
|
// size_type QTorrentHandle::total_size() const {
|
|
|
|
Q_ASSERT(h.is_valid()); |
|
|
|
// Q_ASSERT(h.is_valid());
|
|
|
|
return h.get_torrent_info().total_size(); |
|
|
|
// return h.get_torrent_info().total_size();
|
|
|
|
} |
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
size_type QTorrentHandle::total_done() const { |
|
|
|
size_type QTorrentHandle::total_done() const { |
|
|
|
Q_ASSERT(h.is_valid()); |
|
|
|
Q_ASSERT(h.is_valid()); |
|
|
@ -127,34 +127,14 @@ QStringList QTorrentHandle::url_seeds() const { |
|
|
|
// get the size of the torrent without the filtered files
|
|
|
|
// get the size of the torrent without the filtered files
|
|
|
|
size_type QTorrentHandle::actual_size() const{ |
|
|
|
size_type QTorrentHandle::actual_size() const{ |
|
|
|
Q_ASSERT(h.is_valid()); |
|
|
|
Q_ASSERT(h.is_valid()); |
|
|
|
unsigned int nbFiles = h.get_torrent_info().num_files(); |
|
|
|
size_type size = 0; |
|
|
|
if(!h.is_valid()){ |
|
|
|
std::vector<int> piece_priorities = h.piece_priorities(); |
|
|
|
qDebug("/!\\ Error: Invalid handle"); |
|
|
|
for(unsigned int i = 0; i<piece_priorities.size(); ++i){ |
|
|
|
return h.get_torrent_info().total_size(); |
|
|
|
if(piece_priorities[i]) |
|
|
|
|
|
|
|
size += h.get_torrent_info().piece_size(i); |
|
|
|
} |
|
|
|
} |
|
|
|
QString hash = misc::toQString(h.get_torrent_info().info_hash()); |
|
|
|
Q_ASSERT(size >= 0 && size <= h.get_torrent_info().total_size()); |
|
|
|
QFile pieces_file(misc::qBittorrentPath()+QString::fromUtf8("BT_backup")+QDir::separator()+hash+QString::fromUtf8(".priorities")); |
|
|
|
return size; |
|
|
|
// 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; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int QTorrentHandle::download_limit() const { |
|
|
|
int QTorrentHandle::download_limit() const { |
|
|
|