From d425f9b49ad4f0b93830ac81a89df81abcec6a6f Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Fri, 17 Jun 2022 17:30:46 +0200 Subject: give each thread a string, require UI Thread to clear string to progress --- .github/workflows/build.yml | 3 ++- src/qt/mainwindow.cpp | 3 ++- src/qt/workers.cpp | 14 +++++++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 27ad46e..c0e553d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -67,4 +67,5 @@ jobs: uses: actions/upload-artifact@v2 with: name: Windows Binaries - path: ${{runner.workspace}}/build/{OFQT,OFCL}.exe + path: | + ${{runner.workspace}}/build/*.exe diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 35151ca..9d1ea85 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -97,6 +97,7 @@ void MainWindow::workerResult(const enum Worker::Results_t& result) case Worker::RESULT_UPDATE_TEXT: ui->progressBar->setValue(worker->progress); ui->infoLabel->setText(worker->infoText); + worker->infoText.clear(); break; case Worker::RESULT_IS_INSTALLED: @@ -233,7 +234,7 @@ void MainWindow::openWebsite() void MainWindow::resetProgress() { - ui->progressBar->setFormat(""); + ui->progressBar->setFormat("%p%"); ui->progressBar->setValue(-1); } diff --git a/src/qt/workers.cpp b/src/qt/workers.cpp index 3fce706..8eb26df 100644 --- a/src/qt/workers.cpp +++ b/src/qt/workers.cpp @@ -14,7 +14,7 @@ struct thread_object_info { int working; - QString* infoText; + QString infoText; char* of_dir; char* remote; struct revision_t* rev; @@ -26,7 +26,6 @@ static void* thread_download(void* pinfo) struct thread_object_info* info = (struct thread_object_info*)pinfo; if (info) { - QString* infoText = info->infoText; char* of_dir = info->of_dir; char* remote = info->remote; struct revision_t* rev = info->rev; @@ -35,10 +34,10 @@ static void* thread_download(void* pinfo) struct file_info* file = &rev->files[i]; if (file->type == TYPE_WRITE) { - *info->infoText = QString("Verifying %1").arg(file->object); + info->infoText = QString("Verifying %1").arg(file->object); if (verifyFileHash(of_dir, file)) { - *infoText = QString("Downloading %1").arg(file->object); + info->infoText = QString("Downloading %1").arg(file->object); downloadObject(of_dir, remote, file); } } @@ -132,23 +131,24 @@ int Worker::update_setup(int local_rev, int remote_rev) pthread_t* thread = &download_threads[tindex]; struct thread_object_info* info = &thread_info[tindex]; - QString* threadString = &infoStrings[tindex]; + QString* threadString = &info->infoText; if (!threadString->isEmpty()) { infoText = *threadString; emit resultReady(RESULT_UPDATE_TEXT); + + // allow the main thread to clear the string before we continue + while (!infoText.isEmpty() && do_work) {}; } info->working = 1; - info->infoText = threadString; info->of_dir = of_dir; info->remote = remote; info->rev = rev; info->index = i; progress = (int)(((i * 100) + 1) / rev->file_count); - emit resultReady(RESULT_UPDATE_TEXT); pthread_create(thread, NULL, thread_download, info); } -- cgit v1.2.3