From 3e7c2d59e8d0ff6706665794426336984f8b2e27 Mon Sep 17 00:00:00 2001 From: lordmulder Date: Fri, 13 May 2011 13:17:21 +0200 Subject: [PATCH] Show working banner while parsing a Cue Sheet file + reject Cue Sheet files larger than 10 MB (these probably are not Cue Sheets, but parsing would take very long). --- src/Config.h | 2 +- src/Dialog_CueImport.cpp | 10 ++++++++-- src/Dialog_MainWindow.cpp | 4 ++-- src/Model_CueSheet.cpp | 40 +++++++++++++++++++++++++++------------ src/Model_CueSheet.h | 5 +++-- 5 files changed, 42 insertions(+), 19 deletions(-) diff --git a/src/Config.h b/src/Config.h index 99e82b38..42ff735b 100644 --- a/src/Config.h +++ b/src/Config.h @@ -30,7 +30,7 @@ #define VER_LAMEXP_MINOR_LO 2 #define VER_LAMEXP_TYPE Alpha #define VER_LAMEXP_PATCH 14 -#define VER_LAMEXP_BUILD 508 +#define VER_LAMEXP_BUILD 509 /////////////////////////////////////////////////////////////////////////////// // Tools versions diff --git a/src/Dialog_CueImport.cpp b/src/Dialog_CueImport.cpp index d4684c9b..73b5a18b 100644 --- a/src/Dialog_CueImport.cpp +++ b/src/Dialog_CueImport.cpp @@ -23,11 +23,13 @@ #include "Global.h" #include "Model_CueSheet.h" +#include "Dialog_WorkingBanner.h" #include #include #include #include +#include #include #define SET_FONT_BOLD(WIDGET,BOLD) { QFont _font = WIDGET->font(); _font.setBold(BOLD); WIDGET->setFont(_font); } @@ -88,7 +90,11 @@ void CueImportDialog::showEvent(QShowEvent *event) int CueImportDialog::exec(const QString &cueFile) { - int iResult = m_model->loadCueSheet(cueFile); + WorkingBanner *progress = new WorkingBanner(dynamic_cast(parent())); + progress->show(tr("Loading Cue Sheet file, please be patient...")); + int iResult = m_model->loadCueSheet(cueFile, QApplication::instance()); + progress->close(); + LAMEXP_DELETE(progress); if(iResult) { @@ -100,7 +106,7 @@ int CueImportDialog::exec(const QString &cueFile) errorMsg = tr("The file could not be opened for reading!"); break; case 2: - errorMsg = tr("The file does not look like a valid Cue Sheet file!"); + errorMsg = tr("The file does not look like a valid Cue Sheet disc image file!"); break; case 3: errorMsg = tr("Could not find a supported audio track in the Cue Sheet!"); diff --git a/src/Dialog_MainWindow.cpp b/src/Dialog_MainWindow.cpp index acc3437e..23be3c69 100644 --- a/src/Dialog_MainWindow.cpp +++ b/src/Dialog_MainWindow.cpp @@ -1023,8 +1023,8 @@ void MainWindow::aboutButtonClicked(void) */ void MainWindow::encodeButtonClicked(void) { - static const __int64 oneGigabyte = 1073741824; - static const __int64 minimumFreeDiskspaceMultiplier = 2; + static const __int64 oneGigabyte = 1073741824i64; + static const __int64 minimumFreeDiskspaceMultiplier = 2i64; ABORT_IF_BUSY; diff --git a/src/Model_CueSheet.cpp b/src/Model_CueSheet.cpp index 4be2e16f..30b52e79 100644 --- a/src/Model_CueSheet.cpp +++ b/src/Model_CueSheet.cpp @@ -23,6 +23,7 @@ #include "Model_CueSheet.h" #include "Genres.h" +#include #include #include #include @@ -262,7 +263,7 @@ void CueSheetModel::clearData(void) // Cue Sheet Parser //////////////////////////////////////////////////////////// -int CueSheetModel::loadCueSheet(const QString &cueFileName) +int CueSheetModel::loadCueSheet(const QString &cueFileName, QCoreApplication *application) { QFile cueFile(cueFileName); if(!cueFile.open(QIODevice::ReadOnly)) @@ -273,43 +274,54 @@ int CueSheetModel::loadCueSheet(const QString &cueFileName) clearData(); beginResetModel(); - int iResult = parseCueFile(cueFile); + int iResult = parseCueFile(cueFile, application); endResetModel(); return iResult; } -int CueSheetModel::parseCueFile(QFile &cueFile) +int CueSheetModel::parseCueFile(QFile &cueFile, QCoreApplication *application) { cueFile.seek(0); + qDebug("\n[Cue Sheet Import]"); - //Check for UTF-8 BOM to guess encoding - bool bUTF8 = false; - QByteArray bomCheck = cueFile.peek(3); - if(bomCheck.size() == 3) + //Reject very large files, as parsing might take until forever + if(cueFile.size() >= 10485760i64) { - bUTF8 = ((bomCheck.at(0) == '\xef') && (bomCheck.at(1) == '\xbb') && (bomCheck.at(2) == '\xbf')); - qDebug("Encoding is %s.", (bUTF8 ? "UTF-8" : "Local 8-Bit")); + qWarning("File is very big. Probably not a Cue Sheet. Rejecting..."); + return 2; } + //Check for UTF-8 BOM in order to guess encoding + QByteArray bomCheck = cueFile.peek(128); + bool bUTF8 = bomCheck.contains("\xef\xbb\xbf"); + qDebug("Encoding is %s.", (bUTF8 ? "UTF-8" : "Local 8-Bit")); + bomCheck.clear(); + QRegExp rxFile("^FILE\\s+\"([^\"]+)\"\\s+(\\w+)$", Qt::CaseInsensitive); QRegExp rxTrack("^TRACK\\s+(\\d+)\\s(\\w+)$", Qt::CaseInsensitive); QRegExp rxIndex("^INDEX\\s+(\\d+)\\s+([0-9:]+)$", Qt::CaseInsensitive); QRegExp rxTitle("^TITLE\\s+\"([^\"]+)\"$", Qt::CaseInsensitive); QRegExp rxPerformer("^PERFORMER\\s+\"([^\"]+)\"$", Qt::CaseInsensitive); - CueSheetFile *currentFile = NULL; - CueSheetTrack *currentTrack = NULL; - bool bPreamble = true; bool bUnsupportedTrack = false; + CueSheetFile *currentFile = NULL; + CueSheetTrack *currentTrack = NULL; + QString albumTitle; QString albumPerformer; //Loop over the Cue Sheet until all lines were processed while(true) { + if(application) + { + application->processEvents(); + Sleep(25); + } + QByteArray lineData = cueFile.readLine(); if(lineData.size() <= 0) { @@ -355,6 +367,10 @@ int CueSheetModel::parseCueFile(QFile &cueFile) LAMEXP_DELETE(currentFile); } } + else + { + LAMEXP_DELETE(currentTrack); + } if(!rxFile.cap(2).compare("WAVE", Qt::CaseInsensitive) || !rxFile.cap(2).compare("MP3", Qt::CaseInsensitive) || !rxFile.cap(2).compare("AIFF", Qt::CaseInsensitive)) { currentFile = new CueSheetFile(rxFile.cap(1)); diff --git a/src/Model_CueSheet.h b/src/Model_CueSheet.h index 7cad7aa8..5baeb26c 100644 --- a/src/Model_CueSheet.h +++ b/src/Model_CueSheet.h @@ -26,6 +26,7 @@ #include class CueSheetFile; +class QApplication; class CueSheetModel : public QAbstractItemModel { @@ -45,10 +46,10 @@ public: void clearData(void); //Cue Sheet functions - int loadCueSheet(const QString &cueFile); + int loadCueSheet(const QString &cueFile, QCoreApplication *application = NULL); private: - int parseCueFile(QFile &cueFile); + int parseCueFile(QFile &cueFile, QCoreApplication *application); double parseTimeIndex(const QString &index); QString indexToString(const double index) const; QList m_files;