|
From: Yoda-JM <yo...@us...> - 2012-09-16 21:25:33
|
Author: Vincent Le Ligeour <yo...@us...>
Date: Sun Sep 16 23:23:32 2012 +0200
new: make torrent support optionnal
Automatically detect libtorrent availability. Use cmake NO_TORRENT to
explicitly disable torrent support
---
game/CMakeLists.txt | 17 ++++++++++++++++-
game/downloader.cc | 42 ++++++++++++++++++++++++++++++++----------
game/downloader.hh | 7 +++++++
game/main.cc | 2 ++
game/screen_downloads.cc | 2 ++
5 files changed, 59 insertions(+), 11 deletions(-)
diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt
index 7593f6a..97b3974 100644
--- a/game/CMakeLists.txt
+++ b/game/CMakeLists.txt
@@ -71,7 +71,7 @@ include_directories(${Boost_INCLUDE_DIRS})
list(APPEND LIBS ${Boost_LIBRARIES})
# Find all the libs that don't require extra parameters
-foreach(lib ${OUR_LIBS} SDL PangoCairo LibRSVG LibXML++ GLEW AVFormat SWScale OpenGL Z Jpeg Png PortAudio LibTorrent)
+foreach(lib ${OUR_LIBS} SDL PangoCairo LibRSVG LibXML++ GLEW AVFormat SWScale OpenGL Z Jpeg Png PortAudio)
find_package(${lib} REQUIRED)
include_directories(${${lib}_INCLUDE_DIRS})
list(APPEND LIBS ${${lib}_LIBRARIES})
@@ -116,6 +116,21 @@ else()
message(STATUS "Webcam support: Disabled (explicitly disabled)")
endif()
+if(NOT NO_TORRENT)
+ find_package(LibTorrent)
+ if(LibTorrent_FOUND)
+ include_directories(${LibTorrent_INCLUDE_DIRS})
+ list(APPEND LIBS ${LibTorrent_LIBRARIES})
+ add_definitions(${LibTorrent_DEFINITIONS})
+ add_definitions("-DUSE_TORRENT")
+ message(STATUS "Torrent support: Enabled")
+ else()
+ message(STATUS "Torrent support: Disabled (libtorrent-rasterbar not found)")
+ endif()
+else()
+ message(STATUS "Torrent support: Disabled (explicitly disabled)")
+endif()
+
if(APPLE)
# Needed for ffmpeg.cc to compile cleanly on OSX (it's a (unsigned long) long story)
diff --git a/game/downloader.cc b/game/downloader.cc
index b8a15ca..8f31dcf 100644
--- a/game/downloader.cc
+++ b/game/downloader.cc
@@ -5,16 +5,6 @@
#include "fs.hh"
#include "config.hh"
#include "configuration.hh"
-#include "libtorrent/entry.hpp"
-#include "libtorrent/bencode.hpp"
-#include "libtorrent/magnet_uri.hpp"
-#include "libtorrent/torrent_info.hpp"
-#include "libtorrent/file.hpp"
-#include "libtorrent/session.hpp"
-#include "libtorrent/storage.hpp"
-#include "libtorrent/hasher.hpp"
-#include "libtorrent/create_torrent.hpp"
-#include "libtorrent/torrent_info.hpp"
#include "xtime.hh"
#include <iostream>
#include <fstream>
@@ -26,7 +16,22 @@
#include <boost/thread/thread.hpp>
using namespace boost::filesystem;
+
+#ifdef USE_TORRENT
+
+#include "libtorrent/entry.hpp"
+#include "libtorrent/bencode.hpp"
+#include "libtorrent/magnet_uri.hpp"
+#include "libtorrent/torrent_info.hpp"
+#include "libtorrent/file.hpp"
+#include "libtorrent/session.hpp"
+#include "libtorrent/storage.hpp"
+#include "libtorrent/hasher.hpp"
+#include "libtorrent/create_torrent.hpp"
+#include "libtorrent/torrent_info.hpp"
+
using namespace libtorrent;
+
static char const* state_str[] = {"checking (q)", "checking", "dl metadata", "downloading", "finished", "seeding", "allocating", "checking (r)"};
class Downloader::Impl {
@@ -205,6 +210,23 @@ class Downloader::Impl {
return result;
}
};
+#else
+class Downloader::Impl {
+ public:
+ Impl() : m_uploadRate(0), m_downloadRate(0) {}
+ void pause(bool state) {}
+ void pauseResume(std::string sha1) {}
+ void addTorrent(std::string url) {}
+ void removeTorrent(std::string sha1) {}
+ std::vector<Torrent> getTorrents() const {
+ std::vector<Torrent> result;
+ return result;
+ }
+ public:
+ int m_uploadRate;
+ int m_downloadRate;
+};
+#endif
Downloader::Downloader(): self(new Impl) {
ConfigItem::StringList urls = config["dlc/torrent_urls"].sl();
diff --git a/game/downloader.hh b/game/downloader.hh
index bdbc0b5..e8ce360 100644
--- a/game/downloader.hh
+++ b/game/downloader.hh
@@ -28,6 +28,13 @@ class Downloader : boost::noncopyable {
std::vector<Torrent> getTorrents() const;
int getUploadRate() const;
int getDownloadRate() const;
+ static bool enabled() {
+ #ifdef USE_TORRENT
+ return true;
+ #else
+ return false;
+ #endif
+ }
private:
class Impl;
boost::scoped_ptr<Impl> self;
diff --git a/game/main.cc b/game/main.cc
index 876f9ef..ac33cf2 100644
--- a/game/main.cc
+++ b/game/main.cc
@@ -387,5 +387,7 @@ void outputOptionalFeatureStatus() {
(input::MidiDrums::enabled() ? "Enabled" : "Disabled")
<< std::endl << " Webcam support: " <<
(Webcam::enabled() ? "Enabled" : "Disabled")
+ << std::endl << " Torrent support: " <<
+ (Downloader::enabled() ? "Enabled" : "Disabled")
<< std::endl << std::endl;
}
diff --git a/game/screen_downloads.cc b/game/screen_downloads.cc
index 98f5f8b..4a9ab76 100644
--- a/game/screen_downloads.cc
+++ b/game/screen_downloads.cc
@@ -82,6 +82,8 @@ void ScreenDownloads::draw() {
<< ", " << boost::lexical_cast<std::string>(int(round(torrent.progress*100))) << "%"
<< ", size: " << addSuffix(torrent.size)
<< " (down: " << addSuffix(torrent.downloadRate,"/s") << ", up: " << addSuffix(torrent.uploadRate,"/s") << ")";
+ } else if(!Downloader::enabled()) {
+ info << _("Torrent support disabled");
} else {
info << _("No torrent available");
}
|