|
34 | 34 | #include <libtorrent/torrent_handle.hpp> |
35 | 35 | #include <libtorrent/torrent_info.hpp> |
36 | 36 |
|
| 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 | + |
37 | 44 | static int usage(const char *argv0) { |
38 | 45 | std::cerr << "usage: [options] " << argv0 << " <magnet-url>" << |
39 | 46 | std::endl; |
@@ -163,13 +170,36 @@ int main(int argc, char *argv[]) { |
163 | 170 | // sess.add_extension(<::create_ut_pex_plugin); |
164 | 171 | // sess.add_extension(<::create_smart_ban_plugin); |
165 | 172 | 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... |
166 | 183 | atp.flags = lt::torrent_flags::upload_mode |
167 | 184 | | lt::torrent_flags::auto_managed |
168 | 185 | | lt::torrent_flags::paused; |
169 | 186 | #endif |
| 187 | + |
| 188 | +#if LIBTORRENT_VERSION_NUM < 20000 |
170 | 189 | // Start loading torrent metadata with "storage == disabled" to avoid |
171 | 190 | // pre-allocating any files mentioned in the torrent file on disk: |
172 | 191 | 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 |
173 | 203 | atp.save_path = "."; // save in current dir |
174 | 204 |
|
175 | 205 | lt::torrent_handle torh = sess.add_torrent(atp); |
|
0 commit comments