From 93d4fb14ee30fb4403ccdfcaf2f5a77a02228344 Mon Sep 17 00:00:00 2001 From: lordmulder Date: Thu, 4 Aug 2011 20:35:40 +0200 Subject: [PATCH] Make lamexp_clean_filename() a global function. --- src/Config.h | 2 +- src/Global.cpp | 33 +++++++++++++++++++++++++++++++++ src/Global.h | 2 ++ src/Thread_CueSplitter.cpp | 23 ++--------------------- 4 files changed, 38 insertions(+), 22 deletions(-) diff --git a/src/Config.h b/src/Config.h index 84265510..6a7db31b 100644 --- a/src/Config.h +++ b/src/Config.h @@ -30,7 +30,7 @@ #define VER_LAMEXP_MINOR_LO 3 #define VER_LAMEXP_TYPE Alpha #define VER_LAMEXP_PATCH 6 -#define VER_LAMEXP_BUILD 612 +#define VER_LAMEXP_BUILD 613 /////////////////////////////////////////////////////////////////////////////// // Tools versions diff --git a/src/Global.cpp b/src/Global.cpp index 8e7750f1..5b71f543 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -1535,6 +1535,39 @@ void lamexp_blink_window(QWidget *poWindow, unsigned int count, unsigned int del } } +/* + * Remove forbidden characters from a filename + */ +const QString lamexp_clean_filename(const QString &str) +{ + QString fixedStr(str); + fixedStr.replace("\\", "-"); + fixedStr.replace(" / ", ", "); + fixedStr.replace("/", ","); + fixedStr.replace(":", "-"); + fixedStr.replace("*", "x"); + fixedStr.replace("?", ""); + fixedStr.replace("<", "["); + fixedStr.replace(">", "]"); + fixedStr.replace("|", "!"); + return fixedStr; +} + +/* + * Remove forbidden characters from a file path + */ +const QString lamexp_clean_filepath(const QString &str) +{ + QStringList parts = QString(str).replace("\\", "/").split("/"); + + for(int i = 0; i < parts.count(); i++) + { + parts[i] = lamexp_clean_filename(parts[i]); + } + + return parts.join("/"); +} + /* * Finalization function (final clean-up) */ diff --git a/src/Global.h b/src/Global.h index 6bd12fe6..f6bc00cc 100644 --- a/src/Global.h +++ b/src/Global.h @@ -120,6 +120,8 @@ __int64 lamexp_free_diskspace(const QString &path); bool lamexp_remove_file(const QString &filename); bool lamexp_themes_enabled(void); void lamexp_blink_window(QWidget *poWindow, unsigned int count = 10, unsigned int delay = 150); +const QString lamexp_clean_filename(const QString &str); +const QString lamexp_clean_filepath(const QString &str); //Debug-only functions SIZE_T lamexp_dbg_private_bytes(void); diff --git a/src/Thread_CueSplitter.cpp b/src/Thread_CueSplitter.cpp index 0d2f7e51..6b27841e 100644 --- a/src/Thread_CueSplitter.cpp +++ b/src/Thread_CueSplitter.cpp @@ -39,25 +39,6 @@ #include #include -//////////////////////////////////////////////////////////// -// Helper function -//////////////////////////////////////////////////////////// - -static QString clean(const QString &str) -{ - QString fixedStr(str); - fixedStr.replace("\\", "-"); - fixedStr.replace(" / ", ", "); - fixedStr.replace("/", ","); - fixedStr.replace(":", "-"); - fixedStr.replace("*", "x"); - fixedStr.replace("?", ""); - fixedStr.replace("<", "["); - fixedStr.replace(">", "]"); - fixedStr.replace("|", "!"); - return fixedStr; -} - //////////////////////////////////////////////////////////// // Constructor //////////////////////////////////////////////////////////// @@ -210,10 +191,10 @@ void CueSplitter::run() //Generate output file name QString trackTitle = trackMetaInfo.fileName().isEmpty() ? QString().sprintf("Track %02d", trackNo) : trackMetaInfo.fileName(); - QString outputFile = QString("%1/[%2] %3 - %4.wav").arg(m_outputDir, QString().sprintf("%02d", trackNo), clean(m_baseName), clean(trackTitle)); + QString outputFile = QString("%1/[%2] %3 - %4.wav").arg(m_outputDir, QString().sprintf("%02d", trackNo), lamexp_clean_filename(m_baseName), lamexp_clean_filename(trackTitle)); for(int n = 2; QFileInfo(outputFile).exists(); n++) { - outputFile = QString("%1/[%2] %3 - %4 (%5).wav").arg(m_outputDir, QString().sprintf("%02d", trackNo), clean(m_baseName), clean(trackTitle), QString::number(n)); + outputFile = QString("%1/[%2] %3 - %4 (%5).wav").arg(m_outputDir, QString().sprintf("%02d", trackNo), lamexp_clean_filename(m_baseName), lamexp_clean_filename(trackTitle), QString::number(n)); } //Call split function