fix(cpn): sounds processing extra files and cancel update processes earlier (#5354)

Co-authored-by: elecpower <elecpower@users.noreply.github.com>
This commit is contained in:
Neil Horne
2024-08-01 22:59:22 +10:00
committed by GitHub
co-authored by elecpower
parent b2a603ed21
commit 4390e310d0
13 changed files with 443 additions and 210 deletions
+20 -2
View File
@@ -27,14 +27,17 @@
#include <QFileInfo>
#include <QDebug>
#include <QWidget>
#include <QApplication>
MinizInterface::MinizInterface(ProgressWidget * progress, const ProgressCalcMethod progressMethod, const int & logLevel) :
QObject(nullptr),
progress(progress),
progressMethod(progressMethod),
progressValue(0),
logLevel(logLevel),
path(""),
archiveFile("")
archiveFile(""),
stopping(false)
{
reportProgress(tr("Progress calculation method: file %1").arg(progressMethod == PCM_COUNT ? tr("count") : tr("size")), QtDebugMsg);
}
@@ -171,8 +174,10 @@ bool MinizInterface::addFileToArchive(const QString & path)
bool MinizInterface::unzipArchiveToPath(const QString & archiveFile, const QString & destinationPath)
{
QFileInfo file(archiveFile);
if (progress)
progress->setInfo(tr("Decompressing %1").arg(archiveFile));
progress->setInfo(tr("Decompressing %1").arg(file.fileName()));
else
qDebug() << QString("Decompressing %1 to %2").arg(archiveFile, destinationPath);
@@ -212,6 +217,12 @@ bool MinizInterface::unzipArchiveToPath(const QString & archiveFile, const QStri
}
for (int i = 0; i < fileCount; i++) {
if (isStopping()) {
mz_zip_reader_end(&zip_archive);
reportProgress(tr("Decompression interrupted"), QtWarningMsg);
return false;
}
if (!mz_zip_reader_file_stat(&zip_archive, i, &file_stat)) {
mz_zip_reader_end(&zip_archive);
reportProgress(tr("Unable to obtain file status for index: %1").arg(i), QtFatalMsg);
@@ -254,6 +265,8 @@ bool MinizInterface::unzipArchiveToPath(const QString & archiveFile, const QStri
progress->setValue(progressValue);
reportProgress(tr("Extracted file: %1").arg(file_stat.m_filename), QtDebugMsg);
// to assist in responsiveness and allow stop signal to be received and processed
QApplication::processEvents();
}
}
@@ -290,3 +303,8 @@ void MinizInterface::reportProgress(const QString & text, const int & type, bool
qDebug() << text;
}
}
void MinizInterface::stop()
{
stopping = true;
}
+7 -2
View File
@@ -28,9 +28,9 @@
class ProgressWidget;
class MinizInterface
class MinizInterface : public QObject
{
Q_DECLARE_TR_FUNCTIONS(MinizInterface)
Q_OBJECT
public:
enum ProgressCalcMethod {
@@ -44,6 +44,9 @@ class MinizInterface
bool zipPathToFile(const QString & sourcePath, const QString & archiveFile, bool append = true);
bool unzipArchiveToPath(const QString & archiveFile, const QString & destinationPath);
public slots:
void stop();
private:
ProgressWidget *progress;
ProgressCalcMethod progressMethod;
@@ -51,10 +54,12 @@ class MinizInterface
int logLevel;
QString path;
QString archiveFile;
bool stopping;
mz_zip_archive zip_archive;
bool addFileToArchive(const QString & path);
bool createDirectory(const QString & path);
void reportProgress(const QString & text, const int & type = QtInfoMsg, bool richText = false);
bool isStopping() { return stopping; }
};