OSDN Git Service

Bump version.
[lamexp/LameXP.git] / src / Thread_FileAnalyzer_Task.cpp
index bef209d..cc1f7b5 100644 (file)
@@ -1,11 +1,12 @@
 ///////////////////////////////////////////////////////////////////////////////
 // LameXP - Audio Encoder Front-End
-// Copyright (C) 2004-2013 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 "Thread_FileAnalyzer_Task.h"
 
+//Internal
 #include "Global.h"
 #include "LockedFile.h"
 #include "Model_AudioFile.h"
 
+//MUtils
+#include <MUtils/Global.h>
+#include <MUtils/OSSupport.h>
+#include <MUtils/Exception.h>
+
+//Qt
 #include <QDir>
 #include <QFileInfo>
 #include <QProcess>
@@ -36,6 +44,8 @@
 #include <QWriteLocker>
 #include <QThread>
 
+
+//CRT
 #include <math.h>
 #include <time.h>
 #include <assert.h>
@@ -53,8 +63,8 @@ AnalyzeTask::AnalyzeTask(const int taskId, const QString &inputFile, const QStri
        m_taskId(taskId),
        m_inputFile(inputFile),
        m_templateFile(templateFile),
-       m_mediaInfoBin(lamexp_lookup_tool("mediainfo.exe")),
-       m_avs2wavBin(lamexp_lookup_tool("avs2wav.exe")),
+       m_mediaInfoBin(lamexp_tools_lookup("mediainfo.exe")),
+       m_avs2wavBin(lamexp_tools_lookup("avs2wav.exe")),
        m_abortFlag(abortFlag)
 {
        if(m_mediaInfoBin.isEmpty() || m_avs2wavBin.isEmpty())
@@ -80,15 +90,13 @@ void AnalyzeTask::run()
        }
        catch(const std::exception &error)
        {
-               fflush(stdout); fflush(stderr);
-               fprintf(stderr, "\nGURU MEDITATION !!!\n\nException error:\n%s\n", error.what());
-               lamexp_fatal_exit(L"Unhandeled C++ exception error, application will exit!");
+               MUTILS_PRINT_ERROR("\nGURU MEDITATION !!!\n\nException error:\n%s\n", error.what());
+               MUtils::OS::fatal_exit(L"Unhandeled C++ exception error, application will exit!");
        }
        catch(...)
        {
-               fflush(stdout); fflush(stderr);
-               fprintf(stderr, "\nGURU MEDITATION !!!\n\nUnknown exception error!\n");
-               lamexp_fatal_exit(L"Unhandeled C++ exception error, application will exit!");
+               MUTILS_PRINT_ERROR("\nGURU MEDITATION !!!\n\nUnknown exception error!\n");
+               MUtils::OS::fatal_exit(L"Unhandeled C++ exception error, application will exit!");
        }
 }
 
@@ -96,7 +104,7 @@ void AnalyzeTask::run_ex(void)
 {
        int fileType = fileTypeNormal;
        QString currentFile = QDir::fromNativeSeparators(m_inputFile);
-       qDebug("Analyzing: %s", currentFile.toUtf8().constData());
+       qDebug("Analyzing: %s", MUTILS_UTF8(currentFile));
        
        AudioFileModel file = analyzeFile(currentFile, &fileType);
 
@@ -132,12 +140,12 @@ void AnalyzeTask::run_ex(void)
                                }
                                else
                                {
-                                       qDebug("Rejected Avisynth file: %s", file.filePath().toUtf8().constData());
+                                       qDebug("Rejected Avisynth file: %s", MUTILS_UTF8(file.filePath()));
                                }
                        }
                        else
                        {
-                               qDebug("Rejected file of unknown type: %s", file.filePath().toUtf8().constData());
+                               qDebug("Rejected file of unknown type: %s", MUTILS_UTF8(file.filePath()));
                        }
                }
                break;
@@ -179,8 +187,8 @@ const AudioFileModel AnalyzeTask::analyzeFile(const QString &filePath, int *type
        params << QDir::toNativeSeparators(filePath);
        
        QProcess process;
-       process.setProcessChannelMode(QProcess::MergedChannels);
-       process.setReadChannel(QProcess::StandardOutput);
+       MUtils::init_process(process, QFileInfo(m_mediaInfoBin).absolutePath());
+
        process.start(m_mediaInfoBin, params);
                
        if(!process.waitForStarted())
@@ -219,7 +227,7 @@ const AudioFileModel AnalyzeTask::analyzeFile(const QString &filePath, int *type
                        QString line = QString::fromUtf8(process.readLine().constData()).simplified();
                        if(!line.isEmpty())
                        {
-                               //qDebug("Line:%s", line.toUtf8().constData());
+                               //qDebug("Line:%s", MUTILS_UTF8(line));
                                
                                int index = line.indexOf('=');
                                if(index > 0)
@@ -278,7 +286,7 @@ const AudioFileModel AnalyzeTask::analyzeFile(const QString &filePath, int *type
 
 void AnalyzeTask::updateInfo(AudioFileModel &audioFile, bool *skipNext, unsigned int *id_val, cover_t *coverType, QByteArray *coverData, const QString &key, const QString &value)
 {
-       //qWarning("'%s' -> '%s'", key.toUtf8().constData(), value.toUtf8().constData());
+       //qWarning("'%s' -> '%s'", MUTILS_UTF8(key), MUTILS_UTF8(value));
        
        /*New Stream*/
        if(IS_KEY("Gen_ID") || IS_KEY("Aud_ID"))
@@ -393,7 +401,7 @@ void AnalyzeTask::updateInfo(AudioFileModel &audioFile, bool *skipNext, unsigned
                }
                else
                {
-                       qWarning("Unknown key '%s' with value '%s' found!", key.toUtf8().constData(), value.toUtf8().constData());
+                       qWarning("Unknown key '%s' with value '%s' found!", MUTILS_UTF8(key), MUTILS_UTF8(value));
                }
                return;
        }
@@ -454,13 +462,13 @@ void AnalyzeTask::updateInfo(AudioFileModel &audioFile, bool *skipNext, unsigned
                }
                else
                {
-                       qWarning("Unknown key '%s' with value '%s' found!", key.toUtf8().constData(), value.toUtf8().constData());
+                       qWarning("Unknown key '%s' with value '%s' found!", MUTILS_UTF8(key), MUTILS_UTF8(value));
                }
                return;
        }
 
        /*Section not recognized*/
-       qWarning("Unknown section: %s", key.toUtf8().constData());
+       qWarning("Unknown section: %s", MUTILS_UTF8(key));
 }
 
 bool AnalyzeTask::checkFile_CDDA(QFile &file)
@@ -495,7 +503,7 @@ void AnalyzeTask::retrieveCover(AudioFileModel &audioFile, cover_t coverType, co
        
        if(!(QImage::fromData(coverData, extension.toUpper().toLatin1().constData()).isNull()))
        {
-               QFile coverFile(QString("%1/%2.%3").arg(lamexp_temp_folder2(), lamexp_rand_str(), extension));
+               QFile coverFile(QString("%1/%2.%3").arg(MUtils::temp_folder(), MUtils::rand_str(), extension));
                if(coverFile.open(QIODevice::WriteOnly))
                {
                        coverFile.write(coverData);
@@ -512,8 +520,8 @@ void AnalyzeTask::retrieveCover(AudioFileModel &audioFile, cover_t coverType, co
 bool AnalyzeTask::analyzeAvisynthFile(const QString &filePath, AudioFileModel &info)
 {
        QProcess process;
-       process.setProcessChannelMode(QProcess::MergedChannels);
-       process.setReadChannel(QProcess::StandardOutput);
+       MUtils::init_process(process, QFileInfo(m_avs2wavBin).absolutePath());
+
        process.start(m_avs2wavBin, QStringList() << QDir::toNativeSeparators(filePath) << "?");
 
        if(!process.waitForStarted())