#include "thread_avisynth.h"
//Qt
-#include <QLibrary>
#include <QEventLoop>
#include <QTimer>
#include <QApplication>
QMutex AvisynthCheckThread::m_avsLock;
QScopedPointer<QFile> AvisynthCheckThread::m_avsDllPath[2];
-//Helper
+//-------------------------------------
+// Auxilary functions
+//-------------------------------------
+
#define VALID_DIR(STR) ((!(STR).isEmpty()) && QDir((STR)).exists())
#define BOOLIFY(X) ((X) ? '1' : '0')
-//Utility function
QString AVS_CHECK_BINARY(const SysinfoModel *sysinfo, const bool& x64)
{
return QString("%1/toolset/%2/avs_check_%2.exe").arg(sysinfo->getAppPath(), (x64 ? "x64": "x86"));
public:
Wow64RedirectionDisabler(void)
{
- m_oldValue = NULL;
m_disabled = MUtils::OS::wow64fsredir_disable(m_oldValue);
}
~Wow64RedirectionDisabler(void)
}
private:
bool m_disabled;
- void* m_oldValue;
+ uintptr_t m_oldValue;
};
//-------------------------------------
:
m_sysinfo(sysinfo)
{
- m_success = false;
- m_exception = false;
+ m_basePath.clear();
}
AvisynthCheckThread::~AvisynthCheckThread(void)
void AvisynthCheckThread::run(void)
{
- m_exception = false;
- m_success &= 0;
m_basePath.clear();
-
- detectAvisynthVersion1(m_success, m_basePath, m_sysinfo, &m_exception);
+ StarupThread::run();
}
-void AvisynthCheckThread::detectAvisynthVersion1(int &success, QString &basePath, const SysinfoModel *const sysinfo, volatile bool *exception)
+int AvisynthCheckThread::threadMain(void)
{
- __try
- {
- detectAvisynthVersion2(success, basePath, sysinfo, exception);
- }
- __except(1)
- {
- *exception = true;
- qWarning("Unhandled exception error in Avisynth thread !!!");
- }
-}
-
-void AvisynthCheckThread::detectAvisynthVersion2(int &success, QString &basePath, const SysinfoModel *const sysinfo, volatile bool *exception)
-{
- try
- {
- return detectAvisynthVersion3(success, basePath, sysinfo);
- }
- catch(...)
- {
- *exception = true;
- qWarning("Avisynth initializdation raised an C++ exception!");
- }
-}
-
-void AvisynthCheckThread::detectAvisynthVersion3(int &success, QString &basePath, const SysinfoModel *const sysinfo)
-{
- success &= 0;
+ int flags = 0;
QFile *avsPath32;
- if(checkAvisynth(basePath, sysinfo, avsPath32, false))
+ if(checkAvisynth(m_basePath, m_sysinfo, avsPath32, false))
{
m_avsDllPath[0].reset(avsPath32);
- success |= AVISYNTH_X86;
+ flags |= AVISYNTH_X86;
qDebug("Avisynth 32-Bit edition found!");
}
else
qDebug("Avisynth 32-Bit edition *not* found!");
}
- if(sysinfo->getCPUFeatures(SysinfoModel::CPUFeatures_X64))
+ if(m_sysinfo->getCPUFeatures(SysinfoModel::CPUFeatures_X64))
{
QFile *avsPath64;
- if(checkAvisynth(basePath, sysinfo, avsPath64, true))
+ if(checkAvisynth(m_basePath, m_sysinfo, avsPath64, true))
{
m_avsDllPath[1].reset(avsPath64);
- success |= AVISYNTH_X64;
+ flags |= AVISYNTH_X64;
qDebug("Avisynth 64-Bit edition found!");
}
else
{
qWarning("Skipping 64-Bit Avisynth check on non-x64 system!");
}
+
+ return flags;
}
+//-------------------------------------
+// Internal functions
+//-------------------------------------
+
bool AvisynthCheckThread::checkAvisynth(QString &basePath, const SysinfoModel *const sysinfo, QFile *&path, const bool &x64)
{
qDebug("Avisynth %s-Bit support is being tested.", x64 ? "64" : "32");
AvisynthCheckThread(const SysinfoModel *const sysinfo);
~AvisynthCheckThread(void);
- int getSuccess(void) { return m_success; }
- bool getException(void) { return m_exception; }
QString getPath(void) { return m_basePath; }
typedef enum _AvisynthFlags
void start(Priority priority = InheritPriority) { QThread::start(priority); }
private:
- volatile bool m_exception;
- int m_success;
QString m_basePath;
const SysinfoModel *const m_sysinfo;
//Entry point
virtual void run(void);
- //Functions
- static void detectAvisynthVersion1(int &success, QString &basePath, const SysinfoModel *const sysinfo, volatile bool *exception);
- static void detectAvisynthVersion2(int &success, QString &basePath, const SysinfoModel *const sysinfo, volatile bool *exception);
- static void detectAvisynthVersion3(int &success, QString &basePath, const SysinfoModel *const sysinfo);
+ //Thread main
+ virtual int threadMain(void);
//Internal functions
static bool checkAvisynth(QString &basePath, const SysinfoModel *const sysinfo, QFile *&path, const bool &x64);
//Whatever
#define NEXT(X) ((*reinterpret_cast<int*>(&(X)))++)
#define SHFL(X) ((*reinterpret_cast<int*>(&(X))) <<= 1)
+#define BOOLIFY(X) (!!(X))
//External
QString AVS_CHECK_BINARY(const SysinfoModel *sysinfo, const bool& x64);
return false;
}
- const bool success = thread.getSuccess();
+ const bool success = BOOLIFY(thread.getSuccess());
if ((!success) && failedPath)
{
*failedPath = thread.getFailedPath();
:
m_sysinfo(sysinfo)
{
- m_success = m_exception = false;
+ m_failedPath.clear();
}
BinariesCheckThread::~BinariesCheckThread(void)
void BinariesCheckThread::run(void)
{
- m_success = m_exception = false;
- m_failedPath = QString();
- checkBinaries1(m_success, m_failedPath, m_sysinfo, &m_exception);
+ m_failedPath.clear();
+ StarupThread::run();
}
-void BinariesCheckThread::checkBinaries1(volatile bool &success, QString &failedPath, const SysinfoModel *const sysinfo, volatile bool *exception)
+int BinariesCheckThread::threadMain(void)
{
- __try
- {
- checkBinaries2(success, failedPath, sysinfo, exception);
- }
- __except(1)
- {
- *exception = true;
- qWarning("Unhandled exception error in binaries checker thread !!!");
- }
-}
-
-void BinariesCheckThread::checkBinaries2(volatile bool &success, QString &failedPath, const SysinfoModel *const sysinfo, volatile bool *exception)
-{
- try
- {
- return checkBinaries3(success, failedPath, sysinfo);
- }
- catch(...)
- {
- *exception = true;
- qWarning("Binaries checker initializdation raised an C++ exception!");
- }
-}
-
-void BinariesCheckThread::checkBinaries3(volatile bool &success, QString &failedPath, const SysinfoModel *const sysinfo)
-{
- success = true;
-
//Create list of all required binary files
typedef QPair<QString, bool> FileEntry;
QList<FileEntry> binFiles;
const QStringList variants = encInfo.getVariants();
for (quint32 varntIdx = 0; varntIdx < quint32(variants.count()); ++varntIdx)
{
- const QStringList dependencies = encInfo.getDependencies(sysinfo, archIdx, varntIdx);
+ const QStringList dependencies = encInfo.getDependencies(m_sysinfo, archIdx, varntIdx);
for (QStringList::ConstIterator iter = dependencies.constBegin(); iter != dependencies.constEnd(); iter++)
{
if (!filesSet.contains(*iter))
binFiles << qMakePair(*iter, true);
}
}
- const QString binary = encInfo.getBinaryPath(sysinfo, archIdx, varntIdx);
+ const QString binary = encInfo.getBinaryPath(m_sysinfo, archIdx, varntIdx);
if (!filesSet.contains(binary))
{
filesSet << binary;
}
for(int i = 0; i < 2; i++)
{
- binFiles << qMakePair(SourceFactory::getSourceInfo(SourceFactory::SourceType_AVS).getBinaryPath(sysinfo, bool(i)), false);
- binFiles << qMakePair(AVS_CHECK_BINARY(sysinfo, bool(i)), false);
+ binFiles << qMakePair(SourceFactory::getSourceInfo(SourceFactory::SourceType_AVS).getBinaryPath(m_sysinfo, bool(i)), false);
+ binFiles << qMakePair(AVS_CHECK_BINARY(m_sysinfo, bool(i)), false);
}
for(size_t i = 0; UpdaterDialog::BINARIES[i].name; i++)
{
if(UpdaterDialog::BINARIES[i].exec)
{
- binFiles << qMakePair(QString("%1/toolset/common/%2").arg(sysinfo->getAppPath(), QString::fromLatin1(UpdaterDialog::BINARIES[i].name)), false);
+ binFiles << qMakePair(QString("%1/toolset/common/%2").arg(m_sysinfo->getAppPath(), QString::fromLatin1(UpdaterDialog::BINARIES[i].name)), false);
}
}
{
if (!MUtils::OS::is_executable_file(file->fileName()))
{
- failedPath = file->fileName();
- success = false;
+ m_failedPath = file->fileName();
qWarning("Required tool does NOT look like a valid Win32/Win64 binary:\n%s\n", MUTILS_UTF8(file->fileName()));
- return;
+ return 0;
}
}
else
{
if (!MUtils::OS::is_library_file(file->fileName()))
{
- failedPath = file->fileName();
- success = false;
+ m_failedPath = file->fileName();
qWarning("Required tool does NOT look like a valid Win32/Win64 library:\n%s\n", MUTILS_UTF8(file->fileName()));
- return;
+ return 0;
}
}
if(currentFile < MAX_BINARIES)
}
else
{
- failedPath = file->fileName();
- success = false;
+ m_failedPath = file->fileName();
qWarning("Required tool could not be found or access denied:\n%s\n", MUTILS_UTF8(file->fileName()));
- return;
+ return 0;
}
}
+
+ return 1;
}
#pragma once
-#include <QThread>
+#include "thread_startup.h"
+
+//Qt
#include <QMutex>
class QLibrary;
class SysinfoModel;
class QFile;
-class BinariesCheckThread : public QThread
+class BinariesCheckThread : public StarupThread
{
Q_OBJECT
protected:
BinariesCheckThread(const SysinfoModel *const sysinfo);
~BinariesCheckThread(void);
-
- int getSuccess(void) { return m_success; }
- bool getException(void) { return m_exception; }
const QString& getFailedPath(void) { return m_failedPath; }
-private slots:
- void start(Priority priority = InheritPriority) { QThread::start(priority); }
-
private:
- volatile bool m_exception, m_success;
QString m_failedPath;
const SysinfoModel *const m_sysinfo;
//Entry point
virtual void run(void);
- //Functions
- static void checkBinaries1(volatile bool &success, QString &failedPath, const SysinfoModel *const sysinfo, volatile bool *exception);
- static void checkBinaries2(volatile bool &success, QString &failedPath, const SysinfoModel *const sysinfo, volatile bool *exception);
- static void checkBinaries3(volatile bool &success, QString &failedPath, const SysinfoModel *const sysinfo);
+ //Thread main
+ virtual int threadMain(void);
};
#include <QElapsedTimer>
#include <QProcess>
+//-------------------------------------
+// Constructor
+//-------------------------------------
+
+StarupThread::StarupThread(void)
+{
+ m_exception = false;
+ m_success = 0;
+}
+
+StarupThread::~StarupThread(void)
+{
+}
+
+//-------------------------------------
+// Thread entry point
+//-------------------------------------
+
+void StarupThread::run(void)
+{
+ m_exception = false;
+ m_success = 0;
+ runChecked1(this, m_success, &m_exception);
+}
+
+void StarupThread::runChecked1(StarupThread *const thread, volatile int &success, volatile bool *exception)
+{
+ __try
+ {
+ return runChecked2(thread, success, exception);
+ }
+ __except(1)
+ {
+ *exception = true;
+ qWarning("Unhandled exception error in startup thread !!!");
+ }
+}
+
+void StarupThread::runChecked2(StarupThread *const thread, volatile int &success, volatile bool *exception)
+{
+ try
+ {
+ success = thread->threadMain();
+ }
+ catch(...)
+ {
+ *exception = true;
+ qWarning("Startup thread raised an C++ exception!");
+ }
+}
+
+//-------------------------------------
+// Utility functions
+//-------------------------------------
+
QStringList StarupThread::runProcess(const QString &exePath, const QStringList &arguments, const QStringList *const extraPaths)
{
QProcess process;
processOutput << line;
}
}
- if (timer.hasExpired(15000))
+ if ((process.state() != QProcess::NotRunning) && timer.hasExpired(15000))
+ {
+ process.waitForFinished(125);
+ if (process.state() != QProcess::NotRunning)
+ {
+ qWarning("%s process encountered a deadlock -> aborting now!", MUTILS_UTF8(fileName));
+ break;
+ }
+ }
+ else
{
- qWarning("%s process encountered a deadlock -> aborting now!", MUTILS_UTF8(fileName));
- break;
+ QThread::yieldCurrentThread(); /*yield*/
}
}
{
Q_OBJECT
+public:
+ StarupThread(void);
+ ~StarupThread(void);
+
+ bool getException(void) { return m_exception; }
+ int getSuccess(void) { return m_success; }
+
+protected slots:
+ void start(Priority priority = InheritPriority) { QThread::start(priority); }
+
protected:
+ volatile int m_success;
+ volatile bool m_exception;
+
+ //Entry point
+ virtual void run(void);
+
+ //Error handling
+ static void runChecked1(StarupThread *const thread, volatile int &success, volatile bool *exception);
+ static void runChecked2(StarupThread *const thread, volatile int &success, volatile bool *exception);
+
+ //Thread main
+ virtual int threadMain(void) = 0;
+
+ //Utility functions
static QStringList runProcess(const QString &exePath, const QStringList &args, const QStringList *const extraPaths = NULL);
};
#include <MUtils/Registry.h>
//Qt
-#include <QLibrary>
#include <QEventLoop>
#include <QTimer>
#include <QApplication>
QScopedPointer<QFile> VapourSynthCheckThread::m_vpsExePath[2];
QScopedPointer<QFile> VapourSynthCheckThread::m_vpsDllPath[2];
+//-------------------------------------
+// Auxilary functions
+//-------------------------------------
+
#define VALID_DIR(STR) ((!(STR).isEmpty()) && QDir((STR)).exists())
#define BOOLIFY(X) ((X) ? '1' : '0')
#define VPS_BITNESS(X) (((X) + 1U) * 32U)
}
//-------------------------------------
-// Thread class
+// Thread functions
//-------------------------------------
VapourSynthCheckThread::VapourSynthCheckThread(void)
{
- m_success &= 0;
- m_exception = false;
m_vpsPath.clear();
}
void VapourSynthCheckThread::run(void)
{
- m_success &= 0;
- m_exception = false;
m_vpsPath.clear();
-
- detectVapourSynthPath1(m_success, m_vpsPath, &m_exception);
-}
-
-void VapourSynthCheckThread::detectVapourSynthPath1(int &success, QString &path, volatile bool *exception)
-{
- __try
- {
- return detectVapourSynthPath2(success, path, exception);
- }
- __except(1)
- {
- *exception = true;
- qWarning("Unhandled exception error in VapourSynth thread !!!");
- }
+ StarupThread::run();
}
-void VapourSynthCheckThread::detectVapourSynthPath2(int &success, QString &path, volatile bool *exception)
+int VapourSynthCheckThread::threadMain(void)
{
- try
- {
- return detectVapourSynthPath3(success, path);
- }
- catch(...)
- {
- *exception = true;
- qWarning("VapourSynth initializdation raised an C++ exception!");
- }
-}
-
-void VapourSynthCheckThread::detectVapourSynthPath3(int &success, QString &path)
-{
- success &= 0;
- path.clear();
-
static const char *VPS_CORE_DIR[] =
{
"core32",
};
QString vapoursynthPath;
+ int flags = 0;
//Look for "portable" VapourSynth version
if (ENABLE_PORTABLE_VPS)
if(vapoursynthPath.isEmpty())
{
qWarning("VapourSynth install path not found -> disable VapouSynth support!");
- return;
+ return 0;
}
//Validate the VapourSynth installation now!
{
if (vpsExeFile && checkVapourSynth(vpsExeFile->fileName()))
{
- success |= VPS_BIT_FLAG[i];
+ flags |= VPS_BIT_FLAG[i];
qDebug("VapourSynth %u-Bit edition found!", VPS_BITNESS(i));
m_vpsExePath[i].reset(vpsExeFile);
m_vpsDllPath[i].reset(vpsDllFile);
}
//Return VapourSynth path
- if(success)
+ if(flags)
{
- path = vapoursynthPath;
+ m_vpsPath = vapoursynthPath;
}
+
+ return flags;
}
+//-------------------------------------
+// Internal functions
+//-------------------------------------
+
bool VapourSynthCheckThread::isVapourSynthComplete(const QString &vsCorePath, QFile *&vpsExeFile, QFile *&vpsDllFile)
{
bool complete = false;
static bool detect(SysinfoModel *sysinfo);
protected:
- VapourSynthCheckThread(void);
- ~VapourSynthCheckThread(void);
-
- bool getException(void) { return m_exception; }
- int getSuccess(void) { return m_success; }
- QString getPath(void) { return m_vpsPath; }
-
typedef enum _VapourSynthFlags
{
VAPOURSYNTH_X86 = 0x1,
}
VapourSynthFlags;
-private slots:
- void start(Priority priority = InheritPriority) { QThread::start(priority); }
+ VapourSynthCheckThread(void);
+ ~VapourSynthCheckThread(void);
+
+ QString getPath(void) { return m_vpsPath; }
private:
- volatile bool m_exception;
- int m_success;
QString m_vpsPath;
static QMutex m_vpsLock;
//Entry point
virtual void run(void);
- //Functions
- static void detectVapourSynthPath1(int &success, QString &path, volatile bool *exception);
- static void detectVapourSynthPath2(int &success, QString &path, volatile bool *exception);
- static void detectVapourSynthPath3(int &success, QString &path);
+ //Thread main
+ virtual int threadMain(void);
//Internal functions
static bool isVapourSynthComplete(const QString &vsCorePath, QFile *&vpsExeFile, QFile *&vpsDllFile);
#define VER_X264_MAJOR 2
#define VER_X264_MINOR 9
#define VER_X264_PATCH 0
-#define VER_X264_BUILD 1154
+#define VER_X264_BUILD 1156
#define VER_X264_PORTABLE_EDITION (0)