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.
This commit is contained in:
Leonid Nikitin 2025-05-06 23:08:29 +05:00
parent 9aaee4c183
commit 12dc5c8ef9
Signed by: kor-elf
GPG Key ID: DAB5355A11C22541

View File

@ -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()
}