Fix possibly uncaught invalid_handle exception

This commit is contained in:
Christophe Dumez 2010-12-18 08:45:39 +00:00
parent 29426265a7
commit 15ab369f62
2 changed files with 18 additions and 11 deletions

View file

@ -526,7 +526,14 @@ void MainWindow::displayRSSTab() const {
void MainWindow::askRecursiveTorrentDownloadConfirmation(const QTorrentHandle &h) { void MainWindow::askRecursiveTorrentDownloadConfirmation(const QTorrentHandle &h) {
Preferences pref; Preferences pref;
if(pref.recursiveDownloadDisabled()) return; 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 *yes = confirmBox.addButton(tr("Yes"), QMessageBox::YesRole);
/*QPushButton *no = */confirmBox.addButton(tr("No"), QMessageBox::NoRole); /*QPushButton *no = */confirmBox.addButton(tr("No"), QMessageBox::NoRole);
QPushButton *never = confirmBox.addButton(tr("Never"), QMessageBox::NoRole); QPushButton *never = confirmBox.addButton(tr("Never"), QMessageBox::NoRole);

View file

@ -1880,23 +1880,23 @@ void QBtSession::setProxySettings(const proxy_settings &proxySettings) {
} }
void QBtSession::recursiveTorrentDownload(const QTorrentHandle &h) { void QBtSession::recursiveTorrentDownload(const QTorrentHandle &h) {
torrent_info::file_iterator it; try {
for(it = h.get_torrent_info().begin_files(); it != h.get_torrent_info().end_files(); it++) { torrent_info::file_iterator it;
const QString torrent_relpath = h.filepath(*it); for(it = h.get_torrent_info().begin_files(); it != h.get_torrent_info().end_files(); it++) {
if(torrent_relpath.endsWith(".torrent")) { const QString torrent_relpath = h.filepath(*it);
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())); if(torrent_relpath.endsWith(".torrent")) {
const QString torrent_fullpath = h.save_path()+QDir::separator()+torrent_relpath; 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()));
try { const QString torrent_fullpath = h.save_path()+QDir::separator()+torrent_relpath;
boost::intrusive_ptr<torrent_info> t = new torrent_info(torrent_fullpath.toUtf8().constData()); boost::intrusive_ptr<torrent_info> t = new torrent_info(torrent_fullpath.toUtf8().constData());
const QString sub_hash = misc::toQString(t->info_hash()); const QString sub_hash = misc::toQString(t->info_hash());
// Passing the save path along to the sub torrent file // Passing the save path along to the sub torrent file
TorrentTempData::setSavePath(sub_hash, h.save_path()); TorrentTempData::setSavePath(sub_hash, h.save_path());
addTorrent(torrent_fullpath); 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");
} }
} }