Browse Source

- Forgot to catch an exception when the torrent is invalid

adaptive-webui-19844
Christophe Dumez 18 years ago
parent
commit
a68073a46a
  1. 15
      src/GUI.cpp
  2. 28
      src/torrentAddition.h

15
src/GUI.cpp

@ -438,7 +438,6 @@ void GUI::readParamsInFile(){ @@ -438,7 +438,6 @@ void GUI::readParamsInFile(){
if(params.size()){
qDebug("Received parameters from another instance");
processParams(params);
// addTorrents(params);
}
paramsFile.close();
paramsFile.remove();
@ -1056,12 +1055,12 @@ void GUI::dropEvent(QDropEvent *event){ @@ -1056,12 +1055,12 @@ void GUI::dropEvent(QDropEvent *event){
event->acceptProposedAction();
QStringList files=event->mimeData()->text().split('\n');
// Add file to download list
// addTorrents(files);
QString file;
foreach(file, files){
if(options->useAdditionDialog()){
torrentAdditionDialog *dialog = new torrentAdditionDialog(this, file.trimmed().replace("file://", ""));
connect(dialog, SIGNAL(torrentAddition(QString, bool, QString)), this, SLOT(addTorrent(QString, bool, QString())));
connect(dialog, SIGNAL(setInfoBarGUI(const QString&, const QString&)), this, SLOT(setInfoBar(const QString&, const QString&)));
}else{
addTorrent(file.trimmed().replace("file://", ""));
}
@ -1104,12 +1103,11 @@ void GUI::askForTorrents(){ @@ -1104,12 +1103,11 @@ void GUI::askForTorrents(){
if(options->useAdditionDialog()){
torrentAdditionDialog *dialog = new torrentAdditionDialog(this, pathsList.at(i));
connect(dialog, SIGNAL(torrentAddition(const QString&, bool, const QString&)), this, SLOT(addTorrent(const QString&, bool, const QString&)));
connect(dialog, SIGNAL(setInfoBarGUI(const QString&, const QString&)), this, SLOT(setInfoBar(const QString&, const QString&)));
}else{
addTorrent(pathsList.at(i));
}
}
//Add torrents to download list
// addTorrents(pathsList);
// Save last dir to remember it
lastDirFile.open(QIODevice::WriteOnly | QIODevice::Text);
QStringList top_dir = pathsList.at(0).split(QDir::separator());
@ -1138,13 +1136,11 @@ void GUI::scanDirectory(){ @@ -1138,13 +1136,11 @@ void GUI::scanDirectory(){
if(options->useAdditionDialog()){
torrentAdditionDialog *dialog = new torrentAdditionDialog(this, file, true);
connect(dialog, SIGNAL(torrentAddition(const QString&, bool, const QString&)), this, SLOT(addTorrent(const QString&, bool, const QString&)));
connect(dialog, SIGNAL(setInfoBarGUI(const QString&, const QString&)), this, SLOT(setInfoBar(const QString&, const QString&)));
}else{
addTorrent(file, true);
}
}
// if(!to_add.empty()){
// addTorrents(to_add, true);
// }
}
}
@ -1309,7 +1305,6 @@ void GUI::resumeUnfinished(){ @@ -1309,7 +1305,6 @@ void GUI::resumeUnfinished(){
foreach(fileName, filePaths){
addTorrent(fileName);
}
// addTorrents(filePaths);
qDebug("Unfinished torrents resumed");
}
@ -1481,6 +1476,8 @@ void GUI::addTorrent(const QString& path, bool fromScanDir, const QString& from_ @@ -1481,6 +1476,8 @@ void GUI::addTorrent(const QString& path, bool fromScanDir, const QString& from_
}
setInfoBar(tr("This file is either corrupted or this isn't a torrent."),"red");
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");
}
@ -1608,6 +1605,7 @@ void GUI::processParams(const QStringList& params){ @@ -1608,6 +1605,7 @@ void GUI::processParams(const QStringList& params){
if(options->useAdditionDialog()){
torrentAdditionDialog *dialog = new torrentAdditionDialog(this, param);
connect(dialog, SIGNAL(torrentAddition(const QString&, bool, const QString&)), this, SLOT(addTorrent(const QString&, bool, const QString&)));
connect(dialog, SIGNAL(setInfoBarGUI(const QString&, const QString&)), this, SLOT(setInfoBar(const QString&, const QString&)));
}else{
addTorrent(param);
}
@ -2401,6 +2399,7 @@ void GUI::processDownloadedFile(QString url, QString file_path, int return_code, @@ -2401,6 +2399,7 @@ void GUI::processDownloadedFile(QString url, QString file_path, int return_code,
if(options->useAdditionDialog()){
torrentAdditionDialog *dialog = new torrentAdditionDialog(this, file_path, false, url);
connect(dialog, SIGNAL(torrentAddition(const QString&, bool, const QString&)), this, SLOT(addTorrent(const QString&, bool, const QString&)));
connect(dialog, SIGNAL(setInfoBarGUI(const QString&, const QString&)), this, SLOT(setInfoBar(const QString&, const QString&)));
}else{
addTorrent(file_path, false, url);
}

28
src/torrentAddition.h

@ -51,7 +51,6 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{ @@ -51,7 +51,6 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
QString from_url;
public:
// Check if the torrent in already in download list before calling this dialog
torrentAdditionDialog(QWidget *parent, QString filePath, bool fromScanDir=false, QString from_url=QString::null) : QDialog(parent), filePath(filePath), fromScanDir(fromScanDir), from_url(from_url){
setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
@ -88,12 +87,31 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{ @@ -88,12 +87,31 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
}catch (invalid_torrent_file&){ // Raised by torrent_info constructor
// Display warning to tell user we can't decode the torrent file
if(!from_url.isNull()){
emit setInfoBar(tr("Unable to decode torrent file:")+" '"+from_url+"'", "red");
emit setInfoBarGUI(tr("Unable to decode torrent file:")+" '"+from_url+"'", "red");
}else{
emit setInfoBar(tr("Unable to decode torrent file:")+" '"+filePath+"'", "red");
emit setInfoBarGUI(tr("Unable to decode torrent file:")+" '"+filePath+"'", "red");
}
emit setInfoBar(tr("This file is either corrupted or this isn't a torrent."),"red");
emit setInfoBarGUI(tr("This file is either corrupted or this isn't a torrent."),"red");
if(fromScanDir){
// Remove .corrupt file in case it already exists
QFile::remove(filePath+".corrupt");
//Rename file extension so that it won't display error message more than once
QFile::rename(filePath,filePath+".corrupt");
}
close();
}
catch(invalid_encoding& 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 setInfoBarGUI(tr("Unable to decode torrent file:")+" '"+from_url+"'", "red");
}else{
emit setInfoBarGUI(tr("Unable to decode torrent file:")+" '"+filePath+"'", "red");
}
emit setInfoBarGUI(tr("This file is either corrupted or this isn't a torrent."),"red");
if(fromScanDir){
// Remove .corrupt file in case it already exists
QFile::remove(filePath+".corrupt");
//Rename file extension so that it won't display error message more than once
QFile::rename(filePath,filePath+".corrupt");
}
@ -242,7 +260,7 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{ @@ -242,7 +260,7 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
}
signals:
void setInfoBar(QString message, QString color);
void setInfoBarGUI(const QString& message, const QString& color);
void torrentAddition(const QString& filePath, bool fromScanDir, const QString& from_url);
};

Loading…
Cancel
Save