From a6abedd67daad4d1e45417be38fa2af08337a00f Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Tue, 6 Apr 2010 16:52:17 +0000 Subject: [PATCH] Fix deprecation warnings with libtorrent v0.15 --- src/bittorrent.cpp | 39 ++++++++++++++++++++++++++++++++++++++- src/bittorrent.h | 2 ++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index beb30bc65..730410adb 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 @@ -1328,28 +1332,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)) { @@ -1359,8 +1389,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)); @@ -2281,6 +2316,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 @@ -2297,6 +2333,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 9fe9af925..cb53c11da 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);