forked from premiere/premiere-libtorrent
updated filter_file function
This commit is contained in:
parent
c42a8a50d3
commit
3fdf9b378f
|
@ -632,8 +632,9 @@ namespace libtorrent
|
||||||
m_picker->filtered_pieces(bitmask);
|
m_picker->filtered_pieces(bitmask);
|
||||||
}
|
}
|
||||||
|
|
||||||
//idea from Arvid and MooPolice
|
//suggest using this function on single file in a torrent file
|
||||||
//todo refactoring and improving the function body
|
//suggest using this function after filter_files() function
|
||||||
|
//or change selective download policy casually during downloading progress
|
||||||
void torrent::filter_file(int index, bool filter)
|
void torrent::filter_file(int index, bool filter)
|
||||||
{
|
{
|
||||||
// this call is only valid on torrents with metadata
|
// this call is only valid on torrents with metadata
|
||||||
|
@ -642,25 +643,31 @@ namespace libtorrent
|
||||||
assert(index < m_torrent_file.num_files());
|
assert(index < m_torrent_file.num_files());
|
||||||
assert(index >= 0);
|
assert(index >= 0);
|
||||||
|
|
||||||
entry::integer_type start_position = 0;
|
entry::integer_type position = 0;
|
||||||
int start_piece_index = 0;
|
|
||||||
int end_piece_index = 0;
|
if (m_torrent_file.num_pieces())
|
||||||
|
{
|
||||||
|
int piece_length = m_torrent_file.piece_length();
|
||||||
|
entry::integer_type start = position;
|
||||||
|
|
||||||
// TODO: just skipping the first and last piece is not a good idea.
|
|
||||||
// they should only be skipped if there are files that are wanted
|
|
||||||
// that span those pieces. Maybe this function should be removed.
|
|
||||||
for (int i = 0; i < index; ++i)
|
for (int i = 0; i < index; ++i)
|
||||||
start_position += m_torrent_file.file_at(i).size;
|
{
|
||||||
|
start = position;
|
||||||
|
position += m_torrent_file.file_at(i).size;
|
||||||
|
}
|
||||||
|
int start_piece = int(start / piece_length);
|
||||||
|
int last_piece = int(position / piece_length);
|
||||||
|
|
||||||
start_position = start_position + 1;
|
for (int filter_index = start_piece ; filter_index < last_piece ; ++filter_index)
|
||||||
|
{
|
||||||
start_piece_index = start_position / m_torrent_file.piece_length();
|
filter_piece(filter_index, filter);
|
||||||
end_piece_index = start_piece_index + m_torrent_file.file_at(index).size/(m_torrent_file.piece_length());
|
}
|
||||||
|
}
|
||||||
for(int i = start_piece_index; i < end_piece_index; ++i)
|
|
||||||
filter_piece(i, filter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//suggest using this function on a torrent file.
|
||||||
|
//suggest using this function as a static globle selective download policy
|
||||||
|
//"before" downloading progress
|
||||||
void torrent::filter_files(std::vector<bool> const& bitmask)
|
void torrent::filter_files(std::vector<bool> const& bitmask)
|
||||||
{
|
{
|
||||||
// this call is only valid on torrents with metadata
|
// this call is only valid on torrents with metadata
|
||||||
|
|
Loading…
Reference in New Issue