diff --git a/cmd/WiiUDownloader/mainwindow.go b/cmd/WiiUDownloader/mainwindow.go index a43eb04..eaf586c 100644 --- a/cmd/WiiUDownloader/mainwindow.go +++ b/cmd/WiiUDownloader/mainwindow.go @@ -42,7 +42,7 @@ func NewMainWindow(entries []wiiudownloader.TitleEntry) *MainWindow { log.Fatal("Unable to create window:", err) } - win.SetTitle("WiiUDownloaderGo") + win.SetTitle("WiiUDownloader") win.SetDefaultSize(716, 400) win.Connect("destroy", func() { gtk.MainQuit() @@ -544,7 +544,7 @@ func (mw *MainWindow) onDownloadQueueClicked(selectedPath string) { defer wg.Done() 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 { queueCancelled = true } diff --git a/decryption.go b/decryption.go index 592540c..bcaea3b 100644 --- a/decryption.go +++ b/decryption.go @@ -26,7 +26,7 @@ func DecryptContents(path string, progress *ProgressWindow, deleteEncryptedConte wg.Add(1) progressInt := 1 go runDecryption(path, &progressInt, deleteEncryptedContents) - progress.percentLabel.SetText("Decrypting...") + progress.bar.SetText("Decrypting...") for !decryptionDone { progress.bar.SetFraction(float64(progressInt) / 100) time.Sleep(500 * time.Millisecond) diff --git a/downloader.go b/downloader.go index 335acbe..e72f466 100644 --- a/downloader.go +++ b/downloader.go @@ -14,6 +14,7 @@ import ( "time" "github.com/cavaliergopher/grab/v3" + "github.com/dustin/go-humanize" "github.com/gotk3/gotk3/glib" "github.com/gotk3/gotk3/gtk" ) @@ -21,9 +22,8 @@ import ( type ProgressWindow struct { Window *gtk.Window box *gtk.Box - label *gtk.Label + gameLabel *gtk.Label bar *gtk.ProgressBar - percentLabel *gtk.Label cancelButton *gtk.Button cancelled bool } @@ -33,7 +33,7 @@ func CreateProgressWindow(parent *gtk.Window) (ProgressWindow, error) { if err != nil { return ProgressWindow{}, err } - win.SetTitle("File Download") + win.SetTitle("WiiUDownloader - Downloading") win.SetTransientFor(parent) @@ -43,24 +43,19 @@ func CreateProgressWindow(parent *gtk.Window) (ProgressWindow, error) { } win.Add(box) - filenameLabel, err := gtk.LabelNew("File: ") + gameLabel, err := gtk.LabelNew("") if err != nil { return ProgressWindow{}, err } - box.PackStart(filenameLabel, false, false, 0) + box.PackStart(gameLabel, false, false, 0) progressBar, err := gtk.ProgressBarNew() if err != nil { return ProgressWindow{}, err } + progressBar.SetShowText(true) 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") if err != nil { return ProgressWindow{}, err @@ -71,14 +66,17 @@ func CreateProgressWindow(parent *gtk.Window) (ProgressWindow, error) { return ProgressWindow{}, err } bottomhBox.PackEnd(cancelButton, false, false, 0) + box.SetMarginBottom(5) + box.SetMarginEnd(5) + box.SetMarginStart(5) + box.SetMarginTop(5) box.PackEnd(bottomhBox, false, false, 0) return ProgressWindow{ Window: win, box: box, - label: filenameLabel, + gameLabel: gameLabel, bar: progressBar, - percentLabel: percentLabel, cancelButton: cancelButton, cancelled: false, }, nil @@ -93,6 +91,11 @@ func downloadFile(progressWindow *ProgressWindow, client *grab.Client, downloadU filePath := path.Base(dstPath) 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) defer t.Stop() @@ -101,9 +104,11 @@ Loop: select { case <-t.C: glib.IdleAdd(func() { - progressWindow.label.SetText(filePath) 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 { resp.Cancel() @@ -123,6 +128,8 @@ func DownloadTitle(titleID string, outputDirectory string, doDecryption bool, pr progressWindow.cancelButton.Connect("clicked", func() { progressWindow.cancelled = true }) + + progressWindow.gameLabel.SetText(getTitleEntryFromTid(titleID).Name) outputDir := strings.TrimRight(outputDirectory, "/\\") baseURL := fmt.Sprintf("http://ccs.cdn.c.shop.nintendowifi.net/ccs/download/%s", titleID) titleIDBytes, err := hex.DecodeString(titleID) diff --git a/go.mod b/go.mod index 74a2278..a7650af 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.20 require ( github.com/cavaliergopher/grab/v3 v3.0.1 + github.com/dustin/go-humanize v1.0.1 github.com/gotk3/gotk3 v0.6.2 golang.org/x/crypto v0.11.0 ) diff --git a/go.sum b/go.sum index 6cbc4dc..ea7a1f9 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ 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/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/go.mod h1:/hqFpkNa9T3JgNAE2fLvCdov7c5bw//FHNZrZ3Uv9/Q= golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= diff --git a/gtitles.go b/gtitles.go index 494c4cd..323a81a 100644 --- a/gtitles.go +++ b/gtitles.go @@ -9,7 +9,10 @@ package wiiudownloader #include */ import "C" -import "unsafe" +import ( + "strconv" + "unsafe" +) const ( MCP_REGION_JAPAN = 0x01 @@ -150,3 +153,16 @@ func GetCategoryFromFormattedCategory(formattedCategory string) uint8 { 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{} +}