diff --git a/docs/manual.rst b/docs/manual.rst index 4c5cd2f91..957e80528 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -1222,6 +1222,7 @@ The ``torrent_info`` has the following synopsis:: torrent_info(lazy_entry const& torrent_file); torrent_info(char const* buffer, int size); torrent_info(boost::filesystem::path const& filename); + torrent_info(boost::filesystem::wpath const& filename); void add_tracker(std::string const& url, int tier = 0); std::vector const& trackers() const; @@ -1280,6 +1281,7 @@ torrent_info() torrent_info(lazy_entry const& torrent_file); torrent_info(char const* buffer, int size); torrent_info(boost::filesystem::path const& filename); + torrent_info(boost::filesystem::wpath const& filename); The constructor that takes an info-hash will initialize the info-hash to the given value, but leave all other fields empty. This is used internally when downloading torrents without diff --git a/include/libtorrent/torrent_info.hpp b/include/libtorrent/torrent_info.hpp index a6127e534..a02ddec82 100644 --- a/include/libtorrent/torrent_info.hpp +++ b/include/libtorrent/torrent_info.hpp @@ -171,6 +171,7 @@ namespace libtorrent torrent_info(lazy_entry const& torrent_file); torrent_info(char const* buffer, int size); torrent_info(fs::path const& filename); + torrent_info(fs::wpath const& filename); ~torrent_info(); file_storage const& files() const { return m_files; } diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index 30a5cf00b..a75dcf225 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -58,6 +58,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/hasher.hpp" #include "libtorrent/entry.hpp" #include "libtorrent/file.hpp" +#include "libtorrent/utf8.hpp" namespace gr = boost::gregorian; @@ -359,6 +360,35 @@ namespace libtorrent #endif } + torrent_info::torrent_info(fs::wpath const& filename) + : m_creation_date(pt::ptime(pt::not_a_date_time)) + , m_multifile(false) + , m_private(false) + { + std::vector buf; + std::string utf8; + wchar_utf8(filename.string(), utf8); + int ret = load_file(utf8, buf); + if (ret < 0) return; + + if (buf.empty()) +#ifndef BOOST_NO_EXCEPTIONS + throw invalid_torrent_file(); +#else + return; +#endif + + lazy_entry e; + lazy_bdecode(&buf[0], &buf[0] + buf.size(), e); + std::string error; +#ifndef BOOST_NO_EXCEPTIONS + if (!parse_torrent_file(e, error)) + throw invalid_torrent_file(); +#else + parse_torrent_file(e, error); +#endif + } + torrent_info::~torrent_info() {}