1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-15 02:46:57 +01:00

Don't overwrite existing files

This commit is contained in:
David Sansome 2010-05-03 21:24:43 +00:00
parent c1384f0a0c
commit b114b76e10

View File

@ -20,6 +20,7 @@
#include <QtConcurrentMap>
#include <QtDebug>
#include <QEventLoop>
#include <QFile>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
@ -107,11 +108,24 @@ void Transcoder::AddJob(const QString &input,
job.input = input;
job.output_format = output_format;
// Use the supplied filename if there was one, otherwise take the file
// extension off the input filename and append the correct one.
if (!output.isEmpty())
job.output = output;
else
job.output = input.section('.', 0, -2) + '.' + output_format->file_extension();
// Never overwrite existing files
if (QFile::exists(job.output)) {
for (int i=0 ; ; ++i) {
QString new_filename = QString("%1.%2").arg(job.output).arg(i);
if (!QFile::exists(new_filename)) {
job.output = new_filename;
break;
}
}
}
jobs_ << job;
}