Some improvements to binary checker thread.

This commit is contained in:
LoRd_MuldeR 2019-05-02 15:45:30 +02:00
parent b8e5f3795c
commit 40fe40be80
3 changed files with 34 additions and 21 deletions

View File

@ -56,7 +56,7 @@ QString AVS_CHECK_BINARY(const SysinfoModel *sysinfo, const bool& x64);
// External API
//-------------------------------------
bool BinariesCheckThread::check(SysinfoModel *sysinfo)
bool BinariesCheckThread::check(const SysinfoModel *const sysinfo, QString *const failedPath)
{
QMutexLocker lock(&m_binLock);
@ -65,7 +65,7 @@ bool BinariesCheckThread::check(SysinfoModel *sysinfo)
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
connect(&thread, SIGNAL(finished()), &loop, SLOT(quit()));
connect(&thread, SIGNAL(finished()), &loop, SLOT(quit()));
connect(&thread, SIGNAL(terminated()), &loop, SLOT(quit()));
thread.start();
@ -77,7 +77,7 @@ bool BinariesCheckThread::check(SysinfoModel *sysinfo)
QApplication::restoreOverrideCursor();
if(!thread.wait(1000))
if(!thread.wait(5000))
{
qWarning("Binaries checker thread encountered timeout -> probably deadlock!");
thread.terminate();
@ -91,7 +91,13 @@ bool BinariesCheckThread::check(SysinfoModel *sysinfo)
return false;
}
return thread.getSuccess();
const bool success = thread.getSuccess();
if ((!success) && failedPath)
{
*failedPath = thread.getFailedPath();
}
return success;
}
//-------------------------------------
@ -112,14 +118,15 @@ BinariesCheckThread::~BinariesCheckThread(void)
void BinariesCheckThread::run(void)
{
m_success = m_exception = false;
checkBinaries1(m_success, m_sysinfo, &m_exception);
m_failedPath = QString();
checkBinaries1(m_success, m_failedPath, m_sysinfo, &m_exception);
}
void BinariesCheckThread::checkBinaries1(volatile bool &success, const SysinfoModel *const sysinfo, volatile bool *exception)
void BinariesCheckThread::checkBinaries1(volatile bool &success, QString &failedPath, const SysinfoModel *const sysinfo, volatile bool *exception)
{
__try
{
checkBinaries2(success, sysinfo, exception);
checkBinaries2(success, failedPath, sysinfo, exception);
}
__except(1)
{
@ -128,11 +135,11 @@ void BinariesCheckThread::checkBinaries1(volatile bool &success, const SysinfoMo
}
}
void BinariesCheckThread::checkBinaries2(volatile bool &success, const SysinfoModel *const sysinfo, volatile bool *exception)
void BinariesCheckThread::checkBinaries2(volatile bool &success, QString &failedPath, const SysinfoModel *const sysinfo, volatile bool *exception)
{
try
{
return checkBinaries3(success, sysinfo);
return checkBinaries3(success, failedPath, sysinfo);
}
catch(...)
{
@ -141,7 +148,7 @@ void BinariesCheckThread::checkBinaries2(volatile bool &success, const SysinfoMo
}
}
void BinariesCheckThread::checkBinaries3(volatile bool &success, const SysinfoModel *const sysinfo)
void BinariesCheckThread::checkBinaries3(volatile bool &success, QString &failedPath, const SysinfoModel *const sysinfo)
{
success = true;
@ -202,6 +209,7 @@ void BinariesCheckThread::checkBinaries3(volatile bool &success, const SysinfoMo
{
if (!MUtils::OS::is_executable_file(file->fileName()))
{
failedPath = file->fileName();
success = false;
qWarning("Required tool does NOT look like a valid Win32/Win64 binary:\n%s\n", MUTILS_UTF8(file->fileName()));
return;
@ -211,6 +219,7 @@ void BinariesCheckThread::checkBinaries3(volatile bool &success, const SysinfoMo
{
if (!MUtils::OS::is_library_file(file->fileName()))
{
failedPath = file->fileName();
success = false;
qWarning("Required tool does NOT look like a valid Win32/Win64 library:\n%s\n", MUTILS_UTF8(file->fileName()));
return;
@ -225,6 +234,7 @@ void BinariesCheckThread::checkBinaries3(volatile bool &success, const SysinfoMo
}
else
{
failedPath = file->fileName();
success = false;
qWarning("Required tool could not be found or access denied:\n%s\n", MUTILS_UTF8(file->fileName()));
return;

View File

@ -33,21 +33,23 @@ class BinariesCheckThread : public QThread
Q_OBJECT
public:
static bool check(SysinfoModel *sysinfo);
static bool check(const SysinfoModel *const sysinfo, QString *const failedPath = NULL);
protected:
BinariesCheckThread(const SysinfoModel *const sysinfo);
~BinariesCheckThread(void);
int getSuccess(void) { return m_success; }
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;
volatile bool m_success;
volatile bool m_exception, m_success;
QString m_failedPath;
const SysinfoModel *const m_sysinfo;
static const size_t MAX_BINARIES = 32;
@ -58,7 +60,7 @@ private:
virtual void run(void);
//Functions
static void checkBinaries1(volatile bool &success, const SysinfoModel *const sysinfo, volatile bool *exception);
static void checkBinaries2(volatile bool &success, const SysinfoModel *const sysinfo, volatile bool *exception);
static void checkBinaries3(volatile bool &success, const SysinfoModel *const sysinfo);
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);
};

View File

@ -71,7 +71,7 @@
#include <QFileDialog>
#include <QSystemTrayIcon>
#include <QMovie>
#include <QTextDocument>
#include <ctime>
//Constants
@ -894,10 +894,11 @@ void MainWindow::init(void)
//---------------------------------------
qDebug("[Validating binaries]");
if(!BinariesCheckThread::check(m_sysinfo.data()))
QString failedPath;
if(!BinariesCheckThread::check(m_sysinfo.data(), &failedPath))
{
QMessageBox::critical(this, tr("Invalid File!"), tr("<nobr>At least one tool is missing or is not a valid Win32/Win64 binary.<br>Please re-install the program in order to fix the problem!</nobr>").replace("-", "&minus;"));
qFatal("At least one tool is missing or is not a valid Win32/Win64 binary!");
QMessageBox::critical(this, tr("Invalid File!"), tr("<nobr>At least one tool is missing or is not a valid Win32/Win64 binary:</nobr><br><tt>%1</tt><br><br><nobr>Please re-install the program in order to fix the problem!</nobr>").replace("-", "&minus;").arg(Qt::escape(QDir::toNativeSeparators(failedPath))));
qFatal("At least one tool is missing or is not a valid Win32/Win64 binary. Program will exit now!");
}
qDebug(" ");