formatting fixes in client test, and made the test build when resolve countries is...
[libtorrent-kjk.git] / examples / dump_torrent.cpp
blob92ba663fe15f177a6746914ea0441862943227f0
1 /*
3 Copyright (c) 2003, Arvid Norberg
4 All rights reserved.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
10 * Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in
14 the documentation and/or other materials provided with the distribution.
15 * Neither the name of the author nor the names of its
16 contributors may be used to endorse or promote products derived
17 from this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 POSSIBILITY OF SUCH DAMAGE.
33 #include <iostream>
34 #include <fstream>
35 #include <iterator>
36 #include <iomanip>
38 #include "libtorrent/entry.hpp"
39 #include "libtorrent/bencode.hpp"
40 #include "libtorrent/torrent_info.hpp"
43 int main(int argc, char* argv[])
45 using namespace libtorrent;
47 if (argc != 2)
49 std::cerr << "usage: dump_torrent torrent-file\n";
50 return 1;
52 #if BOOST_VERSION < 103400
53 boost::filesystem::path::default_name_check(boost::filesystem::no_check);
54 #endif
56 try
58 std::ifstream in(argv[1], std::ios_base::binary);
59 in.unsetf(std::ios_base::skipws);
60 entry e = bdecode(std::istream_iterator<char>(in), std::istream_iterator<char>());
62 std::cout << "\n\n----- raw info -----\n\n";
63 e.print(std::cout);
65 torrent_info t(e);
67 // print info about torrent
68 std::cout << "\n\n----- torrent file info -----\n\n";
69 std::cout << "nodes:\n";
70 typedef std::vector<std::pair<std::string, int> > node_vec;
71 node_vec const& nodes = t.nodes();
72 for (node_vec::const_iterator i = nodes.begin(), end(nodes.end());
73 i != end; ++i)
75 std::cout << i->first << ":" << i->second << "\n";
77 std::cout << "trackers:\n";
78 for (std::vector<announce_entry>::const_iterator i = t.trackers().begin();
79 i != t.trackers().end(); ++i)
81 std::cout << i->tier << ": " << i->url << "\n";
84 std::cout << "number of pieces: " << t.num_pieces() << "\n";
85 std::cout << "piece length: " << t.piece_length() << "\n";
86 std::cout << "info hash: " << t.info_hash() << "\n";
87 std::cout << "comment: " << t.comment() << "\n";
88 std::cout << "created by: " << t.creator() << "\n";
89 std::cout << "files:\n";
90 for (torrent_info::file_iterator i = t.begin_files();
91 i != t.end_files(); ++i)
93 std::cout << " " << std::setw(11) << i->size
94 << " " << i->path.string() << "\n";
98 catch (std::exception& e)
100 std::cout << e.what() << "\n";
103 return 0;