OSDN Git Service

Set creation/modified time of the encoded file the same value as the original file...
[lamexp/LameXP.git] / src / Decoder_WMA.cpp
index b2fc93f..f64c9ba 100644 (file)
@@ -1,11 +1,12 @@
 ///////////////////////////////////////////////////////////////////////////////
 // LameXP - Audio Encoder Front-End
-// Copyright (C) 2004-2010 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2015 LoRd_MuldeR <MuldeR2@GMX.de>
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
 // the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
+// (at your option) any later version, but always including the *additional*
+// restrictions defined in the "License.txt" file.
 //
 // This program is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 #include "Decoder_WMA.h"
 
+//Internal
 #include "Global.h"
 
+//MUtils
+#include <MUtils/Exception.h>
+
+//Qt
 #include <QDir>
 #include <QProcess>
 #include <QRegExp>
 
 WMADecoder::WMADecoder(void)
 :
-       m_binary(lamexp_lookup_tool("wmawav.exe")),
-       m_semaphore(new QSystemSemaphore("{84BB780D-67D3-49DC-ADF0-97C795A55D5C}", 1))
+       m_binary(lamexp_tools_lookup("wma2wav.exe"))
 {
        if(m_binary.isEmpty())
        {
-               throw "Error initializing WMA decoder. Tool 'wmawav.exe' is not registred!";
+               MUTILS_THROW("Error initializing WMA decoder. Tool 'wma2wav.exe' is not registred!");
        }
 }
 
@@ -49,26 +54,18 @@ bool WMADecoder::decode(const QString &sourceFile, const QString &outputFile, vo
        QProcess process;
        QStringList args;
 
-       args << pathToShort(QDir::toNativeSeparators(sourceFile)); 
-       args << pathToShort(QDir::toNativeSeparators(outputFile));
-
-       if(!m_semaphore->acquire())
-       {
-               emit messageLogged("Failed to acquire the semaphore!");
-               return false;
-       }
+       args << "-i" << QDir::toNativeSeparators(sourceFile); 
+       args << "-o" << QDir::toNativeSeparators(outputFile) << "-f";
 
        if(!startProcess(process, m_binary, args))
        {
-               m_semaphore->release();
                return false;
        }
 
        bool bTimeout = false;
        bool bAborted = false;
 
-       //The WMA Decoder doesn't actually send any status updates :-[
-       emit statusUpdated(20 + (QUuid::createUuid().data1 % 80));
+       QRegExp regExp("\\[(\\d+)\\.(\\d+)%\\]");
 
        while(process.state() != QProcess::NotRunning)
        {
@@ -79,11 +76,12 @@ bool WMADecoder::decode(const QString &sourceFile, const QString &outputFile, vo
                        emit messageLogged("\nABORTED BY USER !!!");
                        break;
                }
-               process.waitForReadyRead();
+               process.waitForReadyRead(m_processTimeoutInterval);
                if(!process.bytesAvailable() && process.state() == QProcess::Running)
                {
                        process.kill();
-                       qWarning("WmaWav process timed out <-- killing!");
+                       qWarning("wma2wav process timed out <-- killing!");
+                       emit messageLogged("\nPROCESS TIMEOUT !!!");
                        bTimeout = true;
                        break;
                }
@@ -91,7 +89,13 @@ bool WMADecoder::decode(const QString &sourceFile, const QString &outputFile, vo
                {
                        QByteArray line = process.readLine();
                        QString text = QString::fromUtf8(line.constData()).simplified();
-                       if(!text.isEmpty())
+                       if(regExp.lastIndexIn(text) >= 0)
+                       {
+                               bool ok = false;
+                               int progress = regExp.cap(1).toInt(&ok);
+                               if(ok) emit statusUpdated(progress);
+                       }
+                       else if(!text.isEmpty())
                        {
                                emit messageLogged(text);
                        }
@@ -107,9 +111,8 @@ bool WMADecoder::decode(const QString &sourceFile, const QString &outputFile, vo
        
        emit statusUpdated(100);
        emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
-       m_semaphore->release();
 
-       if(bTimeout || bAborted || process.exitStatus() != QProcess::NormalExit || QFileInfo(outputFile).size() == 0)
+       if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS || QFileInfo(outputFile).size() == 0)
        {
                return false;
        }
@@ -133,7 +136,18 @@ bool WMADecoder::isFormatSupported(const QString &containerType, const QString &
        return false;
 }
 
-bool WMADecoder::isDecoderAvailable(void)
+const AbstractDecoder::supportedType_t *WMADecoder::supportedTypes(void)
 {
-       return lamexp_check_tool("wmawav.exe");
+       static const char *exts[] =
+       {
+               "wma", "asf", NULL
+       };
+
+       static const supportedType_t s_supportedTypes[] =
+       {
+               { "Windows Media Audio", exts },
+               { NULL, NULL }
+       };
+
+       return s_supportedTypes;
 }