本文整理汇总了C++中bdecode_node::dict_find_list方法的典型用法代码示例。如果您正苦于以下问题:C++ bdecode_node::dict_find_list方法的具体用法?C++ bdecode_node::dict_find_list怎么用?C++ bdecode_node::dict_find_list使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bdecode_node
的用法示例。
在下文中一共展示了bdecode_node::dict_find_list方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: extract_single_file
// 'top_level' is extracting the file for a single-file torrent. The
// distinction is that the filename is found in "name" rather than
// "path"
// root_dir is the name of the torrent, unless this is a single file
// torrent, in which case it's empty.
bool extract_single_file(bdecode_node const& dict, file_storage& files
, std::string const& root_dir, ptrdiff_t info_ptr_diff, bool top_level
, int& pad_file_cnt, error_code& ec)
{
if (dict.type() != bdecode_node::dict_t) return false;
boost::uint32_t file_flags = get_file_attributes(dict);
// symlinks have an implied "size" of zero. i.e. they use up 0 bytes of
// the torrent payload space
boost::int64_t const file_size = (file_flags & file_storage::flag_symlink)
? 0
: dict.dict_find_int_value("length", -1);
if (file_size < 0 )
{
ec = errors::torrent_invalid_length;
return false;
}
boost::int64_t const mtime = dict.dict_find_int_value("mtime", 0);
std::string path = root_dir;
std::string path_element;
char const* filename = NULL;
int filename_len = 0;
if (top_level)
{
// prefer the name.utf-8 because if it exists, it is more likely to be
// correctly encoded
bdecode_node p = dict.dict_find_string("name.utf-8");
if (!p) p = dict.dict_find_string("name");
if (!p || p.string_length() == 0)
{
ec = errors::torrent_missing_name;
return false;
}
filename = p.string_ptr() + info_ptr_diff;
filename_len = p.string_length();
while (filename_len > 0 && filename[0] == TORRENT_SEPARATOR)
{
filename += 1;
filename_len -= 1;
}
sanitize_append_path_element(path, p.string_ptr(), p.string_length());
}
else
{
bdecode_node p = dict.dict_find_list("path.utf-8");
if (!p) p = dict.dict_find_list("path");
if (p && p.list_size() > 0)
{
std::size_t const orig_path_len = path.size();
int const preallocate = path.size() + path_length(p, ec);
if (ec) return false;
path.reserve(preallocate);
for (int i = 0, end(p.list_size()); i < end; ++i)
{
bdecode_node e = p.list_at(i);
if (i == end - 1)
{
filename = e.string_ptr() + info_ptr_diff;
filename_len = e.string_length();
}
while (filename_len > 0 && filename[0] == TORRENT_SEPARATOR)
{
filename += 1;
filename_len -= 1;
}
sanitize_append_path_element(path, e.string_ptr(), e.string_length());
}
// if all path elements were sanitized away, we need to use another
// name instead
if (path.size() == orig_path_len)
{
path += TORRENT_SEPARATOR;
path += "_";
}
}
else if (file_flags & file_storage::flag_pad_file)
{
// pad files don't need a path element, we'll just store them
// under the .pad directory
char cnt[10];
snprintf(cnt, sizeof(cnt), "%d", pad_file_cnt);
path = combine_path(".pad", cnt);
++pad_file_cnt;
}
else
{
ec = errors::torrent_missing_name;
//.........这里部分代码省略.........