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:
parent
9aaee4c183
commit
12dc5c8ef9
@ -42,7 +42,7 @@ func (h ConvertorHandler) downloadFFmpeg(progressBar *widget.ProgressBar, progre
|
|||||||
MessageID: "unzipRun",
|
MessageID: "unzipRun",
|
||||||
})
|
})
|
||||||
progressMessage.Refresh()
|
progressMessage.Refresh()
|
||||||
err = unZip("ffmpeg/ffmpeg.zip", "ffmpeg")
|
err = unZip("ffmpeg/ffmpeg.zip", "ffmpeg", progressBar)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -100,13 +100,23 @@ func downloadFile(filepath string, url string, progressBar *widget.ProgressBar)
|
|||||||
return nil
|
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)
|
archive, err := zip.OpenReader(fileZip)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer archive.Close()
|
defer archive.Close()
|
||||||
|
|
||||||
|
totalBytes := int64(0)
|
||||||
|
for _, f := range archive.File {
|
||||||
|
totalBytes += int64(f.UncompressedSize64)
|
||||||
|
}
|
||||||
|
|
||||||
|
unpackedBytes := int64(0)
|
||||||
|
|
||||||
for _, f := range archive.File {
|
for _, f := range archive.File {
|
||||||
filePath := filepath.Join(directory, f.Name)
|
filePath := filepath.Join(directory, f.Name)
|
||||||
|
|
||||||
@ -132,10 +142,15 @@ func unZip(fileZip string, directory string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := io.Copy(dstFile, fileInArchive); err != nil {
|
bytesRead, err := io.Copy(dstFile, fileInArchive)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unpackedBytes += bytesRead
|
||||||
|
progressBar.Value = float64(unpackedBytes) / float64(totalBytes) * 100
|
||||||
|
progressBar.Refresh()
|
||||||
|
|
||||||
dstFile.Close()
|
dstFile.Close()
|
||||||
fileInArchive.Close()
|
fileInArchive.Close()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user