merged get_torrent_info deprecation from libtorrent_aio, replaced by torrent_file()

This commit is contained in:
Arvid Norberg 2012-10-02 16:07:55 +00:00
parent bff648a89e
commit 5bc322c031
6 changed files with 73 additions and 51 deletions

View File

@ -2302,7 +2302,7 @@ Its declaration looks like this::
void file_progress(std::vector<size_type>& fp, int flags = 0);
void get_download_queue(std::vector<partial_piece_info>& queue) const;
void get_peer_info(std::vector<peer_info>& v) const;
torrent_info const& get_torrent_info() const;
boost::intrusive_ptr<torrent_info> torrent_file() const;
bool is_valid() const;
std::string name() const;
@ -3204,7 +3204,7 @@ Example code to pause and save resume data for all torrents and wait for the ale
}
torrent_handle h = rd->handle;
std::ofstream out((h.save_path() + "/" + h.get_torrent_info().name() + ".fastresume").c_str()
std::ofstream out((h.save_path() + "/" + h.torrent_file()->name() + ".fastresume").c_str()
, std::ios_base::binary);
out.unsetf(std::ios_base::skipws);
bencode(std::ostream_iterator<char>(out), *rd->resume_data);
@ -3347,18 +3347,18 @@ torrent_handle_ is invalid, it will throw libtorrent_exception_ exception. Each
the vector contains information about that particular peer. See peer_info_.
get_torrent_info()
------------------
torrent_file()
--------------
::
torrent_info const& get_torrent_info() const;
boost::intrusive_ptr<torrent_info> torrent_file() const;
Returns a const reference to the torrent_info_ object associated with this torrent.
This reference is valid as long as the torrent_handle_ is valid, no longer. If the
torrent_handle_ is invalid or if it doesn't have any metadata, libtorrent_exception_
exception will be thrown. The torrent may be in a state without metadata only if
it was started without a .torrent file, i.e. by using the libtorrent extension of
Returns a pointer to the torrent_info_ object associated with this torrent. The
``torrent_info`` object is a copy of the internal object. If the torrent doesn't
have metadata, the object being returned will not be fully filled in.
The torrent may be in a state without metadata only if
it was started without a .torrent file, e.g. by using the libtorrent extension of
just supplying a tracker and info-hash.
@ -3616,8 +3616,7 @@ set to priority 0, i.e. are not downloaded.
``has_metadata`` is true if this torrent has metadata (either it was started from a
.torrent file or the metadata has been downloaded). The only scenario where this can be
false is when the torrent was started torrent-less (i.e. with just an info-hash and tracker
ip, a magnet link for instance). Note that if the torrent doesn't have metadata, the member
`get_torrent_info()`_ will throw.
ip, a magnet link for instance).
``error`` may be set to an error message describing why the torrent was paused, in
case it was paused by an error. If the torrent is not paused or if it's paused but
@ -7171,12 +7170,12 @@ code to do that::
torrent_handle h = alert->handle();
if (h.is_valid()) {
torrent_info const& ti = h.get_torrent_info();
create_torrent ct(ti);
boost::intrusive_ptr<torrent_info const> ti = h.torrent_file();
create_torrent ct(*ti);
entry te = ct.generate();
std::vector<char> buffer;
bencode(std::back_inserter(buffer), te);
FILE* f = fopen((to_hex(ti.info_hash().to_string()) + ".torrent").c_str(), "w+");
FILE* f = fopen((to_hex(ti->info_hash().to_string()) + ".torrent").c_str(), "w+");
if (f) {
fwrite(&buffer[0], 1, buffer.size(), f);
fclose(f);
@ -7594,7 +7593,7 @@ Examples usage::
// write fast resume data
// ...
std::cout << a.handle.get_torrent_info().name() << "completed"
std::cout << a.handle.torrent_file()->name() << "completed"
<< std::endl;
}
};

View File

@ -884,6 +884,8 @@ bool handle_alert(libtorrent::session& ses, libtorrent::alert* a
}
#endif
boost::intrusive_ptr<torrent_info> ti;
if (metadata_received_alert* p = alert_cast<metadata_received_alert>(a))
{
// if we have a monitor dir, save the .torrent file we just received in it
@ -891,12 +893,12 @@ bool handle_alert(libtorrent::session& ses, libtorrent::alert* a
// to keep the scan dir logic in sync so it's not removed, or added twice
torrent_handle h = p->handle;
if (h.is_valid()) {
torrent_info const& ti = h.get_torrent_info();
create_torrent ct(ti);
if (!ti) ti = h.torrent_file();
create_torrent ct(*ti);
entry te = ct.generate();
std::vector<char> buffer;
bencode(std::back_inserter(buffer), te);
std::string filename = ti.name() + "." + to_hex(ti.info_hash().to_string()) + ".torrent";
std::string filename = ti->name() + "." + to_hex(ti->info_hash().to_string()) + ".torrent";
filename = combine_path(monitor_dir, filename);
save_file(filename, buffer);
@ -930,7 +932,9 @@ bool handle_alert(libtorrent::session& ses, libtorrent::alert* a
h.set_max_uploads(-1);
h.set_upload_limit(torrent_upload_limit);
h.set_download_limit(torrent_download_limit);
#ifndef TORRENT_NO_DEPRECATE
h.use_interface(outgoing_interface.c_str());
#endif
#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
h.resolve_countries(true);
#endif
@ -2273,15 +2277,15 @@ int main(int argc, char* argv[])
{
std::vector<size_type> file_progress;
h.file_progress(file_progress);
torrent_info const& info = h.get_torrent_info();
for (int i = 0; i < info.num_files(); ++i)
boost::intrusive_ptr<torrent_info> ti = h.torrent_file();
for (int i = 0; i < ti->num_files(); ++i)
{
bool pad_file = info.file_at(i).pad_file;
bool pad_file = ti->file_at(i).pad_file;
if (!show_pad_files && pad_file) continue;
int progress = info.file_at(i).size > 0
?file_progress[i] * 1000 / info.file_at(i).size:1000;
int progress = ti->file_at(i).size > 0
?file_progress[i] * 1000 / ti->file_at(i).size:1000;
char const* color = (file_progress[i] == info.file_at(i).size)
char const* color = (file_progress[i] == ti->file_at(i).size)
?"32":"33";
snprintf(str, sizeof(str), "%s %s %-5.2f%% %s %s%s\n",
@ -2289,7 +2293,7 @@ int main(int argc, char* argv[])
, pad_file?esc("34"):""
, progress / 10.f
, add_suffix(file_progress[i]).c_str()
, filename(info.files().file_path(info.file_at(i))).c_str()
, ti->files().file_name(i).c_str()
, pad_file?esc("0"):"");
out += str;
}

View File

@ -721,6 +721,8 @@ namespace libtorrent
torrent_info const& torrent_file() const
{ return *m_torrent_file; }
boost::intrusive_ptr<torrent_info> get_torrent_copy();
std::string const& uuid() const { return m_uuid; }
void set_uuid(std::string const& s) { m_uuid = s; }
std::string const& url() const { return m_url; }

View File

@ -226,7 +226,7 @@ namespace libtorrent
#endif
bool set_metadata(char const* metadata, int size) const;
const torrent_info& get_torrent_info() const;
bool is_valid() const;
enum pause_flags_t { graceful_pause = 1 };
@ -264,12 +264,16 @@ namespace libtorrent
storage_interface* get_storage_impl() const;
// all these are deprecated, use piece
// priority functions instead
boost::intrusive_ptr<torrent_info> torrent_file() const;
#ifndef TORRENT_NO_DEPRECATE
// ================ start deprecation ============
#ifndef TORRENT_NO_DEPRECATE
// use torrent_file() instead
TORRENT_DEPRECATED_PREFIX
const torrent_info& get_torrent_info() const TORRENT_DEPRECATED;
// deprecated in 0.16, feature will be removed
TORRENT_DEPRECATED_PREFIX
int get_peer_upload_limit(tcp::endpoint ip) const TORRENT_DEPRECATED;
@ -301,6 +305,8 @@ namespace libtorrent
bool super_seeding() const TORRENT_DEPRECATED;
// deprecated in 0.13
// all these are deprecated, use piece
// priority functions instead
// marks the piece with the given index as filtered
// it will not be downloaded
TORRENT_DEPRECATED_PREFIX
@ -316,6 +322,14 @@ namespace libtorrent
TORRENT_DEPRECATED_PREFIX
void filter_files(std::vector<bool> const& files) const TORRENT_DEPRECATED;
TORRENT_DEPRECATED_PREFIX
void use_interface(const char* net_interface) const TORRENT_DEPRECATED;
// deprecated in 0.14
// use save_resume_data() instead. It is async. and
// will return the resume data in an alert
TORRENT_DEPRECATED_PREFIX
entry write_resume_data() const TORRENT_DEPRECATED;
// ================ end deprecation ============
#endif
@ -335,18 +349,6 @@ namespace libtorrent
void prioritize_files(std::vector<int> const& files) const;
std::vector<int> file_priorities() const;
// set the interface to bind outgoing connections
// to.
void use_interface(const char* net_interface) const;
#ifndef TORRENT_NO_DEPRECATE
// deprecated in 0.14
// use save_resume_data() instead. It is async. and
// will return the resume data in an alert
TORRENT_DEPRECATED_PREFIX
entry write_resume_data() const TORRENT_DEPRECATED;
#endif
// forces this torrent to reannounce
// (make a rerequest from the tracker)
void force_reannounce() const;

View File

@ -5185,6 +5185,12 @@ namespace libtorrent
}
}
}
boost::intrusive_ptr<torrent_info> torrent::get_torrent_copy()
{
// copy the torrent_info object
return boost::intrusive_ptr<torrent_info>(new torrent_info(*m_torrent_file));
}
void torrent::write_resume_data(entry& ret) const
{
@ -8197,7 +8203,7 @@ namespace libtorrent
for (int i = 0; i < m_torrent_file->num_files(); ++i)
{
peer_request ret = m_torrent_file->files().map_file(i, 0, 0);
size_type size = m_torrent_file->files().at(i).size;
size_type size = m_torrent_file->files().file_size(i);
// zero sized files are considered
// 100% done all the time

View File

@ -825,6 +825,23 @@ namespace libtorrent
return r;
}
bool torrent_handle::is_valid() const
{
INVARIANT_CHECK;
return !m_torrent.expired();
}
boost::intrusive_ptr<torrent_info> torrent_handle::torrent_file() const
{
INVARIANT_CHECK;
TORRENT_SYNC_CALL_RET(boost::intrusive_ptr<torrent_info>, boost::intrusive_ptr<torrent_info>(), get_torrent_copy);
return r;
}
#ifndef TORRENT_NO_DEPRECATE
// this function should either be removed, or return
// reference counted handle to the torrent_info which
// forces the torrent to stay loaded while the client holds it
torrent_info const& torrent_handle::get_torrent_info() const
{
INVARIANT_CHECK;
@ -838,7 +855,6 @@ namespace libtorrent
#else
throw_invalid_handle();
#endif
// mutex::scoped_lock l(t->session().m_mutex);
if (!t->valid_metadata())
#ifdef BOOST_NO_EXCEPTIONS
return empty;
@ -848,13 +864,6 @@ namespace libtorrent
return t->torrent_file();
}
bool torrent_handle::is_valid() const
{
INVARIANT_CHECK;
return !m_torrent.expired();
}
#ifndef TORRENT_NO_DEPRECATE
entry torrent_handle::write_resume_data() const
{
INVARIANT_CHECK;