Browse Source

- Optimized a lot torrent real size calculation

adaptive-webui-19844
Christophe Dumez 18 years ago
parent
commit
63334ea6fb
  1. 2
      src/FinishedTorrents.cpp
  2. 42
      src/qtorrenthandle.cpp
  3. 2
      src/qtorrenthandle.h

2
src/FinishedTorrents.cpp

@ -95,7 +95,7 @@ void FinishedTorrents::addTorrent(QString hash){
// Adding torrent to download list // Adding torrent to download list
finishedListModel->insertRow(row); finishedListModel->insertRow(row);
finishedListModel->setData(finishedListModel->index(row, F_NAME), QVariant(h.name())); 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_UPSPEED), QVariant((double)0.));
finishedListModel->setData(finishedListModel->index(row, F_SEEDSLEECH), QVariant("0/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()))); finishedListModel->setData(finishedListModel->index(row, F_RATIO), QVariant(QString::fromUtf8(misc::toString(BTSession->getRealRatio(hash)).c_str())));

42
src/qtorrenthandle.cpp

@ -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 {

2
src/qtorrenthandle.h

@ -56,7 +56,7 @@ class QTorrentHandle {
QString current_tracker() const; QString current_tracker() const;
bool is_valid() const; bool is_valid() const;
bool is_paused() const; bool is_paused() const;
size_type total_size() const; // size_type total_size() const;
size_type total_done() const; size_type total_done() const;
float download_payload_rate() const; float download_payload_rate() const;
float upload_payload_rate() const; float upload_payload_rate() const;

Loading…
Cancel
Save