1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-20 06:25:02 +01:00

Remove . from the beginning of filenames when organising files. Fixes #4338

This commit is contained in:
David Sansome 2014-05-11 17:50:29 +10:00
parent cf6cdc6936
commit 41425b3c5c
2 changed files with 22 additions and 4 deletions

View File

@ -47,9 +47,13 @@ const QStringList OrganiseFormat::kKnownTags = QStringList() << "title"
<< "grouping"; << "grouping";
// From http://en.wikipedia.org/wiki/8.3_filename#Directory_table // From http://en.wikipedia.org/wiki/8.3_filename#Directory_table
const char* OrganiseFormat::kInvalidFatCharacters = "\"*/\\:<>?|"; const char OrganiseFormat::kInvalidFatCharacters[] = "\"*/\\:<>?|";
const int OrganiseFormat::kInvalidFatCharactersCount = const int OrganiseFormat::kInvalidFatCharactersCount =
strlen(OrganiseFormat::kInvalidFatCharacters); sizeof(OrganiseFormat::kInvalidFatCharacters) - 1;
const char OrganiseFormat::kInvalidPrefixCharacters[] = ".";
const int OrganiseFormat::kInvalidPrefixCharactersCount =
sizeof(OrganiseFormat::kInvalidPrefixCharacters) - 1;
const QRgb OrganiseFormat::SyntaxHighlighter::kValidTagColorLight = const QRgb OrganiseFormat::SyntaxHighlighter::kValidTagColorLight =
qRgb(64, 64, 255); qRgb(64, 64, 255);
@ -116,7 +120,19 @@ QString OrganiseFormat::GetFilenameForSong(const Song& song) const {
filename = stripped; filename = stripped;
} }
return filename; // Fix any parts of the path that start with dots.
QStringList parts = filename.split("/");
for (int i = 0; i < parts.count(); ++i) {
QString* part = &parts[i];
for (int j = 0; j < kInvalidPrefixCharactersCount; ++j) {
if (part->startsWith(kInvalidPrefixCharacters[j])) {
part->replace(0, 1, '_');
break;
}
}
}
return parts.join("/");
} }
QString OrganiseFormat::ParseBlock(QString block, const Song& song, QString OrganiseFormat::ParseBlock(QString block, const Song& song,

View File

@ -30,8 +30,10 @@ class OrganiseFormat {
static const char* kTagPattern; static const char* kTagPattern;
static const char* kBlockPattern; static const char* kBlockPattern;
static const QStringList kKnownTags; static const QStringList kKnownTags;
static const char* kInvalidFatCharacters; static const char kInvalidFatCharacters[];
static const int kInvalidFatCharactersCount; static const int kInvalidFatCharactersCount;
static const char kInvalidPrefixCharacters[];
static const int kInvalidPrefixCharactersCount;
QString format() const { return format_; } QString format() const { return format_; }
bool replace_non_ascii() const { return replace_non_ascii_; } bool replace_non_ascii() const { return replace_non_ascii_; }