Ejemplo n.º 1
0
void generate_files(libtorrent::torrent_info const& ti, std::string const& path
	, bool alternate_data)
{
	file_pool fp;

	storage_params params;
	params.files = &ti.files();
	params.path = path;
	params.pool = &fp;

	default_storage st(params);

	int const num_pieces = ti.num_pieces();

	std::vector<char> buffer;
	for (int i = 0; i < num_pieces; ++i)
	{
		int const piece_size = ti.piece_size(i);
		buffer.resize(ti.piece_length());

		std::uint8_t const data = std::uint8_t((alternate_data ? 255 - i : i) & 0xff);
		for (int o = 0; o < piece_size; ++o)
		{
			memcpy(&buffer[o], &data, 1);
		}

		file::iovec_t b = { &buffer[0], size_t(piece_size) };
		storage_error ec;
		int ret = st.writev(&b, 1, i, 0, 0, ec);
		if (ret != piece_size || ec)
		{
			std::fprintf(stderr, "ERROR writing files: (%d expected %d) %s\n"
				, ret, piece_size, ec.ec.message().c_str());
		}
	}
}
Ejemplo n.º 2
0
QString QTorrentHandle::filepath_at(const libtorrent::torrent_info &info, unsigned int index)
{
    return fsutils::fromNativePath(misc::toQStringU(info.files().file_path(index)));

}