Browse Source

FEATURE: Download first/last pieces first now applies to all media files in the torrent (Thanks Ahmad)

adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
6d1ad28d8c
  1. 2
      Changelog
  2. 4
      src/properties/propertieswidget.cpp
  3. 66
      src/qtlibtorrent/qtorrenthandle.cpp
  4. 4
      src/qtlibtorrent/qtorrenthandle.h

2
Changelog

@ -14,6 +14,8 @@ @@ -14,6 +14,8 @@
- FEATURE: Optimized and improved the peer country resolution code
- FEATURE: Download first/last pieces first when sequential download is
enabled (Thanks Ahmad)
- FEATURE: Download first/last pieces first now applies to all media files
in the torrent (Thanks Ahmad)
- BUGFIX: Fix SOCKS5 proxy authentication in search engine(closes #680072)
- BUGFIX: Fix two advanced settings (ignore limits on LAN and protocol
overhead inclusion in rate limiter)

4
src/properties/propertieswidget.cpp

@ -677,10 +677,8 @@ void PropertiesWidget::renameSelectedFile() { @@ -677,10 +677,8 @@ void PropertiesWidget::renameSelectedFile() {
bool PropertiesWidget::applyPriorities() {
qDebug("Saving files priorities");
const std::vector<int> priorities = PropListModel->getFilesPriorities(h.get_torrent_info().num_files());
bool first_last_piece_first = false;
// Save first/last piece first option state
if(h.first_last_piece_first())
first_last_piece_first = true;
bool first_last_piece_first = h.first_last_piece_first();
// Prioritize the files
qDebug("prioritize files: %d", priorities[0]);
h.prioritize_files(priorities);

66
src/qtlibtorrent/qtorrenthandle.cpp

@ -122,27 +122,23 @@ int QTorrentHandle::num_pieces() const { @@ -122,27 +122,23 @@ int QTorrentHandle::num_pieces() const {
}
bool QTorrentHandle::first_last_piece_first() const {
// Detect main file
int rank=0;
int main_file_index = 0;
file_entry main_file = torrent_handle::get_torrent_info().file_at(0);
torrent_info::file_iterator it = torrent_handle::get_torrent_info().begin_files();
it++; ++rank;
while(it != torrent_handle::get_torrent_info().end_files()) {
if(it->size > main_file.size) {
main_file = *it;
main_file_index = rank;
// Detect first media file
torrent_info::file_iterator it;
int index = 0;
for(it = get_torrent_info().begin_files(); it != get_torrent_info().end_files(); it++) {
const QString ext = misc::toQStringU(it->path.string()).split(".").last();
if(misc::isPreviewable(ext) && torrent_handle::file_priority(index) > 0) {
break;
}
it++;
++rank;
++index;
}
qDebug() << "Main file in the torrent is" << filepath(main_file);
file_entry media_file = torrent_handle::get_torrent_info().file_at(index);
int piece_size = torrent_handle::get_torrent_info().piece_length();
Q_ASSERT(piece_size>0);
int first_piece = floor((main_file.offset+1)/(double)piece_size);
int first_piece = floor((media_file.offset+1)/(double)piece_size);
Q_ASSERT(first_piece >= 0 && first_piece < torrent_handle::get_torrent_info().num_pieces());
qDebug("First piece of the file is %d/%d", first_piece, torrent_handle::get_torrent_info().num_pieces()-1);
int num_pieces_in_file = ceil(main_file.size/(double)piece_size);
int num_pieces_in_file = ceil(media_file.size/(double)piece_size);
int last_piece = first_piece+num_pieces_in_file-1;
Q_ASSERT(last_piece >= 0 && last_piece < torrent_handle::get_torrent_info().num_pieces());
qDebug("last piece of the file is %d/%d", last_piece, torrent_handle::get_torrent_info().num_pieces()-1);
@ -550,32 +546,18 @@ void QTorrentHandle::add_tracker(const announce_entry& url) const { @@ -550,32 +546,18 @@ void QTorrentHandle::add_tracker(const announce_entry& url) const {
#endif
}
void QTorrentHandle::prioritize_first_last_piece(bool b) const {
// Detect main file
int rank=0;
int main_file_index = 0;
file_entry main_file = torrent_handle::get_torrent_info().file_at(0);
torrent_info::file_iterator it = torrent_handle::get_torrent_info().begin_files();
it++; ++rank;
while(it != torrent_handle::get_torrent_info().end_files()) {
if(it->size > main_file.size) {
main_file = *it;
main_file_index = rank;
}
it++;
++rank;
}
qDebug() << "Main file in the torrent is" << filepath(main_file);
void QTorrentHandle::prioritize_first_last_piece(int file_index, bool b) const {
// Determine the priority to set
int prio = 7; // MAX
if(!b) prio = torrent_handle::file_priority(main_file_index);
// Determine the first and last piece of the main file
if(!b) prio = torrent_handle::file_priority(file_index);
file_entry file = get_torrent_info().file_at(file_index);
// Determine the first and last piece of the file
int piece_size = torrent_handle::get_torrent_info().piece_length();
Q_ASSERT(piece_size>0);
int first_piece = floor((main_file.offset+1)/(double)piece_size);
int first_piece = floor((file.offset+1)/(double)piece_size);
Q_ASSERT(first_piece >= 0 && first_piece < torrent_handle::get_torrent_info().num_pieces());
qDebug("First piece of the file is %d/%d", first_piece, torrent_handle::get_torrent_info().num_pieces()-1);
int num_pieces_in_file = ceil(main_file.size/(double)piece_size);
int num_pieces_in_file = ceil(file.size/(double)piece_size);
int last_piece = first_piece+num_pieces_in_file-1;
Q_ASSERT(last_piece >= 0 && last_piece < torrent_handle::get_torrent_info().num_pieces());
qDebug("last piece of the file is %d/%d", last_piece, torrent_handle::get_torrent_info().num_pieces()-1);
@ -583,6 +565,20 @@ void QTorrentHandle::prioritize_first_last_piece(bool b) const { @@ -583,6 +565,20 @@ void QTorrentHandle::prioritize_first_last_piece(bool b) const {
torrent_handle::piece_priority(last_piece, prio);
}
void QTorrentHandle::prioritize_first_last_piece(bool b) const {
// Download first and last pieces first for all media files in the torrent
torrent_info::file_iterator it;
int index = 0;
for(it = get_torrent_info().begin_files(); it != get_torrent_info().end_files(); it++) {
const QString ext = misc::toQStringU(it->path.string()).split(".").last();
if(misc::isPreviewable(ext) && torrent_handle::file_priority(index) > 0) {
qDebug() << "File" << it->path.string().c_str() << "is previewable, toggle downloading of first/last pieces first";
prioritize_first_last_piece(index, b);
}
++index;
}
}
void QTorrentHandle::rename_file(int index, QString name) const {
torrent_handle::rename_file(index, std::string(name.toUtf8().constData()));
}

4
src/qtlibtorrent/qtorrenthandle.h

@ -135,6 +135,10 @@ class QTorrentHandle : public libtorrent::torrent_handle { @@ -135,6 +135,10 @@ class QTorrentHandle : public libtorrent::torrent_handle {
// Operators
//
bool operator ==(const QTorrentHandle& new_h) const;
private:
void prioritize_first_last_piece(int file_index, bool b) const;
};
#endif

Loading…
Cancel
Save