diff --git a/src/Config.h b/src/Config.h index 8611572e..bda96369 100644 --- a/src/Config.h +++ b/src/Config.h @@ -30,7 +30,7 @@ #define VER_LAMEXP_MINOR_LO 2 #define VER_LAMEXP_TYPE Beta #define VER_LAMEXP_PATCH 1 -#define VER_LAMEXP_BUILD 528 +#define VER_LAMEXP_BUILD 529 /////////////////////////////////////////////////////////////////////////////// // Tools versions diff --git a/src/Dialog_CueImport.cpp b/src/Dialog_CueImport.cpp index 4d6e5f5d..7f14ac70 100644 --- a/src/Dialog_CueImport.cpp +++ b/src/Dialog_CueImport.cpp @@ -260,6 +260,7 @@ bool CueImportDialog::analyzeFiles(QStringList &files) connect(analyzer, SIGNAL(fileSelected(QString)), progress, SLOT(setText(QString)), Qt::QueuedConnection); connect(analyzer, SIGNAL(fileAnalyzed(AudioFileModel)), this, SLOT(analyzedFile(AudioFileModel)), Qt::QueuedConnection); + connect(progress, SIGNAL(userAbort()), analyzer, SLOT(abortProcess()), Qt::DirectConnection); progress->show(tr("Analyzing file(s), please wait..."), analyzer); progress->close(); @@ -286,8 +287,8 @@ void CueImportDialog::splitFiles(void) CueSplitter *splitter = new CueSplitter(m_outputDir, baseName, m_model, m_fileInfo); connect(splitter, SIGNAL(fileSelected(QString)), progress, SLOT(setText(QString)), Qt::QueuedConnection); - connect(progress, SIGNAL(userAbort()), splitter, SLOT(abortProcess()), Qt::DirectConnection); connect(splitter, SIGNAL(fileSplit(AudioFileModel)), m_fileList, SLOT(addFile(AudioFileModel)), Qt::QueuedConnection); + connect(progress, SIGNAL(userAbort()), splitter, SLOT(abortProcess()), Qt::DirectConnection); progress->show(tr("Splitting file(s), please wait..."), splitter); progress->close(); diff --git a/src/Dialog_MainWindow.cpp b/src/Dialog_MainWindow.cpp index baec9ad6..2d1f4a1e 100644 --- a/src/Dialog_MainWindow.cpp +++ b/src/Dialog_MainWindow.cpp @@ -457,6 +457,7 @@ void MainWindow::addFiles(const QStringList &files) FileAnalyzer *analyzer = new FileAnalyzer(files); connect(analyzer, SIGNAL(fileSelected(QString)), m_banner, SLOT(setText(QString)), Qt::QueuedConnection); connect(analyzer, SIGNAL(fileAnalyzed(AudioFileModel)), m_fileListModel, SLOT(addFile(AudioFileModel)), Qt::QueuedConnection); + connect(m_banner, SIGNAL(userAbort()), analyzer, SLOT(abortProcess()), Qt::DirectConnection); m_banner->show(tr("Adding file(s), please wait..."), analyzer); diff --git a/src/Dialog_WorkingBanner.cpp b/src/Dialog_WorkingBanner.cpp index 8340dfc4..f39f8110 100644 --- a/src/Dialog_WorkingBanner.cpp +++ b/src/Dialog_WorkingBanner.cpp @@ -141,6 +141,7 @@ void WorkingBanner::keyPressEvent(QKeyEvent *event) { if(event->key() == Qt::Key_Escape) { + qDebug("QT::KEY_ESCAPE pressed!"); emit userAbort(); } diff --git a/src/Thread_FileAnalyzer.cpp b/src/Thread_FileAnalyzer.cpp index 31d87912..1bf91ef9 100644 --- a/src/Thread_FileAnalyzer.cpp +++ b/src/Thread_FileAnalyzer.cpp @@ -42,10 +42,12 @@ FileAnalyzer::FileAnalyzer(const QStringList &inputFiles) : m_inputFiles(inputFiles), - m_mediaInfoBin(lamexp_lookup_tool("mediainfo.exe")) + m_mediaInfoBin(lamexp_lookup_tool("mediainfo.exe")), + m_abortFlag(false) { m_bSuccess = false; - + m_bAborted = false; + if(m_mediaInfoBin.isEmpty()) { qFatal("Invalid path to MediaInfo binary. Tool not initialized properly."); @@ -64,6 +66,7 @@ FileAnalyzer::FileAnalyzer(const QStringList &inputFiles) void FileAnalyzer::run() { m_bSuccess = false; + m_bAborted = false; m_filesAccepted = 0; m_filesRejected = 0; @@ -71,22 +74,23 @@ void FileAnalyzer::run() m_filesDummyCDDA = 0; m_inputFiles.sort(); - GetAsyncKeyState(VK_ESCAPE); + m_abortFlag = false; while(!m_inputFiles.isEmpty()) { - if(GetAsyncKeyState(VK_ESCAPE) & 0x0001) - { - MessageBeep(MB_ICONERROR); - qWarning("Operation cancelled by user!"); - break; - } - QString currentFile = QDir::fromNativeSeparators(m_inputFiles.takeFirst()); qDebug64("Analyzing: %1", currentFile); emit fileSelected(QFileInfo(currentFile).fileName()); AudioFileModel file = analyzeFile(currentFile); + if(m_abortFlag) + { + MessageBeep(MB_ICONERROR); + m_bAborted = true; + qWarning("Operation cancelled by user!"); + return; + } + if(file.fileName().isEmpty() || file.formatContainerType().isEmpty() || file.formatAudioType().isEmpty()) { if(!PlaylistImporter::importPlaylist(m_inputFiles, currentFile)) @@ -148,6 +152,13 @@ const AudioFileModel FileAnalyzer::analyzeFile(const QString &filePath) while(process.state() != QProcess::NotRunning) { + if(m_abortFlag) + { + process.kill(); + qWarning("Process was aborted on user request!"); + break; + } + if(!process.waitForReadyRead()) { if(process.state() == QProcess::Running) @@ -445,6 +456,13 @@ void FileAnalyzer::retrieveCover(AudioFileModel &audioFile, const QString &fileP while(process.state() != QProcess::NotRunning) { + if(m_abortFlag) + { + process.kill(); + qWarning("Process was aborted on user request!"); + break; + } + if(!process.waitForReadyRead()) { if(process.state() == QProcess::Running) diff --git a/src/Thread_FileAnalyzer.h b/src/Thread_FileAnalyzer.h index b5d61d65..9407cc08 100644 --- a/src/Thread_FileAnalyzer.h +++ b/src/Thread_FileAnalyzer.h @@ -52,6 +52,9 @@ signals: void fileSelected(const QString &fileName); void fileAnalyzed(const AudioFileModel &file); +public slots: + void abortProcess(void) { m_abortFlag = true; } + private: enum section_t { @@ -83,5 +86,9 @@ private: unsigned int m_filesRejected; unsigned int m_filesDenied; unsigned int m_filesDummyCDDA; + + volatile bool m_abortFlag; + + bool m_bAborted; bool m_bSuccess; };