From 5d1bfc497a25c98108e6c5365b96bba69d2bfc17 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 27 Nov 2009 22:15:34 +0000 Subject: [PATCH] added torrent_info::remap_files() --- ChangeLog | 1 + docs/manual.rst | 15 +++++++++++++++ include/libtorrent/torrent_info.hpp | 2 ++ src/torrent_info.cpp | 11 +++++++++++ 4 files changed, 29 insertions(+) diff --git a/ChangeLog b/ChangeLog index 65e634c69..b8e2bd3ea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -80,6 +80,7 @@ * automatically caps files and connections by default to rlimit * added session::is_dht_running() function * added torrent_handle::force_dht_announce() + * added torrent_info::remap_files() release 0.14.8 diff --git a/docs/manual.rst b/docs/manual.rst index 11e1d458a..4203ddb39 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -1408,6 +1408,8 @@ The ``torrent_info`` has the following synopsis:: file_storage const& files() const; file_storage const& orig_files() const; + void remap_files(file_storage const& f); + void rename_file(int index, std::string const& new_filename); void rename_file(int index, std::wstring const& new_filename); @@ -1528,6 +1530,19 @@ names. Filename may be chaged using ``torrent_info::rename_file()``. For more information on the ``file_storage`` object, see the separate document on how to create torrents. +remap_files() +------------- + + :: + + void remap_files(file_storage const& f); + +Remaps the file storage to a new file layout. This can be used to, for instance, +download all data in a torrent to a single file, or to a number of fixed size +sector aligned files, regardless of the number and sizes of the files in the torrent. + +The new specified ``file_storage`` must have the exact same size as the current one. + rename_file() ------------- diff --git a/include/libtorrent/torrent_info.hpp b/include/libtorrent/torrent_info.hpp index 402f49589..d213d72f4 100644 --- a/include/libtorrent/torrent_info.hpp +++ b/include/libtorrent/torrent_info.hpp @@ -195,6 +195,8 @@ namespace libtorrent } #endif // TORRENT_USE_WSTRING + void remap_files(file_storage const& f); + void add_tracker(std::string const& url, int tier = 0); std::vector const& trackers() const { return m_urls; } diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index ab42cbdae..fc122dea0 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -451,6 +451,17 @@ namespace libtorrent } } + void torrent_info::remap_files(file_storage const& f) + { + // the new specified file storage must have the exact + // same size as the current file storage + TORRENT_ASSERT(m_files.total_size() == f.total_size()); + + if (m_files.total_size() != f.total_size()) return; + copy_on_write(); + m_files = f; + } + #ifndef TORRENT_NO_DEPRECATE // standard constructor that parses a torrent file torrent_info::torrent_info(entry const& torrent_file)