Fix GTK warnings

This commit is contained in:
Xpl0itU 2023-08-26 19:20:53 +02:00
parent 40d174fd4e
commit 2d7d23fc68
4 changed files with 25 additions and 31 deletions

View file

@ -44,6 +44,7 @@ func main() {
win.ShowAll() win.ShowAll()
app.AddWindow(win.window) app.AddWindow(win.window)
app.GetActiveWindow().Show() app.GetActiveWindow().Show()
gtk.Main()
}) })
app.Run(nil) app.Run(nil)
app.Quit() app.Quit()

View file

@ -285,7 +285,7 @@ func (mw *MainWindow) ShowAll() {
mw.logger.Fatal("Unable to create box:", err) mw.logger.Fatal("Unable to create box:", err)
} }
mw.categoryButtons = make([]*gtk.ToggleButton, 5) mw.categoryButtons = make([]*gtk.ToggleButton, 0)
for _, cat := range []string{"Game", "Update", "DLC", "Demo", "All"} { for _, cat := range []string{"Game", "Update", "DLC", "Demo", "All"} {
button, err := gtk.ToggleButtonNewWithLabel(cat) button, err := gtk.ToggleButtonNewWithLabel(cat)
if err != nil { if err != nil {

View file

@ -19,7 +19,6 @@ import (
"unsafe" "unsafe"
"github.com/gotk3/gotk3/glib" "github.com/gotk3/gotk3/glib"
"github.com/gotk3/gotk3/gtk"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
) )
@ -48,9 +47,7 @@ func DecryptContents(path string, progress *ProgressWindow, deleteEncryptedConte
glib.IdleAdd(func() { glib.IdleAdd(func() {
progress.bar.SetFraction(float64(progressInt) / 100) progress.bar.SetFraction(float64(progressInt) / 100)
}) })
for gtk.EventsPending() { forceUpdateUI()
gtk.MainIteration()
}
} }
time.Sleep(time.Millisecond * 10) time.Sleep(time.Millisecond * 10)
} }

View file

@ -98,13 +98,7 @@ func downloadFile(progressWindow *ProgressWindow, client *grab.Client, downloadU
req.BufferSize = bufferSize req.BufferSize = bufferSize
resp := client.Do(req) resp := client.Do(req)
glib.IdleAdd(func() { updateProgressWindow(progressWindow, resp, filePath)
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()
}
t := time.NewTicker(500 * time.Millisecond) t := time.NewTicker(500 * time.Millisecond)
defer t.Stop() defer t.Stop()
@ -113,21 +107,13 @@ func downloadFile(progressWindow *ProgressWindow, client *grab.Client, downloadU
for { for {
select { select {
case <-t.C: case <-t.C:
glib.IdleAdd(func() { updateProgressWindow(progressWindow, resp, filePath)
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()
}
if progressWindow.cancelled { if progressWindow.cancelled {
resp.Cancel() resp.Cancel()
break Loop break Loop
} }
case <-resp.Done: case <-resp.Done:
for gtk.EventsPending() { forceUpdateUI()
gtk.MainIteration()
}
if err := resp.Err(); err != nil { if err := resp.Err(); err != nil {
if doRetries && attempt < maxRetries { if doRetries && attempt < maxRetries {
time.Sleep(retryDelay) time.Sleep(retryDelay)
@ -143,6 +129,20 @@ func downloadFile(progressWindow *ProgressWindow, client *grab.Client, downloadU
return nil return nil
} }
func forceUpdateUI() {
for gtk.EventsPending() {
gtk.MainIteration()
}
}
func updateProgressWindow(progressWindow *ProgressWindow, resp *grab.Response, filePath string) {
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()))))
})
forceUpdateUI()
}
func DownloadTitle(titleID string, outputDirectory string, doDecryption bool, progressWindow *ProgressWindow, deleteEncryptedContents bool, logger *Logger) error { func DownloadTitle(titleID string, outputDirectory string, doDecryption bool, progressWindow *ProgressWindow, deleteEncryptedContents bool, logger *Logger) error {
progressWindow.cancelButton.Connect("clicked", func() { progressWindow.cancelButton.Connect("clicked", func() {
progressWindow.cancelled = true progressWindow.cancelled = true
@ -166,9 +166,8 @@ func DownloadTitle(titleID string, outputDirectory string, doDecryption bool, pr
client := grab.NewClient() client := grab.NewClient()
client.BufferSize = bufferSize client.BufferSize = bufferSize
downloadURL := fmt.Sprintf("%s/%s", baseURL, "tmd")
tmdPath := filepath.Join(outputDir, "title.tmd") tmdPath := filepath.Join(outputDir, "title.tmd")
if err := downloadFile(progressWindow, client, downloadURL, tmdPath, true); err != nil { if err := downloadFile(progressWindow, client, fmt.Sprintf("%s/%s", baseURL, "tmd"), tmdPath, true); err != nil {
return err return err
} }
@ -183,8 +182,7 @@ func DownloadTitle(titleID string, outputDirectory string, doDecryption bool, pr
} }
tikPath := filepath.Join(outputDir, "title.tik") tikPath := filepath.Join(outputDir, "title.tik")
downloadURL = fmt.Sprintf("%s/%s", baseURL, "cetk") if err := downloadFile(progressWindow, client, fmt.Sprintf("%s/%s", baseURL, "cetk"), tikPath, false); err != nil {
if err := downloadFile(progressWindow, client, downloadURL, tikPath, false); err != nil {
titleKey, err := GenerateKey(titleID) titleKey, err := GenerateKey(titleID)
if err != nil { if err != nil {
return err return err
@ -235,6 +233,7 @@ func DownloadTitle(titleID string, outputDirectory string, doDecryption bool, pr
} }
var id uint32 var id uint32
var content contentInfo
tmdDataReader := bytes.NewReader(tmdData) tmdDataReader := bytes.NewReader(tmdData)
for i := 0; i < int(contentCount); i++ { for i := 0; i < int(contentCount); i++ {
@ -244,18 +243,15 @@ func DownloadTitle(titleID string, outputDirectory string, doDecryption bool, pr
return err return err
} }
filePath := filepath.Join(outputDir, fmt.Sprintf("%08X.app", id)) filePath := filepath.Join(outputDir, fmt.Sprintf("%08X.app", id))
downloadURL = fmt.Sprintf("%s/%08X", baseURL, id) if err := downloadFile(progressWindow, client, fmt.Sprintf("%s/%08X", baseURL, id), filePath, true); err != nil {
if err := downloadFile(progressWindow, client, downloadURL, filePath, true); err != nil {
return err return err
} }
if tmdData[offset+7]&0x2 == 2 { if tmdData[offset+7]&0x2 == 2 {
filePath = filepath.Join(outputDir, fmt.Sprintf("%08X.h3", id)) filePath = filepath.Join(outputDir, fmt.Sprintf("%08X.h3", id))
downloadURL = fmt.Sprintf("%s/%08X.h3", baseURL, id) if err := downloadFile(progressWindow, client, fmt.Sprintf("%s/%08X.h3", baseURL, id), filePath, true); err != nil {
if err := downloadFile(progressWindow, client, downloadURL, filePath, true); err != nil {
return err return err
} }
var content contentInfo
content.Hash = tmdData[offset+16 : offset+0x14] content.Hash = tmdData[offset+16 : offset+0x14]
content.ID = fmt.Sprintf("%08X", id) content.ID = fmt.Sprintf("%08X", id)
tmdDataReader.Seek(int64(offset+8), 0) tmdDataReader.Seek(int64(offset+8), 0)