From 40fe40be8002f5f9c4d7aa70b81ad8b821abae7f Mon Sep 17 00:00:00 2001 From: lordmulder Date: Thu, 2 May 2019 15:45:30 +0200 Subject: [PATCH] Some improvements to binary checker thread. --- src/thread_binaries.cpp | 30 ++++++++++++++++++++---------- src/thread_binaries.h | 16 +++++++++------- src/win_main.cpp | 9 +++++---- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/thread_binaries.cpp b/src/thread_binaries.cpp index cacd0eb..0df2e84 100644 --- a/src/thread_binaries.cpp +++ b/src/thread_binaries.cpp @@ -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; diff --git a/src/thread_binaries.h b/src/thread_binaries.h index 8b258f4..0d00f0c 100644 --- a/src/thread_binaries.h +++ b/src/thread_binaries.h @@ -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); }; diff --git a/src/win_main.cpp b/src/win_main.cpp index 9270494..15e8ee8 100644 --- a/src/win_main.cpp +++ b/src/win_main.cpp @@ -71,7 +71,7 @@ #include #include #include - +#include #include //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("At least one tool is missing or is not a valid Win32/Win64 binary.
Please re-install the program in order to fix the problem!
").replace("-", "−")); - qFatal("At least one tool is missing or is not a valid Win32/Win64 binary!"); + QMessageBox::critical(this, tr("Invalid File!"), tr("At least one tool is missing or is not a valid Win32/Win64 binary:
%1

Please re-install the program in order to fix the problem!").replace("-", "−").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(" ");