1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2016 LoRd_MuldeR <MuldeR2@GMX.de>
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"
26 #define LAMEXP_INC_TOOLS 1
28 #include "LockedFile.h"
30 #include "Tool_Abstract.h"
33 #include <MUtils/Global.h>
34 #include <MUtils/OSSupport.h>
35 #include <MUtils/Translation.h>
36 #include <MUtils/Exception.h>
40 #include <QCoreApplication>
45 #include <QTextStream>
47 #include <QThreadPool>
50 #include <QElapsedTimer>
53 /* enable custom tools? */
54 static const bool ENABLE_CUSTOM_TOOLS
= true;
57 #define PRINT_CPU_TYPE(X) case X: qDebug("Selected CPU is: " #X)
58 #define MAKE_REGEXP(STR) (((STR) && ((STR)[0])) ? QRegExp((STR)) : QRegExp())
61 static const double g_allowedExtractDelay
= 12.0;
62 static const size_t BUFF_SIZE
= 512;
63 static const size_t EXPECTED_TOOL_COUNT
= 28;
65 /* number of CPU cores -> number of threads */
66 static unsigned int cores2threads(const unsigned int cores
)
68 static const size_t LUT_LEN
= 4;
72 const unsigned int upperBound
;
73 const double coeffs
[4];
77 { 4, { -0.052695810565, 0.158087431694, 4.982841530055, -1.088233151184 } },
78 { 8, { 0.042431693989, -0.983442622951, 9.548961748634, -7.176393442623 } },
79 { 12, { -0.006277322404, 0.185573770492, 0.196830601093, 17.762622950820 } },
80 { 32, { 0.000673497268, -0.064655737705, 3.199584699454, 5.751606557377 } }
84 while((cores
> LUT
[index
].upperBound
) && (index
< (LUT_LEN
-1))) index
++;
86 const double x
= qBound(1.0, double(cores
), double(LUT
[LUT_LEN
-1].upperBound
));
87 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];
89 return qRound(abs(y
));
92 ////////////////////////////////////////////////////////////
94 ////////////////////////////////////////////////////////////
96 class BaseTask
: public QRunnable
107 static void clearFlags(QMutexLocker
&lock
= QMutexLocker(&s_mutex
))
110 s_errMsg
[0] = char(0);
113 static bool getExcept(void)
116 QMutexLocker
lock(&s_mutex
);
121 static bool getErrMsg(char *buffer
, const size_t buffSize
)
123 QMutexLocker
lock(&s_mutex
);
126 strncpy_s(buffer
, BUFF_SIZE
, s_errMsg
, _TRUNCATE
);
133 virtual void taskMain(void) = 0;
139 if(!getExcept()) taskMain();
141 catch(const std::exception
&e
)
143 QMutexLocker
lock(&s_mutex
);
147 strncpy_s(s_errMsg
, BUFF_SIZE
, e
.what(), _TRUNCATE
);
150 qWarning("OptionalInitTask exception error:\n%s\n\n", e
.what());
154 QMutexLocker
lock(&s_mutex
);
158 strncpy_s(s_errMsg
, BUFF_SIZE
, "Unknown exception error!", _TRUNCATE
);
161 qWarning("OptionalInitTask encountered an unknown exception!");
165 static volatile bool s_bExcept
;
166 static QMutex s_mutex
;
167 static char s_errMsg
[BUFF_SIZE
];
170 QMutex
BaseTask::s_mutex
;
171 char BaseTask::s_errMsg
[BUFF_SIZE
] = {'\0'};
172 volatile bool BaseTask::s_bExcept
= false;
174 ////////////////////////////////////////////////////////////
175 // ExtractorTask class
176 ////////////////////////////////////////////////////////////
178 class ExtractorTask
: public BaseTask
181 ExtractorTask(QResource
*const toolResource
, const QDir
&appDir
, const QString
&toolName
, const QByteArray
&toolHash
, const unsigned int toolVersion
, const QString
&toolTag
)
184 m_tempPath(MUtils::temp_folder()),
185 m_toolName(toolName
),
186 m_toolHash(toolHash
),
187 m_toolVersion(toolVersion
),
189 m_toolResource(toolResource
)
198 static bool getCustom(void)
201 QMutexLocker
lock(&s_mutex
);
206 static void clearFlags(void)
208 QMutexLocker
lock(&s_mutex
);
210 BaseTask::clearFlags(lock
);
216 QScopedPointer
<LockedFile
> lockedFile
;
217 unsigned int version
= m_toolVersion
;
219 const QFileInfo
toolFileInfo(m_toolName
);
220 const QString toolShrtName
= QString("%1.%2").arg(toolFileInfo
.baseName().toLower(), toolFileInfo
.suffix().toLower());
222 //Try to load a "custom" tool first
223 if(ENABLE_CUSTOM_TOOLS
)
225 const QFileInfo
customTool(QString("%1/tools/%2/%3").arg(m_appDir
.canonicalPath(), QString::number(lamexp_version_build()), toolShrtName
));
226 if(customTool
.exists() && customTool
.isFile())
228 qDebug("Setting up file: %s <- %s", toolShrtName
.toLatin1().constData(), m_appDir
.relativeFilePath(customTool
.canonicalFilePath()).toLatin1().constData());
231 lockedFile
.reset(new LockedFile(customTool
.canonicalFilePath()));
232 version
= UINT_MAX
; s_bCustom
= true;
234 catch(std::runtime_error
&)
241 //Try to load the tool from the "cache" next
242 if(lockedFile
.isNull())
244 const QFileInfo
chachedTool(QString("%1/cache/%2").arg(m_appDir
.canonicalPath(), toolFileInfo
.fileName()));
245 if(chachedTool
.exists() && chachedTool
.isFile())
247 qDebug("Validating file: %s <- %s", toolShrtName
.toLatin1().constData(), m_appDir
.relativeFilePath(chachedTool
.canonicalFilePath()).toLatin1().constData());
250 lockedFile
.reset(new LockedFile(chachedTool
.canonicalFilePath(), m_toolHash
));
252 catch(std::runtime_error
&)
259 //If still not initialized, extract tool now!
260 if(lockedFile
.isNull())
262 qDebug("Extracting file: %s -> %s", m_toolName
.toLatin1().constData(), toolShrtName
.toLatin1().constData());
263 lockedFile
.reset(new LockedFile(m_toolResource
.data(), QString("%1/lxp_%2").arg(m_tempPath
, toolShrtName
), m_toolHash
));
267 lamexp_tools_register(toolShrtName
, lockedFile
.take(), version
, m_toolTag
);
271 static volatile bool s_bCustom
;
272 QScopedPointer
<QResource
> m_toolResource
;
274 const QString m_tempPath
;
275 const QString m_toolName
;
276 const QByteArray m_toolHash
;
277 const unsigned int m_toolVersion
;
278 const QString m_toolTag
;
281 volatile bool ExtractorTask::s_bCustom
= false;
283 ////////////////////////////////////////////////////////////
284 // InitAacEncTask class
285 ////////////////////////////////////////////////////////////
287 class InitAacEncTask
: public BaseTask
290 InitAacEncTask(const aac_encoder_t
*const encoder_info
)
292 m_encoder_info(encoder_info
)
296 ~InitAacEncTask(void)
303 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
));
306 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
®ExpVer
, QRegExp
®ExpSig
= QRegExp());
309 const aac_encoder_t
*const m_encoder_info
;
312 ////////////////////////////////////////////////////////////
314 ////////////////////////////////////////////////////////////
316 InitializationThread::InitializationThread(const MUtils::CPUFetaures::cpu_info_t
&cpuFeatures
)
319 m_slowIndicator(false)
322 memcpy(&m_cpuFeatures
, &cpuFeatures
, sizeof(MUtils::CPUFetaures::cpu_info_t
));
325 ////////////////////////////////////////////////////////////
327 ////////////////////////////////////////////////////////////
329 void InitializationThread::run(void)
335 catch(const std::exception
&error
)
337 MUTILS_PRINT_ERROR("\nGURU MEDITATION !!!\n\nException error:\n%s\n", error
.what());
338 MUtils::OS::fatal_exit(L
"Unhandeled C++ exception error, application will exit!");
342 MUTILS_PRINT_ERROR("\nGURU MEDITATION !!!\n\nUnknown exception error!\n");
343 MUtils::OS::fatal_exit(L
"Unhandeled C++ exception error, application will exit!");
347 double InitializationThread::doInit(const size_t threadCount
)
353 unsigned int cpuSupport
= 0;
354 if((m_cpuFeatures
.features
& MUtils::CPUFetaures::FLAG_SSE
) && (m_cpuFeatures
.features
& MUtils::CPUFetaures::FLAG_SSE2
) && m_cpuFeatures
.intel
)
356 cpuSupport
= m_cpuFeatures
.x64
? CPU_TYPE_X64_SSE
: CPU_TYPE_X86_SSE
;
360 cpuSupport
= m_cpuFeatures
.x64
? CPU_TYPE_X64_GEN
: CPU_TYPE_X86_GEN
;
363 //Hack to disable x64 on Wine, as x64 binaries won't run under Wine (tested with Wine 1.4 under Ubuntu 12.04 x64)
364 if(cpuSupport
& CPU_TYPE_X64_ALL
)
366 if(MUtils::OS::running_on_wine())
368 qWarning("Running under Wine on a 64-Bit system. Going to disable all x64 support!\n");
369 cpuSupport
= (cpuSupport
== CPU_TYPE_X64_SSE
) ? CPU_TYPE_X86_SSE
: CPU_TYPE_X86_GEN
;
373 //Print selected CPU type
376 PRINT_CPU_TYPE(CPU_TYPE_X86_GEN
); break;
377 PRINT_CPU_TYPE(CPU_TYPE_X86_SSE
); break;
378 PRINT_CPU_TYPE(CPU_TYPE_X64_GEN
); break;
379 PRINT_CPU_TYPE(CPU_TYPE_X64_SSE
); break;
380 default: MUTILS_THROW("CPU support undefined!");
384 QQueue
<QString
> queueToolName
;
385 QQueue
<QString
> queueChecksum
;
386 QQueue
<QString
> queueVersInfo
;
387 QQueue
<unsigned int> queueVersions
;
388 QQueue
<unsigned int> queueCpuTypes
;
391 for(int i
= 0; true; i
++)
393 if(!(g_lamexp_tools
[i
].pcName
|| g_lamexp_tools
[i
].pcHash
|| g_lamexp_tools
[i
].uiVersion
))
397 else if(g_lamexp_tools
[i
].pcName
&& g_lamexp_tools
[i
].pcHash
&& g_lamexp_tools
[i
].uiVersion
)
399 queueToolName
.enqueue(QString::fromLatin1(g_lamexp_tools
[i
].pcName
));
400 queueChecksum
.enqueue(QString::fromLatin1(g_lamexp_tools
[i
].pcHash
));
401 queueVersInfo
.enqueue(QString::fromLatin1(g_lamexp_tools
[i
].pcVersTag
));
402 queueCpuTypes
.enqueue(g_lamexp_tools
[i
].uiCpuType
);
403 queueVersions
.enqueue(g_lamexp_tools
[i
].uiVersion
);
407 qFatal("Inconsistent checksum data detected. Take care!");
411 QDir appDir
= QDir(QCoreApplication::applicationDirPath()).canonicalPath();
413 QScopedPointer
<QThreadPool
> pool(new QThreadPool());
414 pool
->setMaxThreadCount((threadCount
> 0) ? threadCount
: qBound(2U, cores2threads(m_cpuFeatures
.count
), EXPECTED_TOOL_COUNT
));
415 /* qWarning("Using %u threads for extraction.", pool->maxThreadCount()); */
417 FileHash::selfTest();
418 ExtractorTask::clearFlags();
421 QElapsedTimer timeExtractStart
;
422 timeExtractStart
.start();
425 while(!(queueToolName
.isEmpty() || queueChecksum
.isEmpty() || queueVersInfo
.isEmpty() || queueCpuTypes
.isEmpty() || queueVersions
.isEmpty()))
427 const QString toolName
= queueToolName
.dequeue();
428 const QString checksum
= queueChecksum
.dequeue();
429 const QString versInfo
= queueVersInfo
.dequeue();
430 const unsigned int cpuType
= queueCpuTypes
.dequeue();
431 const unsigned int version
= queueVersions
.dequeue();
433 const QByteArray
toolHash(checksum
.toLatin1());
434 if(toolHash
.size() != 96)
436 qFatal("The checksum for \"%s\" has an invalid size!", MUTILS_UTF8(toolName
));
440 QScopedPointer
<QResource
> resource(new QResource(QString(":/tools/%1").arg(toolName
)));
441 if(!(resource
->isValid() && resource
->data()))
443 qFatal("The resource for \"%s\" could not be found!", MUTILS_UTF8(toolName
));
447 if(cpuType
& cpuSupport
)
449 pool
->start(new ExtractorTask(resource
.take(), appDir
, toolName
, toolHash
, version
, versInfo
));
455 if(!(queueToolName
.isEmpty() && queueChecksum
.isEmpty() && queueVersInfo
.isEmpty() && queueCpuTypes
.isEmpty() && queueVersions
.isEmpty()))
457 qFatal("Checksum queues *not* empty fater verification completed. Take care!");
460 //Wait for extrator threads to finish
463 //Performance measure
464 const double delayExtract
= double(timeExtractStart
.elapsed()) / 1000.0;
465 timeExtractStart
.invalidate();
467 //Make sure all files were extracted correctly
468 if(ExtractorTask::getExcept())
470 char errorMsg
[BUFF_SIZE
];
471 if(ExtractorTask::getErrMsg(errorMsg
, BUFF_SIZE
))
473 qFatal("At least one of the required tools could not be initialized:\n%s", errorMsg
);
476 qFatal("At least one of the required tools could not be initialized!");
480 qDebug("All extracted.\n");
482 //Using any custom tools?
483 if(ExtractorTask::getCustom())
485 qWarning("Warning: Using custom tools, you might encounter unexpected problems!\n");
489 if(delayExtract
> g_allowedExtractDelay
)
491 m_slowIndicator
= true;
492 qWarning("Extracting tools took %.3f seconds -> probably slow realtime virus scanner.", delayExtract
);
493 qWarning("Please report performance problems to your anti-virus developer !!!\n");
497 qDebug("Extracting the tools took %.3f seconds (OK).\n", delayExtract
);
500 //Register all translations
503 //Look for AAC encoders
504 InitAacEncTask::clearFlags();
505 for(size_t i
= 0; g_lamexp_aacenc
[i
].toolName
; i
++)
507 pool
->start(new InitAacEncTask(&(g_lamexp_aacenc
[i
])));
511 //Make sure initialization finished correctly
512 if(InitAacEncTask::getExcept())
514 char errorMsg
[BUFF_SIZE
];
515 if(InitAacEncTask::getErrMsg(errorMsg
, BUFF_SIZE
))
517 qFatal("At least one optional component failed to initialize:\n%s", errorMsg
);
520 qFatal("At least one optional component failed to initialize!");
530 ////////////////////////////////////////////////////////////
531 // INTERNAL FUNCTIONS
532 ////////////////////////////////////////////////////////////
534 void InitializationThread::delay(void)
536 MUtils::OS::sleep_ms(333);
539 ////////////////////////////////////////////////////////////
540 // Translation Support
541 ////////////////////////////////////////////////////////////
543 void InitializationThread::initTranslations(void)
545 //Search for language files
546 const QDir
qmDirectory(":/localization");
547 const QStringList qmFiles
= qmDirectory
.entryList(QStringList() << "LameXP_??.qm", QDir::Files
, QDir::Name
);
549 //Make sure we found at least one translation
550 if(qmFiles
.count() < 1)
552 qFatal("Could not find any translation files!");
556 //Initialize variables
557 const QString
langResTemplate(":/localization/%1.txt");
558 QRegExp
langIdExp("^LameXP_(\\w\\w)\\.qm$", Qt::CaseInsensitive
);
560 //Add all available translations
561 for(QStringList::ConstIterator iter
= qmFiles
.constBegin(); iter
!= qmFiles
.constEnd(); iter
++)
563 const QString langFile
= qmDirectory
.absoluteFilePath(*iter
);
564 QString langId
, langName
;
565 unsigned int systemId
= 0, country
= 0;
567 if(QFileInfo(langFile
).isFile() && (langIdExp
.indexIn(*iter
) >= 0))
569 langId
= langIdExp
.cap(1).toLower();
570 QScopedPointer
<QResource
> langRes(new QResource(langResTemplate
.arg(*iter
)));
571 if(langRes
->isValid() && langRes
->size() > 0)
573 QByteArray data
= QByteArray::fromRawData(reinterpret_cast<const char*>(langRes
->data()), langRes
->size());
574 QTextStream
stream(&data
, QIODevice::ReadOnly
);
575 stream
.setAutoDetectUnicode(false); stream
.setCodec("UTF-8");
577 while(!(stream
.atEnd() || (stream
.status() != QTextStream::Ok
)))
579 QStringList langInfo
= stream
.readLine().simplified().split(",", QString::SkipEmptyParts
);
580 if(langInfo
.count() >= 3)
582 systemId
= langInfo
.at(0).trimmed().toUInt();
583 country
= langInfo
.at(1).trimmed().toUInt();
584 langName
= langInfo
.at(2).trimmed();
591 if(!(langId
.isEmpty() || langName
.isEmpty() || (systemId
== 0)))
593 if(MUtils::Translation::insert(langId
, langFile
, langName
, systemId
, country
))
595 qDebug("Registering translation: %s = %s (%u) [%u]", MUTILS_UTF8(*iter
), MUTILS_UTF8(langName
), systemId
, country
);
599 qWarning("Failed to register: %s", langFile
.toLatin1().constData());
604 qDebug("All registered.\n");
607 ////////////////////////////////////////////////////////////
608 // AAC Encoder Detection
609 ////////////////////////////////////////////////////////////
611 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
®ExpVer
, QRegExp
®ExpSig
)
613 static const size_t MAX_FILES
= 8;
614 const QString appPath
= QDir(QCoreApplication::applicationDirPath()).canonicalPath();
616 QFileInfoList fileInfo
;
617 for(size_t i
= 0; fileNames
[i
] && (fileInfo
.count() < MAX_FILES
); i
++)
619 fileInfo
.append(QFileInfo(QString("%1/%2").arg(appPath
, QString::fromLatin1(fileNames
[i
]))));
622 for(QFileInfoList::ConstIterator iter
= fileInfo
.constBegin(); iter
!= fileInfo
.constEnd(); iter
++)
624 if(!(iter
->exists() && iter
->isFile()))
626 qDebug("%s encoder binaries not found -> Encoding support will be disabled!\n", toolName
);
629 if((iter
->suffix().compare("exe", Qt::CaseInsensitive
) == 0) && (!MUtils::OS::is_executable_file(iter
->canonicalFilePath())))
631 qDebug("%s executable is invalid -> %s support will be disabled!\n", MUTILS_UTF8(iter
->fileName()), toolName
);
636 qDebug("Found %s encoder binary:\n%s\n", toolName
, MUTILS_UTF8(fileInfo
.first().canonicalFilePath()));
638 //Lock the encoder binaries
639 QScopedPointer
<LockedFile
> binaries
[MAX_FILES
];
643 for(QFileInfoList::ConstIterator iter
= fileInfo
.constBegin(); iter
!= fileInfo
.constEnd(); iter
++)
645 binaries
[index
++].reset(new LockedFile(iter
->canonicalFilePath()));
650 qWarning("Failed to get excluive lock to encoder binary -> %s support will be disabled!", toolName
);
655 MUtils::init_process(process
, fileInfo
.first().absolutePath());
657 process
.start(fileInfo
.first().canonicalFilePath(), QStringList() << "-help");
659 if(!process
.waitForStarted())
661 qWarning("%s process failed to create!", toolName
);
662 qWarning("Error message: \"%s\"\n", process
.errorString().toLatin1().constData());
664 process
.waitForFinished(-1);
668 quint32 toolVersion
= 0;
669 bool sigFound
= regExpSig
.isEmpty() ? true : false;
671 while(process
.state() != QProcess::NotRunning
)
673 if(!process
.waitForReadyRead())
675 if(process
.state() == QProcess::Running
)
677 qWarning("%s process time out -> killing!", toolName
);
679 process
.waitForFinished(-1);
683 while(process
.canReadLine())
685 QString line
= QString::fromUtf8(process
.readLine().constData()).simplified();
686 if((!sigFound
) && regExpSig
.lastIndexIn(line
) >= 0)
691 if(sigFound
&& (regExpVer
.lastIndexIn(line
) >= 0))
694 if(MUtils::regexp_parse_uint32(regExpVer
, tmp
, qMin(verDigits
, 8U)))
697 for(quint32 i
= 0; i
< verDigits
; i
++)
699 toolVersion
= (toolVersion
* verShift
) + qBound(0U, tmp
[i
], (verShift
- 1));
708 qWarning("%s version could not be determined -> Encoding support will be disabled!", toolName
);
711 else if(toolVersion
< toolMinVersion
)
713 qWarning("%s version is too much outdated (%s) -> Encoding support will be disabled!", toolName
, MUTILS_UTF8(lamexp_version2string(verStr
, toolVersion
, "N/A")));
714 qWarning("Minimum required %s version currently is: %s\n", toolName
, MUTILS_UTF8(lamexp_version2string(verStr
, toolMinVersion
, "N/A")));
718 qDebug("Enabled %s encoder %s.\n", toolName
, MUTILS_UTF8(lamexp_version2string(verStr
, toolVersion
, "N/A")));
721 for(QFileInfoList::ConstIterator iter
= fileInfo
.constBegin(); iter
!= fileInfo
.constEnd(); iter
++)
723 lamexp_tools_register(iter
->fileName(), binaries
[index
++].take(), toolVersion
);
727 ////////////////////////////////////////////////////////////
728 // Self-Test Function
729 ////////////////////////////////////////////////////////////
731 void InitializationThread::selfTest(void)
733 const unsigned int cpu
[4] = {CPU_TYPE_X86_GEN
, CPU_TYPE_X86_SSE
, CPU_TYPE_X64_GEN
, CPU_TYPE_X64_SSE
};
735 FileHash::selfTest();
737 for(size_t k
= 0; k
< 4; k
++)
742 PRINT_CPU_TYPE(CPU_TYPE_X86_GEN
); break;
743 PRINT_CPU_TYPE(CPU_TYPE_X86_SSE
); break;
744 PRINT_CPU_TYPE(CPU_TYPE_X64_GEN
); break;
745 PRINT_CPU_TYPE(CPU_TYPE_X64_SSE
); break;
746 default: MUTILS_THROW("CPU support undefined!");
749 for(int i
= 0; true; i
++)
751 if(!(g_lamexp_tools
[i
].pcName
|| g_lamexp_tools
[i
].pcHash
|| g_lamexp_tools
[i
].uiVersion
))
755 else if(g_lamexp_tools
[i
].pcName
&& g_lamexp_tools
[i
].pcHash
&& g_lamexp_tools
[i
].uiVersion
)
757 const QString toolName
= QString::fromLatin1(g_lamexp_tools
[i
].pcName
);
758 const QByteArray expectedHash
= QByteArray(g_lamexp_tools
[i
].pcHash
);
759 if(g_lamexp_tools
[i
].uiCpuType
& cpu
[k
])
761 qDebug("%02i -> %s", ++n
, MUTILS_UTF8(toolName
));
762 QFile
resource(QString(":/tools/%1").arg(toolName
));
763 if(!resource
.open(QIODevice::ReadOnly
))
765 qFatal("The resource for \"%s\" could not be opened!", MUTILS_UTF8(toolName
));
768 QByteArray hash
= FileHash::computeHash(resource
);
769 if(hash
.isNull() || _stricmp(hash
.constData(), expectedHash
.constData()))
771 qFatal("Hash check for tool \"%s\" has failed!", MUTILS_UTF8(toolName
));
779 qFatal("Inconsistent checksum data detected. Take care!");
782 if(n
!= EXPECTED_TOOL_COUNT
)
784 qFatal("Tool count mismatch for CPU type %u !!!", cpu
[k
]);
790 ////////////////////////////////////////////////////////////
792 ////////////////////////////////////////////////////////////