From 47c2f2e30a536c3a8a2071fa50ed32ffdcf7d92d Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sun, 23 Jan 2011 19:31:48 +0000 Subject: [PATCH] Stop using load_file from libtorrent --- src/qtlibtorrent/qbtsession.cpp | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index 3a5ad4da7..c68fcebc6 100644 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -74,6 +74,7 @@ #include "libtorrent/error_code.hpp" #endif #include +#include using namespace libtorrent; @@ -746,7 +747,13 @@ void QBtSession::resumeTorrent(QString hash) { bool QBtSession::loadFastResumeData(QString hash, std::vector &buf) { const QString fastresume_path = QDir(misc::BTBackupLocation()).absoluteFilePath(hash+QString(".fastresume")); qDebug("Trying to load fastresume data: %s", qPrintable(fastresume_path)); - return (load_file(qPrintable(fastresume_path), buf) == 0); + QFile fastresume_file(fastresume_path); + if(!fastresume_file.open(QIODevice::ReadOnly)) return false; + const QByteArray content = fastresume_file.readAll(); + const int content_size = content.size(); + buf.resize(content_size); + memcpy(&buf[0], content.data(), content_size); + return true; } void QBtSession::loadTorrentSettings(QTorrentHandle h) { @@ -1299,20 +1306,17 @@ void QBtSession::loadSessionState() { return; } #if LIBTORRENT_VERSION_MINOR > 14 + QFile state_file(state_path); + if(!state_file.open(QIODevice::ReadOnly)) return; std::vector in; - if (load_file(state_path.toUtf8().constData(), in) == 0) - { - lazy_entry e; -#if LIBTORRENT_VERSION_MINOR > 15 - error_code ec; - lazy_bdecode(&in[0], &in[0] + in.size(), e, ec); - if(!ec) - s->load_state(e); -#else - if (lazy_bdecode(&in[0], &in[0] + in.size(), e) == 0) - s->load_state(e); -#endif - } + const QByteArray content = state_file.readAll(); + const int content_size = content.size(); + in.resize(content_size); + memcpy(&in[0], content.data(), content_size); + // bdecode + 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.toUtf8().constData() , std::ios_base::binary);