transition mapped_files over to the new add_torrent_params

This commit is contained in:
arvidn 2016-02-13 15:07:02 -08:00 committed by arvidn
parent 6e88771981
commit 4ef55073e3
4 changed files with 30 additions and 14 deletions

View File

@ -473,6 +473,10 @@ namespace libtorrent
// first entry. See torrent_info::set_merkle_tree() for more info.
std::vector<sha1_hash> merkle_tree;
// this is a map of file indices in the torrent and new filenames to be
// applied before the torrent is added.
std::map<int, std::string> renamed_files;
#ifndef TORRENT_NO_DEPRECATE
// The optional parameter, ``resume_data`` can be given if up to date
// fast-resume data is available. The fast-resume data can be acquired

View File

@ -81,10 +81,10 @@ namespace libtorrent
return ret;
}
#error we need to verify the info-hash from the resume data \
matches the torrent_info object or the magnet link in the URL field. This \
can only be done reliably on the libtorrent side as the torrent is being \
added. i.e. the info_hash needs to be saved
//TODO: 4 we need to verify the info-hash from the resume data
// matches the torrent_info object or the magnet link in the URL field. This
// can only be done reliably on the libtorrent side as the torrent is being
// added. i.e. the info_hash needs to be saved
ret.total_uploaded = rd.dict_find_int_value("total_uploaded");
ret.total_downloaded = rd.dict_find_int_value("total_downloaded");
@ -118,18 +118,14 @@ namespace libtorrent
ret.uuid = rd.dict_find_string_value("uuid");
ret.source_feed_url = rd.dict_find_string_value("feed");
#error add a field for this. The mapping has to happen in the torrent \
constructor probably, and passed on to the storage. possibly, the \
mapped_storage should be passed directly in when the storage is constructed
bdecode_node mapped_files = rd.dict_find_list("mapped_files");
if (mapped_files && mapped_files.list_size() == m_torrent_file->num_files())
if (mapped_files)
{
for (int i = 0; i < m_torrent_file->num_files(); ++i)
for (int i = 0; i < mapped_files.list_size(); ++i)
{
std::string new_filename = mapped_files.list_string_value_at(i);
if (new_filename.empty()) continue;
m_torrent_file->rename_file(i, new_filename);
ret.renamed_files[i] = new_filename;
}
}

View File

@ -239,6 +239,8 @@ namespace libtorrent
atp.merkle_tree.swap(resume_data.merkle_tree);
atp.renamed_files.swap(resume_data.renamed_files);
if ((atp.flags & add_torrent_params::flag_override_resume_data) == 0)
{
atp.download_limit = resume_data.download_limit;
@ -299,7 +301,7 @@ namespace libtorrent
#ifndef TORRENT_NO_DEPRECATE
error_code ec;
handle_backwards_compatible_resume_data(*p, ec);
#error what should we do about error handling here?
//TODO: 3 what should we do about error handling here?
if (ec)
{
delete p;

View File

@ -795,7 +795,7 @@ namespace libtorrent
{
TORRENT_ASSERT(is_single_thread());
#error why isn't this done in the constructor?
// TODO: 3 why isn't this done in the constructor?
#ifndef TORRENT_DISABLE_LOGGING
debug_log("creating torrent: %s max-uploads: %d max-connections: %d "
@ -1891,6 +1891,19 @@ namespace libtorrent
return;
}
// --- MAPPED FILES ---
if (m_add_torrent_params)
{
for (std::map<int, std::string>::const_iterator i
= m_add_torrent_params->renamed_files.begin()
, end(m_add_torrent_params->renamed_files.end());
i != end; ++i)
{
if (i->first < 0 || i->first >= m_torrent_file->num_files()) continue;
m_torrent_file->rename_file(i->first, i->second);
}
}
construct_storage();
if (m_share_mode && valid_metadata())
@ -2084,7 +2097,8 @@ namespace libtorrent
inc_refcount("check_fastresume");
// async_check_fastresume will gut links
#error I don't think we need to pass in any resume-data anymore, do we?
// TODO: 4 we need to at least pass in the have-bitfield here.
// check_fastresume should probably be renamed check_files.
m_ses.disk_thread().async_check_fastresume(
m_storage.get(), m_resume_data ? &m_resume_data->node : NULL
, links, boost::bind(&torrent::on_resume_data_checked