diff --git a/src/Config.h b/src/Config.h
index f9a42a2b..3c82590e 100644
--- a/src/Config.h
+++ b/src/Config.h
@@ -35,7 +35,7 @@
#define VER_LAMEXP_MINOR_LO 6
#define VER_LAMEXP_TYPE Beta
#define VER_LAMEXP_PATCH 1
-#define VER_LAMEXP_BUILD 2068
+#define VER_LAMEXP_BUILD 2071
#define VER_LAMEXP_CONFG 2002
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/Decoder_WMA.cpp b/src/Decoder_WMA.cpp
index 87177fe4..aae6ef82 100644
--- a/src/Decoder_WMA.cpp
+++ b/src/Decoder_WMA.cpp
@@ -70,7 +70,7 @@ bool WMADecoder::decode(const QString &sourceFile, const QString &outputFile, QA
if (regExp.lastIndexIn(text) >= 0)
{
qint32 newProgress;
- if (MUtils::regexp_parse_int32(regExp, newProgress, 2U))
+ if (MUtils::regexp_parse_int32(regExp, newProgress))
{
if (newProgress > prevProgress)
{
diff --git a/src/Dialog_MainWindow.cpp b/src/Dialog_MainWindow.cpp
index 62910813..1e8e3ee7 100644
--- a/src/Dialog_MainWindow.cpp
+++ b/src/Dialog_MainWindow.cpp
@@ -1594,7 +1594,7 @@ void MainWindow::windowShown(void)
messageText += NOBR(tr("LameXP detected that your version of the Nero AAC encoder is outdated!")).append("
");
messageText += NOBR(tr("The current version available is %1 (or later), but you still have version %2 installed.").arg(lamexp_version2string("?.?.?.?", lamexp_toolver_neroaac(), tr("n/a")), lamexp_version2string("?.?.?.?", lamexp_tools_version("neroAacEnc.exe"), tr("n/a")))).append("
");
messageText += NOBR(tr("You can download the latest version of the Nero AAC encoder from the Nero website at:")).append("
");
- messageText += "" + LINK(AboutDialog::neroAacUrl) + "
";
+ messageText += QString("").append(LINK(AboutDialog::neroAacUrl)).append("
");
messageText += NOBR(tr("(Hint: Please ignore the name of the downloaded ZIP file and check the included 'changelog.txt' instead!)")).append("
");
QMessageBox::information(this, tr("AAC Encoder Outdated"), messageText);
}
@@ -1609,10 +1609,10 @@ void MainWindow::windowShown(void)
QString messageText;
messageText += NOBR(tr("The Nero AAC encoder could not be found. AAC encoding support will be disabled.")).append("
");
messageText += NOBR(tr("Please put 'neroAacEnc.exe', 'neroAacDec.exe' and 'neroAacTag.exe' into the LameXP directory!")).append("
");
- messageText += NOBR(tr("Your LameXP directory is located here:")).append("
");
+ messageText += QString("").append(NOBR(tr("Your LameXP install directory is located here:"))).append("
");
messageText += QString("%1
").arg(FSLINK(QDir::toNativeSeparators(appPath)));
- messageText += NOBR(tr("You can download the Nero AAC encoder for free from the official Nero website at:")).append("
");
- messageText += "" + LINK(AboutDialog::neroAacUrl) + "
";
+ messageText += QString("").append(NOBR(tr("You can download the Nero AAC encoder for free from this website:"))).append("
");
+ messageText += QString("").append(LINK(AboutDialog::neroAacUrl)).append("
");
if(QMessageBox::information(this, tr("AAC Support Disabled"), messageText, tr("Discard"), tr("Don't Show Again")) == 1)
{
m_settings->neroAacNotificationsEnabled(false);
diff --git a/src/Encoder_AAC.cpp b/src/Encoder_AAC.cpp
index 91919f57..37ed646d 100644
--- a/src/Encoder_AAC.cpp
+++ b/src/Encoder_AAC.cpp
@@ -208,97 +208,45 @@ bool AACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo
return false;
}
- bool bTimeout = false;
- bool bAborted = false;
int prevProgress = -1;
+ QRegExp regExp_sp(L1S("\\bprocessed\\s+(\\d+)\\s+seconds"), Qt::CaseInsensitive);
+ QRegExp regExp_mp(L1S("(\\w+)\\s+pass:\\s+processed\\s+(\\d+)\\s+seconds"), Qt::CaseInsensitive);
-
- QRegExp regExp(L1S("Processed\\s+(\\d+)\\s+seconds"));
- QRegExp regExp_pass1(L1S("First\\s+pass:\\s+processed\\s+(\\d+)\\s+seconds"));
- QRegExp regExp_pass2(L1S("Second\\s+pass:\\s+processed\\s+(\\d+)\\s+seconds"));
-
- while(process.state() != QProcess::NotRunning)
+ const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, &duration, ®Exp_sp, ®Exp_mp](const QString &text)
{
- if(checkFlag(abortFlag))
+ if (regExp_mp.lastIndexIn(text) >= 0)
{
- process.kill();
- bAborted = true;
- emit messageLogged(L1S("\nABORTED BY USER !!!"));
- break;
- }
- process.waitForReadyRead(m_processTimeoutInterval);
- if(!process.bytesAvailable() && process.state() == QProcess::Running)
- {
- process.kill();
- qWarning("NeroAacEnc process timed out <-- killing!");
- emit messageLogged(L1S("\nPROCESS TIMEOUT !!!"));
- bTimeout = true;
- break;
- }
- while(process.bytesAvailable() > 0)
- {
- QByteArray line = process.readLine();
- QString text = QString::fromUtf8(line.constData()).simplified();
- if(regExp_pass1.lastIndexIn(text) >= 0)
+ int timeElapsed;
+ if ((duration > 0) && MUtils::regexp_parse_int32(regExp_mp, timeElapsed, 2))
{
- bool ok = false;
- int progress = regExp_pass1.cap(1).toInt(&ok);
- if(ok && (duration > 0))
+ const bool second_pass = (regExp_mp.cap(1).compare(L1S("second"), Qt::CaseInsensitive) == 0);
+ int newProgress = qRound((second_pass ? 50.0 : 0.0) + ((static_cast(timeElapsed) / static_cast(duration)) * 50.0));
+ if (newProgress > prevProgress)
{
- int newProgress = qRound((static_cast(progress) / static_cast(duration)) * 50.0);
- if(newProgress > prevProgress)
- {
- emit statusUpdated(newProgress);
- prevProgress = qMin(newProgress + 2, 99);
- }
+ emit statusUpdated(newProgress);
+ prevProgress = qMin(newProgress + 2, 99);
}
}
- else if(regExp_pass2.lastIndexIn(text) >= 0)
- {
- bool ok = false;
- int progress = regExp_pass2.cap(1).toInt(&ok);
- if(ok && (duration > 0))
- {
- int newProgress = qRound((static_cast(progress) / static_cast(duration)) * 50.0) + 50;
- if(newProgress > prevProgress)
- {
- emit statusUpdated(newProgress);
- prevProgress = qMin(newProgress + 2, 99);
- }
- }
- }
- else if(regExp.lastIndexIn(text) >= 0)
- {
- bool ok = false;
- int progress = regExp.cap(1).toInt(&ok);
- if(ok && (duration > 0))
- {
- int newProgress = qRound((static_cast(progress) / static_cast(duration)) * 100.0);
- if(newProgress > prevProgress)
- {
- emit statusUpdated(newProgress);
- prevProgress = qMin(newProgress + 2, 99);
- }
- }
- }
- else if(!text.isEmpty())
- {
- emit messageLogged(text);
- }
+ return true;
}
- }
+ if (regExp_sp.lastIndexIn(text) >= 0)
+ {
+ int timeElapsed;
+ if ((duration > 0) && MUtils::regexp_parse_int32(regExp_sp, timeElapsed))
+ {
+ int newProgress = qRound((static_cast(timeElapsed) / static_cast(duration)) * 100.0);
+ if (newProgress > prevProgress)
+ {
+ emit statusUpdated(newProgress);
+ prevProgress = qMin(newProgress + 2, 99);
+ }
+ }
+ return true;
+ }
+ return false;
+ });
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
- {
- process.kill();
- process.waitForFinished(-1);
- }
-
- emit statusUpdated(100);
- emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-
- if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS)
+ if(result != RESULT_SUCCESS)
{
return false;
}
@@ -327,52 +275,7 @@ bool AACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo
return false;
}
- bTimeout = false;
-
- while(process.state() != QProcess::NotRunning)
- {
- if(checkFlag(abortFlag))
- {
- process.kill();
- bAborted = true;
- emit messageLogged(L1S("\nABORTED BY USER !!!"));
- break;
- }
- process.waitForReadyRead(m_processTimeoutInterval);
- if(!process.bytesAvailable() && process.state() == QProcess::Running)
- {
- process.kill();
- qWarning("NeroAacTag process timed out <-- killing!");
- emit messageLogged(L1S("\nPROCESS TIMEOUT !!!"));
- bTimeout = true;
- break;
- }
- while(process.bytesAvailable() > 0)
- {
- QByteArray line = process.readLine();
- QString text = QString::fromUtf8(line.constData()).simplified();
- if(!text.isEmpty())
- {
- emit messageLogged(text);
- }
- }
- }
-
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
- {
- process.kill();
- process.waitForFinished(-1);
- }
-
- emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-
- if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS)
- {
- return false;
- }
-
- return true;
+ return (awaitProcess(process, abortFlag) == RESULT_SUCCESS);
}
bool AACEncoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
diff --git a/src/Encoder_AAC_FDK.cpp b/src/Encoder_AAC_FDK.cpp
index 07b29b95..21408743 100644
--- a/src/Encoder_AAC_FDK.cpp
+++ b/src/Encoder_AAC_FDK.cpp
@@ -201,67 +201,28 @@ bool FDKAACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaI
return false;
}
- bool bTimeout = false;
- bool bAborted = false;
int prevProgress = -1;
-
QRegExp regExp(L1S("\\[(\\d+)%\\]\\s+(\\d+):(\\d+)"));
- while(process.state() != QProcess::NotRunning)
+ const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, ®Exp](const QString &text)
{
- if(checkFlag(abortFlag))
+ if (regExp.lastIndexIn(text) >= 0)
{
- process.kill();
- bAborted = true;
- emit messageLogged(L1S("\nABORTED BY USER !!!"));
- break;
- }
- process.waitForReadyRead(m_processTimeoutInterval);
- if(!process.bytesAvailable() && process.state() == QProcess::Running)
- {
- process.kill();
- qWarning("FDKAAC process timed out <-- killing!");
- emit messageLogged(L1S("\nPROCESS TIMEOUT !!!"));
- bTimeout = true;
- break;
- }
- while(process.bytesAvailable() > 0)
- {
- QByteArray line = process.readLine();
- QString text = QString::fromUtf8(line.constData()).simplified();
- if(regExp.lastIndexIn(text) >= 0)
+ qint32 newProgress;
+ if (MUtils::regexp_parse_int32(regExp, newProgress))
{
- bool ok = false;
- int progress = regExp.cap(1).toInt(&ok);
- if(ok && (progress > prevProgress))
+ if (newProgress > prevProgress)
{
- emit statusUpdated(progress);
- prevProgress = qMin(progress + 2, 99);
+ emit statusUpdated(newProgress);
+ prevProgress = qMin(newProgress + 2, 99);
}
}
- else if(!text.isEmpty())
- {
- emit messageLogged(text);
- }
+ return true;
}
- }
-
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
- {
- process.kill();
- process.waitForFinished(-1);
- }
-
- emit statusUpdated(100);
- emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-
- if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS)
- {
return false;
- }
+ });
- return true;
+ return (result == RESULT_SUCCESS);
}
bool FDKAACEncoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
diff --git a/src/Encoder_AAC_FHG.cpp b/src/Encoder_AAC_FHG.cpp
index 1c0e2528..7f80ea7c 100644
--- a/src/Encoder_AAC_FHG.cpp
+++ b/src/Encoder_AAC_FHG.cpp
@@ -196,67 +196,28 @@ bool FHGAACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaI
return false;
}
- bool bTimeout = false;
- bool bAborted = false;
int prevProgress = -1;
-
QRegExp regExp(L1S("Progress:\\s*(\\d+)%"));
- while(process.state() != QProcess::NotRunning)
+ const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, ®Exp](const QString &text)
{
- if (checkFlag(abortFlag))
+ if (regExp.lastIndexIn(text) >= 0)
{
- process.kill();
- bAborted = true;
- emit messageLogged(L1S("\nABORTED BY USER !!!"));
- break;
- }
- process.waitForReadyRead(m_processTimeoutInterval);
- if(!process.bytesAvailable() && process.state() == QProcess::Running)
- {
- process.kill();
- qWarning("FhgAacEnc process timed out <-- killing!");
- emit messageLogged(L1S("\nPROCESS TIMEOUT !!!"));
- bTimeout = true;
- break;
- }
- while(process.bytesAvailable() > 0)
- {
- QByteArray line = process.readLine();
- QString text = QString::fromUtf8(line.constData()).simplified();
- if(regExp.lastIndexIn(text) >= 0)
+ qint32 newProgress;
+ if (MUtils::regexp_parse_int32(regExp, newProgress))
{
- bool ok = false;
- int progress = regExp.cap(1).toInt(&ok);
- if(ok && (progress > prevProgress))
+ if (newProgress > prevProgress)
{
- emit statusUpdated(progress);
- prevProgress = qMin(progress + 2, 99);
+ emit statusUpdated(newProgress);
+ prevProgress = qMin(newProgress + 2, 99);
}
}
- else if(!text.isEmpty())
- {
- emit messageLogged(text);
- }
+ return true;
}
- }
-
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
- {
- process.kill();
- process.waitForFinished(-1);
- }
-
- emit statusUpdated(100);
- emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-
- if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS)
- {
return false;
- }
+ });
- return true;
+ return (result == RESULT_SUCCESS);
}
bool FHGAACEncoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
diff --git a/src/Encoder_AAC_QAAC.cpp b/src/Encoder_AAC_QAAC.cpp
index ef7a70d5..4e291b92 100644
--- a/src/Encoder_AAC_QAAC.cpp
+++ b/src/Encoder_AAC_QAAC.cpp
@@ -222,67 +222,28 @@ bool QAACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInf
return false;
}
- bool bTimeout = false;
- bool bAborted = false;
int prevProgress = -1;
-
QRegExp regExp(L1S("\\[(\\d+)\\.(\\d)%\\]"));
- while(process.state() != QProcess::NotRunning)
+ const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, ®Exp](const QString &text)
{
- if (checkFlag(abortFlag))
+ if (regExp.lastIndexIn(text) >= 0)
{
- process.kill();
- bAborted = true;
- emit messageLogged(L1S("\nABORTED BY USER !!!"));
- break;
- }
- process.waitForReadyRead(m_processTimeoutInterval);
- if(!process.bytesAvailable() && process.state() == QProcess::Running)
- {
- process.kill();
- qWarning("QAAC process timed out <-- killing!");
- emit messageLogged(L1S("\nPROCESS TIMEOUT !!!"));
- bTimeout = true;
- break;
- }
- while(process.bytesAvailable() > 0)
- {
- QByteArray line = process.readLine();
- QString text = QString::fromUtf8(line.constData()).simplified();
- if(regExp.lastIndexIn(text) >= 0)
+ qint32 newProgress;
+ if (MUtils::regexp_parse_int32(regExp, newProgress))
{
- bool ok = false;
- int progress = regExp.cap(1).toInt(&ok);
- if(ok && (progress > prevProgress))
+ if (newProgress > prevProgress)
{
- emit statusUpdated(progress);
- prevProgress = qMin(progress + 2, 99);
+ emit statusUpdated(newProgress);
+ prevProgress = qMin(newProgress + 2, 99);
}
}
- else if(!text.isEmpty())
- {
- emit messageLogged(text);
- }
+ return true;
}
- }
-
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
- {
- process.kill();
- process.waitForFinished(-1);
- }
-
- emit statusUpdated(100);
- emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-
- if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS)
- {
return false;
- }
+ });
- return true;
+ return (result == RESULT_SUCCESS);
}
bool QAACEncoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
diff --git a/src/Encoder_AC3.cpp b/src/Encoder_AC3.cpp
index b9348a44..1703aa59 100644
--- a/src/Encoder_AC3.cpp
+++ b/src/Encoder_AC3.cpp
@@ -189,67 +189,28 @@ bool AC3Encoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo
return false;
}
- bool bTimeout = false;
- bool bAborted = false;
int prevProgress = -1;
+ QRegExp regExp(L1S("progress:\\s+(\\d+)%"));
- QRegExp regExp(L1S("progress:(\\s+)(\\d+)%(\\s+)\\|"));
-
- while(process.state() != QProcess::NotRunning)
+ const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, ®Exp](const QString &text)
{
- if (checkFlag(abortFlag))
+ if (regExp.lastIndexIn(text) >= 0)
{
- process.kill();
- bAborted = true;
- emit messageLogged(L1S("\nABORTED BY USER !!!"));
- break;
- }
- process.waitForReadyRead(m_processTimeoutInterval);
- if(!process.bytesAvailable() && process.state() == QProcess::Running)
- {
- process.kill();
- qWarning("Aften process timed out <-- killing!");
- emit messageLogged(L1S("\nPROCESS TIMEOUT !!!"));
- bTimeout = true;
- break;
- }
- while(process.bytesAvailable() > 0)
- {
- QByteArray line = process.readLine();
- QString text = QString::fromUtf8(line.constData()).simplified();
- if(regExp.lastIndexIn(text) >= 0)
+ qint32 newProgress;
+ if (MUtils::regexp_parse_int32(regExp, newProgress))
{
- bool ok = false;
- int progress = regExp.cap(2).toInt(&ok);
- if(ok && (progress > prevProgress))
+ if (newProgress > prevProgress)
{
- emit statusUpdated(progress);
- prevProgress = qMin(progress + 2, 99);
+ emit statusUpdated(newProgress);
+ prevProgress = qMin(newProgress + 2, 99);
}
}
- else if(!text.isEmpty())
- {
- emit messageLogged(text);
- }
+ return true;
}
- }
-
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
- {
- process.kill();
- process.waitForFinished(-1);
- }
-
- emit statusUpdated(100);
- emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-
- if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS)
- {
return false;
- }
+ });
- return true;
+ return (result == RESULT_SUCCESS);
}
void AC3Encoder::setAudioCodingMode(int value)
diff --git a/src/Encoder_DCA.cpp b/src/Encoder_DCA.cpp
index 218d9551..08c5a222 100644
--- a/src/Encoder_DCA.cpp
+++ b/src/Encoder_DCA.cpp
@@ -155,67 +155,28 @@ bool DCAEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo
return false;
}
- bool bTimeout = false;
- bool bAborted = false;
int prevProgress = -1;
-
QRegExp regExp(L1S("\\[(\\d+)\\.(\\d+)%\\]"));
- while(process.state() != QProcess::NotRunning)
+ const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, ®Exp](const QString &text)
{
- if (checkFlag(abortFlag))
+ if (regExp.lastIndexIn(text) >= 0)
{
- process.kill();
- bAborted = true;
- emit messageLogged(L1S("\nABORTED BY USER !!!"));
- break;
- }
- process.waitForReadyRead(m_processTimeoutInterval);
- if(!process.bytesAvailable() && process.state() == QProcess::Running)
- {
- process.kill();
- qWarning("DCAENC process timed out <-- killing!");
- emit messageLogged(L1S("\nPROCESS TIMEOUT !!!"));
- bTimeout = true;
- break;
- }
- while(process.bytesAvailable() > 0)
- {
- QByteArray line = process.readLine();
- QString text = QString::fromUtf8(line.constData()).simplified();
- if(regExp.lastIndexIn(text) >= 0)
+ qint32 newProgress;
+ if (MUtils::regexp_parse_int32(regExp, newProgress))
{
- bool ok = false;
- int progress = regExp.cap(1).toInt(&ok);
- if(ok && (progress > prevProgress))
+ if (newProgress > prevProgress)
{
- emit statusUpdated(progress);
- prevProgress = qMin(progress + 2, 99);
+ emit statusUpdated(newProgress);
+ prevProgress = qMin(newProgress + 2, 99);
}
}
- else if(!text.isEmpty())
- {
- emit messageLogged(text);
- }
+ return true;
}
- }
-
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
- {
- process.kill();
- process.waitForFinished(-1);
- }
-
- emit statusUpdated(100);
- emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-
- if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS)
- {
return false;
- }
+ });
- return true;
+ return (result == RESULT_SUCCESS);
}
bool DCAEncoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
diff --git a/src/Encoder_FLAC.cpp b/src/Encoder_FLAC.cpp
index 94f2b9cc..eeb034e3 100644
--- a/src/Encoder_FLAC.cpp
+++ b/src/Encoder_FLAC.cpp
@@ -164,67 +164,28 @@ bool FLACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInf
return false;
}
- bool bTimeout = false;
- bool bAborted = false;
int prevProgress = -1;
-
QRegExp regExp(L1S("\\b(\\d+)% complete"));
- while(process.state() != QProcess::NotRunning)
+ const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, ®Exp](const QString &text)
{
- if(checkFlag(abortFlag))
+ if (regExp.lastIndexIn(text) >= 0)
{
- process.kill();
- bAborted = true;
- emit messageLogged(L1S("\nABORTED BY USER !!!"));
- break;
- }
- process.waitForReadyRead(m_processTimeoutInterval);
- if(!process.bytesAvailable() && process.state() == QProcess::Running)
- {
- process.kill();
- qWarning("FLAC process timed out <-- killing!");
- emit messageLogged(L1S("\nPROCESS TIMEOUT !!!"));
- bTimeout = true;
- break;
- }
- while(process.bytesAvailable() > 0)
- {
- QByteArray line = process.readLine().replace('\b', char(0x20));
- QString text = QString::fromUtf8(line.constData()).simplified();
- if(regExp.lastIndexIn(text) >= 0)
+ qint32 newProgress;
+ if (MUtils::regexp_parse_int32(regExp, newProgress))
{
- bool ok = false;
- int progress = regExp.cap(1).toInt(&ok);
- if(ok && (progress > prevProgress))
+ if (newProgress > prevProgress)
{
- emit statusUpdated(progress);
- prevProgress = qMin(progress + 2, 99);
+ emit statusUpdated(newProgress);
+ prevProgress = qMin(newProgress + 2, 99);
}
}
- else if(!text.isEmpty())
- {
- emit messageLogged(text);
- }
+ return true;
}
- }
-
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
- {
- process.kill();
- process.waitForFinished(-1);
- }
-
- emit statusUpdated(100);
- emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-
- if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS)
- {
return false;
- }
-
- return true;
+ });
+
+ return (result == RESULT_SUCCESS);
}
bool FLACEncoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
diff --git a/src/Encoder_MAC.cpp b/src/Encoder_MAC.cpp
index 2df14854..33bd88cc 100644
--- a/src/Encoder_MAC.cpp
+++ b/src/Encoder_MAC.cpp
@@ -161,62 +161,28 @@ bool MACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo
return false;
}
- bool bTimeout = false;
- bool bAborted = false;
int prevProgress = -1;
-
QRegExp regExp(L1S("Progress: (\\d+).(\\d+)%"));
- while(process.state() != QProcess::NotRunning)
+ const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, ®Exp](const QString &text)
{
- if (checkFlag(abortFlag))
+ if (regExp.lastIndexIn(text) >= 0)
{
- process.kill();
- bAborted = true;
- emit messageLogged(L1S("\nABORTED BY USER !!!"));
- break;
- }
- process.waitForReadyRead(m_processTimeoutInterval);
- if(!process.bytesAvailable() && process.state() == QProcess::Running)
- {
- process.kill();
- qWarning("MAC process timed out <-- killing!");
- emit messageLogged(L1S("\nPROCESS TIMEOUT !!!"));
- bTimeout = true;
- break;
- }
- while(process.bytesAvailable() > 0)
- {
- QByteArray line = process.readLine();
- QString text = QString::fromUtf8(line.constData()).simplified();
- if(regExp.lastIndexIn(text) >= 0)
+ qint32 newProgress;
+ if (MUtils::regexp_parse_int32(regExp, newProgress))
{
- bool ok = false;
- int progress = regExp.cap(1).toInt(&ok);
- if(ok && (progress > prevProgress))
+ if (newProgress > prevProgress)
{
- emit statusUpdated(progress);
- prevProgress = qMin(progress + 2, 99);
+ emit statusUpdated(newProgress);
+ prevProgress = qMin(newProgress + 2, 99);
}
}
- else if(!text.isEmpty())
- {
- emit messageLogged(text);
- }
+ return true;
}
- }
+ return false;
+ });
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
- {
- process.kill();
- process.waitForFinished(-1);
- }
-
- emit statusUpdated(100);
- emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-
- if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS)
+ if(result != RESULT_SUCCESS)
{
return false;
}
@@ -246,52 +212,7 @@ bool MACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo
return false;
}
- bTimeout = false;
-
- while(process.state() != QProcess::NotRunning)
- {
- if(checkFlag(abortFlag))
- {
- process.kill();
- bAborted = true;
- emit messageLogged(L1S("\nABORTED BY USER !!!"));
- break;
- }
- process.waitForReadyRead(m_processTimeoutInterval);
- if(!process.bytesAvailable() && process.state() == QProcess::Running)
- {
- process.kill();
- qWarning("Tag process timed out <-- killing!");
- emit messageLogged(L1S("\nPROCESS TIMEOUT !!!"));
- bTimeout = true;
- break;
- }
- while(process.bytesAvailable() > 0)
- {
- QByteArray line = process.readLine();
- QString text = QString::fromUtf8(line.constData()).simplified();
- if(!text.isEmpty())
- {
- emit messageLogged(text);
- }
- }
- }
-
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
- {
- process.kill();
- process.waitForFinished(-1);
- }
-
- emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-
- if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS)
- {
- return false;
- }
-
- return true;
+ return (awaitProcess(process, abortFlag) == RESULT_SUCCESS);
}
bool MACEncoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
diff --git a/src/Encoder_MP3.cpp b/src/Encoder_MP3.cpp
index f37fae8d..68e120c5 100644
--- a/src/Encoder_MP3.cpp
+++ b/src/Encoder_MP3.cpp
@@ -237,67 +237,28 @@ bool MP3Encoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo
return false;
}
- bool bTimeout = false;
- bool bAborted = false;
int prevProgress = -1;
-
QRegExp regExp(L1S("\\(.*(\\d+)%\\)\\|"));
- while(process.state() != QProcess::NotRunning)
+ const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, ®Exp](const QString &text)
{
- if (checkFlag(abortFlag))
+ if (regExp.lastIndexIn(text) >= 0)
{
- process.kill();
- bAborted = true;
- emit messageLogged(L1S("\nABORTED BY USER !!!"));
- break;
- }
- process.waitForReadyRead(m_processTimeoutInterval);
- if(!process.bytesAvailable() && process.state() == QProcess::Running)
- {
- process.kill();
- qWarning("LAME process timed out <-- killing!");
- emit messageLogged(L1S("\nPROCESS TIMEOUT !!!"));
- bTimeout = true;
- break;
- }
- while(process.bytesAvailable() > 0)
- {
- QByteArray line = process.readLine();
- QString text = QString::fromUtf8(line.constData()).simplified();
- if(regExp.lastIndexIn(text) >= 0)
+ qint32 newProgress;
+ if (MUtils::regexp_parse_int32(regExp, newProgress))
{
- bool ok = false;
- int progress = regExp.cap(1).toInt(&ok);
- if(ok && (progress > prevProgress))
+ if (newProgress > prevProgress)
{
- emit statusUpdated(progress);
- prevProgress = qMin(progress + 2, 99);
+ emit statusUpdated(newProgress);
+ prevProgress = qMin(newProgress + 2, 99);
}
}
- else if(!text.isEmpty())
- {
- emit messageLogged(text);
- }
+ return true;
}
- }
-
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
- {
- process.kill();
- process.waitForFinished(-1);
- }
-
- emit statusUpdated(100);
- emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-
- if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS)
- {
return false;
- }
-
- return true;
+ });
+
+ return (result == RESULT_SUCCESS);
}
bool MP3Encoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
diff --git a/src/Encoder_Opus.cpp b/src/Encoder_Opus.cpp
index 9b6ac922..3f3d1436 100644
--- a/src/Encoder_Opus.cpp
+++ b/src/Encoder_Opus.cpp
@@ -206,67 +206,28 @@ bool OpusEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInf
return false;
}
- bool bTimeout = false;
- bool bAborted = false;
int prevProgress = -1;
-
QRegExp regExp(L1S("\\((\\d+)%\\)"));
- while(process.state() != QProcess::NotRunning)
+ const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, ®Exp](const QString &text)
{
- if (checkFlag(abortFlag))
+ if (regExp.lastIndexIn(text) >= 0)
{
- process.kill();
- bAborted = true;
- emit messageLogged(L1S("\nABORTED BY USER !!!"));
- break;
- }
- process.waitForReadyRead(m_processTimeoutInterval);
- if(!process.bytesAvailable() && process.state() == QProcess::Running)
- {
- process.kill();
- qWarning("Opus process timed out <-- killing!");
- emit messageLogged(L1S("\nPROCESS TIMEOUT !!!"));
- bTimeout = true;
- break;
- }
- while(process.bytesAvailable() > 0)
- {
- QByteArray line = process.readLine();
- QString text = QString::fromUtf8(line.constData()).simplified();
- if(regExp.lastIndexIn(text) >= 0)
+ qint32 newProgress;
+ if (MUtils::regexp_parse_int32(regExp, newProgress))
{
- bool ok = false;
- int progress = regExp.cap(1).toInt(&ok);
- if(ok && (progress > prevProgress))
+ if (newProgress > prevProgress)
{
- emit statusUpdated(progress);
- prevProgress = qMin(progress + 2, 99);
+ emit statusUpdated(newProgress);
+ prevProgress = qMin(newProgress + 2, 99);
}
}
- else if(!text.isEmpty())
- {
- emit messageLogged(text);
- }
+ return true;
}
- }
-
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
- {
- process.kill();
- process.waitForFinished(-1);
- }
-
- emit statusUpdated(100);
- emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-
- if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS)
- {
return false;
- }
+ });
- return true;
+ return (result == RESULT_SUCCESS);
}
QString OpusEncoder::detectMimeType(const QString &coverFile)
diff --git a/src/Encoder_Vorbis.cpp b/src/Encoder_Vorbis.cpp
index 058f33ae..5170ae2b 100644
--- a/src/Encoder_Vorbis.cpp
+++ b/src/Encoder_Vorbis.cpp
@@ -196,67 +196,28 @@ bool VorbisEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaI
return false;
}
- bool bTimeout = false;
- bool bAborted = false;
int prevProgress = -1;
-
QRegExp regExp(L1S("\\[.*(\\d+)[.,](\\d+)%\\]"));
- while(process.state() != QProcess::NotRunning)
+ const result_t result = awaitProcess(process, abortFlag, [this, &prevProgress, ®Exp](const QString &text)
{
- if(checkFlag(abortFlag))
+ if (regExp.lastIndexIn(text) >= 0)
{
- process.kill();
- bAborted = true;
- emit messageLogged(L1S("\nABORTED BY USER !!!"));
- break;
- }
- process.waitForReadyRead(m_processTimeoutInterval);
- if(!process.bytesAvailable() && process.state() == QProcess::Running)
- {
- process.kill();
- qWarning("OggEnc process timed out <-- killing!");
- emit messageLogged(L1S("\nPROCESS TIMEOUT !!!"));
- bTimeout = true;
- break;
- }
- while(process.bytesAvailable() > 0)
- {
- QByteArray line = process.readLine();
- QString text = QString::fromUtf8(line.constData()).simplified();
- if(regExp.lastIndexIn(text) >= 0)
+ qint32 newProgress;
+ if (MUtils::regexp_parse_int32(regExp, newProgress))
{
- bool ok = false;
- int progress = regExp.cap(1).toInt(&ok);
- if(ok && (progress > prevProgress))
+ if (newProgress > prevProgress)
{
- emit statusUpdated(progress);
- prevProgress = qMin(progress + 2, 99);
+ emit statusUpdated(newProgress);
+ prevProgress = qMin(newProgress + 2, 99);
}
}
- else if(!text.isEmpty())
- {
- emit messageLogged(text);
- }
+ return true;
}
- }
-
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
- {
- process.kill();
- process.waitForFinished(-1);
- }
-
- emit statusUpdated(100);
- emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-
- if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS)
- {
return false;
- }
+ });
- return true;
+ return (result == RESULT_SUCCESS);
}
bool VorbisEncoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
diff --git a/src/Tool_Abstract.cpp b/src/Tool_Abstract.cpp
index 66989fc0..4cb8fd00 100644
--- a/src/Tool_Abstract.cpp
+++ b/src/Tool_Abstract.cpp
@@ -156,6 +156,14 @@ bool AbstractTool::startProcess(QProcess &process, const QString &program, const
return false;
}
+/*
+* Wait for process to terminate while processing its output
+*/
+AbstractTool::result_t AbstractTool::awaitProcess(QProcess &process, QAtomicInt &abortFlag, int *const exitCode)
+{
+ return awaitProcess(process, abortFlag, [](const QString &text) { return false; }, exitCode);
+}
+
/*
* Wait for process to terminate while processing its output
*/
@@ -223,8 +231,8 @@ AbstractTool::result_t AbstractTool::awaitProcess(QProcess &process, QAtomicInt
*exitCode = process.exitCode();
}
- emit statusUpdated(100);
emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
+ if (!(bAborted || bTimeout)) emit statusUpdated(100);
if (bAborted || bTimeout || (process.exitCode() != EXIT_SUCCESS))
{
diff --git a/src/Tool_Abstract.h b/src/Tool_Abstract.h
index 0d93af39..d8a5da89 100644
--- a/src/Tool_Abstract.h
+++ b/src/Tool_Abstract.h
@@ -67,6 +67,7 @@ protected:
static QString commandline2string(const QString &program, const QStringList &arguments);
bool startProcess(QProcess &process, const QString &program, const QStringList &args, const QString &workingDir = QString());
+ result_t awaitProcess(QProcess &process, QAtomicInt &abortFlag, int *const exitCode = NULL);
result_t awaitProcess(QProcess &process, QAtomicInt &abortFlag, std::function &&handler, int *const exitCode = NULL);
private: