From 12dc5c8ef9aae9db8ba7d6fbb0eb6af5bda6ba9c Mon Sep 17 00:00:00 2001 From: Leonid Nikitin Date: Tue, 6 May 2025 23:08:29 +0500 Subject: [PATCH] Add progress tracking to unzip operation on Windows Introduced a progress bar to display the extraction progress when unzipping files using the `unZip` function. This enhancement provides visual feedback by updating the progress as file data is unpacked, improving user experience. --- handler/convertor_windows.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/handler/convertor_windows.go b/handler/convertor_windows.go index 9ea6702..0f4594b 100644 --- a/handler/convertor_windows.go +++ b/handler/convertor_windows.go @@ -42,7 +42,7 @@ func (h ConvertorHandler) downloadFFmpeg(progressBar *widget.ProgressBar, progre MessageID: "unzipRun", }) progressMessage.Refresh() - err = unZip("ffmpeg/ffmpeg.zip", "ffmpeg") + err = unZip("ffmpeg/ffmpeg.zip", "ffmpeg", progressBar) if err != nil { return err } @@ -100,13 +100,23 @@ func downloadFile(filepath string, url string, progressBar *widget.ProgressBar) return nil } -func unZip(fileZip string, directory string) error { +func unZip(fileZip string, directory string, progressBar *widget.ProgressBar) error { + progressBar.Value = 0 + progressBar.Max = 100 + archive, err := zip.OpenReader(fileZip) if err != nil { return err } defer archive.Close() + totalBytes := int64(0) + for _, f := range archive.File { + totalBytes += int64(f.UncompressedSize64) + } + + unpackedBytes := int64(0) + for _, f := range archive.File { filePath := filepath.Join(directory, f.Name) @@ -132,10 +142,15 @@ func unZip(fileZip string, directory string) error { return err } - if _, err := io.Copy(dstFile, fileInArchive); err != nil { + bytesRead, err := io.Copy(dstFile, fileInArchive) + if err != nil { return err } + unpackedBytes += bytesRead + progressBar.Value = float64(unpackedBytes) / float64(totalBytes) * 100 + progressBar.Refresh() + dstFile.Close() fileInArchive.Close() }