///////////////////////////////////////////////////////////////////////////////
// Simple x264 Launcher
-// Copyright (C) 2004-2016 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2020 LoRd_MuldeR <MuldeR2@GMX.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
#include "thread_avisynth.h"
//Qt
-#include <QLibrary>
#include <QEventLoop>
#include <QTimer>
-#include <QMutexLocker>
#include <QApplication>
-#include <QProcess>
#include <QDir>
//Internal
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;
};
//-------------------------------------
connect(&thread, SIGNAL(terminated()), &loop, SLOT(quit()));
thread.start();
- QTimer::singleShot(15000, &loop, SLOT(quit()));
+ QTimer::singleShot(30000, &loop, SLOT(quit()));
qDebug("Avisynth thread has been created, please wait...");
loop.exec(QEventLoop::ExcludeUserInputEvents);
:
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");
- QProcess process;
- QStringList output;
- QString extraPath;
-
//Look for "portable" Avisynth version
+ static const char *const ARCH_DIR[] = { "x64", "x86" };
+ const QLatin1String archSuffix = QLatin1String(ARCH_DIR[x64 ? 1 : 0]);
if (ENABLE_PORTABLE_AVS)
{
const QString avsPortableDir = QString("%1/extra/Avisynth").arg(QCoreApplication::applicationDirPath());
if (VALID_DIR(avsPortableDir))
{
- const QString archDir = x64 ? QLatin1String("x64") : QLatin1String("x86");
- QFileInfo avsDllFile(QString("%1/%2/avisynth.dll").arg(avsPortableDir, archDir)), devilDllFile(QString("%1/%2/devil.dll").arg(avsPortableDir, archDir));
+ QFileInfo avsDllFile(QString("%1/%2/avisynth.dll").arg(avsPortableDir, archSuffix)), devilDllFile(QString("%1/%2/devil.dll").arg(avsPortableDir, archSuffix));
if (avsDllFile.exists() && devilDllFile.exists() && avsDllFile.isFile() && devilDllFile.isFile())
{
qWarning("Adding portable Avisynth to PATH environment variable: %s", MUTILS_UTF8(avsPortableDir));
basePath = avsPortableDir;
- extraPath = QString("%1/%2").arg(avsPortableDir, archDir);
}
}
}
- //Setup process object
- MUtils::init_process(process, QDir::tempPath(), true, extraPath);
-
- //Try to start VSPIPE.EXE
- process.start(AVS_CHECK_BINARY(sysinfo, x64), QStringList());
- if(!process.waitForStarted())
+ //Get extra paths
+ QStringList avisynthExtraPaths;
+ if (!basePath.isEmpty())
{
- qWarning("Failed to launch AVS_CHECK.EXE -> %s", process.errorString().toUtf8().constData());
- return false;
+ avisynthExtraPaths << QString("%1/%2").arg(basePath, archSuffix);
}
- //Wait for process to finish
- while(process.state() != QProcess::NotRunning)
- {
- if(process.waitForReadyRead(12000))
- {
- while(process.canReadLine())
- {
- output << QString::fromUtf8(process.readLine()).simplified();
- }
- continue;
- }
- if(process.state() != QProcess::NotRunning)
- {
- qWarning("AVS_CHECK.EXE process encountered a deadlock -> aborting now!");
- break;
- }
- }
-
- //Make sure VSPIPE.EXE has terminated!
- process.waitForFinished(2500);
- if(process.state() != QProcess::NotRunning)
- {
- qWarning("AVS_CHECK.EXE process still running, going to kill it!");
- process.kill();
- process.waitForFinished(-1);
- }
-
- //Read pending lines
- while(process.canReadLine())
- {
- output << QString::fromUtf8(process.readLine()).simplified();
- }
-
- //Check exit code
- if(process.exitCode() != 0)
- {
- qWarning("AVS_CHECK.EXE failed with code 0x%08X -> disable Avisynth support!", process.exitCode());
- return false;
- }
+ //Setup process object
+ const QStringList output = runProcess(AVS_CHECK_BINARY(sysinfo, x64), QStringList(), &avisynthExtraPaths);
//Init regular expressions
QRegExp avsLogo("Avisynth\\s+Checker\\s+(x86|x64)");