From 35eb01952408629d992800ccc2f5b2ece6fd9969 Mon Sep 17 00:00:00 2001 From: NissimHadar Date: Thu, 13 Sep 2018 15:34:10 -0700 Subject: [PATCH] Can run installer in a thread. --- tools/auto-tester/src/TestRunner.cpp | 51 ++++++++++++++++++++-------- tools/auto-tester/src/TestRunner.h | 44 ++++++++++++++++-------- 2 files changed, 66 insertions(+), 29 deletions(-) diff --git a/tools/auto-tester/src/TestRunner.cpp b/tools/auto-tester/src/TestRunner.cpp index dddc30e8a8..0d777fbecb 100644 --- a/tools/auto-tester/src/TestRunner.cpp +++ b/tools/auto-tester/src/TestRunner.cpp @@ -32,6 +32,8 @@ TestRunner::TestRunner(std::vector dayCheckboxes, _timeEditCheckboxes = timeEditCheckboxes; _timeEdits = timeEdits; _workingFolderLabel = workingFolderLabel; + + thread = new QThread(); } TestRunner::~TestRunner() { @@ -103,7 +105,32 @@ void TestRunner::installerDownloadComplete() { killProcesses(); runInstaller(); +} +void TestRunner::runInstaller() { + // Qt cannot start an installation process using QProcess::start (Qt Bug 9761) + // To allow installation, the installer is run using the `system` command + + QStringList arguments{ QStringList() << QString("/S") << QString("/D=") + QDir::toNativeSeparators(_installationFolder) }; + + QString installerFullPath = _workingFolder + "/" + INSTALLER_FILENAME; + + QString commandLine = + QDir::toNativeSeparators(installerFullPath) + " /S /D=" + QDir::toNativeSeparators(_installationFolder); + + + worker = new Worker(commandLine); + worker->moveToThread(thread); + connect(worker, SIGNAL(error(QString)), this, SLOT(errorString(QString))); + connect(thread, SIGNAL(started()), worker, SLOT(process())); + connect(worker, SIGNAL(finished()), this, SLOT(installationComplete())); + connect(worker, SIGNAL(finished()), thread, SLOT(quit())); + connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater())); + connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); + thread->start(); +} + +void TestRunner::installationComplete() { createSnapshotFolder(); updateStatusLabel("Running tests"); @@ -117,19 +144,6 @@ void TestRunner::installerDownloadComplete() { // The High Fidelity AppData folder will be restored after evaluation has completed } -void TestRunner::runInstaller() { - // Qt cannot start an installation process using QProcess::start (Qt Bug 9761) - // To allow installation, the installer is run using the `system` command - QStringList arguments{ QStringList() << QString("/S") << QString("/D=") + QDir::toNativeSeparators(_installationFolder) }; - - QString installerFullPath = _workingFolder + "/" + INSTALLER_FILENAME; - - QString commandLine = - QDir::toNativeSeparators(installerFullPath) + " /S /D=" + QDir::toNativeSeparators(_installationFolder); - - system(commandLine.toStdString().c_str()); -} - void TestRunner::saveExistingHighFidelityAppDataFolder() { QString dataDirectory{ "NOT FOUND" }; @@ -414,4 +428,13 @@ void TestRunner::appendLog(const QString& message) { _logFile.close(); autoTester->appendLogWindow(message); -} \ No newline at end of file +} + +Worker::Worker(const QString commandLine) { + _commandLine = commandLine; +} + +void Worker::process() { + system(_commandLine.toStdString().c_str()); + emit finished(); +} diff --git a/tools/auto-tester/src/TestRunner.h b/tools/auto-tester/src/TestRunner.h index e13b0be070..dfb670bb6d 100644 --- a/tools/auto-tester/src/TestRunner.h +++ b/tools/auto-tester/src/TestRunner.h @@ -15,11 +15,11 @@ #include #include #include -#include +#include #include #include -#include "Downloader.h" +class Worker; class TestRunner : public QObject { Q_OBJECT @@ -56,29 +56,27 @@ public: private slots: void checkTime(); + void installationComplete(); private: bool _automatedTestIsRunning{ false }; - QDir _appDataFolder; - QDir _savedAppDataFolder; - - QString _workingFolder; - QString _snapshotFolder; - - QString _installationFolder; - - Downloader* _downloader; - - const QString UNIQUE_FOLDER_NAME{ "fgadhcUDHSFaidsfh3478JJJFSDFIUSOEIrf" }; - const QString SNAPSHOT_FOLDER_NAME{ "snapshots" }; - const QString INSTALLER_URL{ "http://builds.highfidelity.com/HighFidelity-Beta-latest-dev.exe" }; const QString INSTALLER_FILENAME{ "HighFidelity-Beta-latest-dev.exe" }; const QString BUILD_XML_URL{ "https://highfidelity.com/dev-builds.xml" }; const QString BUILD_XML_FILENAME{ "dev-builds.xml" }; + QDir _appDataFolder; + QDir _savedAppDataFolder; + + QString _workingFolder; + QString _installationFolder; + QString _snapshotFolder; + + const QString UNIQUE_FOLDER_NAME{ "fgadhcUDHSFaidsfh3478JJJFSDFIUSOEIrf" }; + const QString SNAPSHOT_FOLDER_NAME{ "snapshots" }; + QString _branch; QString _user; @@ -92,6 +90,22 @@ private: QFile _logFile; QDateTime _testStartDateTime; + + QThread* thread; + Worker* worker; }; +class Worker : public QObject { + Q_OBJECT +public: + Worker(const QString commandLine); +public slots: + void process(); + +signals: + void finished(); + +private: + QString _commandLine; +}; #endif // hifi_testRunner_h \ No newline at end of file