Avoid having empty filenames, or filenames with extension only.
In this case, keep the original filename.
This commit is contained in:
parent
dac137cf11
commit
06184cc5fb
@ -20,6 +20,7 @@
|
||||
#include "taskmanager.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/tagreaderclient.h"
|
||||
#include "core/utilities.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
@ -138,8 +139,8 @@ void Organise::ProcessSomeFiles() {
|
||||
song.set_filetype(task.new_filetype_);
|
||||
|
||||
// Fiddle the filename extension as well to match the new type
|
||||
song.set_url(QUrl::fromLocalFile(FiddleFileExtension(song.basefilename(), task.new_extension_)));
|
||||
song.set_basefilename(FiddleFileExtension(song.basefilename(), task.new_extension_));
|
||||
song.set_url(QUrl::fromLocalFile(Utilities::FiddleFileExtension(song.basefilename(), task.new_extension_)));
|
||||
song.set_basefilename(Utilities::FiddleFileExtension(song.basefilename(), task.new_extension_));
|
||||
|
||||
// Have to set this to the size of the new file or else funny stuff happens
|
||||
song.set_filesize(QFileInfo(task.transcoded_filename_).size());
|
||||
@ -274,12 +275,6 @@ void Organise::FileTranscoded(const QString& filename, bool success) {
|
||||
QTimer::singleShot(0, this, SLOT(ProcessSomeFiles()));
|
||||
}
|
||||
|
||||
QString Organise::FiddleFileExtension(const QString& filename, const QString& new_extension) {
|
||||
if (filename.section('/', -1, -1).contains('.'))
|
||||
return filename.section('.', 0, -2) + "." + new_extension;
|
||||
return filename + "." + new_extension;
|
||||
}
|
||||
|
||||
void Organise::timerEvent(QTimerEvent* e) {
|
||||
QObject::timerEvent(e);
|
||||
|
||||
|
@ -59,8 +59,6 @@ private:
|
||||
void UpdateProgress();
|
||||
Song::FileType CheckTranscode(Song::FileType original_type) const;
|
||||
|
||||
static QString FiddleFileExtension(const QString& filename, const QString& new_extension);
|
||||
|
||||
private:
|
||||
struct Task {
|
||||
explicit Task(const Song& song = Song())
|
||||
|
@ -18,10 +18,12 @@
|
||||
#include "core/organiseformat.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QFileInfo>
|
||||
#include <QPalette>
|
||||
#include <QUrl>
|
||||
|
||||
#include "core/timeconstants.h"
|
||||
#include "core/utilities.h"
|
||||
|
||||
const char* OrganiseFormat::kTagPattern = "\\%([a-zA-Z]*)";
|
||||
const char* OrganiseFormat::kBlockPattern = "\\{([^{}]+)\\}";
|
||||
@ -73,6 +75,14 @@ bool OrganiseFormat::IsValid() const {
|
||||
QString OrganiseFormat::GetFilenameForSong(const Song &song) const {
|
||||
QString filename = ParseBlock(format_, song);
|
||||
|
||||
if (QFileInfo(filename).completeBaseName().isEmpty()) {
|
||||
// Avoid having empty filenames, or filenames with extension only: in this
|
||||
// case, keep the original filename.
|
||||
// We remove the extension from "filename" if it exists, as song.basefilename()
|
||||
// also contains the extension.
|
||||
filename = Utilities::PathWithoutFilenameExtension(filename) + song.basefilename();
|
||||
}
|
||||
|
||||
if (replace_spaces_)
|
||||
filename.replace(QRegExp("\\s"), "_");
|
||||
|
||||
|
@ -667,6 +667,16 @@ QUrl GetRelativePathToClementineBin(const QUrl& url) {
|
||||
return QUrl::fromLocalFile(appPath.relativeFilePath(url.toLocalFile()));
|
||||
}
|
||||
|
||||
QString PathWithoutFilenameExtension(const QString& filename) {
|
||||
if (filename.section('/', -1, -1).contains('.'))
|
||||
return filename.section('.', 0, -2);
|
||||
return filename;
|
||||
}
|
||||
|
||||
QString FiddleFileExtension(const QString& filename, const QString& new_extension) {
|
||||
return PathWithoutFilenameExtension(filename) + "." + new_extension;
|
||||
}
|
||||
|
||||
} // namespace Utilities
|
||||
|
||||
|
||||
|
@ -113,6 +113,9 @@ namespace Utilities {
|
||||
// Get relative path to clementine binary
|
||||
QUrl GetRelativePathToClementineBin(const QUrl& url);
|
||||
|
||||
// Get the path without the filename extension
|
||||
QString PathWithoutFilenameExtension(const QString& filename);
|
||||
QString FiddleFileExtension(const QString& filename, const QString& new_extension);
|
||||
|
||||
enum ConfigPath {
|
||||
Path_Root,
|
||||
|
Loading…
x
Reference in New Issue
Block a user