From 15ab369f628dc2d7c6eebb6899f851471786057c Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sat, 18 Dec 2010 08:45:39 +0000 Subject: [PATCH] Fix possibly uncaught invalid_handle exception --- src/mainwindow.cpp | 9 ++++++++- src/qtlibtorrent/qbtsession.cpp | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 96227573a..8a86b0722 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -526,7 +526,14 @@ void MainWindow::displayRSSTab() const { void MainWindow::askRecursiveTorrentDownloadConfirmation(const QTorrentHandle &h) { Preferences pref; if(pref.recursiveDownloadDisabled()) return; - QMessageBox confirmBox(QMessageBox::Question, tr("Recursive download confirmation"), tr("The torrent %1 contains torrent files, do you want to proceed with their download?").arg(h.name())); + // Get Torrent name + QString torrent_name; + try { + torrent_name = h.name(); + } catch(invalid_handle&){ + return; + } + QMessageBox confirmBox(QMessageBox::Question, tr("Recursive download confirmation"), tr("The torrent %1 contains torrent files, do you want to proceed with their download?").arg(torrent_name)); QPushButton *yes = confirmBox.addButton(tr("Yes"), QMessageBox::YesRole); /*QPushButton *no = */confirmBox.addButton(tr("No"), QMessageBox::NoRole); QPushButton *never = confirmBox.addButton(tr("Never"), QMessageBox::NoRole); diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index 3c4dd1068..c1188a4fe 100644 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -1880,23 +1880,23 @@ void QBtSession::setProxySettings(const proxy_settings &proxySettings) { } void QBtSession::recursiveTorrentDownload(const QTorrentHandle &h) { - torrent_info::file_iterator it; - for(it = h.get_torrent_info().begin_files(); it != h.get_torrent_info().end_files(); it++) { - const QString torrent_relpath = h.filepath(*it); - if(torrent_relpath.endsWith(".torrent")) { - addConsoleMessage(tr("Recursive download of file %1 embedded in torrent %2", "Recursive download of test.torrent embedded in torrent test2").arg(torrent_relpath).arg(h.name())); - const QString torrent_fullpath = h.save_path()+QDir::separator()+torrent_relpath; - try { + try { + torrent_info::file_iterator it; + for(it = h.get_torrent_info().begin_files(); it != h.get_torrent_info().end_files(); it++) { + const QString torrent_relpath = h.filepath(*it); + if(torrent_relpath.endsWith(".torrent")) { + addConsoleMessage(tr("Recursive download of file %1 embedded in torrent %2", "Recursive download of test.torrent embedded in torrent test2").arg(torrent_relpath).arg(h.name())); + const QString torrent_fullpath = h.save_path()+QDir::separator()+torrent_relpath; + boost::intrusive_ptr t = new torrent_info(torrent_fullpath.toUtf8().constData()); const QString sub_hash = misc::toQString(t->info_hash()); // Passing the save path along to the sub torrent file TorrentTempData::setSavePath(sub_hash, h.save_path()); addTorrent(torrent_fullpath); - } catch(std::exception&) { - qDebug("Caught error loading torrent"); - addConsoleMessage(tr("Unable to decode %1 torrent file.").arg(torrent_fullpath), QString::fromUtf8("red")); } } + } catch(std::exception&) { + qDebug("Caught error loading torrent"); } }