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).
This commit is contained in:
parent
ecd4c4c762
commit
3e7c2d59e8
@ -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
|
||||
|
@ -23,11 +23,13 @@
|
||||
|
||||
#include "Global.h"
|
||||
#include "Model_CueSheet.h"
|
||||
#include "Dialog_WorkingBanner.h"
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
#include <QFileDialog>
|
||||
#include <QProgressDialog>
|
||||
#include <QMenu>
|
||||
|
||||
#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<QWidget*>(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!");
|
||||
|
@ -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;
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "Model_CueSheet.h"
|
||||
#include "Genres.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMessageBox>
|
||||
#include <QInputDialog>
|
||||
#include <QFileInfo>
|
||||
@ -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));
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <QIcon>
|
||||
|
||||
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<CueSheetFile*> m_files;
|
||||
|
Loading…
Reference in New Issue
Block a user