///////////////////////////////////////////////////////////////////////////////
// LameXP - Audio Encoder Front-End
-// Copyright (C) 2004-2011 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_Initialization.h"
+//Internal
+#define LAMEXP_INC_TOOLS 1
+#include "Tools.h"
#include "LockedFile.h"
+#include "Tool_Abstract.h"
+//MUtils
+#include <MUtils/Global.h>
+#include <MUtils/OSSupport.h>
+#include <MUtils/Translation.h>
+#include <MUtils/Exception.h>
+
+//Qt
#include <QFileInfo>
#include <QCoreApplication>
#include <QProcess>
#include <QMap>
#include <QDir>
-#include <QLibrary>
#include <QResource>
-#include <QTime>
+#include <QTextStream>
+#include <QRunnable>
+#include <QThreadPool>
+#include <QMutex>
+#include <QQueue>
+#include <QElapsedTimer>
+
+/* helper macros */
+#define PRINT_CPU_TYPE(X) case X: qDebug("Selected CPU is: " #X)
+
+/* constants */
+static const double g_allowedExtractDelay = 12.0;
+static const size_t BUFF_SIZE = 512;
+static const size_t EXPECTED_TOOL_COUNT = 28;
+
+/* number of CPU cores -> number of threads */
+static unsigned int cores2threads(const unsigned int cores)
+{
+ static const size_t LUT_LEN = 4;
+
+ static const struct
+ {
+ const unsigned int upperBound;
+ const double coeffs[4];
+ }
+ LUT[LUT_LEN] =
+ {
+ { 4, { -0.052695810565, 0.158087431694, 4.982841530055, -1.088233151184 } },
+ { 8, { 0.042431693989, -0.983442622951, 9.548961748634, -7.176393442623 } },
+ { 12, { -0.006277322404, 0.185573770492, 0.196830601093, 17.762622950820 } },
+ { 32, { 0.000673497268, -0.064655737705, 3.199584699454, 5.751606557377 } }
+ };
+
+ size_t index = 0;
+ while((cores > LUT[index].upperBound) && (index < (LUT_LEN-1))) index++;
+
+ const double x = qBound(1.0, double(cores), double(LUT[LUT_LEN-1].upperBound));
+ const double y = (LUT[index].coeffs[0] * pow(x, 3.0)) + (LUT[index].coeffs[1] * pow(x, 2.0)) + (LUT[index].coeffs[2] * x) + LUT[index].coeffs[3];
+
+ return qRound(abs(y));
+}
////////////////////////////////////////////////////////////
-// CPU FLags
+// ExtractorTask class
////////////////////////////////////////////////////////////
-/* CPU_TYPE_<ARCH>_<TYPE> */
+class ExtractorTask : public QRunnable
+{
+public:
+ ExtractorTask(QResource *const toolResource, const QDir &appDir, const QString &toolName, const QByteArray &toolHash, const unsigned int toolVersion, const QString &toolTag)
+ :
+ m_appDir(appDir),
+ m_toolName(toolName),
+ m_toolHash(toolHash),
+ m_toolVersion(toolVersion),
+ m_toolTag(toolTag),
+ m_toolResource(toolResource)
+ {
+ /* Nothing to do */
+ }
-#define CPU_TYPE_X86_GEN 0x00000001UL //x86, no enhanced instruction set
-#define CPU_TYPE_X86_SSE 0x00000002UL //x86, with SSE and SSE2 support (Intel only!)
-#define CPU_TYPE_X64_GEN 0x00000004UL //x64, generic (x64 always includes SSE2)
+ ~ExtractorTask(void)
+ {
+ delete m_toolResource;
+ }
-#define CPU_TYPE_X86_ALL (CPU_TYPE_X86_GEN|CPU_TYPE_X86_SSE) //all x86 CPU's, but not x64)
-#define CPU_TYPE_ALL_SSE (CPU_TYPE_X86_SSE|CPU_TYPE_X64_GEN) //all SSE2-capable CPU's (x86 and x64)
-#define CPU_TYPE_ALL_ALL (CPU_TYPE_X86_ALL|CPU_TYPE_X64_GEN) //all CPU's, no exceptions
+ static void clearFlags(void)
+ {
+ QMutexLocker lock(&s_mutex);
+ s_bExcept = false;
+ s_bCustom = false;
+ s_errMsg[0] = char(0);
+ }
-#define IS_CPU_TYPE_X64_GEN (m_cpuFeatures.x64 && m_cpuFeatures.sse && m_cpuFeatures.sse2)
-#define IS_CPU_TYPE_X86_SSE (m_cpuFeatures.intel && m_cpuFeatures.sse && m_cpuFeatures.sse2)
+ static bool getExcept(void) { bool ret; QMutexLocker lock(&s_mutex); ret = s_bExcept; return ret; }
+ static bool getCustom(void) { bool ret; QMutexLocker lock(&s_mutex); ret = s_bCustom; return ret; }
-////////////////////////////////////////////////////////////
-// TOOLS
-////////////////////////////////////////////////////////////
+ static bool getErrMsg(char *buffer, const size_t buffSize)
+ {
+ QMutexLocker lock(&s_mutex);
+ if(s_errMsg[0])
+ {
+ strncpy_s(buffer, BUFF_SIZE, s_errMsg, _TRUNCATE);
+ return true;
+ }
+ return false;
+ }
-static const struct
-{
- char *pcHash;
- unsigned int uiCpuType;
- char *pcName;
- unsigned int uiVersion;
-}
-g_lamexp_tools[] =
-{
- {"1e4c983fe00ccc6236ee1c3f76250f64139cf86a6f4aa68f36929907fe45cf37b00862d8", CPU_TYPE_X86_GEN, "aften.i386.exe", 8},
- {"7c843f1eaf61823285237911493d8d20da11149853d4bb7953a3279196f6dbbd310c61e3", CPU_TYPE_X86_SSE, "aften.sse2.exe", 8},
- {"29da0d3e810bc3e8d2cddb3db452325eefca0d0c1fff1379fa17806ad447752be1b88e2f", CPU_TYPE_X64_GEN, "aften.x64.exe", 8},
- {"1cca303fabd889a18fc01c32a7fd861194cfcac60ba63740ea2d7c55d049dbf8f59259fa", CPU_TYPE_ALL_ALL, "alac.exe", 20},
- {"6d22d4bbd7ce2162e38f70ac9187bc84eb28233b36ee6c0492d0a6195318782d7f05c444", CPU_TYPE_ALL_ALL, "avs2wav.exe", 13},
- {"c6f23fb7ba18a7972802e013b66ec6ce52088bf4fe783774eb1d33dd3401fa8aad76cc8b", CPU_TYPE_ALL_ALL, "elevator.exe", UINT_MAX},
- {"9ae98a3fc779f69ee876a3b477fbc35a709ba5066823b2eb62eeb015057c38807e4be51f", CPU_TYPE_ALL_ALL, "faad.exe", 27},
- {"446054f9a7f705f1aadc9053ca7b8a86a775499ef159978954ebdea92de056c34f8841f7", CPU_TYPE_ALL_ALL, "flac.exe", 121},
- {"dd68d074c5e13a607580f3a24595c0f3882e37211d2ca628f46e6df20fabcc832dad488a", CPU_TYPE_ALL_ALL, "gpgv.exe", 1411},
- {"b3fca757b3567dab75c042e62213c231de378ea0fdd7fe29b733417cd5d3d33558452f94", CPU_TYPE_ALL_ALL, "gpgv.gpg", UINT_MAX},
- {"df995d8a9e4e5fab551d0e3460b9209320714dead70f662929fcc00a4bd72d8a6d23844a", CPU_TYPE_X86_GEN, "lame.i386.exe", 3990},
- {"873faeddc44243b4712cd42dd0bfc3174a07113d245dd834657519ffe5dbd4b1e395ce32", CPU_TYPE_ALL_SSE, "lame.sse2.exe", 3990},
- {"67933924d68ce319795989648f29e7bd1abaac4ec09c26cbb0ff0d15a67a9df17e257933", CPU_TYPE_ALL_ALL, "mac.exe", 406},
- {"743db1020556b1815c4d6e6093a2538ae813d7fed1e11d254b8809ce54795b77fa696bca", CPU_TYPE_X86_ALL, "mediainfo.i386.exe", 748},
- {"86ed4b4bd445b9d0c6ee094987d87fe5161102b59c8c74d11f294206c13f1a2ce899e100", CPU_TYPE_X64_GEN, "mediainfo.x64.exe", 748},
- {"a93ec86187025e66fb78026af35555bd3b4e30fe1a40e8d66f600cfd918f07f431f0b2f2", CPU_TYPE_ALL_ALL, "mpcdec.exe", 435},
- {"5a89768010efb1ddfd88ccc378a89433ceaecb403a7b1f83f8716f6848d9a05b3d3c6d93", CPU_TYPE_ALL_ALL, "mpg123.exe", 1133},
- {"0c781805dda931c529bd16069215f616a7a4c5e5c2dfb6b75fe85d52b20511830693e528", CPU_TYPE_ALL_ALL, "oggdec.exe", UINT_MAX},
- {"0c019e13450dc664987e21f4e5489d182be7d6d0d81efbbaaf1c78693dfe3e38e0355b93", CPU_TYPE_X86_GEN, "oggenc2.i386.exe", 287603},
- {"693dd6f779df70a047c15c2c79350855db38d5b0cd7e529b6877b7c821cfe6addfdd50a4", CPU_TYPE_X86_SSE, "oggenc2.sse2.exe", 287603},
- {"32cb0b2182488e5e9278ba6b9fc9141214c7546eec67ee02fa895810b0e56900368695be", CPU_TYPE_X64_GEN, "oggenc2.x64.exe", 287603},
- {"58c2b8bcff8f27bfa8fab8172b80f5da731221d072c7dba4dd3a3d7d6423490a25dc6760", CPU_TYPE_ALL_ALL, "shorten.exe", 361},
- {"abdf9b20a8031a09d0abca9cb10c31c8418f72403b5d1350fd69bfa34041591aca3060ab", CPU_TYPE_ALL_ALL, "sox.exe", 1432},
- {"48e7f81c024cd17dac0eaeab253aad6b223e72dc80688f7576276b0563209514ff0bb9c8", CPU_TYPE_ALL_ALL, "speexdec.exe", 12},
- {"9b50cf64747d4afbad5d8d9b5a0a2d41c5a58256f47ebdbd8cc920e7e576085dfe1b14ff", CPU_TYPE_ALL_ALL, "tta.exe", 21},
- {"875871c942846f6ad163f9e4949bba2f4331bec678ca5aefe58c961b6825bd0d419a078b", CPU_TYPE_ALL_ALL, "valdec.exe", 31},
- {"e657331e281840878a37eb4fb357cb79f33d528ddbd5f9b2e2f7d2194bed4720e1af8eaf", CPU_TYPE_ALL_ALL, "wget.exe", 1114},
- {"437d3817072d0b9c0bf5a1cf2daf0d7bc22106571f53cf6b6fe10942cdfdc50829847d8f", CPU_TYPE_ALL_ALL, "wma2wav.exe", 20110816},
- {"a258711f7a8a0c75528f3ed4d2c17513ff8598b7e0a9d7db13ca941a3140094ffc2ffb62", CPU_TYPE_ALL_ALL, "wupdate.exe", UINT_MAX},
- {"6b053b37d47a9c8659ebf2de43ad19dcba17b9cd868b26974b9cc8c27b6167e8bf07a5a2", CPU_TYPE_ALL_ALL, "wvunpack.exe", 4601},
- {NULL, NULL, NULL, NULL}
+protected:
+ void run(void)
+ {
+ try
+ {
+ if(!getExcept()) doExtract();
+ }
+ catch(const std::exception &e)
+ {
+ QMutexLocker lock(&s_mutex);
+ if(!s_bExcept)
+ {
+ s_bExcept = true;
+ strncpy_s(s_errMsg, BUFF_SIZE, e.what(), _TRUNCATE);
+ }
+ lock.unlock();
+ qWarning("ExtractorTask exception error:\n%s\n\n", e.what());
+ }
+ catch(...)
+ {
+ QMutexLocker lock(&s_mutex);
+ if(!s_bExcept)
+ {
+ s_bExcept = true;
+ strncpy_s(s_errMsg, BUFF_SIZE, "Unknown exception error!", _TRUNCATE);
+ }
+ lock.unlock();
+ qWarning("ExtractorTask encountered an unknown exception!");
+ }
+ }
+
+ void doExtract(void)
+ {
+ LockedFile *lockedFile = NULL;
+ unsigned int version = m_toolVersion;
+
+ QFileInfo toolFileInfo(m_toolName);
+ const QString toolShortName = QString("%1.%2").arg(toolFileInfo.baseName().toLower(), toolFileInfo.suffix().toLower());
+
+ QFileInfo customTool(QString("%1/tools/%2/%3").arg(m_appDir.canonicalPath(), QString::number(lamexp_version_build()), toolShortName));
+ if(customTool.exists() && customTool.isFile())
+ {
+ qDebug("Setting up file: %s <- %s", toolShortName.toLatin1().constData(), m_appDir.relativeFilePath(customTool.canonicalFilePath()).toLatin1().constData());
+ lockedFile = new LockedFile(customTool.canonicalFilePath()); version = UINT_MAX; s_bCustom = true;
+ }
+ else
+ {
+ qDebug("Extracting file: %s -> %s", m_toolName.toLatin1().constData(), toolShortName.toLatin1().constData());
+ lockedFile = new LockedFile(m_toolResource, QString("%1/lxp_%2").arg(MUtils::temp_folder(), toolShortName), m_toolHash);
+ }
+
+ if(lockedFile)
+ {
+ lamexp_tools_register(toolShortName, lockedFile, version, m_toolTag);
+ }
+ }
+
+private:
+ QResource *const m_toolResource;
+ const QDir m_appDir;
+ const QString m_toolName;
+ const QByteArray m_toolHash;
+ const unsigned int m_toolVersion;
+ const QString m_toolTag;
+
+ static volatile bool s_bExcept;
+ static volatile bool s_bCustom;
+ static QMutex s_mutex;
+ static char s_errMsg[BUFF_SIZE];
};
-static const double g_allowedExtractDelay = 10.0;
+QMutex ExtractorTask::s_mutex;
+char ExtractorTask::s_errMsg[BUFF_SIZE] = {'\0'};
+volatile bool ExtractorTask::s_bExcept = false;
+volatile bool ExtractorTask::s_bCustom = false;
////////////////////////////////////////////////////////////
// Constructor
////////////////////////////////////////////////////////////
-InitializationThread::InitializationThread(const lamexp_cpu_t *cpuFeatures)
+InitializationThread::InitializationThread(const MUtils::CPUFetaures::cpu_info_t &cpuFeatures)
+:
+ m_bSuccess(false),
+ m_slowIndicator(false)
{
- m_bSuccess = false;
- memset(&m_cpuFeatures, 0, sizeof(lamexp_cpu_t));
- m_slowIndicator = false;
-
- if(cpuFeatures)
- {
- memcpy(&m_cpuFeatures, cpuFeatures, sizeof(lamexp_cpu_t));
- }
+
+ memcpy(&m_cpuFeatures, &cpuFeatures, sizeof(MUtils::CPUFetaures::cpu_info_t));
}
////////////////////////////////////////////////////////////
// Thread Main
////////////////////////////////////////////////////////////
-void InitializationThread::run()
+void InitializationThread::run(void)
+{
+ try
+ {
+ doInit();
+ }
+ catch(const std::exception &error)
+ {
+ 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(...)
+ {
+ MUTILS_PRINT_ERROR("\nGURU MEDITATION !!!\n\nUnknown exception error!\n");
+ MUtils::OS::fatal_exit(L"Unhandeled C++ exception error, application will exit!");
+ }
+}
+
+double InitializationThread::doInit(const size_t threadCount)
{
m_bSuccess = false;
- bool bCustom = false;
delay();
//CPU type selection
- const unsigned int cpuSupport = IS_CPU_TYPE_X64_GEN ? CPU_TYPE_X64_GEN : (IS_CPU_TYPE_X86_SSE ? CPU_TYPE_X86_SSE : CPU_TYPE_X86_GEN);
-
- //Allocate maps
- QMap<QString, QString> mapChecksum;
- QMap<QString, unsigned int> mapVersion;
- QMap<QString, unsigned int> mapCpuType;
+ unsigned int cpuSupport = 0;
+ if((m_cpuFeatures.features & MUtils::CPUFetaures::FLAG_SSE) && (m_cpuFeatures.features & MUtils::CPUFetaures::FLAG_SSE2) && m_cpuFeatures.intel)
+ {
+ cpuSupport = m_cpuFeatures.x64 ? CPU_TYPE_X64_SSE : CPU_TYPE_X86_SSE;
+ }
+ else
+ {
+ cpuSupport = m_cpuFeatures.x64 ? CPU_TYPE_X64_GEN : CPU_TYPE_X86_GEN;
+ }
+
+ //Hack to disable x64 on Wine, as x64 binaries won't run under Wine (tested with Wine 1.4 under Ubuntu 12.04 x64)
+ if(cpuSupport & CPU_TYPE_X64_ALL)
+ {
+ if(MUtils::OS::running_on_wine())
+ {
+ qWarning("Running under Wine on a 64-Bit system. Going to disable all x64 support!\n");
+ cpuSupport = (cpuSupport == CPU_TYPE_X64_SSE) ? CPU_TYPE_X86_SSE : CPU_TYPE_X86_GEN;
+ }
+ }
+
+ //Print selected CPU type
+ switch(cpuSupport)
+ {
+ PRINT_CPU_TYPE(CPU_TYPE_X86_GEN); break;
+ PRINT_CPU_TYPE(CPU_TYPE_X86_SSE); break;
+ PRINT_CPU_TYPE(CPU_TYPE_X64_GEN); break;
+ PRINT_CPU_TYPE(CPU_TYPE_X64_SSE); break;
+ default: MUTILS_THROW("CPU support undefined!");
+ }
+
+ //Allocate queues
+ QQueue<QString> queueToolName;
+ QQueue<QString> queueChecksum;
+ QQueue<QString> queueVersInfo;
+ QQueue<unsigned int> queueVersions;
+ QQueue<unsigned int> queueCpuTypes;
//Init properties
- for(int i = 0; i < INT_MAX; i++)
+ for(int i = 0; true; i++)
{
- if(!g_lamexp_tools[i].pcName && !g_lamexp_tools[i].pcHash && !g_lamexp_tools[i].uiVersion)
+ if(!(g_lamexp_tools[i].pcName || g_lamexp_tools[i].pcHash || g_lamexp_tools[i].uiVersion))
{
break;
}
else if(g_lamexp_tools[i].pcName && g_lamexp_tools[i].pcHash && g_lamexp_tools[i].uiVersion)
{
- const QString currentTool = QString::fromLatin1(g_lamexp_tools[i].pcName);
- mapChecksum.insert(currentTool, QString::fromLatin1(g_lamexp_tools[i].pcHash));
- mapCpuType.insert(currentTool, g_lamexp_tools[i].uiCpuType);
- mapVersion.insert(currentTool, g_lamexp_tools[i].uiVersion);
+ queueToolName.enqueue(QString::fromLatin1(g_lamexp_tools[i].pcName));
+ queueChecksum.enqueue(QString::fromLatin1(g_lamexp_tools[i].pcHash));
+ queueVersInfo.enqueue(QString::fromLatin1(g_lamexp_tools[i].pcVersTag));
+ queueCpuTypes.enqueue(g_lamexp_tools[i].uiCpuType);
+ queueVersions.enqueue(g_lamexp_tools[i].uiVersion);
}
else
{
}
}
- QDir toolsDir(":/tools/");
- QList<QFileInfo> toolsList = toolsDir.entryInfoList(QStringList("*.*"), QDir::Files, QDir::Name);
QDir appDir = QDir(QCoreApplication::applicationDirPath()).canonicalPath();
- QTime timer;
- timer.start();
+ QThreadPool *pool = new QThreadPool();
+ pool->setMaxThreadCount((threadCount > 0) ? threadCount : qBound(2U, cores2threads(m_cpuFeatures.count), EXPECTED_TOOL_COUNT));
+ /* qWarning("Using %u threads for extraction.", pool->maxThreadCount()); */
+
+ LockedFile::selfTest();
+ ExtractorTask::clearFlags();
+
+ //Start the timer
+ QElapsedTimer timeExtractStart;
+ timeExtractStart.start();
//Extract all files
- while(!toolsList.isEmpty())
+ while(!(queueToolName.isEmpty() || queueChecksum.isEmpty() || queueVersInfo.isEmpty() || queueCpuTypes.isEmpty() || queueVersions.isEmpty()))
{
- try
- {
- QFileInfo currentTool = toolsList.takeFirst();
- QString toolName = currentTool.fileName().toLower();
- QString toolShortName = QString("%1.%2").arg(currentTool.baseName().toLower(), currentTool.suffix().toLower());
+ const QString toolName = queueToolName.dequeue();
+ const QString checksum = queueChecksum.dequeue();
+ const QString versInfo = queueVersInfo.dequeue();
+ const unsigned int cpuType = queueCpuTypes.dequeue();
+ const unsigned int version = queueVersions.dequeue();
- QByteArray toolHash = mapChecksum.take(toolName).toLatin1();
- unsigned int toolCpuType = mapCpuType.take(toolName);
- unsigned int toolVersion = mapVersion.take(toolName);
-
- if(toolHash.size() != 72)
- {
- throw "The required checksum is missing, take care!";
- }
+ const QByteArray toolHash(checksum.toLatin1());
+ if(toolHash.size() != 96)
+ {
+ qFatal("The checksum for \"%s\" has an invalid size!", MUTILS_UTF8(toolName));
+ return -1.0;
+ }
- if(toolCpuType & cpuSupport)
- {
- QFileInfo customTool(QString("%1/tools/%2/%3").arg(appDir.canonicalPath(), QString::number(lamexp_version_build()), toolShortName));
- if(customTool.exists() && customTool.isFile())
- {
- bCustom = true;
- qDebug("Setting up file: %s <- %s", toolShortName.toLatin1().constData(), appDir.relativeFilePath(customTool.canonicalFilePath()).toLatin1().constData());
- LockedFile *lockedFile = new LockedFile(customTool.canonicalFilePath());
- lamexp_register_tool(toolShortName, lockedFile, UINT_MAX);
- }
- else
- {
- qDebug("Extracting file: %s -> %s", toolName.toLatin1().constData(), toolShortName.toLatin1().constData());
- LockedFile *lockedFile = new LockedFile(QString(":/tools/%1").arg(toolName), QString("%1/tool_%2").arg(lamexp_temp_folder2(), toolShortName), toolHash);
- lamexp_register_tool(toolShortName, lockedFile, toolVersion);
- }
- }
+ QResource *resource = new QResource(QString(":/tools/%1").arg(toolName));
+ if(!(resource->isValid() && resource->data()))
+ {
+ MUTILS_DELETE(resource);
+ qFatal("The resource for \"%s\" could not be found!", MUTILS_UTF8(toolName));
+ return -1.0;
}
- catch(char *errorMsg)
+
+ if(cpuType & cpuSupport)
{
- qFatal("At least one of the required tools could not be initialized:\n%s", errorMsg);
- return;
+ pool->start(new ExtractorTask(resource, appDir, toolName, toolHash, version, versInfo));
+ continue;
}
+
+ MUTILS_DELETE(resource);
}
-
- //Make sure all files were extracted
- if(!mapChecksum.isEmpty())
+
+ //Sanity Check
+ if(!(queueToolName.isEmpty() && queueChecksum.isEmpty() && queueVersInfo.isEmpty() && queueCpuTypes.isEmpty() && queueVersions.isEmpty()))
{
- qFatal("At least one required tool could not be found:\n%s", toolsDir.filePath(mapChecksum.keys().first()).toLatin1().constData());
- return;
+ qFatal("Checksum queues *not* empty fater verification completed. Take care!");
}
-
+
+ //Wait for extrator threads to finish
+ pool->waitForDone();
+ MUTILS_DELETE(pool);
+
+ //Performance measure
+ const double delayExtract = double(timeExtractStart.elapsed()) / 1000.0;
+ timeExtractStart.invalidate();
+
+ //Make sure all files were extracted correctly
+ if(ExtractorTask::getExcept())
+ {
+ char errorMsg[BUFF_SIZE];
+ if(ExtractorTask::getErrMsg(errorMsg, BUFF_SIZE))
+ {
+ qFatal("At least one of the required tools could not be initialized:\n%s", errorMsg);
+ return -1.0;
+ }
+ qFatal("At least one of the required tools could not be initialized!");
+ return -1.0;
+ }
+
qDebug("All extracted.\n");
- //Clean-up
- mapChecksum.clear();
- mapVersion.clear();
- mapCpuType.clear();
-
//Using any custom tools?
- if(bCustom)
+ if(ExtractorTask::getCustom())
{
qWarning("Warning: Using custom tools, you might encounter unexpected problems!\n");
}
//Check delay
- double delayExtract = static_cast<double>(timer.elapsed()) / 1000.0;
if(delayExtract > g_allowedExtractDelay)
{
m_slowIndicator = true;
qWarning("Extracting tools took %.3f seconds -> probably slow realtime virus scanner.", delayExtract);
qWarning("Please report performance problems to your anti-virus developer !!!\n");
}
+ else
+ {
+ qDebug("Extracting the tools took %.3f seconds (OK).\n", delayExtract);
+ }
//Register all translations
initTranslations();
- //Look for Nero AAC encoder
- initNeroAac();
-
- //Look for FHG AAC encoder
- initFhgAac();
+ //Look for AAC encoders
+ initAacEnc_Nero();
+ initAacEnc_FHG();
+ initAacEnc_QAAC();
- delay();
m_bSuccess = true;
+ delay();
+
+ return delayExtract;
}
////////////////////////////////////////////////////////////
-// PUBLIC FUNCTIONS
+// INTERNAL FUNCTIONS
////////////////////////////////////////////////////////////
void InitializationThread::delay(void)
{
- const char *temp = "|/-\\";
- printf("Thread is doing something important... ?\b", temp[4]);
-
- for(int i = 0; i < 20; i++)
- {
- printf("%c\b", temp[i%4]);
- msleep(25);
- }
-
- printf("Done\n\n");
+ MUtils::OS::sleep_ms(333);
}
+////////////////////////////////////////////////////////////
+// Translation Support
+////////////////////////////////////////////////////////////
+
void InitializationThread::initTranslations(void)
{
//Search for language files
- QStringList qmFiles = QDir(":/localization").entryList(QStringList() << "LameXP_??.qm", QDir::Files, QDir::Name);
+ const QDir qmDirectory(":/localization");
+ const QStringList qmFiles = qmDirectory.entryList(QStringList() << "LameXP_??.qm", QDir::Files, QDir::Name);
//Make sure we found at least one translation
if(qmFiles.count() < 1)
return;
}
+ //Initialize variables
+ const QString langResTemplate(":/localization/%1.txt");
+ QRegExp langIdExp("^LameXP_(\\w\\w)\\.qm$", Qt::CaseInsensitive);
+
//Add all available translations
- while(!qmFiles.isEmpty())
+ for(QStringList::ConstIterator iter = qmFiles.constBegin(); iter != qmFiles.constEnd(); iter++)
{
+ const QString langFile = qmDirectory.absoluteFilePath(*iter);
QString langId, langName;
- unsigned int systemId = 0;
- QString qmFile = qmFiles.takeFirst();
+ unsigned int systemId = 0, country = 0;
- QRegExp langIdExp("LameXP_(\\w\\w)\\.qm", Qt::CaseInsensitive);
- if(langIdExp.indexIn(qmFile) >= 0)
+ if(QFileInfo(langFile).isFile() && (langIdExp.indexIn(*iter) >= 0))
{
langId = langIdExp.cap(1).toLower();
+ QResource langRes = QResource(langResTemplate.arg(*iter));
+ if(langRes.isValid() && langRes.size() > 0)
+ {
+ QByteArray data = QByteArray::fromRawData(reinterpret_cast<const char*>(langRes.data()), langRes.size());
+ QTextStream stream(&data, QIODevice::ReadOnly);
+ stream.setAutoDetectUnicode(false); stream.setCodec("UTF-8");
+
+ while(!(stream.atEnd() || (stream.status() != QTextStream::Ok)))
+ {
+ QStringList langInfo = stream.readLine().simplified().split(",", QString::SkipEmptyParts);
+ if(langInfo.count() >= 3)
+ {
+ systemId = langInfo.at(0).trimmed().toUInt();
+ country = langInfo.at(1).trimmed().toUInt();
+ langName = langInfo.at(2).trimmed();
+ break;
+ }
+ }
+ }
}
- QResource langRes = (QString(":/localization/%1.txt").arg(qmFile));
- if(langRes.isValid() && langRes.size() > 0)
+ if(!(langId.isEmpty() || langName.isEmpty() || (systemId == 0)))
{
- QStringList langInfo = QString::fromUtf8(reinterpret_cast<const char*>(langRes.data()), langRes.size()).simplified().split(",", QString::SkipEmptyParts);
- if(langInfo.count() == 2)
+ if(MUtils::Translation::insert(langId, langFile, langName, systemId, country))
{
- systemId = langInfo.at(0).toUInt();
- langName = langInfo.at(1);
+ qDebug("Registering translation: %s = %s (%u) [%u]", MUTILS_UTF8(*iter), MUTILS_UTF8(langName), systemId, country);
+ }
+ else
+ {
+ qWarning("Failed to register: %s", langFile.toLatin1().constData());
}
- }
-
- if(lamexp_translation_register(langId, qmFile, langName, systemId))
- {
- qDebug64("Registering translation: %1 = %2 (%3)", qmFile, langName, QString::number(systemId));
- }
- else
- {
- qWarning("Failed to register: %s", qmFile.toLatin1().constData());
}
}
qDebug("All registered.\n");
}
-void InitializationThread::initNeroAac(void)
+////////////////////////////////////////////////////////////
+// AAC Encoder Detection
+////////////////////////////////////////////////////////////
+
+void InitializationThread::initAacEnc_Nero(void)
{
const QString appPath = QDir(QCoreApplication::applicationDirPath()).canonicalPath();
- QFileInfo neroFileInfo[3];
- neroFileInfo[0] = QFileInfo(QString("%1/neroAacEnc.exe").arg(appPath));
- neroFileInfo[1] = QFileInfo(QString("%1/neroAacDec.exe").arg(appPath));
- neroFileInfo[2] = QFileInfo(QString("%1/neroAacTag.exe").arg(appPath));
+ const QFileInfo neroFileInfo[3] =
+ {
+ QFileInfo(QString("%1/neroAacEnc.exe").arg(appPath)),
+ QFileInfo(QString("%1/neroAacDec.exe").arg(appPath)),
+ QFileInfo(QString("%1/neroAacTag.exe").arg(appPath))
+ };
bool neroFilesFound = true;
- for(int i = 0; i < 3; i++) { if(!neroFileInfo[i].exists()) neroFilesFound = false; }
+ for(int i = 0; i < 3; i++)
+ {
+ if(!(neroFileInfo[i].exists() && neroFileInfo[i].isFile()))
+ {
+ neroFilesFound = false;
+ }
+ }
- //Lock the Nero binaries
if(!neroFilesFound)
{
- qDebug("Nero encoder binaries not found -> AAC encoding support will be disabled!\n");
+ qDebug("Nero encoder binaries not found -> NeroAAC encoding support will be disabled!\n");
return;
}
- qDebug("Found Nero AAC encoder binary:\n%s\n", neroFileInfo[0].canonicalFilePath().toUtf8().constData());
+ for(int i = 0; i < 3; i++)
+ {
+ if(!MUtils::OS::is_executable_file(neroFileInfo[i].canonicalFilePath()))
+ {
+ qDebug("%s executbale is invalid -> NeroAAC encoding support will be disabled!\n", MUTILS_UTF8(neroFileInfo[i].fileName()));
+ return;
+ }
+ }
- LockedFile *neroBin[3];
- for(int i = 0; i < 3; i++) neroBin[i] = NULL;
+ qDebug("Found Nero AAC encoder binary:\n%s\n", MUTILS_UTF8(neroFileInfo[0].canonicalFilePath()));
+ //Lock the Nero binaries
+ QScopedPointer<LockedFile> neroBin[3];
try
{
for(int i = 0; i < 3; i++)
{
- neroBin[i] = new LockedFile(neroFileInfo[i].canonicalFilePath());
+ neroBin[i].reset(new LockedFile(neroFileInfo[i].canonicalFilePath()));
}
}
catch(...)
{
- for(int i = 0; i < 3; i++) LAMEXP_DELETE(neroBin[i]);
- qWarning("Failed to get excluive lock to Nero encoder binary -> AAC encoding support will be disabled!");
+ qWarning("Failed to get excluive lock to Nero encoder binary -> NeroAAC encoding support will be disabled!");
return;
}
QProcess process;
- process.setProcessChannelMode(QProcess::MergedChannels);
- process.setReadChannel(QProcess::StandardOutput);
+ MUtils::init_process(process, neroFileInfo[0].absolutePath());
+
process.start(neroFileInfo[0].canonicalFilePath(), QStringList() << "-help");
if(!process.waitForStarted())
qWarning("Error message: \"%s\"\n", process.errorString().toLatin1().constData());
process.kill();
process.waitForFinished(-1);
- for(int i = 0; i < 3; i++) LAMEXP_DELETE(neroBin[i]);
return;
}
- unsigned int neroVersion = 0;
+ bool neroSigFound = false;
+ quint32 neroVersion = 0;
+
+ QRegExp neroAacEncSig("Nero\\s+AAC\\s+Encoder", Qt::CaseInsensitive);
+ QRegExp neroAacEncVer("Package\\s+version:\\s+(\\d)\\.(\\d)\\.(\\d)\\.(\\d)", Qt::CaseInsensitive);
while(process.state() != QProcess::NotRunning)
{
{
if(process.state() == QProcess::Running)
{
- qWarning("Nero process time out -> killing!");
+ qWarning("NeroAAC process time out -> killing!");
process.kill();
process.waitForFinished(-1);
- for(int i = 0; i < 3; i++) LAMEXP_DELETE(neroBin[i]);
return;
}
}
-
while(process.canReadLine())
{
QString line = QString::fromUtf8(process.readLine().constData()).simplified();
- QStringList tokens = line.split(" ", QString::SkipEmptyParts, Qt::CaseInsensitive);
- int index1 = tokens.indexOf("Package");
- int index2 = tokens.indexOf("version:");
- if(index1 >= 0 && index2 >= 0 && index1 + 1 == index2 && index2 < tokens.count() - 1)
+ if(neroAacEncSig.lastIndexIn(line) >= 0)
{
- QStringList versionTokens = tokens.at(index2 + 1).split(".", QString::SkipEmptyParts, Qt::CaseInsensitive);
- if(versionTokens.count() == 4)
+ neroSigFound = true;
+ continue;
+ }
+ if(neroSigFound && (neroAacEncVer.lastIndexIn(line) >= 0))
+ {
+ quint32 tmp[4];
+ if(MUtils::regexp_parse_uint32(neroAacEncVer, tmp, 4))
{
- neroVersion = 0;
- neroVersion += min(9, max(0, versionTokens.at(3).toInt()));
- neroVersion += min(9, max(0, versionTokens.at(2).toInt())) * 10;
- neroVersion += min(9, max(0, versionTokens.at(1).toInt())) * 100;
- neroVersion += min(9, max(0, versionTokens.at(0).toInt())) * 1000;
+ neroVersion = (qBound(0U, tmp[0], 9U) * 1000U) + (qBound(0U, tmp[1], 9U) * 100U) + (qBound(0U, tmp[2], 9U) * 10U) + qBound(0U, tmp[3], 9U);
}
}
}
}
- if(!(neroVersion > 0))
+ if(neroVersion <= 0)
{
- qWarning("Nero AAC version could not be determined -> AAC encoding support will be disabled!");
- for(int i = 0; i < 3; i++) LAMEXP_DELETE(neroBin[i]);
+ qWarning("NeroAAC version could not be determined -> NeroAAC encoding support will be disabled!");
return;
}
-
+ else if(neroVersion < lamexp_toolver_neroaac())
+ {
+ qWarning("NeroAAC version is too much outdated (%s) -> NeroAAC support will be disabled!", MUTILS_UTF8(lamexp_version2string("v?.?.?.?", neroVersion, "N/A")));
+ qWarning("Minimum required NeroAAC version currently is: %s\n", MUTILS_UTF8(lamexp_version2string("v?.?.?.?", lamexp_toolver_neroaac(), "N/A")));
+ return;
+ }
+
+ qDebug("Enabled NeroAAC encoder %s.\n", MUTILS_UTF8(lamexp_version2string("v?.?.?.?", neroVersion, "N/A")));
+
for(int i = 0; i < 3; i++)
{
- lamexp_register_tool(neroFileInfo[i].fileName(), neroBin[i], neroVersion);
+ lamexp_tools_register(neroFileInfo[i].fileName(), neroBin[i].take(), neroVersion);
}
}
-void InitializationThread::initFhgAac(void)
+void InitializationThread::initAacEnc_FHG(void)
{
const QString appPath = QDir(QCoreApplication::applicationDirPath()).canonicalPath();
- QFileInfo fhgFileInfo[4];
- fhgFileInfo[0] = QFileInfo(QString("%1/fhgaacenc.exe").arg(appPath));
- fhgFileInfo[1] = QFileInfo(QString("%1/enc_fhgaac.dll").arg(appPath));
- fhgFileInfo[2] = QFileInfo(QString("%1/nsutil.dll").arg(appPath));
- fhgFileInfo[3] = QFileInfo(QString("%1/libmp4v2.dll").arg(appPath));
+ const QFileInfo fhgFileInfo[5] =
+ {
+ QFileInfo(QString("%1/fhgaacenc.exe") .arg(appPath)),
+ QFileInfo(QString("%1/enc_fhgaac.dll") .arg(appPath)),
+ QFileInfo(QString("%1/nsutil.dll") .arg(appPath)),
+ QFileInfo(QString("%1/libmp4v2.dll") .arg(appPath)),
+ QFileInfo(QString("%1/libsndfile-1.dll").arg(appPath))
+ };
bool fhgFilesFound = true;
- for(int i = 0; i < 4; i++) { if(!fhgFileInfo[i].exists()) fhgFilesFound = false; }
+ for(int i = 0; i < 5; i++)
+ {
+ if(!(fhgFileInfo[i].exists() && fhgFileInfo[i].isFile()))
+ {
+ fhgFilesFound = false;
+ }
+ }
- //Lock the FhgAacEnc binaries
if(!fhgFilesFound)
{
qDebug("FhgAacEnc binaries not found -> FhgAacEnc support will be disabled!\n");
return;
}
- qDebug("Found FhgAacEnc cli_exe:\n%s\n", fhgFileInfo[0].canonicalFilePath().toUtf8().constData());
- qDebug("Found FhgAacEnc enc_dll:\n%s\n", fhgFileInfo[1].canonicalFilePath().toUtf8().constData());
+ if(!MUtils::OS::is_executable_file(fhgFileInfo[0].canonicalFilePath()))
+ {
+ qDebug("FhgAacEnc executbale is invalid -> FhgAacEnc support will be disabled!\n");
+ return;
+ }
- LockedFile *fhgBin[4];
- for(int i = 0; i < 4; i++) fhgBin[i] = NULL;
+ qDebug("Found FhgAacEnc cli_exe:\n%s\n", MUTILS_UTF8(fhgFileInfo[0].canonicalFilePath()));
+ qDebug("Found FhgAacEnc enc_dll:\n%s\n", MUTILS_UTF8(fhgFileInfo[1].canonicalFilePath()));
+ //Lock the FhgAacEnc binaries
+ QScopedPointer<LockedFile> fhgBin[5];
try
{
- for(int i = 0; i < 4; i++)
+ for(int i = 0; i < 5; i++)
{
- fhgBin[i] = new LockedFile(fhgFileInfo[i].canonicalFilePath());
+ fhgBin[i].reset(new LockedFile(fhgFileInfo[i].canonicalFilePath()));
}
}
catch(...)
{
- for(int i = 0; i < 4; i++) LAMEXP_DELETE(fhgBin[i]);
qWarning("Failed to get excluive lock to FhgAacEnc binary -> FhgAacEnc support will be disabled!");
return;
}
QProcess process;
- process.setProcessChannelMode(QProcess::MergedChannels);
- process.setReadChannel(QProcess::StandardOutput);
+ MUtils::init_process(process, fhgFileInfo[0].absolutePath());
+
process.start(fhgFileInfo[0].canonicalFilePath(), QStringList() << "--version");
if(!process.waitForStarted())
qWarning("Error message: \"%s\"\n", process.errorString().toLatin1().constData());
process.kill();
process.waitForFinished(-1);
- for(int i = 0; i < 4; i++) LAMEXP_DELETE(fhgBin[i]);
return;
}
+ quint32 fhgVersion = 0;
QRegExp fhgAacEncSig("fhgaacenc version (\\d+) by tmkk", Qt::CaseInsensitive);
- unsigned int fhgVersion = 0;
while(process.state() != QProcess::NotRunning)
{
qWarning("FhgAacEnc process time out -> killing!");
process.kill();
process.waitForFinished(-1);
- for(int i = 0; i < 4; i++) LAMEXP_DELETE(fhgBin[i]);
return;
}
while(process.bytesAvailable() > 0)
QString line = QString::fromUtf8(process.readLine().constData()).simplified();
if(fhgAacEncSig.lastIndexIn(line) >= 0)
{
- bool ok = false;
- unsigned int temp = fhgAacEncSig.cap(1).toUInt(&ok);
- if(ok) fhgVersion = temp;
+ quint32 tmp;
+ if(MUtils::regexp_parse_uint32(fhgAacEncSig, tmp))
+ {
+ fhgVersion = tmp;
+ }
}
}
}
- if(!(fhgVersion > 0))
+ if(fhgVersion <= 0)
{
qWarning("FhgAacEnc version couldn't be determined -> FhgAacEnc support will be disabled!");
- for(int i = 0; i < 4; i++) LAMEXP_DELETE(fhgBin[i]);
return;
}
else if(fhgVersion < lamexp_toolver_fhgaacenc())
{
- qWarning("FhgAacEnc version is too much outdated -> FhgAacEnc support will be disabled!");
- for(int i = 0; i < 4; i++) LAMEXP_DELETE(fhgBin[i]);
+ qWarning("FhgAacEnc version is too much outdated (%s) -> FhgAacEnc support will be disabled!", MUTILS_UTF8(lamexp_version2string("????-??-??", fhgVersion, "N/A")));
+ qWarning("Minimum required FhgAacEnc version currently is: %s\n", MUTILS_UTF8(lamexp_version2string("????-??-??", lamexp_toolver_fhgaacenc(), "N/A")));
return;
}
- for(int i = 0; i < 4; i++)
+ qDebug("Enabled FhgAacEnc %s.\n", MUTILS_UTF8(lamexp_version2string("????-??-??", fhgVersion, "N/A")));
+
+ for(int i = 0; i < 5; i++)
{
- lamexp_register_tool(fhgFileInfo[i].fileName(), fhgBin[i], fhgVersion);
+ lamexp_tools_register(fhgFileInfo[i].fileName(), fhgBin[i].take(), fhgVersion);
}
}
-//void InitializationThread::initWmaDec(void)
-//{
-// static const char* wmaDecoderComponentPath = "NCH Software/Components/wmawav/wmawav.exe";
-//
-// LockedFile *wmaFileBin = NULL;
-// QFileInfo wmaFileInfo = QFileInfo(QString("%1/%2").arg(lamexp_known_folder(lamexp_folder_programfiles), wmaDecoderComponentPath));
-//
-// if(!(wmaFileInfo.exists() && wmaFileInfo.isFile()))
-// {
-// wmaFileInfo.setFile(QString("%1/%2").arg(QDir(QCoreApplication::applicationDirPath()).canonicalPath(), "wmawav.exe"));
-// }
-// if(!(wmaFileInfo.exists() && wmaFileInfo.isFile()))
-// {
-// qDebug("WMA File Decoder not found -> WMA decoding support will be disabled!\n");
-// return;
-// }
-//
-// try
-// {
-// wmaFileBin = new LockedFile(wmaFileInfo.canonicalFilePath());
-// }
-// catch(...)
-// {
-// qWarning("Failed to get excluive lock to WMA File Decoder binary -> WMA decoding support will be disabled!");
-// return;
-// }
-//
-// QProcess process;
-// process.setProcessChannelMode(QProcess::MergedChannels);
-// process.setReadChannel(QProcess::StandardOutput);
-// process.start(wmaFileInfo.canonicalFilePath(), QStringList());
-//
-// if(!process.waitForStarted())
-// {
-// qWarning("WmaWav process failed to create!");
-// qWarning("Error message: \"%s\"\n", process.errorString().toLatin1().constData());
-// process.kill();
-// process.waitForFinished(-1);
-// return;
-// }
-//
-// bool b_wmaWavFound = false;
-//
-// while(process.state() != QProcess::NotRunning)
-// {
-// if(!process.waitForReadyRead())
-// {
-// if(process.state() == QProcess::Running)
-// {
-// qWarning("WmaWav process time out -> killing!");
-// process.kill();
-// process.waitForFinished(-1);
-// return;
-// }
-// }
-// while(process.canReadLine())
-// {
-// QString line = QString::fromUtf8(process.readLine().constData()).simplified();
-// if(line.contains("Usage: wmatowav.exe WMAFileSpec WAVFileSpec", Qt::CaseInsensitive))
-// {
-// b_wmaWavFound = true;
-// }
-// }
-// }
-//
-// if(!b_wmaWavFound)
-// {
-// qWarning("WmaWav could not be identified -> WMA decoding support will be disabled!\n");
-// LAMEXP_DELETE(wmaFileBin);
-// return;
-// }
-//
-// qDebug("Found WMA File Decoder binary:\n%s\n", wmaFileInfo.canonicalFilePath().toUtf8().constData());
-//
-// if(wmaFileBin)
-// {
-// lamexp_register_tool(wmaFileInfo.fileName(), wmaFileBin);
-// }
-//}
+void InitializationThread::initAacEnc_QAAC(void)
+{
+ const QString appPath = QDir(QCoreApplication::applicationDirPath()).canonicalPath();
+
+ const QFileInfo qaacFileInfo[3] =
+ {
+ QFileInfo(QString("%1/qaac.exe") .arg(appPath)),
+ QFileInfo(QString("%1/libsoxr.dll") .arg(appPath)),
+ QFileInfo(QString("%1/libsoxconvolver.dll").arg(appPath))
+ };
+
+ bool qaacFilesFound = true;
+ for(int i = 0; i < 3; i++)
+ {
+ if(!(qaacFileInfo[i].exists() && qaacFileInfo[i].isFile()))
+ {
+ qaacFilesFound = false;
+ }
+ }
+
+ if(!qaacFilesFound)
+ {
+ qDebug("QAAC binary or companion DLL's not found -> QAAC support will be disabled!\n");
+ return;
+ }
+
+ if(!MUtils::OS::is_executable_file(qaacFileInfo[0].canonicalFilePath()))
+ {
+ qDebug("QAAC executbale is invalid -> QAAC support will be disabled!\n");
+ return;
+ }
+
+ qDebug("Found QAAC encoder:\n%s\n", MUTILS_UTF8(qaacFileInfo[0].canonicalFilePath()));
+
+ //Lock the required QAAC binaries
+ QScopedPointer<LockedFile> qaacBin[3];
+ try
+ {
+ for(int i = 0; i < 3; i++)
+ {
+ qaacBin[i].reset(new LockedFile(qaacFileInfo[i].canonicalFilePath()));
+ }
+ }
+ catch(...)
+ {
+ qWarning("Failed to get excluive lock to QAAC binary -> QAAC support will be disabled!");
+ return;
+ }
+
+ QProcess process;
+ MUtils::init_process(process, qaacFileInfo[0].absolutePath());
+ process.start(qaacFileInfo[0].canonicalFilePath(), QStringList() << "--check");
+
+ if(!process.waitForStarted())
+ {
+ qWarning("QAAC process failed to create!");
+ qWarning("Error message: \"%s\"\n", process.errorString().toLatin1().constData());
+ process.kill();
+ process.waitForFinished(-1);
+ return;
+ }
+
+ QRegExp qaacEncSig("qaac (\\d)\\.(\\d+)", Qt::CaseInsensitive);
+ QRegExp coreEncSig("CoreAudioToolbox (\\d)\\.(\\d)\\.(\\d)\\.(\\d)", Qt::CaseInsensitive);
+ QRegExp soxrEncSig("libsoxr-\\d\\.\\d\\.\\d", Qt::CaseInsensitive);
+ QRegExp soxcEncSig("libsoxconvolver \\d\\.\\d\\.\\d", Qt::CaseInsensitive);
+
+ quint32 qaacVersion = 0;
+ quint32 coreVersion = 0;
+ bool soxrFound = false;
+ bool soxcFound = false;
+
+ while(process.state() != QProcess::NotRunning)
+ {
+ process.waitForReadyRead();
+ if(!process.bytesAvailable() && process.state() == QProcess::Running)
+ {
+ qWarning("QAAC process time out -> killing!");
+ process.kill();
+ process.waitForFinished(-1);
+ return;
+ }
+ while(process.bytesAvailable() > 0)
+ {
+ QString line = QString::fromUtf8(process.readLine().constData()).simplified();
+ if(qaacEncSig.lastIndexIn(line) >= 0)
+ {
+ quint32 tmp[2];
+ if(MUtils::regexp_parse_uint32(qaacEncSig, tmp, 2))
+ {
+ qaacVersion = (qBound(0U, tmp[0], 9U) * 100) + qBound(0U, tmp[1], 99U);
+ }
+ }
+ if(coreEncSig.lastIndexIn(line) >= 0)
+ {
+ quint32 tmp[4];
+ if(MUtils::regexp_parse_uint32(coreEncSig, tmp, 4))
+ {
+ coreVersion = (qBound(0U, tmp[0], 9U) * 1000U) + (qBound(0U, tmp[1], 9U) * 100U) + (qBound(0U, tmp[2], 9U) * 10U) + qBound(0U, tmp[3], 9U);
+ }
+ }
+ if(soxcEncSig.lastIndexIn(line) >= 0)
+ {
+ soxcFound = true;
+ }
+ if(soxrEncSig.lastIndexIn(line) >= 0)
+ {
+ soxrFound = true;
+ }
+ }
+ }
+
+ if(qaacVersion <= 0)
+ {
+ qWarning("QAAC version couldn't be determined -> QAAC support will be disabled!");
+ return;
+ }
+ else if(qaacVersion < lamexp_toolver_qaacenc())
+ {
+ qWarning("QAAC version is too much outdated (%s) -> QAAC support will be disabled!", MUTILS_UTF8(lamexp_version2string("v?.??", qaacVersion, "N/A")));
+ qWarning("Minimum required QAAC version currently is: %s.\n", MUTILS_UTF8(lamexp_version2string("v?.??", lamexp_toolver_qaacenc(), "N/A")));
+ return;
+ }
+
+ if(coreVersion <= 0)
+ {
+ qWarning("CoreAudioToolbox version couldn't be determined -> QAAC support will be disabled!");
+ return;
+ }
+ else if(coreVersion < lamexp_toolver_coreaudio())
+ {
+ qWarning("CoreAudioToolbox version is outdated (%s) -> QAAC support will be disabled!", MUTILS_UTF8(lamexp_version2string("v?.?.?.?", coreVersion, "N/A")));
+ qWarning("Minimum required CoreAudioToolbox version currently is: %s.\n", MUTILS_UTF8(lamexp_version2string("v?.?.?.?", lamexp_toolver_coreaudio(), "N/A")));
+ return;
+ }
+
+ if(!(soxrFound && soxcFound))
+ {
+ qWarning("libsoxr and/or libsoxconvolver not available -> QAAC support will be disabled!\n");
+ return;
+ }
+
+ qDebug("Enabled qaac encoder %s (using CoreAudioToolbox %s).\n", MUTILS_UTF8(lamexp_version2string("v?.??", qaacVersion, "N/A")), MUTILS_UTF8(lamexp_version2string("v?.?.?.?", coreVersion, "N/A")));
+
+ for(int i = 0; i < 3; i++)
+ {
+ lamexp_tools_register(qaacFileInfo[i].fileName(), qaacBin[i].take(), qaacVersion);
+ }
+}
+
+////////////////////////////////////////////////////////////
+// Self-Test Function
+////////////////////////////////////////////////////////////
+
+void InitializationThread::selfTest(void)
+{
+ const unsigned int cpu[4] = {CPU_TYPE_X86_GEN, CPU_TYPE_X86_SSE, CPU_TYPE_X64_GEN, CPU_TYPE_X64_SSE};
+
+ LockedFile::selfTest();
+
+ for(size_t k = 0; k < 4; k++)
+ {
+ qDebug("[TEST]");
+ switch(cpu[k])
+ {
+ PRINT_CPU_TYPE(CPU_TYPE_X86_GEN); break;
+ PRINT_CPU_TYPE(CPU_TYPE_X86_SSE); break;
+ PRINT_CPU_TYPE(CPU_TYPE_X64_GEN); break;
+ PRINT_CPU_TYPE(CPU_TYPE_X64_SSE); break;
+ default: MUTILS_THROW("CPU support undefined!");
+ }
+ unsigned int n = 0;
+ for(int i = 0; true; i++)
+ {
+ if(!(g_lamexp_tools[i].pcName || g_lamexp_tools[i].pcHash || g_lamexp_tools[i].uiVersion))
+ {
+ break;
+ }
+ else if(g_lamexp_tools[i].pcName && g_lamexp_tools[i].pcHash && g_lamexp_tools[i].uiVersion)
+ {
+ const QString toolName = QString::fromLatin1(g_lamexp_tools[i].pcName);
+ const QByteArray expectedHash = QByteArray(g_lamexp_tools[i].pcHash);
+ if(g_lamexp_tools[i].uiCpuType & cpu[k])
+ {
+ qDebug("%02i -> %s", ++n, MUTILS_UTF8(toolName));
+ QFile resource(QString(":/tools/%1").arg(toolName));
+ if(!resource.open(QIODevice::ReadOnly))
+ {
+ qFatal("The resource for \"%s\" could not be opened!", MUTILS_UTF8(toolName));
+ break;
+ }
+ QByteArray hash = LockedFile::fileHash(resource);
+ if(hash.isNull() || _stricmp(hash.constData(), expectedHash.constData()))
+ {
+ qFatal("Hash check for tool \"%s\" has failed!", MUTILS_UTF8(toolName));
+ break;
+ }
+ resource.close();
+ }
+ }
+ else
+ {
+ qFatal("Inconsistent checksum data detected. Take care!");
+ }
+ }
+ if(n != EXPECTED_TOOL_COUNT)
+ {
+ qFatal("Tool count mismatch for CPU type %u !!!", cpu[k]);
+ }
+ qDebug("Done.\n");
+ }
+}
////////////////////////////////////////////////////////////
// EVENTS
////////////////////////////////////////////////////////////
-/*NONE*/
\ No newline at end of file
+/*NONE*/