OSDN Git Service

ba85edb0f79f53afe1a884f6e2c1028715e589a0
[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
26 #include <QFileInfo>
27 #include <QCoreApplication>
28 #include <QProcess>
29 #include <QMap>
30 #include <QDir>
31 #include <QLibrary>
32 #include <QResource>
33 #include <QTime>
34
35 ////////////////////////////////////////////////////////////
36 // CPU FLags
37 ////////////////////////////////////////////////////////////
38
39 /* CPU_TYPE_<ARCH>_<TYPE> */
40
41 #define CPU_TYPE_X86_GEN 0x00000001UL //x86, no enhanced instruction set
42 #define CPU_TYPE_X86_SSE 0x00000002UL //x86, with SSE and SSE2 support (Intel only!)
43 #define CPU_TYPE_X64_GEN 0x00000004UL //x64, generic (x64 always includes SSE2)
44
45 #define CPU_TYPE_X86_ALL (CPU_TYPE_X86_GEN|CPU_TYPE_X86_SSE) //all x86 CPU's, but not x64)
46 #define CPU_TYPE_ALL_SSE (CPU_TYPE_X86_SSE|CPU_TYPE_X64_GEN) //all SSE2-capable CPU's (x86 and x64)
47 #define CPU_TYPE_ALL_ALL (CPU_TYPE_X86_ALL|CPU_TYPE_X64_GEN) //all CPU's, no exceptions
48
49 #define IS_CPU_TYPE_X64_GEN (m_cpuFeatures.x64   && m_cpuFeatures.sse && m_cpuFeatures.sse2)
50 #define IS_CPU_TYPE_X86_SSE (m_cpuFeatures.intel && m_cpuFeatures.sse && m_cpuFeatures.sse2)
51
52 ////////////////////////////////////////////////////////////
53 // TOOLS
54 ////////////////////////////////////////////////////////////
55
56 static const struct
57 {
58         char *pcHash;
59         unsigned int uiCpuType;
60         char *pcName;
61         unsigned int uiVersion;
62 }
63 g_lamexp_tools[] =
64 {
65         {"1e4c983fe00ccc6236ee1c3f76250f64139cf86a6f4aa68f36929907fe45cf37b00862d8", CPU_TYPE_X86_GEN, "aften.i386.exe", 8},
66         {"7c843f1eaf61823285237911493d8d20da11149853d4bb7953a3279196f6dbbd310c61e3", CPU_TYPE_X86_SSE, "aften.sse2.exe", 8},
67         {"29da0d3e810bc3e8d2cddb3db452325eefca0d0c1fff1379fa17806ad447752be1b88e2f", CPU_TYPE_X64_GEN, "aften.x64.exe",  8},
68         {"1cca303fabd889a18fc01c32a7fd861194cfcac60ba63740ea2d7c55d049dbf8f59259fa", CPU_TYPE_ALL_ALL, "alac.exe", 20},
69         {"6d22d4bbd7ce2162e38f70ac9187bc84eb28233b36ee6c0492d0a6195318782d7f05c444", CPU_TYPE_ALL_ALL, "avs2wav.exe", 13},
70         {"c6f23fb7ba18a7972802e013b66ec6ce52088bf4fe783774eb1d33dd3401fa8aad76cc8b", CPU_TYPE_ALL_ALL, "elevator.exe", UINT_MAX},
71         {"9ae98a3fc779f69ee876a3b477fbc35a709ba5066823b2eb62eeb015057c38807e4be51f", CPU_TYPE_ALL_ALL, "faad.exe", 27},
72         {"446054f9a7f705f1aadc9053ca7b8a86a775499ef159978954ebdea92de056c34f8841f7", CPU_TYPE_ALL_ALL, "flac.exe", 121},
73         {"dd68d074c5e13a607580f3a24595c0f3882e37211d2ca628f46e6df20fabcc832dad488a", CPU_TYPE_ALL_ALL, "gpgv.exe", 1411},
74         {"b3fca757b3567dab75c042e62213c231de378ea0fdd7fe29b733417cd5d3d33558452f94", CPU_TYPE_ALL_ALL, "gpgv.gpg", UINT_MAX},
75         {"df995d8a9e4e5fab551d0e3460b9209320714dead70f662929fcc00a4bd72d8a6d23844a", CPU_TYPE_X86_GEN, "lame.i386.exe", 3990},
76         {"873faeddc44243b4712cd42dd0bfc3174a07113d245dd834657519ffe5dbd4b1e395ce32", CPU_TYPE_ALL_SSE, "lame.sse2.exe", 3990},
77         {"67933924d68ce319795989648f29e7bd1abaac4ec09c26cbb0ff0d15a67a9df17e257933", CPU_TYPE_ALL_ALL, "mac.exe", 406},
78         {"e294ea248768cb05013b1a16d4a0183342459ef03691f8ab6b643807c64f2be458fe7efe", CPU_TYPE_X86_ALL, "mediainfo.i386.exe", 749},
79         {"7bb673a5632ea0400c7b97f374b9167b502e7798b0494a2f39b7fa8ff5b371573d757234", CPU_TYPE_X64_GEN, "mediainfo.x64.exe",  749},
80         {"a93ec86187025e66fb78026af35555bd3b4e30fe1a40e8d66f600cfd918f07f431f0b2f2", CPU_TYPE_ALL_ALL, "mpcdec.exe", 435},
81         {"5a89768010efb1ddfd88ccc378a89433ceaecb403a7b1f83f8716f6848d9a05b3d3c6d93", CPU_TYPE_ALL_ALL, "mpg123.exe", 1133},
82         {"0c781805dda931c529bd16069215f616a7a4c5e5c2dfb6b75fe85d52b20511830693e528", CPU_TYPE_ALL_ALL, "oggdec.exe", UINT_MAX},
83         {"0c019e13450dc664987e21f4e5489d182be7d6d0d81efbbaaf1c78693dfe3e38e0355b93", CPU_TYPE_X86_GEN, "oggenc2.i386.exe", 287603},
84         {"693dd6f779df70a047c15c2c79350855db38d5b0cd7e529b6877b7c821cfe6addfdd50a4", CPU_TYPE_X86_SSE, "oggenc2.sse2.exe", 287603},
85         {"32cb0b2182488e5e9278ba6b9fc9141214c7546eec67ee02fa895810b0e56900368695be", CPU_TYPE_X64_GEN, "oggenc2.x64.exe",  287603},
86         {"58c2b8bcff8f27bfa8fab8172b80f5da731221d072c7dba4dd3a3d7d6423490a25dc6760", CPU_TYPE_ALL_ALL, "shorten.exe", 361},
87         {"abdf9b20a8031a09d0abca9cb10c31c8418f72403b5d1350fd69bfa34041591aca3060ab", CPU_TYPE_ALL_ALL, "sox.exe", 1432},
88         {"48e7f81c024cd17dac0eaeab253aad6b223e72dc80688f7576276b0563209514ff0bb9c8", CPU_TYPE_ALL_ALL, "speexdec.exe", 12},
89         {"9b50cf64747d4afbad5d8d9b5a0a2d41c5a58256f47ebdbd8cc920e7e576085dfe1b14ff", CPU_TYPE_ALL_ALL, "tta.exe", 21},
90         {"875871c942846f6ad163f9e4949bba2f4331bec678ca5aefe58c961b6825bd0d419a078b", CPU_TYPE_ALL_ALL, "valdec.exe", 31},
91         {"e657331e281840878a37eb4fb357cb79f33d528ddbd5f9b2e2f7d2194bed4720e1af8eaf", CPU_TYPE_ALL_ALL, "wget.exe", 1114},
92         {"437d3817072d0b9c0bf5a1cf2daf0d7bc22106571f53cf6b6fe10942cdfdc50829847d8f", CPU_TYPE_ALL_ALL, "wma2wav.exe", 20110816},
93         {"a258711f7a8a0c75528f3ed4d2c17513ff8598b7e0a9d7db13ca941a3140094ffc2ffb62", CPU_TYPE_ALL_ALL, "wupdate.exe", UINT_MAX},
94         {"6b053b37d47a9c8659ebf2de43ad19dcba17b9cd868b26974b9cc8c27b6167e8bf07a5a2", CPU_TYPE_ALL_ALL, "wvunpack.exe", 4601},
95         {NULL, NULL, NULL, NULL}
96 };
97
98 static const double g_allowedExtractDelay = 10.0;
99
100 ////////////////////////////////////////////////////////////
101 // Constructor
102 ////////////////////////////////////////////////////////////
103
104 InitializationThread::InitializationThread(const lamexp_cpu_t *cpuFeatures)
105 {
106         m_bSuccess = false;
107         memset(&m_cpuFeatures, 0, sizeof(lamexp_cpu_t));
108         m_slowIndicator = false;
109         
110         if(cpuFeatures)
111         {
112                 memcpy(&m_cpuFeatures, cpuFeatures, sizeof(lamexp_cpu_t));
113         }
114 }
115
116 ////////////////////////////////////////////////////////////
117 // Thread Main
118 ////////////////////////////////////////////////////////////
119
120 void InitializationThread::run()
121 {
122         m_bSuccess = false;
123         bool bCustom = false;
124         delay();
125
126         //CPU type selection
127         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);
128         
129         //Allocate maps
130         QMap<QString, QString> mapChecksum;
131         QMap<QString, unsigned int> mapVersion;
132         QMap<QString, unsigned int> mapCpuType;
133
134         //Init properties
135         for(int i = 0; i < INT_MAX; i++)
136         {
137                 if(!g_lamexp_tools[i].pcName && !g_lamexp_tools[i].pcHash && !g_lamexp_tools[i].uiVersion)
138                 {
139                         break;
140                 }
141                 else if(g_lamexp_tools[i].pcName && g_lamexp_tools[i].pcHash && g_lamexp_tools[i].uiVersion)
142                 {
143                         const QString currentTool = QString::fromLatin1(g_lamexp_tools[i].pcName);
144                         mapChecksum.insert(currentTool, QString::fromLatin1(g_lamexp_tools[i].pcHash));
145                         mapCpuType.insert(currentTool, g_lamexp_tools[i].uiCpuType);
146                         mapVersion.insert(currentTool, g_lamexp_tools[i].uiVersion);
147                 }
148                 else
149                 {
150                         qFatal("Inconsistent checksum data detected. Take care!");
151                 }
152         }
153
154         QDir toolsDir(":/tools/");
155         QList<QFileInfo> toolsList = toolsDir.entryInfoList(QStringList("*.*"), QDir::Files, QDir::Name);
156         QDir appDir = QDir(QCoreApplication::applicationDirPath()).canonicalPath();
157
158         QTime timer;
159         timer.start();
160         
161         //Extract all files
162         while(!toolsList.isEmpty())
163         {
164                 try
165                 {
166                         QFileInfo currentTool = toolsList.takeFirst();
167                         QString toolName = currentTool.fileName().toLower();
168                         QString toolShortName = QString("%1.%2").arg(currentTool.baseName().toLower(), currentTool.suffix().toLower());
169                         
170                         QByteArray toolHash = mapChecksum.take(toolName).toLatin1();
171                         unsigned int toolCpuType = mapCpuType.take(toolName);
172                         unsigned int toolVersion = mapVersion.take(toolName);
173                         
174                         if(toolHash.size() != 72)
175                         {
176                                 throw "The required checksum is missing, take care!";
177                         }
178                         
179                         if(toolCpuType & cpuSupport)
180                         {
181                                 QFileInfo customTool(QString("%1/tools/%2/%3").arg(appDir.canonicalPath(), QString::number(lamexp_version_build()), toolShortName));
182                                 if(customTool.exists() && customTool.isFile())
183                                 {
184                                         bCustom = true;
185                                         qDebug("Setting up file: %s <- %s", toolShortName.toLatin1().constData(), appDir.relativeFilePath(customTool.canonicalFilePath()).toLatin1().constData());
186                                         LockedFile *lockedFile = new LockedFile(customTool.canonicalFilePath());
187                                         lamexp_register_tool(toolShortName, lockedFile, UINT_MAX);
188                                 }
189                                 else
190                                 {
191                                         qDebug("Extracting file: %s -> %s", toolName.toLatin1().constData(),  toolShortName.toLatin1().constData());
192                                         LockedFile *lockedFile = new LockedFile(QString(":/tools/%1").arg(toolName), QString("%1/tool_%2").arg(lamexp_temp_folder2(), toolShortName), toolHash);
193                                         lamexp_register_tool(toolShortName, lockedFile, toolVersion);
194                                 }
195                         }
196                 }
197                 catch(char *errorMsg)
198                 {
199                         qFatal("At least one of the required tools could not be initialized:\n%s", errorMsg);
200                         return;
201                 }
202         }
203         
204         //Make sure all files were extracted
205         if(!mapChecksum.isEmpty())
206         {
207                 qFatal("At least one required tool could not be found:\n%s", toolsDir.filePath(mapChecksum.keys().first()).toLatin1().constData());
208                 return;
209         }
210         
211         qDebug("All extracted.\n");
212
213         //Clean-up
214         mapChecksum.clear();
215         mapVersion.clear();
216         mapCpuType.clear();
217         
218         //Using any custom tools?
219         if(bCustom)
220         {
221                 qWarning("Warning: Using custom tools, you might encounter unexpected problems!\n");
222         }
223
224         //Check delay
225         double delayExtract = static_cast<double>(timer.elapsed()) / 1000.0;
226         if(delayExtract > g_allowedExtractDelay)
227         {
228                 m_slowIndicator = true;
229                 qWarning("Extracting tools took %.3f seconds -> probably slow realtime virus scanner.", delayExtract);
230                 qWarning("Please report performance problems to your anti-virus developer !!!\n");
231         }
232
233         //Register all translations
234         initTranslations();
235
236         //Look for Nero AAC encoder
237         initNeroAac();
238
239         //Look for FHG AAC encoder
240         initFhgAac();
241
242         delay();
243         m_bSuccess = true;
244 }
245
246 ////////////////////////////////////////////////////////////
247 // PUBLIC FUNCTIONS
248 ////////////////////////////////////////////////////////////
249
250 void InitializationThread::delay(void)
251 {
252         const char *temp = "|/-\\";
253         printf("Thread is doing something important... ?\b", temp[4]);
254
255         for(int i = 0; i < 20; i++)
256         {
257                 printf("%c\b", temp[i%4]);
258                 msleep(25);
259         }
260
261         printf("Done\n\n");
262 }
263
264 void InitializationThread::initTranslations(void)
265 {
266         //Search for language files
267         QStringList qmFiles = QDir(":/localization").entryList(QStringList() << "LameXP_??.qm", QDir::Files, QDir::Name);
268
269         //Make sure we found at least one translation
270         if(qmFiles.count() < 1)
271         {
272                 qFatal("Could not find any translation files!");
273                 return;
274         }
275
276         //Add all available translations
277         while(!qmFiles.isEmpty())
278         {
279                 QString langId, langName;
280                 unsigned int systemId = 0;
281                 QString qmFile = qmFiles.takeFirst();
282                 
283                 QRegExp langIdExp("LameXP_(\\w\\w)\\.qm", Qt::CaseInsensitive);
284                 if(langIdExp.indexIn(qmFile) >= 0)
285                 {
286                         langId = langIdExp.cap(1).toLower();
287                 }
288
289                 QResource langRes = (QString(":/localization/%1.txt").arg(qmFile));
290                 if(langRes.isValid() && langRes.size() > 0)
291                 {
292                         QStringList langInfo = QString::fromUtf8(reinterpret_cast<const char*>(langRes.data()), langRes.size()).simplified().split(",", QString::SkipEmptyParts);
293                         if(langInfo.count() == 2)
294                         {
295                                 systemId = langInfo.at(0).toUInt();
296                                 langName = langInfo.at(1);
297                         }
298                 }
299                 
300                 if(lamexp_translation_register(langId, qmFile, langName, systemId))
301                 {
302                         qDebug64("Registering translation: %1 = %2 (%3)", qmFile, langName, QString::number(systemId));
303                 }
304                 else
305                 {
306                         qWarning("Failed to register: %s", qmFile.toLatin1().constData());
307                 }
308         }
309
310         qDebug("All registered.\n");
311 }
312
313 void InitializationThread::initNeroAac(void)
314 {
315         const QString appPath = QDir(QCoreApplication::applicationDirPath()).canonicalPath();
316         
317         QFileInfo neroFileInfo[3];
318         neroFileInfo[0] = QFileInfo(QString("%1/neroAacEnc.exe").arg(appPath));
319         neroFileInfo[1] = QFileInfo(QString("%1/neroAacDec.exe").arg(appPath));
320         neroFileInfo[2] = QFileInfo(QString("%1/neroAacTag.exe").arg(appPath));
321         
322         bool neroFilesFound = true;
323         for(int i = 0; i < 3; i++)      { if(!neroFileInfo[i].exists()) neroFilesFound = false; }
324
325         //Lock the Nero binaries
326         if(!neroFilesFound)
327         {
328                 qDebug("Nero encoder binaries not found -> AAC encoding support will be disabled!\n");
329                 return;
330         }
331
332         qDebug("Found Nero AAC encoder binary:\n%s\n", neroFileInfo[0].canonicalFilePath().toUtf8().constData());
333
334         LockedFile *neroBin[3];
335         for(int i = 0; i < 3; i++) neroBin[i] = NULL;
336
337         try
338         {
339                 for(int i = 0; i < 3; i++)
340                 {
341                         neroBin[i] = new LockedFile(neroFileInfo[i].canonicalFilePath());
342                 }
343         }
344         catch(...)
345         {
346                 for(int i = 0; i < 3; i++) LAMEXP_DELETE(neroBin[i]);
347                 qWarning("Failed to get excluive lock to Nero encoder binary -> AAC encoding support will be disabled!");
348                 return;
349         }
350
351         QProcess process;
352         process.setProcessChannelMode(QProcess::MergedChannels);
353         process.setReadChannel(QProcess::StandardOutput);
354         process.start(neroFileInfo[0].canonicalFilePath(), QStringList() << "-help");
355
356         if(!process.waitForStarted())
357         {
358                 qWarning("Nero process failed to create!");
359                 qWarning("Error message: \"%s\"\n", process.errorString().toLatin1().constData());
360                 process.kill();
361                 process.waitForFinished(-1);
362                 for(int i = 0; i < 3; i++) LAMEXP_DELETE(neroBin[i]);
363                 return;
364         }
365
366         unsigned int neroVersion = 0;
367
368         while(process.state() != QProcess::NotRunning)
369         {
370                 if(!process.waitForReadyRead())
371                 {
372                         if(process.state() == QProcess::Running)
373                         {
374                                 qWarning("Nero process time out -> killing!");
375                                 process.kill();
376                                 process.waitForFinished(-1);
377                                 for(int i = 0; i < 3; i++) LAMEXP_DELETE(neroBin[i]);
378                                 return;
379                         }
380                 }
381
382                 while(process.canReadLine())
383                 {
384                         QString line = QString::fromUtf8(process.readLine().constData()).simplified();
385                         QStringList tokens = line.split(" ", QString::SkipEmptyParts, Qt::CaseInsensitive);
386                         int index1 = tokens.indexOf("Package");
387                         int index2 = tokens.indexOf("version:");
388                         if(index1 >= 0 && index2 >= 0 && index1 + 1 == index2 && index2 < tokens.count() - 1)
389                         {
390                                 QStringList versionTokens = tokens.at(index2 + 1).split(".", QString::SkipEmptyParts, Qt::CaseInsensitive);
391                                 if(versionTokens.count() == 4)
392                                 {
393                                         neroVersion = 0;
394                                         neroVersion += min(9, max(0, versionTokens.at(3).toInt()));
395                                         neroVersion += min(9, max(0, versionTokens.at(2).toInt())) * 10;
396                                         neroVersion += min(9, max(0, versionTokens.at(1).toInt())) * 100;
397                                         neroVersion += min(9, max(0, versionTokens.at(0).toInt())) * 1000;
398                                 }
399                         }
400                 }
401         }
402
403         if(!(neroVersion > 0))
404         {
405                 qWarning("Nero AAC version could not be determined -> AAC encoding support will be disabled!");
406                 for(int i = 0; i < 3; i++) LAMEXP_DELETE(neroBin[i]);
407                 return;
408         }
409         
410         for(int i = 0; i < 3; i++)
411         {
412                 lamexp_register_tool(neroFileInfo[i].fileName(), neroBin[i], neroVersion);
413         }
414 }
415
416 void InitializationThread::initFhgAac(void)
417 {
418         const QString appPath = QDir(QCoreApplication::applicationDirPath()).canonicalPath();
419         
420         QFileInfo fhgFileInfo[4];
421         fhgFileInfo[0] = QFileInfo(QString("%1/fhgaacenc.exe").arg(appPath));
422         fhgFileInfo[1] = QFileInfo(QString("%1/enc_fhgaac.dll").arg(appPath));
423         fhgFileInfo[2] = QFileInfo(QString("%1/nsutil.dll").arg(appPath));
424         fhgFileInfo[3] = QFileInfo(QString("%1/libmp4v2.dll").arg(appPath));
425         
426         bool fhgFilesFound = true;
427         for(int i = 0; i < 4; i++)      { if(!fhgFileInfo[i].exists()) fhgFilesFound = false; }
428
429         //Lock the FhgAacEnc binaries
430         if(!fhgFilesFound)
431         {
432                 qDebug("FhgAacEnc binaries not found -> FhgAacEnc support will be disabled!\n");
433                 return;
434         }
435
436         qDebug("Found FhgAacEnc cli_exe:\n%s\n", fhgFileInfo[0].canonicalFilePath().toUtf8().constData());
437         qDebug("Found FhgAacEnc enc_dll:\n%s\n", fhgFileInfo[1].canonicalFilePath().toUtf8().constData());
438
439         LockedFile *fhgBin[4];
440         for(int i = 0; i < 4; i++) fhgBin[i] = NULL;
441
442         try
443         {
444                 for(int i = 0; i < 4; i++)
445                 {
446                         fhgBin[i] = new LockedFile(fhgFileInfo[i].canonicalFilePath());
447                 }
448         }
449         catch(...)
450         {
451                 for(int i = 0; i < 4; i++) LAMEXP_DELETE(fhgBin[i]);
452                 qWarning("Failed to get excluive lock to FhgAacEnc binary -> FhgAacEnc support will be disabled!");
453                 return;
454         }
455
456         QProcess process;
457         process.setProcessChannelMode(QProcess::MergedChannels);
458         process.setReadChannel(QProcess::StandardOutput);
459         process.start(fhgFileInfo[0].canonicalFilePath(), QStringList() << "--version");
460
461         if(!process.waitForStarted())
462         {
463                 qWarning("FhgAacEnc process failed to create!");
464                 qWarning("Error message: \"%s\"\n", process.errorString().toLatin1().constData());
465                 process.kill();
466                 process.waitForFinished(-1);
467                 for(int i = 0; i < 4; i++) LAMEXP_DELETE(fhgBin[i]);
468                 return;
469         }
470
471         QRegExp fhgAacEncSig("fhgaacenc version (\\d+) by tmkk", Qt::CaseInsensitive);
472         unsigned int fhgVersion = 0;
473
474         while(process.state() != QProcess::NotRunning)
475         {
476                 process.waitForReadyRead();
477                 if(!process.bytesAvailable() && process.state() == QProcess::Running)
478                 {
479                         qWarning("FhgAacEnc process time out -> killing!");
480                         process.kill();
481                         process.waitForFinished(-1);
482                         for(int i = 0; i < 4; i++) LAMEXP_DELETE(fhgBin[i]);
483                         return;
484                 }
485                 while(process.bytesAvailable() > 0)
486                 {
487                         QString line = QString::fromUtf8(process.readLine().constData()).simplified();
488                         if(fhgAacEncSig.lastIndexIn(line) >= 0)
489                         {
490                                 bool ok = false;
491                                 unsigned int temp = fhgAacEncSig.cap(1).toUInt(&ok);
492                                 if(ok) fhgVersion = temp;
493                         }
494                 }
495         }
496
497         if(!(fhgVersion > 0))
498         {
499                 qWarning("FhgAacEnc version couldn't be determined -> FhgAacEnc support will be disabled!");
500                 for(int i = 0; i < 4; i++) LAMEXP_DELETE(fhgBin[i]);
501                 return;
502         }
503         else if(fhgVersion < lamexp_toolver_fhgaacenc())
504         {
505                 qWarning("FhgAacEnc version is too much outdated -> FhgAacEnc support will be disabled!");
506                 for(int i = 0; i < 4; i++) LAMEXP_DELETE(fhgBin[i]);
507                 return;
508         }
509         
510         for(int i = 0; i < 4; i++)
511         {
512                 lamexp_register_tool(fhgFileInfo[i].fileName(), fhgBin[i], fhgVersion);
513         }
514 }
515
516 //void InitializationThread::initWmaDec(void)
517 //{
518 //      static const char* wmaDecoderComponentPath = "NCH Software/Components/wmawav/wmawav.exe";
519 //
520 //      LockedFile *wmaFileBin = NULL;
521 //      QFileInfo wmaFileInfo = QFileInfo(QString("%1/%2").arg(lamexp_known_folder(lamexp_folder_programfiles), wmaDecoderComponentPath));
522 //
523 //      if(!(wmaFileInfo.exists() && wmaFileInfo.isFile()))
524 //      {
525 //              wmaFileInfo.setFile(QString("%1/%2").arg(QDir(QCoreApplication::applicationDirPath()).canonicalPath(), "wmawav.exe"));
526 //      }
527 //      if(!(wmaFileInfo.exists() && wmaFileInfo.isFile()))
528 //      {
529 //              qDebug("WMA File Decoder not found -> WMA decoding support will be disabled!\n");
530 //              return;
531 //      }
532 //
533 //      try
534 //      {
535 //              wmaFileBin = new LockedFile(wmaFileInfo.canonicalFilePath());
536 //      }
537 //      catch(...)
538 //      {
539 //              qWarning("Failed to get excluive lock to WMA File Decoder binary -> WMA decoding support will be disabled!");
540 //              return;
541 //      }
542 //
543 //      QProcess process;
544 //      process.setProcessChannelMode(QProcess::MergedChannels);
545 //      process.setReadChannel(QProcess::StandardOutput);
546 //      process.start(wmaFileInfo.canonicalFilePath(), QStringList());
547 //
548 //      if(!process.waitForStarted())
549 //      {
550 //              qWarning("WmaWav process failed to create!");
551 //              qWarning("Error message: \"%s\"\n", process.errorString().toLatin1().constData());
552 //              process.kill();
553 //              process.waitForFinished(-1);
554 //              return;
555 //      }
556 //
557 //      bool b_wmaWavFound = false;
558 //
559 //      while(process.state() != QProcess::NotRunning)
560 //      {
561 //              if(!process.waitForReadyRead())
562 //              {
563 //                      if(process.state() == QProcess::Running)
564 //                      {
565 //                              qWarning("WmaWav process time out -> killing!");
566 //                              process.kill();
567 //                              process.waitForFinished(-1);
568 //                              return;
569 //                      }
570 //              }
571 //              while(process.canReadLine())
572 //              {
573 //                      QString line = QString::fromUtf8(process.readLine().constData()).simplified();
574 //                      if(line.contains("Usage: wmatowav.exe WMAFileSpec WAVFileSpec", Qt::CaseInsensitive))
575 //                      {
576 //                              b_wmaWavFound = true;
577 //                      }
578 //              }
579 //      }
580 //
581 //      if(!b_wmaWavFound)
582 //      {
583 //              qWarning("WmaWav could not be identified -> WMA decoding support will be disabled!\n");
584 //              LAMEXP_DELETE(wmaFileBin);
585 //              return;
586 //      }
587 //
588 //      qDebug("Found WMA File Decoder binary:\n%s\n", wmaFileInfo.canonicalFilePath().toUtf8().constData());
589 //
590 //      if(wmaFileBin)
591 //      {
592 //              lamexp_register_tool(wmaFileInfo.fileName(), wmaFileBin);
593 //      }
594 //}
595
596 ////////////////////////////////////////////////////////////
597 // EVENTS
598 ////////////////////////////////////////////////////////////
599
600 /*NONE*/