Ejemplo n.º 1
0
static QPair<int, int> get_file_extremity_pieces(const torrent_info& t, int file_index)
{
    const int num_pieces = t.num_pieces();
    const int piece_size = t.piece_length();
    const file_entry& file = t.file_at(file_index);

    // Determine the first and last piece of the file
    int first_piece = floor((file.offset + 1) / (float) piece_size);
    Q_ASSERT(first_piece >= 0 && first_piece < num_pieces);

    int num_pieces_in_file = ceil(file.size / (float) piece_size);
    int last_piece = first_piece + num_pieces_in_file - 1;
    Q_ASSERT(last_piece >= 0 && last_piece < num_pieces);

    return qMakePair(first_piece, last_piece);
}