+static const double g_allowedExtractDelay = 12.0;
+
+////////////////////////////////////////////////////////////
+// ExtractorTask class
+////////////////////////////////////////////////////////////
+
+class ExtractorTask : public QRunnable
+{
+public:
+ ExtractorTask(const QDir &appDir, const QString &toolName, const QString &toolShortName, const QByteArray &toolHash, const unsigned int toolVersion)
+ :
+ QRunnable(), m_appDir(appDir), m_toolName(toolName), m_toolShortName(toolShortName), m_toolHash(toolHash), m_toolVersion(toolVersion)
+ {
+ /* Nothing to do */
+ }
+
+ static void clearFlags(void)
+ {
+ s_bAbort = s_bCustom = false;
+ s_errMsg[0] = '\0';
+ }
+
+ static bool getAbort(void) { return s_bAbort; }
+ static bool getCustom(void) { return s_bCustom; }
+ static char *const getError(void) { return s_errMsg; }
+
+protected:
+ void run()
+ {
+ try
+ {
+ LockedFile *lockedFile = NULL;
+ unsigned int version = m_toolVersion;
+
+ if(!s_bAbort)
+ {
+ QFileInfo customTool(QString("%1/tools/%2/%3").arg(m_appDir.canonicalPath(), QString::number(lamexp_version_build()), m_toolShortName));
+ if(customTool.exists() && customTool.isFile())
+ {
+ qDebug("Setting up file: %s <- %s", m_toolShortName.toLatin1().constData(), m_appDir.relativeFilePath(customTool.canonicalFilePath()).toLatin1().constData());
+ lockedFile = new LockedFile(customTool.canonicalFilePath()); version = UINT_MAX; s_bCustom = true;
+ }
+ else
+ {
+ qDebug("Extracting file: %s -> %s", m_toolName.toLatin1().constData(), m_toolShortName.toLatin1().constData());
+ lockedFile = new LockedFile(QString(":/tools/%1").arg(m_toolName), QString("%1/lamexp_%2").arg(lamexp_temp_folder2(), m_toolShortName), m_toolHash);
+ }
+
+ if(lockedFile)
+ {
+ QMutexLocker lock(&s_mutex);
+ lamexp_register_tool(m_toolShortName, lockedFile, version);
+ }
+ }
+ }
+ catch(char *errorMsg)
+ {
+ qWarning("At least one of the required tools could not be initialized:\n%s", errorMsg);
+ QMutexLocker lock(&s_mutex);
+ if(!s_bAbort) { s_bAbort = true; strncpy_s(s_errMsg, 1024, errorMsg, _TRUNCATE); }
+ }
+ }
+
+private:
+ const QDir m_appDir;
+ const QString m_toolName;
+ const QString m_toolShortName;
+ const QByteArray m_toolHash;
+ const unsigned int m_toolVersion;
+
+ static volatile bool s_bAbort;
+ static volatile bool s_bCustom;
+ static QMutex s_mutex;
+ static char s_errMsg[1024];
+};
+
+volatile bool ExtractorTask::s_bAbort = false;
+volatile bool ExtractorTask::s_bCustom = false;
+char ExtractorTask::s_errMsg[1024] = {'\0'};
+QMutex ExtractorTask::s_mutex;