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

28
src/torrentAddition.h

@ -51,7 +51,6 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
QString from_url; QString from_url;
public: 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){ 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); setupUi(this);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
@ -88,12 +87,31 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
}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 setInfoBar(tr("Unable to decode torrent file:")+" '"+from_url+"'", "red"); emit setInfoBarGUI(tr("Unable to decode torrent file:")+" '"+from_url+"'", "red");
}else{ }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){ 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 //Rename file extension so that it won't display error message more than once
QFile::rename(filePath,filePath+".corrupt"); QFile::rename(filePath,filePath+".corrupt");
} }
@ -242,7 +260,7 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
} }
signals: 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); void torrentAddition(const QString& filePath, bool fromScanDir, const QString& from_url);
}; };

Loading…
Cancel
Save