add file file filter functions to test

This commit is contained in:
spyhole 2005-07-03 23:33:47 +00:00
parent 4a1951f6f2
commit b4a2cc645f
4 changed files with 53 additions and 2 deletions

View File

@ -153,7 +153,11 @@ namespace libtorrent
//idea from Arvid and MooPolice
//todo refactoring and improving the function body
// marks the file with the given index as filtered
// it will not be downloaded
void filter_file(int index, bool filter);
void filter_files(std::vector<bool> const& files);
torrent_status status() const;

View File

@ -233,7 +233,10 @@ namespace libtorrent
//idea from Arvid and MooPolice
//todo refactoring and improving the function body
// marks the file with the given index as filtered
// it will not be downloaded
void filter_file(int index, bool filter);
void filter_files(std::vector<bool> const& files);
// set the interface to bind outgoing connections
// to.

View File

@ -655,6 +655,45 @@ namespace libtorrent
}
}
void torrent::filter_files(std::vector<bool> const& bitmask)
{
// this call is only valid on torrents with metadata
if (!valid_metadata()) return;
try
{
__int64 position = 0, start, piece_length;
int start_piece, end_piece;
if (m_torrent_file.num_pieces())
{
piece_length = m_torrent_file.piece_length();
std::vector<bool> vector_filter_files(m_torrent_file.num_pieces(), false);
for (int i=0;i<bitmask.size();i++)
{
start = position;
position += m_torrent_file.file_at(i).size;
// is the file selected for undownload?
if (true == bitmask[i])
{
// mark all pieces of the file as filtered
start_piece = (int)(start / piece_length);
end_piece = (int)(position / piece_length);
// if one piece spawns several files, we might
// come here several times with the same start_piece, end_piece
for (int index = start_piece;index<=end_piece;index++)
{
vector_filter_files[index] = true;
}
}
}
filter_pieces(vector_filter_files);
}
}
catch (...)
{
}
}
void torrent::replace_trackers(std::vector<announce_entry> const& urls)
{
assert(!urls.empty());

View File

@ -286,8 +286,6 @@ namespace libtorrent
return ret;
}
//idea from Arvid and MooPolice
//todo refactoring and improving the function body
void torrent_handle::filter_file(int index, bool filter)
{
INVARIANT_CHECK;
@ -295,6 +293,13 @@ namespace libtorrent
, bind(&torrent::filter_file, _1, index, filter));
}
void torrent_handle::filter_files(std::vector<bool> const& files)
{
INVARIANT_CHECK;
call_member<void>(m_ses, m_chk, m_info_hash
, bind(&torrent::filter_files, _1, files));
}
std::vector<announce_entry> const& torrent_handle::trackers() const
{
INVARIANT_CHECK;