From c9f6ae77e26a23c6d0fd69fbb17f3681e71b8227 Mon Sep 17 00:00:00 2001 From: Martchus Date: Fri, 13 Aug 2021 21:00:14 +0200 Subject: [PATCH] Emit progress information while applying changes to Ogg file --- ogg/oggcontainer.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ogg/oggcontainer.cpp b/ogg/oggcontainer.cpp index 5b346b2..addc5a1 100644 --- a/ogg/oggcontainer.cpp +++ b/ogg/oggcontainer.cpp @@ -401,6 +401,8 @@ void OggContainer::internalMakeFile(Diagnostics &diag, AbortableProgressFeedback } } + progress.updateStep("Writing OGG pages ..."); + const auto totalFileSize = fileInfo().size(); try { // prepare iterating comments OggVorbisComment *currentComment; @@ -421,8 +423,12 @@ void OggContainer::internalMakeFile(Diagnostics &diag, AbortableProgressFeedback unordered_map pageSequenceNumberBySerialNo; // iterate through all pages of the original file - for (m_iterator.setStream(backupStream), m_iterator.removeFilter(), m_iterator.reset(); m_iterator; m_iterator.nextPage()) { + auto updateTick = 0u; + for (m_iterator.setStream(backupStream), m_iterator.removeFilter(), m_iterator.reset(); m_iterator; m_iterator.nextPage(), ++updateTick) { const OggPage ¤tPage = m_iterator.currentPage(); + if (updateTick % 10) { + progress.updateStepPercentage(currentPage.startOffset() * 100ul / totalFileSize); + } // check for gaps // note: This is not just to print diag messages but also for taking into account that the parser might skip pages @@ -601,6 +607,7 @@ void OggContainer::internalMakeFile(Diagnostics &diag, AbortableProgressFeedback // report new size fileInfo().reportSizeChanged(static_cast(stream().tellp())); + progress.updateStepPercentage(100); // "save as path" is now the regular path if (!fileInfo().saveFilePath().empty()) { @@ -614,12 +621,18 @@ void OggContainer::internalMakeFile(Diagnostics &diag, AbortableProgressFeedback fileInfo().stream().open(BasicFileInfo::pathForOpen(fileInfo().path()).data(), ios_base::in | ios_base::out | ios_base::binary); // update checksums of modified pages + progress.updateStep("Updating checksums ..."); + updateTick = 0u; for (auto offset : updatedPageOffsets) { + if (updateTick++ % 10) { + progress.updateStepPercentage(offset * 100ul / fileInfo().size()); + } OggPage::updateChecksum(fileInfo().stream(), offset); } // prevent deferring final write operations (to catch and handle possible errors here) fileInfo().stream().flush(); + progress.updateStepPercentage(100); // clear iterator m_iterator.clear(fileInfo().stream(), startOffset(), fileInfo().size());