Minor progress window changes

This commit is contained in:
Xpl0itU 2023-07-19 21:25:30 +02:00
parent 2084b1313d
commit 8060005529
6 changed files with 45 additions and 19 deletions

View file

@ -42,7 +42,7 @@ func NewMainWindow(entries []wiiudownloader.TitleEntry) *MainWindow {
log.Fatal("Unable to create window:", err) log.Fatal("Unable to create window:", err)
} }
win.SetTitle("WiiUDownloaderGo") win.SetTitle("WiiUDownloader")
win.SetDefaultSize(716, 400) win.SetDefaultSize(716, 400)
win.Connect("destroy", func() { win.Connect("destroy", func() {
gtk.MainQuit() gtk.MainQuit()
@ -544,7 +544,7 @@ func (mw *MainWindow) onDownloadQueueClicked(selectedPath string) {
defer wg.Done() defer wg.Done()
tidStr := fmt.Sprintf("%016x", title.TitleID) tidStr := fmt.Sprintf("%016x", title.TitleID)
titlePath := fmt.Sprintf("%s/%s [%s]", selectedPath, title.Name, tidStr) titlePath := fmt.Sprintf("%s/%s [%s] [%s]", selectedPath, title.Name, wiiudownloader.GetFormattedKind(title.TitleID), tidStr)
if err := wiiudownloader.DownloadTitle(tidStr, titlePath, mw.decryptContents, progressWindow, mw.getDeleteEncryptedContents()); err != nil { if err := wiiudownloader.DownloadTitle(tidStr, titlePath, mw.decryptContents, progressWindow, mw.getDeleteEncryptedContents()); err != nil {
queueCancelled = true queueCancelled = true
} }

View file

@ -26,7 +26,7 @@ func DecryptContents(path string, progress *ProgressWindow, deleteEncryptedConte
wg.Add(1) wg.Add(1)
progressInt := 1 progressInt := 1
go runDecryption(path, &progressInt, deleteEncryptedContents) go runDecryption(path, &progressInt, deleteEncryptedContents)
progress.percentLabel.SetText("Decrypting...") progress.bar.SetText("Decrypting...")
for !decryptionDone { for !decryptionDone {
progress.bar.SetFraction(float64(progressInt) / 100) progress.bar.SetFraction(float64(progressInt) / 100)
time.Sleep(500 * time.Millisecond) time.Sleep(500 * time.Millisecond)

View file

@ -14,6 +14,7 @@ import (
"time" "time"
"github.com/cavaliergopher/grab/v3" "github.com/cavaliergopher/grab/v3"
"github.com/dustin/go-humanize"
"github.com/gotk3/gotk3/glib" "github.com/gotk3/gotk3/glib"
"github.com/gotk3/gotk3/gtk" "github.com/gotk3/gotk3/gtk"
) )
@ -21,9 +22,8 @@ import (
type ProgressWindow struct { type ProgressWindow struct {
Window *gtk.Window Window *gtk.Window
box *gtk.Box box *gtk.Box
label *gtk.Label gameLabel *gtk.Label
bar *gtk.ProgressBar bar *gtk.ProgressBar
percentLabel *gtk.Label
cancelButton *gtk.Button cancelButton *gtk.Button
cancelled bool cancelled bool
} }
@ -33,7 +33,7 @@ func CreateProgressWindow(parent *gtk.Window) (ProgressWindow, error) {
if err != nil { if err != nil {
return ProgressWindow{}, err return ProgressWindow{}, err
} }
win.SetTitle("File Download") win.SetTitle("WiiUDownloader - Downloading")
win.SetTransientFor(parent) win.SetTransientFor(parent)
@ -43,24 +43,19 @@ func CreateProgressWindow(parent *gtk.Window) (ProgressWindow, error) {
} }
win.Add(box) win.Add(box)
filenameLabel, err := gtk.LabelNew("File: ") gameLabel, err := gtk.LabelNew("")
if err != nil { if err != nil {
return ProgressWindow{}, err return ProgressWindow{}, err
} }
box.PackStart(filenameLabel, false, false, 0) box.PackStart(gameLabel, false, false, 0)
progressBar, err := gtk.ProgressBarNew() progressBar, err := gtk.ProgressBarNew()
if err != nil { if err != nil {
return ProgressWindow{}, err return ProgressWindow{}, err
} }
progressBar.SetShowText(true)
box.PackStart(progressBar, false, false, 0) box.PackStart(progressBar, false, false, 0)
percentLabel, err := gtk.LabelNew("0%")
if err != nil {
return ProgressWindow{}, err
}
box.PackStart(percentLabel, false, false, 0)
cancelButton, err := gtk.ButtonNewWithLabel("Cancel") cancelButton, err := gtk.ButtonNewWithLabel("Cancel")
if err != nil { if err != nil {
return ProgressWindow{}, err return ProgressWindow{}, err
@ -71,14 +66,17 @@ func CreateProgressWindow(parent *gtk.Window) (ProgressWindow, error) {
return ProgressWindow{}, err return ProgressWindow{}, err
} }
bottomhBox.PackEnd(cancelButton, false, false, 0) bottomhBox.PackEnd(cancelButton, false, false, 0)
box.SetMarginBottom(5)
box.SetMarginEnd(5)
box.SetMarginStart(5)
box.SetMarginTop(5)
box.PackEnd(bottomhBox, false, false, 0) box.PackEnd(bottomhBox, false, false, 0)
return ProgressWindow{ return ProgressWindow{
Window: win, Window: win,
box: box, box: box,
label: filenameLabel, gameLabel: gameLabel,
bar: progressBar, bar: progressBar,
percentLabel: percentLabel,
cancelButton: cancelButton, cancelButton: cancelButton,
cancelled: false, cancelled: false,
}, nil }, nil
@ -93,6 +91,11 @@ func downloadFile(progressWindow *ProgressWindow, client *grab.Client, downloadU
filePath := path.Base(dstPath) filePath := path.Base(dstPath)
resp := client.Do(req) 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()))))
for gtk.EventsPending() {
gtk.MainIteration()
}
t := time.NewTicker(500 * time.Millisecond) t := time.NewTicker(500 * time.Millisecond)
defer t.Stop() defer t.Stop()
@ -101,9 +104,11 @@ Loop:
select { select {
case <-t.C: case <-t.C:
glib.IdleAdd(func() { glib.IdleAdd(func() {
progressWindow.label.SetText(filePath)
progressWindow.bar.SetFraction(resp.Progress()) progressWindow.bar.SetFraction(resp.Progress())
progressWindow.percentLabel.SetText(fmt.Sprintf("%.0f%%", 100*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()
@ -123,6 +128,8 @@ func DownloadTitle(titleID string, outputDirectory string, doDecryption bool, pr
progressWindow.cancelButton.Connect("clicked", func() { progressWindow.cancelButton.Connect("clicked", func() {
progressWindow.cancelled = true progressWindow.cancelled = true
}) })
progressWindow.gameLabel.SetText(getTitleEntryFromTid(titleID).Name)
outputDir := strings.TrimRight(outputDirectory, "/\\") outputDir := strings.TrimRight(outputDirectory, "/\\")
baseURL := fmt.Sprintf("http://ccs.cdn.c.shop.nintendowifi.net/ccs/download/%s", titleID) baseURL := fmt.Sprintf("http://ccs.cdn.c.shop.nintendowifi.net/ccs/download/%s", titleID)
titleIDBytes, err := hex.DecodeString(titleID) titleIDBytes, err := hex.DecodeString(titleID)

1
go.mod
View file

@ -4,6 +4,7 @@ go 1.20
require ( require (
github.com/cavaliergopher/grab/v3 v3.0.1 github.com/cavaliergopher/grab/v3 v3.0.1
github.com/dustin/go-humanize v1.0.1
github.com/gotk3/gotk3 v0.6.2 github.com/gotk3/gotk3 v0.6.2
golang.org/x/crypto v0.11.0 golang.org/x/crypto v0.11.0
) )

2
go.sum
View file

@ -1,5 +1,7 @@
github.com/cavaliergopher/grab/v3 v3.0.1 h1:4z7TkBfmPjmLAAmkkAZNX/6QJ1nNFdv3SdIHXju0Fr4= github.com/cavaliergopher/grab/v3 v3.0.1 h1:4z7TkBfmPjmLAAmkkAZNX/6QJ1nNFdv3SdIHXju0Fr4=
github.com/cavaliergopher/grab/v3 v3.0.1/go.mod h1:1U/KNnD+Ft6JJiYoYBAimKH2XrYptb8Kl3DFGmsjpq4= github.com/cavaliergopher/grab/v3 v3.0.1/go.mod h1:1U/KNnD+Ft6JJiYoYBAimKH2XrYptb8Kl3DFGmsjpq4=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/gotk3/gotk3 v0.6.2 h1:sx/PjaKfKULJPTPq8p2kn2ZbcNFxpOJqi4VLzMbEOO8= github.com/gotk3/gotk3 v0.6.2 h1:sx/PjaKfKULJPTPq8p2kn2ZbcNFxpOJqi4VLzMbEOO8=
github.com/gotk3/gotk3 v0.6.2/go.mod h1:/hqFpkNa9T3JgNAE2fLvCdov7c5bw//FHNZrZ3Uv9/Q= github.com/gotk3/gotk3 v0.6.2/go.mod h1:/hqFpkNa9T3JgNAE2fLvCdov7c5bw//FHNZrZ3Uv9/Q=
golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA=

View file

@ -9,7 +9,10 @@ package wiiudownloader
#include <ctype.h> #include <ctype.h>
*/ */
import "C" import "C"
import "unsafe" import (
"strconv"
"unsafe"
)
const ( const (
MCP_REGION_JAPAN = 0x01 MCP_REGION_JAPAN = 0x01
@ -150,3 +153,16 @@ func GetCategoryFromFormattedCategory(formattedCategory string) uint8 {
return TITLE_CATEGORY_ALL return TITLE_CATEGORY_ALL
} }
} }
func getTitleEntryFromTid(tid string) TitleEntry {
titleID, err := strconv.ParseUint(tid, 16, 64)
if err != nil {
return TitleEntry{}
}
for _, entry := range GetTitleEntries(TITLE_CATEGORY_ALL) {
if entry.TitleID == titleID {
return entry
}
}
return TitleEntry{}
}