Use QFileInfo instead of custom functions
This commit is contained in:
@@ -785,15 +785,6 @@ QUrl GetRelativePathToStrawberryBin(const QUrl &url) {
|
|||||||
return QUrl::fromLocalFile(appPath.relativeFilePath(url.toLocalFile()));
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString GetEnv(const QString &key) {
|
QString GetEnv(const QString &key) {
|
||||||
return QString::fromLocal8Bit(qgetenv(key.toLocal8Bit()));
|
return QString::fromLocal8Bit(qgetenv(key.toLocal8Bit()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,10 +114,6 @@ bool UrlOnSameDriveAsStrawberry(const QUrl &url);
|
|||||||
// Get relative path to Strawberry binary
|
// Get relative path to Strawberry binary
|
||||||
QUrl GetRelativePathToStrawberryBin(const QUrl &url);
|
QUrl GetRelativePathToStrawberryBin(const QUrl &url);
|
||||||
|
|
||||||
// Get the path without the filename extension
|
|
||||||
QString PathWithoutFilenameExtension(const QString &filename);
|
|
||||||
QString FiddleFileExtension(const QString &filename, const QString &new_extension);
|
|
||||||
|
|
||||||
QString GetEnv(const QString &key);
|
QString GetEnv(const QString &key);
|
||||||
void SetEnv(const char *key, const QString &value);
|
void SetEnv(const char *key, const QString &value);
|
||||||
void IncreaseFDLimit();
|
void IncreaseFDLimit();
|
||||||
|
|||||||
@@ -33,7 +33,6 @@
|
|||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
|
||||||
#include "core/logging.h"
|
#include "core/logging.h"
|
||||||
#include "core/utilities.h"
|
|
||||||
#include "core/taskmanager.h"
|
#include "core/taskmanager.h"
|
||||||
#include "core/musicstorage.h"
|
#include "core/musicstorage.h"
|
||||||
#include "core/tagreaderclient.h"
|
#include "core/tagreaderclient.h"
|
||||||
@@ -172,9 +171,9 @@ void Organize::ProcessSomeFiles() {
|
|||||||
song.set_filetype(task.new_filetype_);
|
song.set_filetype(task.new_filetype_);
|
||||||
|
|
||||||
// Fiddle the filename extension as well to match the new type
|
// Fiddle the filename extension as well to match the new type
|
||||||
song.set_url(QUrl::fromLocalFile(Utilities::FiddleFileExtension(song.basefilename(), task.new_extension_)));
|
song.set_url(QUrl::fromLocalFile(QFileInfo(song.basefilename()).completeBaseName() + "." + task.new_extension_));
|
||||||
song.set_basefilename(Utilities::FiddleFileExtension(song.basefilename(), task.new_extension_));
|
song.set_basefilename(QFileInfo(song.basefilename()).completeBaseName() + "." + task.new_extension_);
|
||||||
task.song_info_.new_filename_ = Utilities::FiddleFileExtension(task.song_info_.new_filename_, task.new_extension_);
|
task.song_info_.new_filename_ = QFileInfo(task.song_info_.new_filename_).completeBaseName() + "." + task.new_extension_;
|
||||||
|
|
||||||
// Have to set this to the size of the new file or else funny stuff happens
|
// Have to set this to the size of the new file or else funny stuff happens
|
||||||
song.set_filesize(QFileInfo(task.transcoded_filename_).size());
|
song.set_filesize(QFileInfo(task.transcoded_filename_).size());
|
||||||
|
|||||||
@@ -420,7 +420,7 @@ Organize::NewSongInfoList OrganizeDialog::ComputeNewSongsFilenames(const SongLis
|
|||||||
QString new_filename = format.GetFilenameForSong(song, extension);
|
QString new_filename = format.GetFilenameForSong(song, extension);
|
||||||
if (filenames.contains(new_filename)) {
|
if (filenames.contains(new_filename)) {
|
||||||
QString song_number = QString::number(++filenames[new_filename]);
|
QString song_number = QString::number(++filenames[new_filename]);
|
||||||
new_filename = Utilities::PathWithoutFilenameExtension(new_filename) + "(" + song_number + ")." + QFileInfo(new_filename).suffix();
|
new_filename = QFileInfo(new_filename).completeBaseName() + "(" + song_number + ")." + QFileInfo(new_filename).suffix();
|
||||||
}
|
}
|
||||||
filenames.insert(new_filename, 1);
|
filenames.insert(new_filename, 1);
|
||||||
new_songs_info << Organize::NewSongInfo(song, new_filename);
|
new_songs_info << Organize::NewSongInfo(song, new_filename);
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ QString OrganizeFormat::GetFilenameForSong(const Song &song, QString extension)
|
|||||||
if (QFileInfo(filename).completeBaseName().isEmpty()) {
|
if (QFileInfo(filename).completeBaseName().isEmpty()) {
|
||||||
// Avoid having empty filenames, or filenames with extension only: in this case, keep the original filename.
|
// 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.
|
// We remove the extension from "filename" if it exists, as song.basefilename() also contains the extension.
|
||||||
filename = Utilities::PathWithoutFilenameExtension(filename) + song.basefilename();
|
filename = QFileInfo(filename).path() + "/" + song.basefilename();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (remove_problematic_) filename = filename.remove(kProblematicCharacters);
|
if (remove_problematic_) filename = filename.remove(kProblematicCharacters);
|
||||||
|
|||||||
Reference in New Issue
Block a user