forked from premiere/premiere-libtorrent
saves torrent settings in resume data (up/down rate limits, max connections, upload slots, paused state, auto managed, piece priorities, renamed files)
This commit is contained in:
parent
d4ee273573
commit
8c91fff1d6
|
@ -686,15 +686,29 @@ namespace libtorrent
|
||||||
p.push_back(entry(i->second));
|
p.push_back(entry(i->second));
|
||||||
fl.push_back(entry(p));
|
fl.push_back(entry(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_mapped_files)
|
||||||
|
{
|
||||||
|
entry::list_type& fl = rd["mapped_files"].list();
|
||||||
|
for (file_storage::iterator i = m_mapped_files->begin()
|
||||||
|
, end(m_mapped_files->end()); i != end; ++i)
|
||||||
|
{
|
||||||
|
fl.push_back(i->path.string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool storage::verify_resume_data(lazy_entry const& rd, std::string& error)
|
bool storage::verify_resume_data(lazy_entry const& rd, std::string& error)
|
||||||
{
|
{
|
||||||
if (rd.type() != lazy_entry::dict_t)
|
lazy_entry const* mapped_files = rd.dict_find_list("mapped_files");
|
||||||
|
if (mapped_files && mapped_files->list_size() == m_files.num_files())
|
||||||
{
|
{
|
||||||
error = "invalid fastresume file (not a dictionary)";
|
if (!m_mapped_files)
|
||||||
return true;
|
{ m_mapped_files.reset(new file_storage(m_files)); }
|
||||||
|
for (int i = 0; i < m_files.num_files(); ++i)
|
||||||
|
m_mapped_files->rename_file(i, mapped_files->list_string_value_at(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::pair<size_type, std::time_t> > file_sizes;
|
std::vector<std::pair<size_type, std::time_t> > file_sizes;
|
||||||
|
|
|
@ -2437,6 +2437,22 @@ namespace libtorrent
|
||||||
m_seeding_time = seconds(rd.dict_find_int_value("seeding_time"));
|
m_seeding_time = seconds(rd.dict_find_int_value("seeding_time"));
|
||||||
m_complete = rd.dict_find_int_value("num_seeds", -1);
|
m_complete = rd.dict_find_int_value("num_seeds", -1);
|
||||||
m_incomplete = rd.dict_find_int_value("num_downloaders", -1);
|
m_incomplete = rd.dict_find_int_value("num_downloaders", -1);
|
||||||
|
set_upload_limit(rd.dict_find_int_value("upload_rate_limit", -1));
|
||||||
|
set_download_limit(rd.dict_find_int_value("download_rate_limit", -1));
|
||||||
|
set_max_connections(rd.dict_find_int_value("max_connections", -1));
|
||||||
|
set_max_uploads(rd.dict_find_int_value("max_uploads", -1));
|
||||||
|
|
||||||
|
lazy_entry const* piece_priority = rd.dict_find_string("piece_priority");
|
||||||
|
if (piece_priority && piece_priority->string_length()
|
||||||
|
== m_torrent_file->num_pieces())
|
||||||
|
{
|
||||||
|
char const* p = piece_priority->string_ptr();
|
||||||
|
for (int i = 0; i < piece_priority->string_length(); ++i)
|
||||||
|
m_picker->set_piece_priority(i, p[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rd.dict_find_int_value("auto_managed")) auto_managed(true);
|
||||||
|
if (rd.dict_find_int_value("paused")) pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
void torrent::write_resume_data(entry& ret) const
|
void torrent::write_resume_data(entry& ret) const
|
||||||
|
@ -2515,8 +2531,7 @@ namespace libtorrent
|
||||||
pieces.resize(m_torrent_file->num_pieces());
|
pieces.resize(m_torrent_file->num_pieces());
|
||||||
if (is_seed())
|
if (is_seed())
|
||||||
{
|
{
|
||||||
for (int i = 0, end(pieces.size()); i < end; ++i)
|
std::memset(&pieces[0], 1, pieces.size());
|
||||||
pieces[i] = 1;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -2562,6 +2577,26 @@ namespace libtorrent
|
||||||
peer["port"] = i->second.port;
|
peer["port"] = i->second.port;
|
||||||
peer_list.push_back(peer);
|
peer_list.push_back(peer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret["upload_rate_limit"] = upload_limit();
|
||||||
|
ret["download_rate_limit"] = download_limit();
|
||||||
|
ret["max_connections"] = max_connections();
|
||||||
|
ret["max_uploads"] = max_uploads();
|
||||||
|
ret["paused"] = m_paused;
|
||||||
|
ret["auto_managed"] = m_auto_managed;
|
||||||
|
|
||||||
|
// write piece priorities
|
||||||
|
entry::string_type& piece_priority = ret["piece_priority"].string();
|
||||||
|
piece_priority.resize(m_torrent_file->num_pieces());
|
||||||
|
if (is_seed())
|
||||||
|
{
|
||||||
|
std::memset(&piece_priority[0], 1, pieces.size());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = 0, end(piece_priority.size()); i < end; ++i)
|
||||||
|
piece_priority[i] = m_picker->piece_priority(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void torrent::get_full_peer_list(std::vector<peer_list_entry>& v) const
|
void torrent::get_full_peer_list(std::vector<peer_list_entry>& v) const
|
||||||
|
|
Loading…
Reference in New Issue