Browse Source

- Catch more exceptions when adding a torrent

adaptive-webui-19844
Christophe Dumez 17 years ago
parent
commit
07c195f475
  1. 16
      src/bittorrent.cpp
  2. 21
      src/torrentAddition.h

16
src/bittorrent.cpp

@ -557,6 +557,22 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url, bo
QFile::rename(file,file+".corrupt"); QFile::rename(file,file+".corrupt");
} }
} }
catch (std::exception& e) {
std::cerr << "Could not decode file, reason: " << e.what() << '\n';
// Display warning to tell user we can't decode the torrent file
if(!from_url.isNull()) {
emit invalidTorrent(from_url);
QFile::remove(file);
}else{
emit invalidTorrent(file);
}
if(fromScanDir) {
// Remove .corrupt file in case it already exists
QFile::remove(file+".corrupt");
//Rename file extension so that it won't display error message more than once
QFile::rename(file,file+".corrupt");
}
}
} }
// Check in .priorities file if the user filtered files // Check in .priorities file if the user filtered files

21
src/torrentAddition.h

@ -121,7 +121,8 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
delete arb; delete arb;
connect(PropListModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updatePriorities(QStandardItem*))); connect(PropListModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updatePriorities(QStandardItem*)));
torrentContentList->expandAll(); torrentContentList->expandAll();
}catch (invalid_torrent_file&){ // Raised by torrent_info constructor }
catch (invalid_torrent_file&){ // Raised by torrent_info constructor
// Display warning to tell user we can't decode the torrent file // Display warning to tell user we can't decode the torrent file
if(!from_url.isNull()){ if(!from_url.isNull()){
emit setInfoBarGUI(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+from_url+QString::fromUtf8("'"), QString::fromUtf8("red")); emit setInfoBarGUI(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+from_url+QString::fromUtf8("'"), QString::fromUtf8("red"));
@ -157,6 +158,24 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
} }
close(); close();
} }
catch(std::exception& e){
std::cerr << "Could not decode file, reason: " << e.what() << '\n';
if(!from_url.isNull()){
emit setInfoBarGUI(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+from_url+QString::fromUtf8("'"), QString::fromUtf8("red"));
QFile::remove(filePath);
}else{
emit setInfoBarGUI(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+filePath+QString::fromUtf8("'"), QString::fromUtf8("red"));
}
qDebug("path is %s", filePath.toUtf8().data());
emit setInfoBarGUI(tr("This file is either corrupted or this isn't a torrent."), QString::fromUtf8("red"));
if(fromScanDir){
// Remove .corrupt file in case it already exists
QFile::remove(filePath+QString::fromUtf8(".corrupt"));
//Rename file extension so that it won't display error message more than once
QFile::rename(filePath,filePath+QString::fromUtf8(".corrupt"));
}
close();
}
show(); show();
} }

Loading…
Cancel
Save