From 78409570a923507a236d263fb349c945e5d4a017 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Mon, 15 Dec 2008 17:28:05 +0000 Subject: [PATCH] - Fixed crash when dht_state is missing --- src/bittorrent.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 0f05fab3c..d0def6ed5 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -738,12 +738,15 @@ void bittorrent::saveSessionState() { bool bittorrent::enableDHT(bool b) { if(b) { if(!DHTEnabled) { - boost::filesystem::ifstream dht_state_file((misc::qBittorrentPath()+QString::fromUtf8("dht_state")).toUtf8().data(), std::ios_base::binary); - dht_state_file.unsetf(std::ios_base::skipws); entry dht_state; - try{ - dht_state = bdecode(std::istream_iterator(dht_state_file), std::istream_iterator()); - }catch (std::exception&) {} + QString dht_state_path = misc::qBittorrentPath()+QString::fromUtf8("dht_state"); + if(QFile::exists(dht_state_path)) { + boost::filesystem::ifstream dht_state_file(dht_state_path.toUtf8().data(), std::ios_base::binary); + dht_state_file.unsetf(std::ios_base::skipws); + try{ + dht_state = bdecode(std::istream_iterator(dht_state_file), std::istream_iterator()); + }catch (std::exception&) {} + } try { s->start_dht(dht_state); s->add_dht_router(std::make_pair(std::string("router.bittorrent.com"), 6881));