From 41425b3c5c3c7fda890fab42b8008ddc41fad9de Mon Sep 17 00:00:00 2001 From: David Sansome Date: Sun, 11 May 2014 17:50:29 +1000 Subject: [PATCH] Remove . from the beginning of filenames when organising files. Fixes #4338 --- src/core/organiseformat.cpp | 22 +++++++++++++++++++--- src/core/organiseformat.h | 4 +++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/core/organiseformat.cpp b/src/core/organiseformat.cpp index b0e650c10..8e00f3d1b 100644 --- a/src/core/organiseformat.cpp +++ b/src/core/organiseformat.cpp @@ -47,9 +47,13 @@ const QStringList OrganiseFormat::kKnownTags = QStringList() << "title" << "grouping"; // From http://en.wikipedia.org/wiki/8.3_filename#Directory_table -const char* OrganiseFormat::kInvalidFatCharacters = "\"*/\\:<>?|"; +const char OrganiseFormat::kInvalidFatCharacters[] = "\"*/\\:<>?|"; 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 = qRgb(64, 64, 255); @@ -116,7 +120,19 @@ QString OrganiseFormat::GetFilenameForSong(const Song& song) const { 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, diff --git a/src/core/organiseformat.h b/src/core/organiseformat.h index 04c3b8f35..e11a24006 100644 --- a/src/core/organiseformat.h +++ b/src/core/organiseformat.h @@ -30,8 +30,10 @@ class OrganiseFormat { static const char* kTagPattern; static const char* kBlockPattern; static const QStringList kKnownTags; - static const char* kInvalidFatCharacters; + static const char kInvalidFatCharacters[]; static const int kInvalidFatCharactersCount; + static const char kInvalidPrefixCharacters[]; + static const int kInvalidPrefixCharactersCount; QString format() const { return format_; } bool replace_non_ascii() const { return replace_non_ascii_; }