OSDN Git Service

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