Fixed a possible use-after-free bug in initialization code.
[LameXP.git] / src / Thread_Initialization.cpp
blob2598b65d53c522f8c09589d7e3483a1ea6c6a6b2
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2015 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, but always including the *additional*
9 // restrictions defined in the "License.txt" file.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
23 #include "Thread_Initialization.h"
25 //Internal
26 #define LAMEXP_INC_TOOLS 1
27 #include "Tools.h"
28 #include "LockedFile.h"
29 #include "Tool_Abstract.h"
31 //MUtils
32 #include <MUtils/Global.h>
33 #include <MUtils/OSSupport.h>
34 #include <MUtils/Translation.h>
35 #include <MUtils/Exception.h>
37 //Qt
38 #include <QFileInfo>
39 #include <QCoreApplication>
40 #include <QProcess>
41 #include <QMap>
42 #include <QDir>
43 #include <QResource>
44 #include <QTextStream>
45 #include <QRunnable>
46 #include <QThreadPool>
47 #include <QMutex>
48 #include <QQueue>
49 #include <QElapsedTimer>
50 #include <QVector>
52 /* helper macros */
53 #define PRINT_CPU_TYPE(X) case X: qDebug("Selected CPU is: " #X)
54 #define MAKE_REGEXP(STR) (((STR) && ((STR)[0])) ? QRegExp((STR)) : QRegExp())
56 /* constants */
57 static const double g_allowedExtractDelay = 12.0;
58 static const size_t BUFF_SIZE = 512;
59 static const size_t EXPECTED_TOOL_COUNT = 28;
61 /* number of CPU cores -> number of threads */
62 static unsigned int cores2threads(const unsigned int cores)
64 static const size_t LUT_LEN = 4;
66 static const struct
68 const unsigned int upperBound;
69 const double coeffs[4];
71 LUT[LUT_LEN] =
73 { 4, { -0.052695810565, 0.158087431694, 4.982841530055, -1.088233151184 } },
74 { 8, { 0.042431693989, -0.983442622951, 9.548961748634, -7.176393442623 } },
75 { 12, { -0.006277322404, 0.185573770492, 0.196830601093, 17.762622950820 } },
76 { 32, { 0.000673497268, -0.064655737705, 3.199584699454, 5.751606557377 } }
79 size_t index = 0;
80 while((cores > LUT[index].upperBound) && (index < (LUT_LEN-1))) index++;
82 const double x = qBound(1.0, double(cores), double(LUT[LUT_LEN-1].upperBound));
83 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];
85 return qRound(abs(y));
88 ////////////////////////////////////////////////////////////
89 // BaseTask class
90 ////////////////////////////////////////////////////////////
92 class BaseTask : public QRunnable
94 public:
95 BaseTask(void)
99 ~BaseTask(void)
103 static void clearFlags(QMutexLocker &lock = QMutexLocker(&s_mutex))
105 s_bExcept = false;
106 s_errMsg[0] = char(0);
109 static bool getExcept(void)
111 bool ret;
112 QMutexLocker lock(&s_mutex);
113 ret = s_bExcept;
114 return ret;
117 static bool getErrMsg(char *buffer, const size_t buffSize)
119 QMutexLocker lock(&s_mutex);
120 if(s_errMsg[0])
122 strncpy_s(buffer, BUFF_SIZE, s_errMsg, _TRUNCATE);
123 return true;
125 return false;
128 protected:
129 virtual void taskMain(void) = 0;
131 void run(void)
135 if(!getExcept()) taskMain();
137 catch(const std::exception &e)
139 QMutexLocker lock(&s_mutex);
140 if(!s_bExcept)
142 s_bExcept = true;
143 strncpy_s(s_errMsg, BUFF_SIZE, e.what(), _TRUNCATE);
145 lock.unlock();
146 qWarning("OptionalInitTask exception error:\n%s\n\n", e.what());
148 catch(...)
150 QMutexLocker lock(&s_mutex);
151 if(!s_bExcept)
153 s_bExcept = true;
154 strncpy_s(s_errMsg, BUFF_SIZE, "Unknown exception error!", _TRUNCATE);
156 lock.unlock();
157 qWarning("OptionalInitTask encountered an unknown exception!");
161 static volatile bool s_bExcept;
162 static QMutex s_mutex;
163 static char s_errMsg[BUFF_SIZE];
166 QMutex BaseTask::s_mutex;
167 char BaseTask::s_errMsg[BUFF_SIZE] = {'\0'};
168 volatile bool BaseTask::s_bExcept = false;
170 ////////////////////////////////////////////////////////////
171 // ExtractorTask class
172 ////////////////////////////////////////////////////////////
174 class ExtractorTask : public BaseTask
176 public:
177 ExtractorTask(QResource *const toolResource, const QDir &appDir, const QString &toolName, const QByteArray &toolHash, const unsigned int toolVersion, const QString &toolTag)
179 m_appDir(appDir),
180 m_toolName(toolName),
181 m_toolHash(toolHash),
182 m_toolVersion(toolVersion),
183 m_toolTag(toolTag),
184 m_toolResource(toolResource)
186 /* Nothing to do */
189 ~ExtractorTask(void)
193 static bool getCustom(void)
195 bool ret;
196 QMutexLocker lock(&s_mutex);
197 ret = s_bCustom;
198 return ret;
201 static void clearFlags(void)
203 QMutexLocker lock(&s_mutex);
204 s_bCustom = false;
205 BaseTask::clearFlags(lock);
208 protected:
209 void taskMain(void)
211 LockedFile *lockedFile = NULL;
212 unsigned int version = m_toolVersion;
214 QFileInfo toolFileInfo(m_toolName);
215 const QString toolShortName = QString("%1.%2").arg(toolFileInfo.baseName().toLower(), toolFileInfo.suffix().toLower());
217 QFileInfo customTool(QString("%1/tools/%2/%3").arg(m_appDir.canonicalPath(), QString::number(lamexp_version_build()), toolShortName));
218 if(customTool.exists() && customTool.isFile())
220 qDebug("Setting up file: %s <- %s", toolShortName.toLatin1().constData(), m_appDir.relativeFilePath(customTool.canonicalFilePath()).toLatin1().constData());
221 lockedFile = new LockedFile(customTool.canonicalFilePath()); version = UINT_MAX; s_bCustom = true;
223 else
225 qDebug("Extracting file: %s -> %s", m_toolName.toLatin1().constData(), toolShortName.toLatin1().constData());
226 lockedFile = new LockedFile(m_toolResource.data(), QString("%1/lxp_%2").arg(MUtils::temp_folder(), toolShortName), m_toolHash);
229 if(lockedFile)
231 lamexp_tools_register(toolShortName, lockedFile, version, m_toolTag);
235 private:
236 QScopedPointer<QResource> m_toolResource;
237 const QDir m_appDir;
238 const QString m_toolName;
239 const QByteArray m_toolHash;
240 const unsigned int m_toolVersion;
241 const QString m_toolTag;
243 static volatile bool s_bCustom;
246 volatile bool ExtractorTask::s_bCustom = false;
248 ////////////////////////////////////////////////////////////
249 // InitAacEncTask class
250 ////////////////////////////////////////////////////////////
252 class InitAacEncTask : public BaseTask
254 public:
255 InitAacEncTask(const aac_encoder_t *const encoder_info)
257 m_encoder_info(encoder_info)
261 ~InitAacEncTask(void)
265 protected:
266 void taskMain(void)
268 initAacEncImpl(m_encoder_info->toolName, m_encoder_info->fileNames, m_encoder_info->toolMinVersion, m_encoder_info->verDigits, m_encoder_info->verShift, m_encoder_info->verStr, MAKE_REGEXP(m_encoder_info->regExpVer), MAKE_REGEXP(m_encoder_info->regExpSig));
271 static void initAacEncImpl(const char *const toolName, const char *const fileNames[], const quint32 &toolMinVersion, const quint32 &verDigits, const quint32 &verShift, const char *const verStr, QRegExp &regExpVer, QRegExp &regExpSig = QRegExp());
273 private:
274 const aac_encoder_t *const m_encoder_info;
277 ////////////////////////////////////////////////////////////
278 // Constructor
279 ////////////////////////////////////////////////////////////
281 InitializationThread::InitializationThread(const MUtils::CPUFetaures::cpu_info_t &cpuFeatures)
283 m_bSuccess(false),
284 m_slowIndicator(false)
287 memcpy(&m_cpuFeatures, &cpuFeatures, sizeof(MUtils::CPUFetaures::cpu_info_t));
290 ////////////////////////////////////////////////////////////
291 // Thread Main
292 ////////////////////////////////////////////////////////////
294 void InitializationThread::run(void)
298 doInit();
300 catch(const std::exception &error)
302 MUTILS_PRINT_ERROR("\nGURU MEDITATION !!!\n\nException error:\n%s\n", error.what());
303 MUtils::OS::fatal_exit(L"Unhandeled C++ exception error, application will exit!");
305 catch(...)
307 MUTILS_PRINT_ERROR("\nGURU MEDITATION !!!\n\nUnknown exception error!\n");
308 MUtils::OS::fatal_exit(L"Unhandeled C++ exception error, application will exit!");
312 double InitializationThread::doInit(const size_t threadCount)
314 m_bSuccess = false;
315 delay();
317 //CPU type selection
318 unsigned int cpuSupport = 0;
319 if((m_cpuFeatures.features & MUtils::CPUFetaures::FLAG_SSE) && (m_cpuFeatures.features & MUtils::CPUFetaures::FLAG_SSE2) && m_cpuFeatures.intel)
321 cpuSupport = m_cpuFeatures.x64 ? CPU_TYPE_X64_SSE : CPU_TYPE_X86_SSE;
323 else
325 cpuSupport = m_cpuFeatures.x64 ? CPU_TYPE_X64_GEN : CPU_TYPE_X86_GEN;
328 //Hack to disable x64 on Wine, as x64 binaries won't run under Wine (tested with Wine 1.4 under Ubuntu 12.04 x64)
329 if(cpuSupport & CPU_TYPE_X64_ALL)
331 if(MUtils::OS::running_on_wine())
333 qWarning("Running under Wine on a 64-Bit system. Going to disable all x64 support!\n");
334 cpuSupport = (cpuSupport == CPU_TYPE_X64_SSE) ? CPU_TYPE_X86_SSE : CPU_TYPE_X86_GEN;
338 //Print selected CPU type
339 switch(cpuSupport)
341 PRINT_CPU_TYPE(CPU_TYPE_X86_GEN); break;
342 PRINT_CPU_TYPE(CPU_TYPE_X86_SSE); break;
343 PRINT_CPU_TYPE(CPU_TYPE_X64_GEN); break;
344 PRINT_CPU_TYPE(CPU_TYPE_X64_SSE); break;
345 default: MUTILS_THROW("CPU support undefined!");
348 //Allocate queues
349 QQueue<QString> queueToolName;
350 QQueue<QString> queueChecksum;
351 QQueue<QString> queueVersInfo;
352 QQueue<unsigned int> queueVersions;
353 QQueue<unsigned int> queueCpuTypes;
355 //Init properties
356 for(int i = 0; true; i++)
358 if(!(g_lamexp_tools[i].pcName || g_lamexp_tools[i].pcHash || g_lamexp_tools[i].uiVersion))
360 break;
362 else if(g_lamexp_tools[i].pcName && g_lamexp_tools[i].pcHash && g_lamexp_tools[i].uiVersion)
364 queueToolName.enqueue(QString::fromLatin1(g_lamexp_tools[i].pcName));
365 queueChecksum.enqueue(QString::fromLatin1(g_lamexp_tools[i].pcHash));
366 queueVersInfo.enqueue(QString::fromLatin1(g_lamexp_tools[i].pcVersTag));
367 queueCpuTypes.enqueue(g_lamexp_tools[i].uiCpuType);
368 queueVersions.enqueue(g_lamexp_tools[i].uiVersion);
370 else
372 qFatal("Inconsistent checksum data detected. Take care!");
376 QDir appDir = QDir(QCoreApplication::applicationDirPath()).canonicalPath();
378 QScopedPointer<QThreadPool> pool(new QThreadPool());
379 pool->setMaxThreadCount((threadCount > 0) ? threadCount : qBound(2U, cores2threads(m_cpuFeatures.count), EXPECTED_TOOL_COUNT));
380 /* qWarning("Using %u threads for extraction.", pool->maxThreadCount()); */
382 LockedFile::selfTest();
383 ExtractorTask::clearFlags();
385 //Start the timer
386 QElapsedTimer timeExtractStart;
387 timeExtractStart.start();
389 //Extract all files
390 while(!(queueToolName.isEmpty() || queueChecksum.isEmpty() || queueVersInfo.isEmpty() || queueCpuTypes.isEmpty() || queueVersions.isEmpty()))
392 const QString toolName = queueToolName.dequeue();
393 const QString checksum = queueChecksum.dequeue();
394 const QString versInfo = queueVersInfo.dequeue();
395 const unsigned int cpuType = queueCpuTypes.dequeue();
396 const unsigned int version = queueVersions.dequeue();
398 const QByteArray toolHash(checksum.toLatin1());
399 if(toolHash.size() != 96)
401 qFatal("The checksum for \"%s\" has an invalid size!", MUTILS_UTF8(toolName));
402 return -1.0;
405 QScopedPointer<QResource> resource(new QResource(QString(":/tools/%1").arg(toolName)));
406 if(!(resource->isValid() && resource->data()))
408 qFatal("The resource for \"%s\" could not be found!", MUTILS_UTF8(toolName));
409 return -1.0;
412 if(cpuType & cpuSupport)
414 pool->start(new ExtractorTask(resource.take(), appDir, toolName, toolHash, version, versInfo));
415 continue;
419 //Sanity Check
420 if(!(queueToolName.isEmpty() && queueChecksum.isEmpty() && queueVersInfo.isEmpty() && queueCpuTypes.isEmpty() && queueVersions.isEmpty()))
422 qFatal("Checksum queues *not* empty fater verification completed. Take care!");
425 //Wait for extrator threads to finish
426 pool->waitForDone();
428 //Performance measure
429 const double delayExtract = double(timeExtractStart.elapsed()) / 1000.0;
430 timeExtractStart.invalidate();
432 //Make sure all files were extracted correctly
433 if(ExtractorTask::getExcept())
435 char errorMsg[BUFF_SIZE];
436 if(ExtractorTask::getErrMsg(errorMsg, BUFF_SIZE))
438 qFatal("At least one of the required tools could not be initialized:\n%s", errorMsg);
439 return -1.0;
441 qFatal("At least one of the required tools could not be initialized!");
442 return -1.0;
445 qDebug("All extracted.\n");
447 //Using any custom tools?
448 if(ExtractorTask::getCustom())
450 qWarning("Warning: Using custom tools, you might encounter unexpected problems!\n");
453 //Check delay
454 if(delayExtract > g_allowedExtractDelay)
456 m_slowIndicator = true;
457 qWarning("Extracting tools took %.3f seconds -> probably slow realtime virus scanner.", delayExtract);
458 qWarning("Please report performance problems to your anti-virus developer !!!\n");
460 else
462 qDebug("Extracting the tools took %.3f seconds (OK).\n", delayExtract);
465 //Register all translations
466 initTranslations();
468 //Look for AAC encoders
469 InitAacEncTask::clearFlags();
470 for(size_t i = 0; g_lamexp_aacenc[i].toolName; i++)
472 pool->start(new InitAacEncTask(&(g_lamexp_aacenc[i])));
474 pool->waitForDone();
476 //Make sure initialization finished correctly
477 if(InitAacEncTask::getExcept())
479 char errorMsg[BUFF_SIZE];
480 if(InitAacEncTask::getErrMsg(errorMsg, BUFF_SIZE))
482 qFatal("At least one optional component failed to initialize:\n%s", errorMsg);
483 return -1.0;
485 qFatal("At least one optional component failed to initialize!");
486 return -1.0;
489 m_bSuccess = true;
490 delay();
492 return delayExtract;
495 ////////////////////////////////////////////////////////////
496 // INTERNAL FUNCTIONS
497 ////////////////////////////////////////////////////////////
499 void InitializationThread::delay(void)
501 MUtils::OS::sleep_ms(333);
504 ////////////////////////////////////////////////////////////
505 // Translation Support
506 ////////////////////////////////////////////////////////////
508 void InitializationThread::initTranslations(void)
510 //Search for language files
511 const QDir qmDirectory(":/localization");
512 const QStringList qmFiles = qmDirectory.entryList(QStringList() << "LameXP_??.qm", QDir::Files, QDir::Name);
514 //Make sure we found at least one translation
515 if(qmFiles.count() < 1)
517 qFatal("Could not find any translation files!");
518 return;
521 //Initialize variables
522 const QString langResTemplate(":/localization/%1.txt");
523 QRegExp langIdExp("^LameXP_(\\w\\w)\\.qm$", Qt::CaseInsensitive);
525 //Add all available translations
526 for(QStringList::ConstIterator iter = qmFiles.constBegin(); iter != qmFiles.constEnd(); iter++)
528 const QString langFile = qmDirectory.absoluteFilePath(*iter);
529 QString langId, langName;
530 unsigned int systemId = 0, country = 0;
532 if(QFileInfo(langFile).isFile() && (langIdExp.indexIn(*iter) >= 0))
534 langId = langIdExp.cap(1).toLower();
535 QScopedPointer<QResource> langRes(new QResource(langResTemplate.arg(*iter)));
536 if(langRes->isValid() && langRes->size() > 0)
538 QByteArray data = QByteArray::fromRawData(reinterpret_cast<const char*>(langRes->data()), langRes->size());
539 QTextStream stream(&data, QIODevice::ReadOnly);
540 stream.setAutoDetectUnicode(false); stream.setCodec("UTF-8");
542 while(!(stream.atEnd() || (stream.status() != QTextStream::Ok)))
544 QStringList langInfo = stream.readLine().simplified().split(",", QString::SkipEmptyParts);
545 if(langInfo.count() >= 3)
547 systemId = langInfo.at(0).trimmed().toUInt();
548 country = langInfo.at(1).trimmed().toUInt();
549 langName = langInfo.at(2).trimmed();
550 break;
556 if(!(langId.isEmpty() || langName.isEmpty() || (systemId == 0)))
558 if(MUtils::Translation::insert(langId, langFile, langName, systemId, country))
560 qDebug("Registering translation: %s = %s (%u) [%u]", MUTILS_UTF8(*iter), MUTILS_UTF8(langName), systemId, country);
562 else
564 qWarning("Failed to register: %s", langFile.toLatin1().constData());
569 qDebug("All registered.\n");
572 ////////////////////////////////////////////////////////////
573 // AAC Encoder Detection
574 ////////////////////////////////////////////////////////////
576 void InitAacEncTask::initAacEncImpl(const char *const toolName, const char *const fileNames[], const quint32 &toolMinVersion, const quint32 &verDigits, const quint32 &verShift, const char *const verStr, QRegExp &regExpVer, QRegExp &regExpSig)
578 static const size_t MAX_FILES = 8;
579 const QString appPath = QDir(QCoreApplication::applicationDirPath()).canonicalPath();
581 QFileInfoList fileInfo;
582 for(size_t i = 0; fileNames[i] && (fileInfo.count() < MAX_FILES); i++)
584 fileInfo.append(QFileInfo(QString("%1/%2").arg(appPath, QString::fromLatin1(fileNames[i]))));
587 for(QFileInfoList::ConstIterator iter = fileInfo.constBegin(); iter != fileInfo.constEnd(); iter++)
589 if(!(iter->exists() && iter->isFile()))
591 qDebug("%s encoder binaries not found -> Encoding support will be disabled!\n", toolName);
592 return;
594 if((iter->suffix().compare("exe", Qt::CaseInsensitive) == 0) && (!MUtils::OS::is_executable_file(iter->canonicalFilePath())))
596 qDebug("%s executable is invalid -> %s support will be disabled!\n", MUTILS_UTF8(iter->fileName()), toolName);
597 return;
601 qDebug("Found %s encoder binary:\n%s\n", toolName, MUTILS_UTF8(fileInfo.first().canonicalFilePath()));
603 //Lock the encoder binaries
604 QScopedPointer<LockedFile> binaries[MAX_FILES];
607 size_t index = 0;
608 for(QFileInfoList::ConstIterator iter = fileInfo.constBegin(); iter != fileInfo.constEnd(); iter++)
610 binaries[index++].reset(new LockedFile(iter->canonicalFilePath()));
613 catch(...)
615 qWarning("Failed to get excluive lock to encoder binary -> %s support will be disabled!", toolName);
616 return;
619 QProcess process;
620 MUtils::init_process(process, fileInfo.first().absolutePath());
622 process.start(fileInfo.first().canonicalFilePath(), QStringList() << "-help");
624 if(!process.waitForStarted())
626 qWarning("%s process failed to create!", toolName);
627 qWarning("Error message: \"%s\"\n", process.errorString().toLatin1().constData());
628 process.kill();
629 process.waitForFinished(-1);
630 return;
633 quint32 toolVersion = 0;
634 bool sigFound = regExpSig.isEmpty() ? true : false;
636 while(process.state() != QProcess::NotRunning)
638 if(!process.waitForReadyRead())
640 if(process.state() == QProcess::Running)
642 qWarning("%s process time out -> killing!", toolName);
643 process.kill();
644 process.waitForFinished(-1);
645 return;
648 while(process.canReadLine())
650 QString line = QString::fromUtf8(process.readLine().constData()).simplified();
651 if((!sigFound) && regExpSig.lastIndexIn(line) >= 0)
653 sigFound = true;
654 continue;
656 if(sigFound && (regExpVer.lastIndexIn(line) >= 0))
658 quint32 tmp[8];
659 if(MUtils::regexp_parse_uint32(regExpVer, tmp, qMin(verDigits, 8U)))
661 toolVersion = 0;
662 for(quint32 i = 0; i < verDigits; i++)
664 toolVersion = (toolVersion * verShift) + qBound(0U, tmp[i], (verShift - 1));
671 if(toolVersion <= 0)
673 qWarning("%s version could not be determined -> Encoding support will be disabled!", toolName);
674 return;
676 else if(toolVersion < toolMinVersion)
678 qWarning("%s version is too much outdated (%s) -> Encoding support will be disabled!", toolName, MUTILS_UTF8(lamexp_version2string(verStr, toolVersion, "N/A")));
679 qWarning("Minimum required %s version currently is: %s\n", toolName, MUTILS_UTF8(lamexp_version2string(verStr, toolMinVersion, "N/A")));
680 return;
683 qDebug("Enabled %s encoder %s.\n", toolName, MUTILS_UTF8(lamexp_version2string(verStr, toolVersion, "N/A")));
685 size_t index = 0;
686 for(QFileInfoList::ConstIterator iter = fileInfo.constBegin(); iter != fileInfo.constEnd(); iter++)
688 lamexp_tools_register(iter->fileName(), binaries[index++].take(), toolVersion);
692 ////////////////////////////////////////////////////////////
693 // Self-Test Function
694 ////////////////////////////////////////////////////////////
696 void InitializationThread::selfTest(void)
698 const unsigned int cpu[4] = {CPU_TYPE_X86_GEN, CPU_TYPE_X86_SSE, CPU_TYPE_X64_GEN, CPU_TYPE_X64_SSE};
700 LockedFile::selfTest();
702 for(size_t k = 0; k < 4; k++)
704 qDebug("[TEST]");
705 switch(cpu[k])
707 PRINT_CPU_TYPE(CPU_TYPE_X86_GEN); break;
708 PRINT_CPU_TYPE(CPU_TYPE_X86_SSE); break;
709 PRINT_CPU_TYPE(CPU_TYPE_X64_GEN); break;
710 PRINT_CPU_TYPE(CPU_TYPE_X64_SSE); break;
711 default: MUTILS_THROW("CPU support undefined!");
713 unsigned int n = 0;
714 for(int i = 0; true; i++)
716 if(!(g_lamexp_tools[i].pcName || g_lamexp_tools[i].pcHash || g_lamexp_tools[i].uiVersion))
718 break;
720 else if(g_lamexp_tools[i].pcName && g_lamexp_tools[i].pcHash && g_lamexp_tools[i].uiVersion)
722 const QString toolName = QString::fromLatin1(g_lamexp_tools[i].pcName);
723 const QByteArray expectedHash = QByteArray(g_lamexp_tools[i].pcHash);
724 if(g_lamexp_tools[i].uiCpuType & cpu[k])
726 qDebug("%02i -> %s", ++n, MUTILS_UTF8(toolName));
727 QFile resource(QString(":/tools/%1").arg(toolName));
728 if(!resource.open(QIODevice::ReadOnly))
730 qFatal("The resource for \"%s\" could not be opened!", MUTILS_UTF8(toolName));
731 break;
733 QByteArray hash = LockedFile::fileHash(resource);
734 if(hash.isNull() || _stricmp(hash.constData(), expectedHash.constData()))
736 qFatal("Hash check for tool \"%s\" has failed!", MUTILS_UTF8(toolName));
737 break;
739 resource.close();
742 else
744 qFatal("Inconsistent checksum data detected. Take care!");
747 if(n != EXPECTED_TOOL_COUNT)
749 qFatal("Tool count mismatch for CPU type %u !!!", cpu[k]);
751 qDebug("Done.\n");
755 ////////////////////////////////////////////////////////////
756 // EVENTS
757 ////////////////////////////////////////////////////////////
759 /*NONE*/