From af0c0dc33e639f116aaa5c0ac4f2541a80106099 Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Mon, 1 Jun 2020 17:40:15 +0200 Subject: Correct handling of 7z errors. --- src/installationmanager.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/installationmanager.cpp') diff --git a/src/installationmanager.cpp b/src/installationmanager.cpp index a60e60eb..639dc88a 100644 --- a/src/installationmanager.cpp +++ b/src/installationmanager.cpp @@ -158,18 +158,12 @@ bool InstallationManager::extractFiles(QString extractPath, QString title, bool QString errorMessage; // The callbacks: - ProgressCallback progressCallback = [&progress, installationProgress, this](float p) { - progress = static_cast(p * 100.0); - - if (installationProgress->wasCanceled()) { - m_ArchiveHandler->cancel(); - installationProgress->reset(); - } - }; + ProgressCallback progressCallback = [&progress](float p) { progress = static_cast(p * 100.0); }; FileChangeCallback fileChangeCallback = [&progressFile](std::wstring const& file) { progressFile = QString::fromStdWString(file); }; ErrorCallback errorCallback = [&errorMessage, this](std::wstring const& message) { + m_ArchiveHandler->cancel(); errorMessage = QString::fromStdWString(message); }; @@ -182,7 +176,13 @@ bool InstallationManager::extractFiles(QString extractPath, QString title, bool errorCallback ); }); + + // Wait for the extraction to complete (or be cancelled): do { + if (installationProgress->wasCanceled()) { + m_ArchiveHandler->cancel(); + installationProgress->reset(); + } if (progress != installationProgress->value()) { installationProgress->setValue(progress); } @@ -191,7 +191,8 @@ bool InstallationManager::extractFiles(QString extractPath, QString title, bool } QCoreApplication::processEvents(); } while (!future.isFinished()); - log::debug("Extraction took {:.3f}s.", std::chrono::duration(std::chrono::system_clock::now() - start).count()); + + // Check the result: if (!future.result()) { if (m_ArchiveHandler->getLastError() == Archive::Error::ERROR_EXTRACT_CANCELLED) { if (!errorMessage.isEmpty()) { @@ -206,6 +207,8 @@ bool InstallationManager::extractFiles(QString extractPath, QString title, bool } } + log::debug("Extraction took {:.3f}s.", std::chrono::duration(std::chrono::system_clock::now() - start).count()); + return true; } -- cgit v1.3.1