OSDN Git Service

If the Cue Sheet isn't clearly UTF-8 (i.e. a BOM is found), then let the user select...
[lamexp/LameXP.git] / src / Thread_Initialization.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2011 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
21
22 #include "Thread_Initialization.h"
23
24 #include "LockedFile.h"
25 #include "Tools.h"
26
27 #include <QFileInfo>
28 #include <QCoreApplication>
29 #include <QProcess>
30 #include <QMap>
31 #include <QDir>
32 #include <QLibrary>
33 #include <QResource>
34 #include <QTime>
35
36 /* helper macros */
37 #define PRINT_CPU_TYPE(X) case X: qDebug("Selected CPU is: " #X)
38 static const double g_allowedExtractDelay = 10.0;
39
40 ////////////////////////////////////////////////////////////
41 // Constructor
42 ////////////////////////////////////////////////////////////
43
44 InitializationThread::InitializationThread(const lamexp_cpu_t *cpuFeatures)
45 {
46         m_bSuccess = false;
47         memset(&m_cpuFeatures, 0, sizeof(lamexp_cpu_t));
48         m_slowIndicator = false;
49         
50         if(cpuFeatures)
51         {
52                 memcpy(&m_cpuFeatures, cpuFeatures, sizeof(lamexp_cpu_t));
53         }
54 }
55
56 ////////////////////////////////////////////////////////////
57 // Thread Main
58 ////////////////////////////////////////////////////////////
59
60 void InitializationThread::run()
61 {
62         m_bSuccess = false;
63         bool bCustom = false;
64         delay();
65
66         //CPU type selection
67         unsigned int cpuSupport = 0;
68         if(m_cpuFeatures.sse && m_cpuFeatures.sse2 && m_cpuFeatures.intel)
69         {
70                 cpuSupport = m_cpuFeatures.x64 ? CPU_TYPE_X64_SSE : CPU_TYPE_X86_SSE;
71         }
72         else
73         {
74                 cpuSupport = m_cpuFeatures.x64 ? CPU_TYPE_X64_GEN : CPU_TYPE_X86_GEN;
75         }
76
77         //Hack to disable x64 on the Windows 8 Developer Preview
78         if(cpuSupport & CPU_TYPE_X64_ALL)
79         {
80                 DWORD osVerNo = lamexp_get_os_version();
81                 if((HIWORD(osVerNo) == 6) && (LOWORD(osVerNo) == 2))
82                 {
83                         qWarning("Windows 8 (x64) developer preview detected. Going to disable all x64 support!\n");
84                         cpuSupport = (cpuSupport == CPU_TYPE_X64_SSE) ? CPU_TYPE_X86_SSE : CPU_TYPE_X86_GEN;
85                 }
86         }
87
88         //Print selected CPU type
89         switch(cpuSupport)
90         {
91                 PRINT_CPU_TYPE(CPU_TYPE_X86_GEN); break;
92                 PRINT_CPU_TYPE(CPU_TYPE_X86_SSE); break;
93                 PRINT_CPU_TYPE(CPU_TYPE_X64_GEN); break;
94                 PRINT_CPU_TYPE(CPU_TYPE_X64_SSE); break;
95                 default: throw "CPU support undefined!";
96         }
97
98         //Allocate maps
99         QMap<QString, QString> mapChecksum;
100         QMap<QString, unsigned int> mapVersion;
101         QMap<QString, unsigned int> mapCpuType;
102
103         //Init properties
104         for(int i = 0; i < INT_MAX; i++)
105         {
106                 if(!g_lamexp_tools[i].pcName && !g_lamexp_tools[i].pcHash && !g_lamexp_tools[i].uiVersion)
107                 {
108                         break;
109                 }
110                 else if(g_lamexp_tools[i].pcName && g_lamexp_tools[i].pcHash && g_lamexp_tools[i].uiVersion)
111                 {
112                         const QString currentTool = QString::fromLatin1(g_lamexp_tools[i].pcName);
113                         mapChecksum.insert(currentTool, QString::fromLatin1(g_lamexp_tools[i].pcHash));
114                         mapCpuType.insert(currentTool, g_lamexp_tools[i].uiCpuType);
115                         mapVersion.insert(currentTool, g_lamexp_tools[i].uiVersion);
116                 }
117                 else
118                 {
119                         qFatal("Inconsistent checksum data detected. Take care!");
120                 }
121         }
122
123         QDir toolsDir(":/tools/");
124         QList<QFileInfo> toolsList = toolsDir.entryInfoList(QStringList("*.*"), QDir::Files, QDir::Name);
125         QDir appDir = QDir(QCoreApplication::applicationDirPath()).canonicalPath();
126
127         QTime timer;
128         timer.start();
129         
130         //Extract all files
131         while(!toolsList.isEmpty())
132         {
133                 try
134                 {
135                         QFileInfo currentTool = toolsList.takeFirst();
136                         QString toolName = currentTool.fileName().toLower();
137                         QString toolShortName = QString("%1.%2").arg(currentTool.baseName().toLower(), currentTool.suffix().toLower());
138                         
139                         QByteArray toolHash = mapChecksum.take(toolName).toLatin1();
140                         unsigned int toolCpuType = mapCpuType.take(toolName);
141                         unsigned int toolVersion = mapVersion.take(toolName);
142                         
143                         if(toolHash.size() != 72)
144                         {
145                                 throw "The required checksum is missing, take care!";
146                         }
147                         
148                         if(toolCpuType & cpuSupport)
149                         {
150                                 QFileInfo customTool(QString("%1/tools/%2/%3").arg(appDir.canonicalPath(), QString::number(lamexp_version_build()), toolShortName));
151                                 if(customTool.exists() && customTool.isFile())
152                                 {
153                                         bCustom = true;
154                                         qDebug("Setting up file: %s <- %s", toolShortName.toLatin1().constData(), appDir.relativeFilePath(customTool.canonicalFilePath()).toLatin1().constData());
155                                         LockedFile *lockedFile = new LockedFile(customTool.canonicalFilePath());
156                                         lamexp_register_tool(toolShortName, lockedFile, UINT_MAX);
157                                 }
158                                 else
159                                 {
160                                         qDebug("Extracting file: %s -> %s", toolName.toLatin1().constData(),  toolShortName.toLatin1().constData());
161                                         LockedFile *lockedFile = new LockedFile(QString(":/tools/%1").arg(toolName), QString("%1/tool_%2").arg(lamexp_temp_folder2(), toolShortName), toolHash);
162                                         lamexp_register_tool(toolShortName, lockedFile, toolVersion);
163                                 }
164                         }
165                 }
166                 catch(char *errorMsg)
167                 {
168                         qFatal("At least one of the required tools could not be initialized:\n%s", errorMsg);
169                         return;
170                 }
171         }
172         
173         //Make sure all files were extracted
174         if(!mapChecksum.isEmpty())
175         {
176                 qFatal("At least one required tool could not be found:\n%s", toolsDir.filePath(mapChecksum.keys().first()).toLatin1().constData());
177                 return;
178         }
179         
180         qDebug("All extracted.\n");
181
182         //Clean-up
183         mapChecksum.clear();
184         mapVersion.clear();
185         mapCpuType.clear();
186         
187         //Using any custom tools?
188         if(bCustom)
189         {
190                 qWarning("Warning: Using custom tools, you might encounter unexpected problems!\n");
191         }
192
193         //Check delay
194         double delayExtract = static_cast<double>(timer.elapsed()) / 1000.0;
195         if(delayExtract > g_allowedExtractDelay)
196         {
197                 m_slowIndicator = true;
198                 qWarning("Extracting tools took %.3f seconds -> probably slow realtime virus scanner.", delayExtract);
199                 qWarning("Please report performance problems to your anti-virus developer !!!\n");
200         }
201
202         //Register all translations
203         initTranslations();
204
205         //Look for AAC encoders
206         initNeroAac();
207         initFhgAac();
208         initQAac();
209
210         delay();
211         m_bSuccess = true;
212 }
213
214 ////////////////////////////////////////////////////////////
215 // PUBLIC FUNCTIONS
216 ////////////////////////////////////////////////////////////
217
218 void InitializationThread::delay(void)
219 {
220         const char *temp = "|/-\\";
221         printf("Thread is doing something important... ?\b", temp[4]);
222
223         for(int i = 0; i < 20; i++)
224         {
225                 printf("%c\b", temp[i%4]);
226                 msleep(25);
227         }
228
229         printf("Done\n\n");
230 }
231
232 void InitializationThread::initTranslations(void)
233 {
234         //Search for language files
235         QStringList qmFiles = QDir(":/localization").entryList(QStringList() << "LameXP_??.qm", QDir::Files, QDir::Name);
236
237         //Make sure we found at least one translation
238         if(qmFiles.count() < 1)
239         {
240                 qFatal("Could not find any translation files!");
241                 return;
242         }
243
244         //Add all available translations
245         while(!qmFiles.isEmpty())
246         {
247                 QString langId, langName;
248                 unsigned int systemId = 0;
249                 QString qmFile = qmFiles.takeFirst();
250                 
251                 QRegExp langIdExp("LameXP_(\\w\\w)\\.qm", Qt::CaseInsensitive);
252                 if(langIdExp.indexIn(qmFile) >= 0)
253                 {
254                         langId = langIdExp.cap(1).toLower();
255                 }
256
257                 QResource langRes = (QString(":/localization/%1.txt").arg(qmFile));
258                 if(langRes.isValid() && langRes.size() > 0)
259                 {
260                         QStringList langInfo = QString::fromUtf8(reinterpret_cast<const char*>(langRes.data()), langRes.size()).simplified().split(",", QString::SkipEmptyParts);
261                         if(langInfo.count() == 2)
262                         {
263                                 systemId = langInfo.at(0).toUInt();
264                                 langName = langInfo.at(1);
265                         }
266                 }
267                 
268                 if(lamexp_translation_register(langId, qmFile, langName, systemId))
269                 {
270                         qDebug("Registering translation: %s = %s (%u)", qmFile.toUtf8().constData(), langName.toUtf8().constData(), systemId);
271                 }
272                 else
273                 {
274                         qWarning("Failed to register: %s", qmFile.toLatin1().constData());
275                 }
276         }
277
278         qDebug("All registered.\n");
279 }
280
281 void InitializationThread::initNeroAac(void)
282 {
283         const QString appPath = QDir(QCoreApplication::applicationDirPath()).canonicalPath();
284         
285         QFileInfo neroFileInfo[3];
286         neroFileInfo[0] = QFileInfo(QString("%1/neroAacEnc.exe").arg(appPath));
287         neroFileInfo[1] = QFileInfo(QString("%1/neroAacDec.exe").arg(appPath));
288         neroFileInfo[2] = QFileInfo(QString("%1/neroAacTag.exe").arg(appPath));
289         
290         bool neroFilesFound = true;
291         for(int i = 0; i < 3; i++)      { if(!neroFileInfo[i].exists()) neroFilesFound = false; }
292
293         //Lock the Nero binaries
294         if(!neroFilesFound)
295         {
296                 qDebug("Nero encoder binaries not found -> AAC encoding support will be disabled!\n");
297                 return;
298         }
299
300         qDebug("Found Nero AAC encoder binary:\n%s\n", neroFileInfo[0].canonicalFilePath().toUtf8().constData());
301
302         LockedFile *neroBin[3];
303         for(int i = 0; i < 3; i++) neroBin[i] = NULL;
304
305         try
306         {
307                 for(int i = 0; i < 3; i++)
308                 {
309                         neroBin[i] = new LockedFile(neroFileInfo[i].canonicalFilePath());
310                 }
311         }
312         catch(...)
313         {
314                 for(int i = 0; i < 3; i++) LAMEXP_DELETE(neroBin[i]);
315                 qWarning("Failed to get excluive lock to Nero encoder binary -> AAC encoding support will be disabled!");
316                 return;
317         }
318
319         QProcess process;
320         process.setProcessChannelMode(QProcess::MergedChannels);
321         process.setReadChannel(QProcess::StandardOutput);
322         process.start(neroFileInfo[0].canonicalFilePath(), QStringList() << "-help");
323
324         if(!process.waitForStarted())
325         {
326                 qWarning("Nero process failed to create!");
327                 qWarning("Error message: \"%s\"\n", process.errorString().toLatin1().constData());
328                 process.kill();
329                 process.waitForFinished(-1);
330                 for(int i = 0; i < 3; i++) LAMEXP_DELETE(neroBin[i]);
331                 return;
332         }
333
334         unsigned int neroVersion = 0;
335
336         while(process.state() != QProcess::NotRunning)
337         {
338                 if(!process.waitForReadyRead())
339                 {
340                         if(process.state() == QProcess::Running)
341                         {
342                                 qWarning("Nero process time out -> killing!");
343                                 process.kill();
344                                 process.waitForFinished(-1);
345                                 for(int i = 0; i < 3; i++) LAMEXP_DELETE(neroBin[i]);
346                                 return;
347                         }
348                 }
349
350                 while(process.canReadLine())
351                 {
352                         QString line = QString::fromUtf8(process.readLine().constData()).simplified();
353                         QStringList tokens = line.split(" ", QString::SkipEmptyParts, Qt::CaseInsensitive);
354                         int index1 = tokens.indexOf("Package");
355                         int index2 = tokens.indexOf("version:");
356                         if(index1 >= 0 && index2 >= 0 && index1 + 1 == index2 && index2 < tokens.count() - 1)
357                         {
358                                 QStringList versionTokens = tokens.at(index2 + 1).split(".", QString::SkipEmptyParts, Qt::CaseInsensitive);
359                                 if(versionTokens.count() == 4)
360                                 {
361                                         neroVersion = 0;
362                                         neroVersion += qMin(9, qMax(0, versionTokens.at(3).toInt()));
363                                         neroVersion += qMin(9, qMax(0, versionTokens.at(2).toInt())) * 10;
364                                         neroVersion += qMin(9, qMax(0, versionTokens.at(1).toInt())) * 100;
365                                         neroVersion += qMin(9, qMax(0, versionTokens.at(0).toInt())) * 1000;
366                                 }
367                         }
368                 }
369         }
370
371         if(!(neroVersion > 0))
372         {
373                 qWarning("Nero AAC version could not be determined -> AAC encoding support will be disabled!");
374                 for(int i = 0; i < 3; i++) LAMEXP_DELETE(neroBin[i]);
375                 return;
376         }
377         
378         for(int i = 0; i < 3; i++)
379         {
380                 lamexp_register_tool(neroFileInfo[i].fileName(), neroBin[i], neroVersion);
381         }
382 }
383
384 void InitializationThread::initFhgAac(void)
385 {
386         const QString appPath = QDir(QCoreApplication::applicationDirPath()).canonicalPath();
387         
388         QFileInfo fhgFileInfo[4];
389         fhgFileInfo[0] = QFileInfo(QString("%1/fhgaacenc.exe").arg(appPath));
390         fhgFileInfo[1] = QFileInfo(QString("%1/enc_fhgaac.dll").arg(appPath));
391         fhgFileInfo[2] = QFileInfo(QString("%1/nsutil.dll").arg(appPath));
392         fhgFileInfo[3] = QFileInfo(QString("%1/libmp4v2.dll").arg(appPath));
393         
394         bool fhgFilesFound = true;
395         for(int i = 0; i < 4; i++)      { if(!fhgFileInfo[i].exists()) fhgFilesFound = false; }
396
397         //Lock the FhgAacEnc binaries
398         if(!fhgFilesFound)
399         {
400                 qDebug("FhgAacEnc binaries not found -> FhgAacEnc support will be disabled!\n");
401                 return;
402         }
403
404         qDebug("Found FhgAacEnc cli_exe:\n%s\n", fhgFileInfo[0].canonicalFilePath().toUtf8().constData());
405         qDebug("Found FhgAacEnc enc_dll:\n%s\n", fhgFileInfo[1].canonicalFilePath().toUtf8().constData());
406
407         LockedFile *fhgBin[4];
408         for(int i = 0; i < 4; i++) fhgBin[i] = NULL;
409
410         try
411         {
412                 for(int i = 0; i < 4; i++)
413                 {
414                         fhgBin[i] = new LockedFile(fhgFileInfo[i].canonicalFilePath());
415                 }
416         }
417         catch(...)
418         {
419                 for(int i = 0; i < 4; i++) LAMEXP_DELETE(fhgBin[i]);
420                 qWarning("Failed to get excluive lock to FhgAacEnc binary -> FhgAacEnc support will be disabled!");
421                 return;
422         }
423
424         QProcess process;
425         process.setProcessChannelMode(QProcess::MergedChannels);
426         process.setReadChannel(QProcess::StandardOutput);
427         process.start(fhgFileInfo[0].canonicalFilePath(), QStringList() << "--version");
428
429         if(!process.waitForStarted())
430         {
431                 qWarning("FhgAacEnc process failed to create!");
432                 qWarning("Error message: \"%s\"\n", process.errorString().toLatin1().constData());
433                 process.kill();
434                 process.waitForFinished(-1);
435                 for(int i = 0; i < 4; i++) LAMEXP_DELETE(fhgBin[i]);
436                 return;
437         }
438
439         QRegExp fhgAacEncSig("fhgaacenc version (\\d+) by tmkk", Qt::CaseInsensitive);
440         unsigned int fhgVersion = 0;
441
442         while(process.state() != QProcess::NotRunning)
443         {
444                 process.waitForReadyRead();
445                 if(!process.bytesAvailable() && process.state() == QProcess::Running)
446                 {
447                         qWarning("FhgAacEnc process time out -> killing!");
448                         process.kill();
449                         process.waitForFinished(-1);
450                         for(int i = 0; i < 4; i++) LAMEXP_DELETE(fhgBin[i]);
451                         return;
452                 }
453                 while(process.bytesAvailable() > 0)
454                 {
455                         QString line = QString::fromUtf8(process.readLine().constData()).simplified();
456                         if(fhgAacEncSig.lastIndexIn(line) >= 0)
457                         {
458                                 bool ok = false;
459                                 unsigned int temp = fhgAacEncSig.cap(1).toUInt(&ok);
460                                 if(ok) fhgVersion = temp;
461                         }
462                 }
463         }
464
465         if(!(fhgVersion > 0))
466         {
467                 qWarning("FhgAacEnc version couldn't be determined -> FhgAacEnc support will be disabled!");
468                 for(int i = 0; i < 4; i++) LAMEXP_DELETE(fhgBin[i]);
469                 return;
470         }
471         else if(fhgVersion < lamexp_toolver_fhgaacenc())
472         {
473                 qWarning("FhgAacEnc version is too much outdated -> FhgAacEnc support will be disabled!");
474                 for(int i = 0; i < 4; i++) LAMEXP_DELETE(fhgBin[i]);
475                 return;
476         }
477         
478         for(int i = 0; i < 4; i++)
479         {
480                 lamexp_register_tool(fhgFileInfo[i].fileName(), fhgBin[i], fhgVersion);
481         }
482 }
483
484 void InitializationThread::initQAac(void)
485 {
486         const QString appPath = QDir(QCoreApplication::applicationDirPath()).canonicalPath();
487
488         QFileInfo qaacFileInfo[2];
489         qaacFileInfo[0] = QFileInfo(QString("%1/qaac.exe").arg(appPath));
490         qaacFileInfo[1] = QFileInfo(QString("%1/libsoxrate.dll").arg(appPath));
491         
492         bool qaacFilesFound = true;
493         for(int i = 0; i < 2; i++)      { if(!qaacFileInfo[i].exists()) qaacFilesFound = false; }
494
495         //Lock the QAAC binaries
496         if(!qaacFilesFound)
497         {
498                 qDebug("QAAC binaries not found -> QAAC support will be disabled!\n");
499                 return;
500         }
501
502         qDebug("Found QAAC encoder:\n%s\n", qaacFileInfo[0].canonicalFilePath().toUtf8().constData());
503
504         LockedFile *qaacBin[2];
505         for(int i = 0; i < 2; i++) qaacBin[i] = NULL;
506
507         try
508         {
509                 for(int i = 0; i < 2; i++)
510                 {
511                         qaacBin[i] = new LockedFile(qaacFileInfo[i].canonicalFilePath());
512                 }
513         }
514         catch(...)
515         {
516                 for(int i = 0; i < 2; i++) LAMEXP_DELETE(qaacBin[i]);
517                 qWarning("Failed to get excluive lock to QAAC binary -> QAAC support will be disabled!");
518                 return;
519         }
520
521         QProcess process;
522         process.setProcessChannelMode(QProcess::MergedChannels);
523         process.setReadChannel(QProcess::StandardOutput);
524         process.start(qaacFileInfo[0].canonicalFilePath(), QStringList() << "--check");
525
526         if(!process.waitForStarted())
527         {
528                 qWarning("QAAC process failed to create!");
529                 qWarning("Error message: \"%s\"\n", process.errorString().toLatin1().constData());
530                 process.kill();
531                 process.waitForFinished(-1);
532                 for(int i = 0; i < 2; i++) LAMEXP_DELETE(qaacBin[i]);
533                 return;
534         }
535
536         QRegExp qaacEncSig("qaac (\\d)\\.(\\d)(\\d)", Qt::CaseInsensitive);
537         QRegExp coreEncSig("CoreAudioToolbox (\\d)\\.(\\d)\\.(\\d)\\.(\\d)", Qt::CaseInsensitive);
538         unsigned int qaacVersion = 0;
539         unsigned int coreVersion = 0;
540
541         while(process.state() != QProcess::NotRunning)
542         {
543                 process.waitForReadyRead();
544                 if(!process.bytesAvailable() && process.state() == QProcess::Running)
545                 {
546                         qWarning("QAAC process time out -> killing!");
547                         process.kill();
548                         process.waitForFinished(-1);
549                 for(int i = 0; i < 2; i++) LAMEXP_DELETE(qaacBin[i]);
550                         return;
551                 }
552                 while(process.bytesAvailable() > 0)
553                 {
554                         QString line = QString::fromUtf8(process.readLine().constData()).simplified();
555                         if(qaacEncSig.lastIndexIn(line) >= 0)
556                         {
557                                 unsigned int tmp[3] = {0, 0, 0};
558                                 bool ok[3] = {false, false, false};
559                                 tmp[0] = qaacEncSig.cap(1).toUInt(&ok[0]);
560                                 tmp[1] = qaacEncSig.cap(2).toUInt(&ok[1]);
561                                 tmp[2] = qaacEncSig.cap(3).toUInt(&ok[2]);
562                                 if(ok[0] && ok[1] && ok[2])
563                                 {
564                                         qaacVersion = (qBound(0U, tmp[0], 9U) * 100) + (qBound(0U, tmp[1], 9U) * 10) + qBound(0U, tmp[2], 9U);
565                                 }
566                         }
567                         if(coreEncSig.lastIndexIn(line) >= 0)
568                         {
569                                 unsigned int tmp[4] = {0, 0, 0, 0};
570                                 bool ok[4] = {false, false, false, false};
571                                 tmp[0] = coreEncSig.cap(1).toUInt(&ok[0]);
572                                 tmp[1] = coreEncSig.cap(2).toUInt(&ok[1]);
573                                 tmp[2] = coreEncSig.cap(3).toUInt(&ok[2]);
574                                 tmp[3] = coreEncSig.cap(4).toUInt(&ok[3]);
575                                 if(ok[0] && ok[1] && ok[2] && ok[3])
576                                 {
577                                         coreVersion = (qBound(0U, tmp[0], 9U) * 1000) + (qBound(0U, tmp[1], 9U) * 100) + (qBound(0U, tmp[2], 9U) * 10) + qBound(0U, tmp[3], 9U);
578                                 }
579                         }
580                 }
581         }
582
583         //qDebug("qaac %d, CoreAudioToolbox %d", qaacVersion, coreVersion);
584
585         if(!(qaacVersion > 0))
586         {
587                 qWarning("QAAC version couldn't be determined -> QAAC support will be disabled!");
588                 for(int i = 0; i < 2; i++) LAMEXP_DELETE(qaacBin[i]);
589                 return;
590         }
591         else if(qaacVersion < lamexp_toolver_qaacenc())
592         {
593                 qWarning("QAAC version is too much outdated (%s) -> QAAC support will be disabled!", lamexp_version2string("v?.??", qaacVersion, "N/A").toLatin1().constData());
594                 for(int i = 0; i < 2; i++) LAMEXP_DELETE(qaacBin[i]);
595                 return;
596         }
597
598         if(!(coreVersion > 0))
599         {
600                 qWarning("CoreAudioToolbox version couldn't be determined -> QAAC support will be disabled!");
601                 for(int i = 0; i < 2; i++) LAMEXP_DELETE(qaacBin[i]);
602                 return;
603         }
604         else if(coreVersion < lamexp_toolver_coreaudio())
605         {
606                 qWarning("CoreAudioToolbox version is too much outdated (%s) -> QAAC support will be disabled!", lamexp_version2string("v?.?.?.?", coreVersion, "N/A").toLatin1().constData());
607                 for(int i = 0; i < 2; i++) LAMEXP_DELETE(qaacBin[i]);
608                 return;
609         }
610
611         lamexp_register_tool(qaacFileInfo[0].fileName(), qaacBin[0], qaacVersion);
612         lamexp_register_tool(qaacFileInfo[1].fileName(), qaacBin[1], qaacVersion);
613 }
614
615 void InitializationThread::selfTest(void)
616 {
617         const unsigned int cpu[4] = {CPU_TYPE_X86_GEN, CPU_TYPE_X86_SSE, CPU_TYPE_X64_GEN, CPU_TYPE_X64_SSE};
618
619         for(size_t k = 0; k < 4; k++)
620         {
621                 qDebug("[TEST]");
622                 switch(cpu[k])
623                 {
624                         PRINT_CPU_TYPE(CPU_TYPE_X86_GEN); break;
625                         PRINT_CPU_TYPE(CPU_TYPE_X86_SSE); break;
626                         PRINT_CPU_TYPE(CPU_TYPE_X64_GEN); break;
627                         PRINT_CPU_TYPE(CPU_TYPE_X64_SSE); break;
628                         default: throw "CPU support undefined!";
629                 }
630                 int n = 0;
631                 for(int i = 0; i < INT_MAX; i++)
632                 {
633                         if(!g_lamexp_tools[i].pcName && !g_lamexp_tools[i].pcHash && !g_lamexp_tools[i].uiVersion)
634                         {
635                                 break;
636                         }
637                         if(g_lamexp_tools[i].uiCpuType & cpu[k])
638                         {
639                                 qDebug("%02i -> %s", ++n, g_lamexp_tools[i].pcName);
640                         }
641                 }
642                 if(n != 24)
643                 {
644                         qFatal("Tool count mismatch !!!");
645                 }
646                 qDebug("Done.\n");
647         }
648 }
649
650 ////////////////////////////////////////////////////////////
651 // EVENTS
652 ////////////////////////////////////////////////////////////
653
654 /*NONE*/