Improve stability

This commit is contained in:
Xpl0itU 2023-08-24 16:18:30 +02:00
parent 93e55baa5f
commit 38e6be51c9
3 changed files with 24 additions and 11 deletions

View file

@ -489,9 +489,11 @@ func (mw *MainWindow) onCategoryToggled(button *gtk.ToggleButton) {
func (mw *MainWindow) onDecryptContentsMenuItemClicked(selectedPath string) error {
err := wiiudownloader.DecryptContents(selectedPath, &mw.progressWindow, false)
if mw.progressWindow.Window.IsVisible() {
mw.progressWindow.Window.Close()
}
glib.IdleAdd(func() {
if mw.progressWindow.Window.IsVisible() {
mw.progressWindow.Window.Close()
}
})
return err
}
@ -778,9 +780,11 @@ queueProcessingLoop:
}
mw.titleQueue = []wiiudownloader.TitleEntry{} // Clear the queue
if mw.progressWindow.Window.IsVisible() {
mw.progressWindow.Window.Close()
}
glib.IdleAdd(func() {
if mw.progressWindow.Window.IsVisible() {
mw.progressWindow.Window.Close()
}
})
mw.updateTitlesInQueue()
mw.onSelectionChanged()

View file

@ -18,6 +18,7 @@ import (
"time"
"unsafe"
"github.com/gotk3/gotk3/glib"
"github.com/gotk3/gotk3/gtk"
)
@ -35,11 +36,15 @@ func DecryptContents(path string, progress *ProgressWindow, deleteEncryptedConte
go runDecryption(path, errorChan, deleteEncryptedContents)
progress.bar.SetText("Decrypting...")
glib.IdleAdd(func() {
progress.bar.SetText("Decrypting...")
})
for progressInt := range progressChan {
if progressInt > 0 {
progress.bar.SetFraction(float64(progressInt) / 100)
glib.IdleAdd(func() {
progress.bar.SetFraction(float64(progressInt) / 100)
})
for gtk.EventsPending() {
gtk.MainIteration()
}

View file

@ -98,8 +98,10 @@ func downloadFile(progressWindow *ProgressWindow, client *grab.Client, downloadU
req.BufferSize = bufferSize
resp := client.Do(req)
progressWindow.bar.SetFraction(resp.Progress())
progressWindow.bar.SetText(fmt.Sprintf("Downloading %s (%s/%s) (%s/s)", filePath, humanize.Bytes(uint64(resp.BytesComplete())), humanize.Bytes(uint64(resp.Size())), humanize.Bytes(uint64(resp.BytesPerSecond()))))
glib.IdleAdd(func() {
progressWindow.bar.SetFraction(resp.Progress())
progressWindow.bar.SetText(fmt.Sprintf("Downloading %s (%s/%s) (%s/s)", filePath, humanize.Bytes(uint64(resp.BytesComplete())), humanize.Bytes(uint64(resp.Size())), humanize.Bytes(uint64(resp.BytesPerSecond()))))
})
for gtk.EventsPending() {
gtk.MainIteration()
}
@ -148,7 +150,9 @@ func DownloadTitle(titleID string, outputDirectory string, doDecryption bool, pr
titleEntry := getTitleEntryFromTid(titleID)
progressWindow.gameLabel.SetText(titleEntry.Name)
glib.IdleAdd(func() {
progressWindow.gameLabel.SetText(titleEntry.Name)
})
outputDir := strings.TrimRight(outputDirectory, "/\\")
baseURL := fmt.Sprintf("http://ccs.cdn.c.shop.nintendowifi.net/ccs/download/%s", titleID)
titleIDBytes, err := hex.DecodeString(titleID)