From d896e9bab372f205f2a98ea94f3a24c3dd9f60b5 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 29 Mar 2017 19:19:23 -0400 Subject: [PATCH] replace use of add_torrent_params::url in some examples (#1866) replace use of add_torrent_params::url in some examples --- docs/tutorial.rst | 4 +++- examples/bt-get.cpp | 9 ++++++++- examples/bt-get2.cpp | 9 ++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/docs/tutorial.rst b/docs/tutorial.rst index a7433ee5b..8b6c1c5b7 100644 --- a/docs/tutorial.rst +++ b/docs/tutorial.rst @@ -29,6 +29,7 @@ For example: #include #include #include + #include namespace lt = libtorrent; int main(int argc, char const* argv[]) @@ -40,7 +41,8 @@ For example: lt::session ses; lt::add_torrent_params atp; - atp.url = argv[1]; + lt::error_code ec; + lt::parse_magnet_uri(argv[1], atp, ec); atp.save_path = "."; // save in current dir lt::torrent_handle h = ses.add_torrent(atp); diff --git a/examples/bt-get.cpp b/examples/bt-get.cpp index 0029a81bf..6609a5214 100644 --- a/examples/bt-get.cpp +++ b/examples/bt-get.cpp @@ -38,6 +38,8 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include +#include namespace lt = libtorrent; int main(int argc, char const* argv[]) @@ -49,7 +51,12 @@ int main(int argc, char const* argv[]) lt::session ses; lt::add_torrent_params atp; - atp.url = argv[1]; + lt::error_code ec; + lt::parse_magnet_uri(argv[1], atp, ec); + if (ec) { + std::cerr << "invalid magnet URI: " << ec.message() << std::endl; + return 1; + } atp.save_path = "."; // save in current dir lt::torrent_handle h = ses.add_torrent(atp); diff --git a/examples/bt-get2.cpp b/examples/bt-get2.cpp index 93389788b..68a7fe5b1 100644 --- a/examples/bt-get2.cpp +++ b/examples/bt-get2.cpp @@ -41,6 +41,8 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include +#include namespace lt = libtorrent; using clk = std::chrono::steady_clock; @@ -82,7 +84,12 @@ int main(int argc, char const* argv[]) ifs.unsetf(std::ios_base::skipws); atp.resume_data.assign(std::istream_iterator(ifs) , std::istream_iterator()); - atp.url = argv[1]; + lt::error_code ec; + lt::parse_magnet_uri(argv[1], atp, ec); + if (ec) { + std::cerr << "invalid magnet URI: " << ec.message() << std::endl; + return 1; + } atp.save_path = "."; // save in current dir ses.async_add_torrent(atp);