Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Various improvements to Avisynth and VapourSynth detection code. Refa…
…ctored common code into a shared base class.
  • Loading branch information
lordmulder committed May 7, 2019
1 parent 798c41f commit 8955a9e
Show file tree
Hide file tree
Showing 11 changed files with 190 additions and 123 deletions.
60 changes: 7 additions & 53 deletions src/thread_avisynth.cpp
Expand Up @@ -25,9 +25,7 @@
#include <QLibrary>
#include <QEventLoop>
#include <QTimer>
#include <QMutexLocker>
#include <QApplication>
#include <QProcess>
#include <QDir>

//Internal
Expand Down Expand Up @@ -97,7 +95,7 @@ bool AvisynthCheckThread::detect(SysinfoModel *sysinfo)
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);
Expand Down Expand Up @@ -225,9 +223,6 @@ bool AvisynthCheckThread::checkAvisynth(QString &basePath, const SysinfoModel *c
{
qDebug("Avisynth %s-Bit support is being tested.", x64 ? "64" : "32");

QProcess process;
QStringList output;

//Look for "portable" Avisynth version
static const char *const ARCH_DIR[] = { "x64", "x86" };
const QLatin1String archSuffix = QLatin1String(ARCH_DIR[x64 ? 1 : 0]);
Expand All @@ -245,56 +240,15 @@ bool AvisynthCheckThread::checkAvisynth(QString &basePath, const SysinfoModel *c
}
}

//Setup process object
MUtils::init_process(process, QDir::tempPath(), true, basePath.isEmpty() ? NULL : &(QStringList() << QString("%1/%2").arg(basePath, archSuffix)));

//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)");
Expand Down
6 changes: 3 additions & 3 deletions src/thread_avisynth.h
Expand Up @@ -21,14 +21,14 @@

#pragma once

#include <QThread>
#include "thread_startup.h"

#include <QMutex>

class QLibrary;
class SysinfoModel;
class QFile;

class AvisynthCheckThread : public QThread
class AvisynthCheckThread : public StarupThread
{
Q_OBJECT

Expand Down
101 changes: 101 additions & 0 deletions src/thread_startup.cpp
@@ -0,0 +1,101 @@
///////////////////////////////////////////////////////////////////////////////
// Simple x264 Launcher
// Copyright (C) 2004-2019 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
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// http://www.gnu.org/licenses/gpl-2.0.txt
///////////////////////////////////////////////////////////////////////////////

#include "thread_startup.h"

//MUtils
#include <MUtils/Global.h>

//Qt
#include <QDir>
#include <QElapsedTimer>
#include <QProcess>

QStringList StarupThread::runProcess(const QString &exePath, const QStringList &arguments, const QStringList *const extraPaths)
{
QProcess process;

//Get file name
const QString fileName = QFileInfo(exePath).fileName().toUpper();

//Setup process object
MUtils::init_process(process, QDir::tempPath(), true, extraPaths);

//Try to start process
process.start(exePath, arguments);
if (!process.waitForStarted())
{
qWarning("Failed to launch %s -> %s", MUTILS_UTF8(fileName), MUTILS_UTF8(process.errorString()));
return QStringList();
}

//Start the timer
QElapsedTimer timer;
timer.start();

//Wait until process has finished
QStringList processOutput;
while (process.state() != QProcess::NotRunning)
{
process.waitForReadyRead(1250);
while (process.canReadLine())
{
const QString line = QString::fromUtf8(process.readLine()).simplified();
if (!line.isEmpty())
{
processOutput << line;
}
}
if (timer.hasExpired(15000))
{
qWarning("%s process encountered a deadlock -> aborting now!", MUTILS_UTF8(fileName));
break;
}
}

//Make sure process has terminated!
process.waitForFinished(1250);
if (process.state() != QProcess::NotRunning)
{
qWarning("%s process still running, going to kill it!", MUTILS_UTF8(fileName));
process.kill();
process.waitForFinished(-1);
}

//Read pending lines
while (process.bytesAvailable() > 0)
{
const QString line = QString::fromUtf8(process.readLine()).simplified();
if (!line.isEmpty())
{
processOutput << line;
}
}

//Check exit code
if (process.exitCode() != 0)
{
qWarning("%s failed with code 0x%08X -> discarding all output!", MUTILS_UTF8(fileName), process.exitCode());
return QStringList();
}

return processOutput;
}
34 changes: 34 additions & 0 deletions src/thread_startup.h
@@ -0,0 +1,34 @@
///////////////////////////////////////////////////////////////////////////////
// Simple x264 Launcher
// Copyright (C) 2004-2019 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
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// http://www.gnu.org/licenses/gpl-2.0.txt
///////////////////////////////////////////////////////////////////////////////

#pragma once

//Qt
#include <QThread>
#include <QStringList>

class StarupThread : public QThread
{
Q_OBJECT

protected:
static QStringList runProcess(const QString &exePath, const QStringList &args, const QStringList *const extraPaths = NULL);
};
61 changes: 3 additions & 58 deletions src/thread_vapoursynth.cpp
Expand Up @@ -29,10 +29,8 @@
#include <QLibrary>
#include <QEventLoop>
#include <QTimer>
#include <QMutexLocker>
#include <QApplication>
#include <QDir>
#include <QProcess>

//Internal
#include "global.h"
Expand Down Expand Up @@ -86,7 +84,7 @@ bool VapourSynthCheckThread::detect(SysinfoModel *sysinfo)
connect(&thread, SIGNAL(terminated()), &loop, SLOT(quit()));

thread.start();
QTimer::singleShot(15000, &loop, SLOT(quit()));
QTimer::singleShot(30000, &loop, SLOT(quit()));

qDebug("VapourSynth thread has been created, please wait...");
loop.exec(QEventLoop::ExcludeUserInputEvents);
Expand Down Expand Up @@ -336,61 +334,8 @@ bool VapourSynthCheckThread::isVapourSynthComplete(const QString &vsCorePath, QF

bool VapourSynthCheckThread::checkVapourSynth(const QString &vspipePath)
{
QProcess process;
QStringList output;

//Setup process object
process.setWorkingDirectory(QDir::tempPath());
process.setProcessChannelMode(QProcess::MergedChannels);
process.setReadChannel(QProcess::StandardOutput);

//Try to start VSPIPE.EXE
process.start(vspipePath, QStringList() << "--version");
if(!process.waitForStarted())
{
qWarning("Failed to launch VSPIPE.EXE -> %s", process.errorString().toUtf8().constData());
return false;
}

//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("VSPIPE.EXE process encountered a deadlock -> aborting now!");
break;
}
}

//Make sure VSPIPE.EXE has terminated!
process.waitForFinished(2500);
if(process.state() != QProcess::NotRunning)
{
qWarning("VSPIPE.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("VSPIPE.EXE failed with code 0x%08X -> disable Vapousynth support!", process.exitCode());
return false;
}
//Try to run VSPIPE.EXE
const QStringList output = runProcess(vspipePath, QStringList() << "--version");

//Init regular expressions
QRegExp vpsLogo("VapourSynth\\s+Video\\s+Processing\\s+Library");
Expand Down
6 changes: 3 additions & 3 deletions src/thread_vapoursynth.h
Expand Up @@ -21,15 +21,15 @@

#pragma once

#include "thread_startup.h"

//Qt
#include <QThread>
#include <QMutex>

class QLibrary;
class QFile;
class SysinfoModel;

class VapourSynthCheckThread : public QThread
class VapourSynthCheckThread : public StarupThread
{
Q_OBJECT

Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Expand Up @@ -26,7 +26,7 @@
#define VER_X264_MAJOR 2
#define VER_X264_MINOR 9
#define VER_X264_PATCH 0
#define VER_X264_BUILD 1146
#define VER_X264_BUILD 1154

#define VER_X264_PORTABLE_EDITION (0)

Expand Down
14 changes: 14 additions & 0 deletions x264_launcher.props
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros">
<XPDeprecationWarning>false</XPDeprecationWarning>
</PropertyGroup>
<PropertyGroup />
<ItemDefinitionGroup />
<ItemGroup>
<BuildMacro Include="XPDeprecationWarning">
<Value>$(XPDeprecationWarning)</Value>
</BuildMacro>
</ItemGroup>
</Project>

0 comments on commit 8955a9e

Please sign in to comment.