2015-03-14 14:01:50 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Simple x264 Launcher
|
2016-01-01 23:59:55 +01:00
|
|
|
// Copyright (C) 2004-2016 LoRd_MuldeR <MuldeR2@GMX.de>
|
2015-03-14 14:01:50 +01:00
|
|
|
//
|
|
|
|
// 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_binaries.h"
|
|
|
|
|
|
|
|
#include <QLibrary>
|
|
|
|
#include <QEventLoop>
|
|
|
|
#include <QTimer>
|
2016-05-08 15:33:09 +02:00
|
|
|
#include <QSet>
|
2015-03-14 14:01:50 +01:00
|
|
|
#include <QMutexLocker>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QProcess>
|
|
|
|
#include <QDir>
|
|
|
|
|
|
|
|
//Internal
|
|
|
|
#include "global.h"
|
|
|
|
#include "model_sysinfo.h"
|
|
|
|
#include "win_updater.h"
|
2015-08-02 19:16:37 +02:00
|
|
|
#include "encoder_factory.h"
|
2015-08-02 21:16:36 +02:00
|
|
|
#include "source_factory.h"
|
2015-03-14 14:01:50 +01:00
|
|
|
|
|
|
|
//MUtils
|
|
|
|
#include <MUtils/Global.h>
|
|
|
|
#include <MUtils/OSSupport.h>
|
|
|
|
|
|
|
|
//Static
|
|
|
|
QMutex BinariesCheckThread::m_binLock;
|
|
|
|
QScopedPointer<QFile> BinariesCheckThread::m_binPath[MAX_BINARIES];
|
|
|
|
|
|
|
|
//Whatever
|
|
|
|
#define NEXT(X) ((*reinterpret_cast<int*>(&(X)))++)
|
2015-08-02 19:16:37 +02:00
|
|
|
#define SHFL(X) ((*reinterpret_cast<int*>(&(X))) <<= 1)
|
2015-03-14 14:01:50 +01:00
|
|
|
|
2015-08-02 21:16:36 +02:00
|
|
|
//External
|
|
|
|
QString AVS_CHECK_BINARY(const SysinfoModel *sysinfo, const bool& x64);
|
|
|
|
|
2015-03-14 14:01:50 +01:00
|
|
|
//-------------------------------------
|
|
|
|
// External API
|
|
|
|
//-------------------------------------
|
|
|
|
|
|
|
|
bool BinariesCheckThread::check(SysinfoModel *sysinfo)
|
|
|
|
{
|
|
|
|
QMutexLocker lock(&m_binLock);
|
|
|
|
|
|
|
|
QEventLoop loop;
|
|
|
|
BinariesCheckThread thread(sysinfo);
|
|
|
|
|
|
|
|
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
|
|
|
|
|
|
|
connect(&thread, SIGNAL(finished()), &loop, SLOT(quit()));
|
|
|
|
connect(&thread, SIGNAL(terminated()), &loop, SLOT(quit()));
|
|
|
|
|
|
|
|
thread.start();
|
|
|
|
QTimer::singleShot(30000, &loop, SLOT(quit()));
|
|
|
|
|
|
|
|
qDebug("Binaries checker thread has been created, please wait...");
|
|
|
|
loop.exec(QEventLoop::ExcludeUserInputEvents);
|
|
|
|
qDebug("Binaries checker thread finished.");
|
|
|
|
|
|
|
|
QApplication::restoreOverrideCursor();
|
|
|
|
|
|
|
|
if(!thread.wait(1000))
|
|
|
|
{
|
|
|
|
qWarning("Binaries checker thread encountered timeout -> probably deadlock!");
|
|
|
|
thread.terminate();
|
|
|
|
thread.wait();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(thread.getException())
|
|
|
|
{
|
|
|
|
qWarning("Binaries checker thread encountered an exception !!!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return thread.getSuccess();
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------
|
|
|
|
// Thread class
|
|
|
|
//-------------------------------------
|
|
|
|
|
|
|
|
BinariesCheckThread::BinariesCheckThread(const SysinfoModel *const sysinfo)
|
|
|
|
:
|
|
|
|
m_sysinfo(sysinfo)
|
|
|
|
{
|
|
|
|
m_success = m_exception = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
BinariesCheckThread::~BinariesCheckThread(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void BinariesCheckThread::run(void)
|
|
|
|
{
|
|
|
|
m_success = m_exception = false;
|
|
|
|
checkBinaries1(m_success, m_sysinfo, &m_exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BinariesCheckThread::checkBinaries1(volatile bool &success, const SysinfoModel *const sysinfo, volatile bool *exception)
|
|
|
|
{
|
|
|
|
__try
|
|
|
|
{
|
|
|
|
checkBinaries2(success, sysinfo, exception);
|
|
|
|
}
|
|
|
|
__except(1)
|
|
|
|
{
|
|
|
|
*exception = true;
|
|
|
|
qWarning("Unhandled exception error in binaries checker thread !!!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BinariesCheckThread::checkBinaries2(volatile bool &success, const SysinfoModel *const sysinfo, volatile bool *exception)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return checkBinaries3(success, sysinfo);
|
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
*exception = true;
|
|
|
|
qWarning("Binaries checker initializdation raised an C++ exception!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BinariesCheckThread::checkBinaries3(volatile bool &success, const SysinfoModel *const sysinfo)
|
|
|
|
{
|
|
|
|
success = true;
|
|
|
|
|
|
|
|
//Create list of all required binary files
|
2016-05-07 17:39:12 +02:00
|
|
|
typedef QPair<QString, bool> FileEntry;
|
|
|
|
QList<FileEntry> binFiles;
|
|
|
|
for(OptionsModel::EncType encdr = OptionsModel::EncType_MIN; encdr <= OptionsModel::EncType_MAX; NEXT(encdr))
|
2015-03-14 14:01:50 +01:00
|
|
|
{
|
2015-08-02 19:16:37 +02:00
|
|
|
const AbstractEncoderInfo &encInfo = EncoderFactory::getEncoderInfo(encdr);
|
2016-05-08 16:30:31 +02:00
|
|
|
const quint32 archCount = encInfo.getArchitectures().count();
|
2016-05-08 15:33:09 +02:00
|
|
|
QSet<QString> dependencySet;
|
2016-05-08 16:30:31 +02:00
|
|
|
for (quint32 archIdx = 0; archIdx < archCount; ++archIdx)
|
2015-03-14 14:01:50 +01:00
|
|
|
{
|
2016-05-08 16:30:31 +02:00
|
|
|
const QStringList variants = encInfo.getVariants();
|
2016-05-08 15:33:09 +02:00
|
|
|
for (quint32 varntIdx = 0; varntIdx < quint32(variants.count()); ++varntIdx)
|
2015-03-14 14:01:50 +01:00
|
|
|
{
|
2016-05-08 15:33:09 +02:00
|
|
|
const QStringList dependencies = encInfo.getDependencies(sysinfo, archIdx, varntIdx);
|
|
|
|
for (QStringList::ConstIterator iter = dependencies.constBegin(); iter != dependencies.constEnd(); iter++)
|
2015-08-02 19:16:37 +02:00
|
|
|
{
|
2016-05-08 15:33:09 +02:00
|
|
|
if (!dependencySet.contains(*iter))
|
2016-05-07 17:39:12 +02:00
|
|
|
{
|
2016-05-08 15:33:09 +02:00
|
|
|
dependencySet << (*iter);
|
|
|
|
binFiles << qMakePair(*iter, true);
|
2016-05-07 17:39:12 +02:00
|
|
|
}
|
2015-08-02 19:16:37 +02:00
|
|
|
}
|
2016-05-08 15:33:09 +02:00
|
|
|
binFiles << qMakePair(encInfo.getBinaryPath(sysinfo, archIdx, varntIdx), false);
|
2015-03-14 14:01:50 +01:00
|
|
|
}
|
|
|
|
}
|
2015-08-02 19:16:37 +02:00
|
|
|
}
|
2015-08-02 21:16:36 +02:00
|
|
|
for(int i = 0; i < 2; i++)
|
2015-08-02 19:16:37 +02:00
|
|
|
{
|
2016-05-07 17:39:12 +02:00
|
|
|
binFiles << qMakePair(SourceFactory::getSourceInfo(SourceFactory::SourceType_AVS).getBinaryPath(sysinfo, bool(i)), false);
|
|
|
|
binFiles << qMakePair(AVS_CHECK_BINARY(sysinfo, bool(i)), false);
|
2015-03-14 14:01:50 +01:00
|
|
|
}
|
|
|
|
for(size_t i = 0; UpdaterDialog::BINARIES[i].name; i++)
|
|
|
|
{
|
|
|
|
if(UpdaterDialog::BINARIES[i].exec)
|
|
|
|
{
|
2016-05-07 17:39:12 +02:00
|
|
|
binFiles << qMakePair(QString("%1/toolset/common/%2").arg(sysinfo->getAppPath(), QString::fromLatin1(UpdaterDialog::BINARIES[i].name)), false);
|
2015-03-14 14:01:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Actually validate the binaries
|
|
|
|
size_t currentFile = 0;
|
2016-05-07 17:39:12 +02:00
|
|
|
for(QList<FileEntry>::ConstIterator iter = binFiles.constBegin(); iter != binFiles.constEnd(); iter++)
|
2015-03-14 14:01:50 +01:00
|
|
|
{
|
2016-05-07 17:39:12 +02:00
|
|
|
QScopedPointer<QFile> file(new QFile(iter->first));
|
2015-03-14 14:01:50 +01:00
|
|
|
qDebug("%s", MUTILS_UTF8(file->fileName()));
|
|
|
|
|
|
|
|
if(file->open(QIODevice::ReadOnly))
|
|
|
|
{
|
2016-05-08 15:33:09 +02:00
|
|
|
if(!iter->second)
|
2015-03-14 14:01:50 +01:00
|
|
|
{
|
2016-05-08 15:33:09 +02:00
|
|
|
if (!MUtils::OS::is_executable_file(file->fileName()))
|
|
|
|
{
|
|
|
|
success = false;
|
|
|
|
qWarning("Required tool does NOT look like a valid Win32/Win64 binary:\n%s\n", MUTILS_UTF8(file->fileName()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!MUtils::OS::is_library_file(file->fileName()))
|
|
|
|
{
|
|
|
|
success = false;
|
|
|
|
qWarning("Required tool does NOT look like a valid Win32/Win64 library:\n%s\n", MUTILS_UTF8(file->fileName()));
|
|
|
|
return;
|
|
|
|
}
|
2015-03-14 14:01:50 +01:00
|
|
|
}
|
|
|
|
if(currentFile < MAX_BINARIES)
|
|
|
|
{
|
|
|
|
m_binPath[currentFile++].reset(file.take());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
qFatal("Current binary file exceeds max. number of binaries!");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
success = false;
|
|
|
|
qWarning("Required tool could not be found or access denied:\n%s\n", MUTILS_UTF8(file->fileName()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|