Some more improvements to VapourSynth detection code.

This commit is contained in:
LoRd_MuldeR 2019-08-06 20:47:59 +02:00
parent e763eeae5b
commit 7402359b36
3 changed files with 37 additions and 46 deletions

View File

@ -31,6 +31,7 @@
#include <QApplication> #include <QApplication>
#include <QDir> #include <QDir>
#include <QHash> #include <QHash>
#include <QAbstractFileEngine.h>
//Internal //Internal
#include "global.h" #include "global.h"
@ -45,7 +46,9 @@ QScopedPointer<QFile> VapourSynthCheckThread::m_vpsExePath[2];
QScopedPointer<QFile> VapourSynthCheckThread::m_vpsDllPath[2]; QScopedPointer<QFile> VapourSynthCheckThread::m_vpsDllPath[2];
//Const //Const
static const char* const VPS_REG_KEYS = "SOFTWARE\\VapourSynth"; static const char* const VPS_DLL_NAME = "vapoursynth.dll";
static const char* const VPS_EXE_NAME = "vspipe.exe";
static const char* const VPS_REG_PATH = "SOFTWARE\\VapourSynth";
static const char* const VPS_REG_NAME = "VapourSynthDLL"; static const char* const VPS_REG_NAME = "VapourSynthDLL";
//Default VapurSynth architecture //Default VapurSynth architecture
@ -65,11 +68,6 @@ static const char* const VPS_REG_NAME = "VapourSynthDLL";
#define BOOLIFY(X) ((X) ? '1' : '0') #define BOOLIFY(X) ((X) ? '1' : '0')
#define VPS_BITNESS(X) (((X) + 1U) * 32U) #define VPS_BITNESS(X) (((X) + 1U) * 32U)
static inline bool VALID_DIR(const QString &path)
{
return (!path.isEmpty()) && QDir(path).exists();
}
//------------------------------------- //-------------------------------------
// External API // External API
//------------------------------------- //-------------------------------------
@ -172,53 +170,50 @@ int VapourSynthCheckThread::threadMain(void)
MUtils::Registry::scope_default MUtils::Registry::scope_default
}; };
QHash<int, QString> vapoursynthPath; QHash<int, QFileInfo> vpsDllInfo, vpsExeInfo;
int flags = 0; int flags = 0;
//Look for "portable" VapourSynth version //Look for "portable" VapourSynth version
for (size_t i = 0; i < 2U; i++) for (size_t i = 0; i < 2U; i++)
{ {
const QString vpsPortableDir = QString("%1/extra/VapourSynth-%2").arg(QCoreApplication::applicationDirPath(), QString::number(VPS_BITNESS(i))); const QDir vpsPortableDir(QString("%1/extra/VapourSynth-%2").arg(QCoreApplication::applicationDirPath(), QString::number(VPS_BITNESS(i))));
if (VALID_DIR(vpsPortableDir)) if (vpsPortableDir.exists())
{ {
const QFileInfo vpsPortableFile = QFileInfo(QString("%1/vspipe.exe").arg(vpsPortableDir)); const QFileInfo vpsPortableDll(vpsPortableDir.absoluteFilePath(VPS_DLL_NAME));
if (vpsPortableFile.exists() && vpsPortableFile.isFile()) const QFileInfo vpsPortableExe(vpsPortableDir.absoluteFilePath(VPS_EXE_NAME));
if ((vpsPortableDll.exists() && vpsPortableDll.isFile()) || (vpsPortableExe.exists() && vpsPortableExe.isFile()))
{ {
vapoursynthPath.insert(VPS_BIT_FLAG[i], vpsPortableDir); vpsDllInfo.insert(VPS_BIT_FLAG[i], vpsPortableDll);
vpsExeInfo.insert(VPS_BIT_FLAG[i], vpsPortableExe);
} }
} }
} }
//Read VapourSynth path from the registry //Read VapourSynth path from registry
if (vapoursynthPath.isEmpty()) if (vpsDllInfo.isEmpty() && vpsExeInfo.isEmpty())
{ {
for (size_t i = 0; i < 3U; i++) for (size_t i = 0; i < 3U; i++)
{ {
if (MUtils::Registry::reg_key_exists(MUtils::Registry::root_machine, QString::fromLatin1(VPS_REG_KEYS), REG_SCOPE[i])) if (MUtils::Registry::reg_key_exists(MUtils::Registry::root_machine, QString::fromLatin1(VPS_REG_PATH), REG_SCOPE[i]))
{ {
QString vpsDllPath; QString vpsRegDllPath;
if (MUtils::Registry::reg_value_read(MUtils::Registry::root_machine, QString::fromLatin1(VPS_REG_KEYS), QString::fromLatin1(VPS_REG_NAME), vpsDllPath, REG_SCOPE[i])) if (MUtils::Registry::reg_value_read(MUtils::Registry::root_machine, QString::fromLatin1(VPS_REG_PATH), QString::fromLatin1(VPS_REG_NAME), vpsRegDllPath, REG_SCOPE[i]))
{ {
const QFileInfo vpsDllInfo(QDir::fromNativeSeparators(vpsDllPath)); QFileInfo vpsRegDllInfo(QDir::fromNativeSeparators(vpsRegDllPath));
if (vpsDllInfo.exists() && vpsDllInfo.isFile()) vpsRegDllInfo.makeAbsolute();
if (vpsRegDllInfo.exists() && vpsRegDllInfo.isFile())
{ {
const QString vpsCorePath = vpsDllInfo.canonicalPath(); const int flag = getVapourSynthType(REG_SCOPE[i]);
if (!vpsCorePath.isEmpty()) vpsDllInfo.insert(flag, vpsRegDllInfo);
{ vpsExeInfo.insert(flag, vpsRegDllInfo.absoluteDir().absoluteFilePath(VPS_EXE_NAME)); /*derive VSPipe.EXE path from VapourSynth.DLL path for now!*/
const int flag = getVapourSynthType(REG_SCOPE[i]);
if (!vapoursynthPath.contains(flag))
{
vapoursynthPath.insert(flag, vpsCorePath);
}
}
} }
} }
} }
} }
} }
//Make sure VapourSynth directory does exist //Abort, if VapourSynth was *not* found
if(vapoursynthPath.isEmpty()) if (vpsDllInfo.isEmpty() || vpsExeInfo.isEmpty())
{ {
qWarning("VapourSynth install path not found -> disable VapouSynth support!"); qWarning("VapourSynth install path not found -> disable VapouSynth support!");
return 0; return 0;
@ -227,19 +222,17 @@ int VapourSynthCheckThread::threadMain(void)
//Validate the VapourSynth installation now! //Validate the VapourSynth installation now!
for (size_t i = 0; i < 2U; i++) for (size_t i = 0; i < 2U; i++)
{ {
if (vapoursynthPath.contains(VPS_BIT_FLAG[i])) if (vpsDllInfo.contains(VPS_BIT_FLAG[i]) && vpsExeInfo.contains(VPS_BIT_FLAG[i]))
{ {
const QString path = vapoursynthPath[VPS_BIT_FLAG[i]];
qDebug("VapourSynth %u-Bit \"core\" path: %s", VPS_BITNESS(i), MUTILS_UTF8(path));
QFile *vpsExeFile, *vpsDllFile; QFile *vpsExeFile, *vpsDllFile;
if (isVapourSynthComplete(path, vpsExeFile, vpsDllFile)) if (isVapourSynthComplete(vpsDllInfo[VPS_BIT_FLAG[i]], vpsExeInfo[VPS_BIT_FLAG[i]], vpsExeFile, vpsDllFile))
{ {
if (vpsExeFile && checkVapourSynth(vpsExeFile->fileName())) m_vpsExePath[i].reset(vpsExeFile);
m_vpsDllPath[i].reset(vpsDllFile);
if (checkVapourSynth(m_vpsExePath[i]->fileEngine()->fileName(QAbstractFileEngine::CanonicalName)))
{ {
qDebug("VapourSynth %u-Bit edition found!", VPS_BITNESS(i)); qDebug("VapourSynth %u-Bit edition found!", VPS_BITNESS(i));
m_vpsExePath[i].reset(vpsExeFile); m_vpsPath[i] = m_vpsExePath[i]->fileEngine()->fileName(QAbstractFileEngine::CanonicalPathName);
m_vpsDllPath[i].reset(vpsDllFile);
m_vpsPath[i] = path;
flags |= VPS_BIT_FLAG[i]; flags |= VPS_BIT_FLAG[i];
} }
else else
@ -278,24 +271,21 @@ VapourSynthCheckThread::VapourSynthFlags VapourSynthCheckThread::getVapourSynthT
} }
} }
bool VapourSynthCheckThread::isVapourSynthComplete(const QString &vsCorePath, QFile *&vpsExeFile, QFile *&vpsDllFile) bool VapourSynthCheckThread::isVapourSynthComplete(const QFileInfo& vpsDllInfo, const QFileInfo& vpsExeInfo, QFile*& vpsExeFile, QFile*& vpsDllFile)
{ {
bool complete = false; bool complete = false;
vpsExeFile = vpsDllFile = NULL; vpsExeFile = vpsDllFile = NULL;
QFileInfo vpsExeInfo(QString("%1/vspipe.exe" ).arg(vsCorePath));
QFileInfo vpsDllInfo(QString("%1/vapoursynth.dll").arg(vsCorePath));
qDebug("VapourSynth EXE: %s", vpsExeInfo.absoluteFilePath().toUtf8().constData()); qDebug("VapourSynth EXE: %s", vpsExeInfo.absoluteFilePath().toUtf8().constData());
qDebug("VapourSynth DLL: %s", vpsDllInfo.absoluteFilePath().toUtf8().constData()); qDebug("VapourSynth DLL: %s", vpsDllInfo.absoluteFilePath().toUtf8().constData());
if(vpsExeInfo.exists() && vpsDllInfo.exists()) if (vpsDllInfo.exists() && vpsDllInfo.isFile() && vpsExeInfo.exists() && vpsExeInfo.isFile())
{ {
vpsExeFile = new QFile(vpsExeInfo.canonicalFilePath()); vpsExeFile = new QFile(vpsExeInfo.canonicalFilePath());
vpsDllFile = new QFile(vpsDllInfo.canonicalFilePath()); vpsDllFile = new QFile(vpsDllInfo.canonicalFilePath());
if(vpsExeFile->open(QIODevice::ReadOnly) && vpsDllFile->open(QIODevice::ReadOnly)) if(vpsExeFile->open(QIODevice::ReadOnly) && vpsDllFile->open(QIODevice::ReadOnly))
{ {
complete = MUtils::OS::is_executable_file(vpsExeFile->fileName()); complete = MUtils::OS::is_executable_file(vpsExeFile->fileEngine()->fileName(QAbstractFileEngine::CanonicalName));
} }
} }

View File

@ -27,6 +27,7 @@
#include <QMutex> #include <QMutex>
class QFile; class QFile;
class QFileInfo;
class SysinfoModel; class SysinfoModel;
class VapourSynthCheckThread : public StarupThread class VapourSynthCheckThread : public StarupThread
@ -65,6 +66,6 @@ private:
//Internal functions //Internal functions
static VapourSynthFlags getVapourSynthType(const int scope); static VapourSynthFlags getVapourSynthType(const int scope);
static bool isVapourSynthComplete(const QString &vsCorePath, QFile *&vpsExeFile, QFile *&vpsDllFile); static bool isVapourSynthComplete(const QFileInfo& vpsDllInfo, const QFileInfo& vpsExeInfo, QFile*& vpsExeFile, QFile*& vpsDllFile);
static bool checkVapourSynth(const QString &vspipePath); static bool checkVapourSynth(const QString &vspipePath);
}; };

View File

@ -26,7 +26,7 @@
#define VER_X264_MAJOR 2 #define VER_X264_MAJOR 2
#define VER_X264_MINOR 9 #define VER_X264_MINOR 9
#define VER_X264_PATCH 2 #define VER_X264_PATCH 2
#define VER_X264_BUILD 1178 #define VER_X264_BUILD 1180
#define VER_X264_PORTABLE_EDITION (0) #define VER_X264_PORTABLE_EDITION (0)