[Libtorrent-commits] SF.net SVN: libtorrent:[10628] branches/mutable_torrents
Brought to you by:
arvidn
From: <ar...@us...> - 2014-12-19 12:49:13
|
Revision: 10628 http://sourceforge.net/p/libtorrent/code/10628 Author: arvidn Date: 2014-12-19 12:49:05 +0000 (Fri, 19 Dec 2014) Log Message: ----------- add mutable torrent support to make_torrent (and fix create_torrent.cpp) Modified Paths: -------------- branches/mutable_torrents/examples/make_torrent.cpp branches/mutable_torrents/src/create_torrent.cpp Modified: branches/mutable_torrents/examples/make_torrent.cpp =================================================================== --- branches/mutable_torrents/examples/make_torrent.cpp 2014-12-19 12:32:32 UTC (rev 10627) +++ branches/mutable_torrents/examples/make_torrent.cpp 2014-12-19 12:49:05 UTC (rev 10628) @@ -39,6 +39,7 @@ #include "libtorrent/create_torrent.hpp" #include "libtorrent/file.hpp" #include "libtorrent/file_pool.hpp" +#include "libtorrent/escape_string.hpp" // for from_hex #include <boost/bind.hpp> @@ -126,29 +127,34 @@ "Generates a torrent file from the specified file\n" "or directory and writes it to standard out\n\n" "OPTIONS:\n" - "-m file generate a merkle hash tree torrent.\n" - " merkle torrents require client support\n" - " the resulting full merkle tree is written to\n" - " the specified file\n" - "-w url adds a web seed to the torrent with\n" - " the specified url\n" - "-t url adds the specified tracker to the\n" - " torrent. For multiple trackers, specify more\n" - " -t options\n" - "-c comment sets the comment to the specified string\n" - "-C creator sets the created-by field to the specified string\n" - "-p bytes enables padding files. Files larger\n" - " than bytes will be piece-aligned\n" - "-s bytes specifies a piece size for the torrent\n" - " This has to be a multiple of 16 kiB\n" - "-l Don't follow symlinks, instead encode them as\n" - " links in the torrent file\n" - "-o file specifies the output filename of the torrent file\n" - " If this is not specified, the torrent file is\n" - " printed to the standard out, except on windows\n" - " where the filename defaults to a.torrent\n" - "-r file add root certificate to the torrent, to verify\n" - " the HTTPS tracker\n" + "-m file generate a merkle hash tree torrent.\n" + " merkle torrents require client support\n" + " the resulting full merkle tree is written to\n" + " the specified file\n" + "-w url adds a web seed to the torrent with\n" + " the specified url\n" + "-t url adds the specified tracker to the\n" + " torrent. For multiple trackers, specify more\n" + " -t options\n" + "-c comment sets the comment to the specified string\n" + "-C creator sets the created-by field to the specified string\n" + "-p bytes enables padding files. Files larger\n" + " than bytes will be piece-aligned\n" + "-s bytes specifies a piece size for the torrent\n" + " This has to be a multiple of 16 kiB\n" + "-l Don't follow symlinks, instead encode them as\n" + " links in the torrent file\n" + "-o file specifies the output filename of the torrent file\n" + " If this is not specified, the torrent file is\n" + " printed to the standard out, except on windows\n" + " where the filename defaults to a.torrent\n" + "-r file add root certificate to the torrent, to verify\n" + " the HTTPS tracker\n" + "-S info-hash add a similar torrent by info-hash. The similar\n" + " torrent is expected to share some files with this one\n" + "-L collection add a collection name to this torrent. Other torrents\n" + " in the same collection is expected to share files\n" + " with this one.\n" , stderr); } @@ -171,6 +177,8 @@ #endif std::vector<std::string> web_seeds; std::vector<std::string> trackers; + std::vector<std::string> collections; + std::vector<sha1_hash> similar; int pad_file_limit = -1; int piece_size = 0; int flags = 0; @@ -235,6 +243,30 @@ ++i; root_cert = argv[i]; break; + case 'S': + { + ++i; + if (strlen(argv[i]) != 40) + { + fprintf(stderr, "invalid info-hash for -S. " + "Expected 40 hex characters\n"); + print_usage(); + return 1; + } + sha1_hash ih; + if (!from_hex(argv[i], 40, (char*)&ih[0])) + { + fprintf(stderr, "invalid info-hash for -S\n"); + print_usage(); + return 1; + } + similar.push_back(ih); + } + break; + case 'L': + ++i; + collections.push_back(argv[i]); + break; default: print_usage(); return 1; @@ -261,6 +293,14 @@ , end(web_seeds.end()); i != end; ++i) t.add_url_seed(*i); + for (std::vector<std::string>::iterator i = collections.begin() + , end(collections.end()); i != end; ++i) + t.add_collection(*i); + + for (std::vector<sha1_hash>::iterator i = similar.begin() + , end(similar.end()); i != end; ++i) + t.add_similar_torrent(*i); + error_code ec; set_piece_hashes(t, parent_path(full_path) , boost::bind(&print_progress, _1, t.num_pieces()), ec); Modified: branches/mutable_torrents/src/create_torrent.cpp =================================================================== --- branches/mutable_torrents/src/create_torrent.cpp 2014-12-19 12:32:32 UTC (rev 10627) +++ branches/mutable_torrents/src/create_torrent.cpp 2014-12-19 12:49:05 UTC (rev 10628) @@ -426,9 +426,16 @@ } } + entry& info = dict["info"]; + if (m_info_dict.type() == entry::dictionary_t) + { + info = m_info_dict; + return dict; + } + if (!m_collections.empty()) { - entry& list = dict["collections"]; + entry& list = info["collections"]; for (std::vector<std::string>::const_iterator i = m_collections.begin(); i != m_collections.end(); ++i) { @@ -438,7 +445,7 @@ if (!m_similar.empty()) { - entry& list = dict["similar"]; + entry& list = info["similar"]; for (std::vector<sha1_hash>::const_iterator i = m_similar.begin(); i != m_similar.end(); ++i) { @@ -446,13 +453,6 @@ } } - entry& info = dict["info"]; - if (m_info_dict.type() == entry::dictionary_t) - { - info = m_info_dict; - return dict; - } - info["name"] = m_files.name(); if (!m_root_cert.empty()) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |