Fix deprecation warnings with libtorrent v0.15

This commit is contained in:
Christophe Dumez
2010-04-06 16:55:11 +00:00
parent fa43393b65
commit aa08552686
3 changed files with 41 additions and 1 deletions

View File

@@ -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 <chris@qbittorrent.org> - v2.2.4
- BUGFIX: Fix possible crash when adding a torrent

View File

@@ -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<char> 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<char>(ses_state_file)
, std::istream_iterator<char>()));
#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<char> 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<char>(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<char>(dht_state_file), std::istream_iterator<char>());
}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");

View File

@@ -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);