|
From: Yoda-JM <yo...@us...> - 2012-09-16 19:22:29
|
Author: Vincent Le Ligeour <yo...@us...>
Date: Sun Sep 16 21:20:44 2012 +0200
change: add capability to set hash and torrent
If you want to set a hash in the configuration just enter hash:<HASH>
and if you want to enter a torrent file : torrent:</path/to/torrent>
---
game/downloader.cc | 18 ++++++++++++++++--
game/downloader.hh | 1 +
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/game/downloader.cc b/game/downloader.cc
index cc377a4..8de8fb8 100644
--- a/game/downloader.cc
+++ b/game/downloader.cc
@@ -18,6 +18,7 @@
#include <fstream>
#include <iterator>
#include <iomanip>
+#include <boost/algorithm/string/predicate.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
@@ -114,7 +115,7 @@ class Downloader::Impl {
m_torrents = torrents;
}
// Sleep a little, much if the cam isn't active
- boost::thread::sleep(now() + 0.5);
+ boost::thread::sleep(now() + 0.2);
}
}
@@ -167,7 +168,20 @@ class Downloader::Impl {
error_code ec;
add_torrent_params params;
params.save_path = savePath.string();
- params.url = url;
+ if (boost::starts_with(url, "hash:")) {
+ // we have a hash
+ params.info_hash = sha1_hash(url.substr(sizeof("hash:")-1));
+ } else if (boost::starts_with(url, "torrent:")) {
+ // we have a torrent file
+ params.ti = new torrent_info(url.substr(sizeof("torrent:")-1).c_str(), ec);
+ if(ec) {
+ std::clog << "torrent/error: cannot add torrent file: " << ec.message() << std::endl;
+ return;
+ }
+ } else {
+ // we have an url (http, magnet, https, other)
+ params.url = url;
+ }
if(config["dlc/autostart"].b()) {
params.flags |= add_torrent_params::flag_auto_managed;
} else {
diff --git a/game/downloader.hh b/game/downloader.hh
index ad301bc..bdbc0b5 100644
--- a/game/downloader.hh
+++ b/game/downloader.hh
@@ -4,6 +4,7 @@
#include <boost/scoped_ptr.hpp>
#include <boost/noncopyable.hpp>
#include <vector>
+#include <string>
struct Torrent {
Torrent() {};
|