Skip to content

Commit 1e3ca8f

Browse files
committed
Add fixes for libtorrent-rasterbar 2.0.6
1 parent f81ac2e commit 1e3ca8f

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

mag2tor.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@
3434
#include <libtorrent/torrent_handle.hpp>
3535
#include <libtorrent/torrent_info.hpp>
3636

37+
#if LIBTORRENT_VERSION_NUM >= 20000
38+
#include <libtorrent/download_priority.hpp> // lt::download_priority_t,
39+
// lt::dont_download
40+
#include <libtorrent/units.hpp> // lt::file_index_t
41+
#include <libtorrent/aux_/vector.hpp> // lt::aux::vector<>
42+
#endif
43+
3744
static int usage(const char *argv0) {
3845
std::cerr << "usage: [options] " << argv0 << " <magnet-url>" <<
3946
std::endl;
@@ -163,13 +170,36 @@ int main(int argc, char *argv[]) {
163170
// sess.add_extension(&lt::create_ut_pex_plugin);
164171
// sess.add_extension(&lt::create_smart_ban_plugin);
165172
lt::add_torrent_params atp = lt::parse_magnet_uri(magnet_url);
173+
// Citing add_torrent_params.hpp:
174+
// The add_torrent_params class has a flags field. It can be used
175+
// to control what state the new torrent will be added in. Common
176+
// flags to want to control are torrent_flags::paused and
177+
// torrent_flags::auto_managed. In order to add a magnet link
178+
// that will just download the metadata, but no payload, set the
179+
// torrent_flags::upload_mode flag.
180+
// Hopefully 'upload_mode' works as advertized above, but in case it
181+
// doesn't, use 'disabled_storage_constructor' or long vector with
182+
// 'dont_download' anyway...
166183
atp.flags = lt::torrent_flags::upload_mode
167184
| lt::torrent_flags::auto_managed
168185
| lt::torrent_flags::paused;
169186
#endif
187+
188+
#if LIBTORRENT_VERSION_NUM < 20000
170189
// Start loading torrent metadata with "storage == disabled" to avoid
171190
// pre-allocating any files mentioned in the torrent file on disk:
172191
atp.storage = lt::disabled_storage_constructor;
192+
#else
193+
// XXX:kludge:
194+
// Disable downloading all files in the torrent. But because we don't
195+
// know beforehand how many files will be there, just disable
196+
// downloading first 65535 files in it:
197+
lt::aux::vector<lt::download_priority_t, lt::file_index_t>
198+
dlprio(65535);
199+
for (int i = 0; i < 65535; i++)
200+
dlprio[i] = lt::dont_download;
201+
atp.file_priorities = dlprio;
202+
#endif
173203
atp.save_path = "."; // save in current dir
174204

175205
lt::torrent_handle torh = sess.add_torrent(atp);

0 commit comments

Comments
 (0)