From aa08552686b64fb68f8083f02d589912d6dbaa50 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Tue, 6 Apr 2010 16:55:11 +0000 Subject: [PATCH] Fix deprecation warnings with libtorrent v0.15 --- Changelog | 1 + src/bittorrent.cpp | 39 ++++++++++++++++++++++++++++++++++++++- src/bittorrent.h | 2 ++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 73794b9dd..47dbeb432 100644 --- a/Changelog +++ b/Changelog @@ -3,6 +3,7 @@ - BUGFIX: Fix HTTPS protocol support in torrent/rss downloader - BUGFIX: Fix default width of file name column in torrent content - BUGFIX: Fix torrent addition dialog buttons height + - BUGFIX: Fix deprecation warnings with libtorrent v0.15 * Tue Apr 06 2010 - Christophe Dumez - v2.2.4 - BUGFIX: Fix possible crash when adding a torrent diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 27170b199..94ee1e9ca 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -151,7 +151,9 @@ session_proxy Bittorrent::asyncDeletion() { qDebug("Bittorrent session async deletion IN"); exiting = true; // Do some BT related saving +#ifndef LIBTORRENT_0_15 saveDHTEntry(); +#endif saveSessionState(); saveFastResumeData(); // Delete session @@ -166,7 +168,9 @@ Bittorrent::~Bittorrent() { qDebug("BTSession destructor IN"); if(!exiting) { // Do some BT related saving + #ifndef LIBTORRENT_0_15 saveDHTEntry(); +#endif saveSessionState(); saveFastResumeData(); // Delete session @@ -1324,28 +1328,54 @@ void Bittorrent::enableLSD(bool b) { void Bittorrent::loadSessionState() { const QString state_path = misc::cacheLocation()+QDir::separator()+QString::fromUtf8("ses_state"); +#ifdef LIBTORRENT_0_15 + std::vector in; + if (load_file(state_path.toLocal8Bit().constData(), in) == 0) + { + lazy_entry e; + if (lazy_bdecode(&in[0], &in[0] + in.size(), e) == 0) + s->load_state(e); + } +#else boost::filesystem::ifstream ses_state_file(state_path.toLocal8Bit().constData() , std::ios_base::binary); ses_state_file.unsetf(std::ios_base::skipws); s->load_state(bdecode( std::istream_iterator(ses_state_file) , std::istream_iterator())); +#endif } void Bittorrent::saveSessionState() { qDebug("Saving session state to disk..."); - entry session_state = s->state(); const QString state_path = misc::cacheLocation()+QDir::separator()+QString::fromUtf8("ses_state"); +#ifdef LIBTORRENT_0_15 + entry session_state; + s->save_state(session_state); + std::vector out; + bencode(std::back_inserter(out), session_state); + file f; + error_code ec; + if (f.open(state_path.toLocal8Bit().data(), file::write_only, ec)) { + if (ec) { + file::iovec_t b = {&out[0], out.size()}; + f.writev(0, &b, 1, ec); + } + } +#else + entry session_state = s->state(); boost::filesystem::ofstream out(state_path.toLocal8Bit().constData() , std::ios_base::binary); out.unsetf(std::ios_base::skipws); bencode(std::ostream_iterator(out), session_state); +#endif } // Enable DHT bool Bittorrent::enableDHT(bool b) { if(b) { if(!DHTEnabled) { +#ifndef LIBTORRENT_0_15 entry dht_state; const QString dht_state_path = misc::cacheLocation()+QDir::separator()+QString::fromUtf8("dht_state"); if(QFile::exists(dht_state_path)) { @@ -1355,8 +1385,13 @@ bool Bittorrent::enableDHT(bool b) { dht_state = bdecode(std::istream_iterator(dht_state_file), std::istream_iterator()); }catch (std::exception&) {} } +#endif try { +#ifdef LIBTORRENT_0_15 + s->start_dht(); +#else s->start_dht(dht_state); +#endif s->add_dht_router(std::make_pair(std::string("router.bittorrent.com"), 6881)); s->add_dht_router(std::make_pair(std::string("router.utorrent.com"), 6881)); s->add_dht_router(std::make_pair(std::string("router.bitcomet.com"), 6881)); @@ -2259,6 +2294,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { return sessionStatus.payload_upload_rate; } +#ifndef LIBTORRENT_0_15 // Save DHT entry to hard drive void Bittorrent::saveDHTEntry() { // Save DHT entry @@ -2275,6 +2311,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { } } } +#endif void Bittorrent::applyEncryptionSettings(pe_settings se) { qDebug("Applying encryption settings"); diff --git a/src/bittorrent.h b/src/bittorrent.h index bb7175855..889962537 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -135,7 +135,9 @@ public slots: void resumeTorrent(QString hash); void resumeAllTorrents(); /* End Web UI */ +#ifndef LIBTORRENT_0_15 void saveDHTEntry(); +#endif void preAllocateAllFiles(bool b); void saveFastResumeData(); void enableIPFilter(QString filter);