mirror of
https://github.com/Xpl0itU/WiiUDownloader.git
synced 2025-05-19 17:55:22 -04:00
Make backend and frontend independent
This commit is contained in:
parent
08505c9eec
commit
99597834ce
8 changed files with 148 additions and 123 deletions
2
.github/workflows/linux.yml
vendored
2
.github/workflows/linux.yml
vendored
|
@ -21,7 +21,7 @@ jobs:
|
||||||
- name: Build artifacts
|
- name: Build artifacts
|
||||||
run: |
|
run: |
|
||||||
docker run --rm -v ${PWD}:/project builder python3 grabTitles.py
|
docker run --rm -v ${PWD}:/project builder python3 grabTitles.py
|
||||||
docker run --rm -v ${PWD}:/project builder go build cmd/WiiUDownloader/main.go cmd/WiiUDownloader/darkMode.go cmd/WiiUDownloader/mainwindow.go cmd/WiiUDownloader/utils.go
|
docker run --rm -v ${PWD}:/project builder go build cmd/WiiUDownloader/main.go cmd/WiiUDownloader/darkMode.go cmd/WiiUDownloader/mainwindow.go cmd/WiiUDownloader/progressWindow.go cmd/WiiUDownloader/utils.go
|
||||||
- name: Deploy WiiUDownloader
|
- name: Deploy WiiUDownloader
|
||||||
run: |
|
run: |
|
||||||
mv main WiiUDownloader
|
mv main WiiUDownloader
|
||||||
|
|
2
.github/workflows/macos.yml
vendored
2
.github/workflows/macos.yml
vendored
|
@ -21,7 +21,7 @@ jobs:
|
||||||
- name: Build
|
- name: Build
|
||||||
run: |
|
run: |
|
||||||
python3 grabTitles.py
|
python3 grabTitles.py
|
||||||
go build cmd/WiiUDownloader/main.go cmd/WiiUDownloader/darkMode.go cmd/WiiUDownloader/mainwindow.go cmd/WiiUDownloader/utils.go
|
go build cmd/WiiUDownloader/main.go cmd/WiiUDownloader/darkMode.go cmd/WiiUDownloader/mainwindow.go cmd/WiiUDownloader/progressWindow.go cmd/WiiUDownloader/utils.go
|
||||||
- name: Package
|
- name: Package
|
||||||
run: |
|
run: |
|
||||||
python3 data/create_bundle.py
|
python3 data/create_bundle.py
|
||||||
|
|
2
.github/workflows/windows.yml
vendored
2
.github/workflows/windows.yml
vendored
|
@ -29,7 +29,7 @@ jobs:
|
||||||
- name: Build
|
- name: Build
|
||||||
run: |
|
run: |
|
||||||
python3 grabTitles.py
|
python3 grabTitles.py
|
||||||
go build -ldflags -H=windowsgui cmd/WiiUDownloader/main.go cmd/WiiUDownloader/darkMode.go cmd/WiiUDownloader/mainwindow.go cmd/WiiUDownloader/utils.go
|
go build -ldflags -H=windowsgui cmd/WiiUDownloader/main.go cmd/WiiUDownloader/darkMode.go cmd/WiiUDownloader/mainwindow.go cmd/WiiUDownloader/progressWindow.go cmd/WiiUDownloader/utils.go
|
||||||
- name: Deploy WiiUDownloader
|
- name: Deploy WiiUDownloader
|
||||||
run: |
|
run: |
|
||||||
mkdir dist
|
mkdir dist
|
||||||
|
|
|
@ -28,12 +28,12 @@ func getCert(tmdData []byte, id int, numContents uint16) ([]byte, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDefaultCert(progressWindow *ProgressWindow, client *grab.Client) ([]byte, error) {
|
func getDefaultCert(progressReporter ProgressReporter, client *grab.Client) ([]byte, error) {
|
||||||
if len(cetkData) >= 0x350+0x300 {
|
if len(cetkData) >= 0x350+0x300 {
|
||||||
return cetkData[0x350 : 0x350+0x300], nil
|
return cetkData[0x350 : 0x350+0x300], nil
|
||||||
}
|
}
|
||||||
cetkDir := path.Join(os.TempDir(), "cetk")
|
cetkDir := path.Join(os.TempDir(), "cetk")
|
||||||
if err := downloadFile(progressWindow, client, "http://ccs.cdn.c.shop.nintendowifi.net/ccs/download/000500101000400a/cetk", cetkDir, true); err != nil {
|
if err := downloadFile(progressReporter, client, "http://ccs.cdn.c.shop.nintendowifi.net/ccs/download/000500101000400a/cetk", cetkDir, true); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
cetkData, err := os.ReadFile(cetkDir)
|
cetkData, err := os.ReadFile(cetkDir)
|
||||||
|
@ -51,7 +51,7 @@ func getDefaultCert(progressWindow *ProgressWindow, client *grab.Client) ([]byte
|
||||||
return nil, fmt.Errorf("failed to download OSv10 cetk, length: %d", len(cetkData))
|
return nil, fmt.Errorf("failed to download OSv10 cetk, length: %d", len(cetkData))
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateCert(tmdData []byte, contentCount uint16, progressWindow *ProgressWindow, client *grab.Client) (bytes.Buffer, error) {
|
func GenerateCert(tmdData []byte, contentCount uint16, progressReporter ProgressReporter, client *grab.Client) (bytes.Buffer, error) {
|
||||||
cert := bytes.Buffer{}
|
cert := bytes.Buffer{}
|
||||||
|
|
||||||
cert0, err := getCert(tmdData, 0, contentCount)
|
cert0, err := getCert(tmdData, 0, contentCount)
|
||||||
|
@ -66,7 +66,7 @@ func GenerateCert(tmdData []byte, contentCount uint16, progressWindow *ProgressW
|
||||||
}
|
}
|
||||||
cert.Write(cert1)
|
cert.Write(cert1)
|
||||||
|
|
||||||
defaultCert, err := getDefaultCert(progressWindow, client)
|
defaultCert, err := getDefaultCert(progressReporter, client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return bytes.Buffer{}, err
|
return bytes.Buffer{}, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ type MainWindow struct {
|
||||||
searchEntry *gtk.Entry
|
searchEntry *gtk.Entry
|
||||||
deleteEncryptedContentsCheckbox *gtk.CheckButton
|
deleteEncryptedContentsCheckbox *gtk.CheckButton
|
||||||
addToQueueButton *gtk.Button
|
addToQueueButton *gtk.Button
|
||||||
progressWindow wiiudownloader.ProgressWindow
|
progressWindow *ProgressWindow
|
||||||
lastSearchText string
|
lastSearchText string
|
||||||
titleQueue []wiiudownloader.TitleEntry
|
titleQueue []wiiudownloader.TitleEntry
|
||||||
categoryButtons []*gtk.ToggleButton
|
categoryButtons []*gtk.ToggleButton
|
||||||
|
@ -200,7 +200,7 @@ func (mw *MainWindow) ShowAll() {
|
||||||
mw.logger.Fatal("Unable to create menu item:", err)
|
mw.logger.Fatal("Unable to create menu item:", err)
|
||||||
}
|
}
|
||||||
decryptContentsMenuItem.Connect("activate", func() {
|
decryptContentsMenuItem.Connect("activate", func() {
|
||||||
mw.progressWindow, err = wiiudownloader.CreateProgressWindow(mw.window)
|
mw.progressWindow, err = createProgressWindow(mw.window)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -260,7 +260,7 @@ func (mw *MainWindow) ShowAll() {
|
||||||
|
|
||||||
wiiudownloader.GenerateTicket(filepath.Join(parentDir, "title.tik"), titleID, titleKey, titleVersion)
|
wiiudownloader.GenerateTicket(filepath.Join(parentDir, "title.tik"), titleID, titleKey, titleVersion)
|
||||||
|
|
||||||
cert, err := wiiudownloader.GenerateCert(tmdData, contentCount, &mw.progressWindow, grab.NewClient())
|
cert, err := wiiudownloader.GenerateCert(tmdData, contentCount, mw.progressWindow, grab.NewClient())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -347,7 +347,7 @@ func (mw *MainWindow) ShowAll() {
|
||||||
if len(mw.titleQueue) == 0 {
|
if len(mw.titleQueue) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
mw.progressWindow, err = wiiudownloader.CreateProgressWindow(mw.window)
|
mw.progressWindow, err = createProgressWindow(mw.window)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -483,7 +483,7 @@ func (mw *MainWindow) onCategoryToggled(button *gtk.ToggleButton) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mw *MainWindow) onDecryptContentsMenuItemClicked(selectedPath string) error {
|
func (mw *MainWindow) onDecryptContentsMenuItemClicked(selectedPath string) error {
|
||||||
err := wiiudownloader.DecryptContents(selectedPath, &mw.progressWindow, false)
|
err := wiiudownloader.DecryptContents(selectedPath, mw.progressWindow, false)
|
||||||
|
|
||||||
glib.IdleAdd(func() {
|
glib.IdleAdd(func() {
|
||||||
if mw.progressWindow.Window.IsVisible() {
|
if mw.progressWindow.Window.IsVisible() {
|
||||||
|
@ -740,7 +740,7 @@ queueProcessingLoop:
|
||||||
errGroup.Go(func() error {
|
errGroup.Go(func() error {
|
||||||
tidStr := fmt.Sprintf("%016x", title.TitleID)
|
tidStr := fmt.Sprintf("%016x", title.TitleID)
|
||||||
titlePath := filepath.Join(selectedPath, fmt.Sprintf("%s [%s] [%s]", normalizeFilename(title.Name), wiiudownloader.GetFormattedKind(title.TitleID), tidStr))
|
titlePath := filepath.Join(selectedPath, fmt.Sprintf("%s [%s] [%s]", normalizeFilename(title.Name), wiiudownloader.GetFormattedKind(title.TitleID), tidStr))
|
||||||
if err := wiiudownloader.DownloadTitle(tidStr, titlePath, mw.decryptContents, &mw.progressWindow, mw.getDeleteEncryptedContents(), mw.logger); err != nil {
|
if err := wiiudownloader.DownloadTitle(tidStr, titlePath, mw.decryptContents, mw.progressWindow, mw.getDeleteEncryptedContents(), mw.logger); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
112
cmd/WiiUDownloader/progressWindow.go
Normal file
112
cmd/WiiUDownloader/progressWindow.go
Normal file
|
@ -0,0 +1,112 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/cavaliergopher/grab/v3"
|
||||||
|
"github.com/dustin/go-humanize"
|
||||||
|
"github.com/gotk3/gotk3/glib"
|
||||||
|
"github.com/gotk3/gotk3/gtk"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ProgressWindow struct {
|
||||||
|
Window *gtk.Window
|
||||||
|
box *gtk.Box
|
||||||
|
gameLabel *gtk.Label
|
||||||
|
bar *gtk.ProgressBar
|
||||||
|
cancelButton *gtk.Button
|
||||||
|
cancelled bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pw *ProgressWindow) SetGameTitle(title string) {
|
||||||
|
glib.IdleAdd(func() {
|
||||||
|
pw.gameLabel.SetText(title)
|
||||||
|
})
|
||||||
|
for gtk.EventsPending() {
|
||||||
|
gtk.MainIteration()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pw *ProgressWindow) UpdateDownloadProgress(resp *grab.Response, filePath string) {
|
||||||
|
glib.IdleAdd(func() {
|
||||||
|
pw.bar.SetFraction(resp.Progress())
|
||||||
|
pw.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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pw *ProgressWindow) UpdateDecryptionProgress(progress float64) {
|
||||||
|
glib.IdleAdd(func() {
|
||||||
|
pw.bar.SetFraction(progress)
|
||||||
|
pw.bar.SetText(fmt.Sprintf("Decrypting (%.2f%%)", progress*100))
|
||||||
|
})
|
||||||
|
for gtk.EventsPending() {
|
||||||
|
gtk.MainIteration()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pw *ProgressWindow) Cancelled() bool {
|
||||||
|
return pw.cancelled
|
||||||
|
}
|
||||||
|
|
||||||
|
func createProgressWindow(parent *gtk.ApplicationWindow) (*ProgressWindow, error) {
|
||||||
|
win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
win.SetTitle("WiiUDownloader - Downloading")
|
||||||
|
|
||||||
|
win.SetTransientFor(parent)
|
||||||
|
|
||||||
|
box, err := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 5)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
win.Add(box)
|
||||||
|
|
||||||
|
gameLabel, err := gtk.LabelNew("")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
box.PackStart(gameLabel, false, false, 0)
|
||||||
|
|
||||||
|
progressBar, err := gtk.ProgressBarNew()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
progressBar.SetShowText(true)
|
||||||
|
box.PackStart(progressBar, false, false, 0)
|
||||||
|
|
||||||
|
cancelButton, err := gtk.ButtonNewWithLabel("Cancel")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
bottomhBox, err := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 5)
|
||||||
|
if err != nil {
|
||||||
|
return nil, 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)
|
||||||
|
|
||||||
|
progressWindow := ProgressWindow{
|
||||||
|
Window: win,
|
||||||
|
box: box,
|
||||||
|
gameLabel: gameLabel,
|
||||||
|
bar: progressBar,
|
||||||
|
cancelButton: cancelButton,
|
||||||
|
cancelled: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
progressWindow.cancelButton.Connect("clicked", func() {
|
||||||
|
progressWindow.cancelled = true
|
||||||
|
})
|
||||||
|
|
||||||
|
return &progressWindow, nil
|
||||||
|
}
|
|
@ -18,7 +18,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"github.com/gotk3/gotk3/glib"
|
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -29,7 +28,7 @@ func callProgressCallback(progress C.int) {
|
||||||
|
|
||||||
var progressChan chan int
|
var progressChan chan int
|
||||||
|
|
||||||
func DecryptContents(path string, progress *ProgressWindow, deleteEncryptedContents bool) error {
|
func DecryptContents(path string, progress ProgressReporter, deleteEncryptedContents bool) error {
|
||||||
progressChan = make(chan int)
|
progressChan = make(chan int)
|
||||||
|
|
||||||
errGroup := errgroup.Group{}
|
errGroup := errgroup.Group{}
|
||||||
|
@ -38,16 +37,9 @@ func DecryptContents(path string, progress *ProgressWindow, deleteEncryptedConte
|
||||||
return runDecryption(path, deleteEncryptedContents)
|
return runDecryption(path, deleteEncryptedContents)
|
||||||
})
|
})
|
||||||
|
|
||||||
glib.IdleAdd(func() {
|
|
||||||
progress.bar.SetText("Decrypting...")
|
|
||||||
})
|
|
||||||
|
|
||||||
for progressInt := range progressChan {
|
for progressInt := range progressChan {
|
||||||
if progressInt > 0 {
|
if progressInt > 0 {
|
||||||
glib.IdleAdd(func() {
|
progress.UpdateDecryptionProgress(float64(progressInt) / 100)
|
||||||
progress.bar.SetFraction(float64(progressInt) / 100)
|
|
||||||
})
|
|
||||||
forceUpdateUI()
|
|
||||||
}
|
}
|
||||||
time.Sleep(time.Millisecond * 10)
|
time.Sleep(time.Millisecond * 10)
|
||||||
}
|
}
|
||||||
|
|
121
downloader.go
121
downloader.go
|
@ -13,9 +13,6 @@ 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/gtk"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -24,70 +21,14 @@ const (
|
||||||
bufferSize = 1048576
|
bufferSize = 1048576
|
||||||
)
|
)
|
||||||
|
|
||||||
type ProgressWindow struct {
|
type ProgressReporter interface {
|
||||||
Window *gtk.Window
|
SetGameTitle(title string)
|
||||||
box *gtk.Box
|
UpdateDownloadProgress(resp *grab.Response, filePath string)
|
||||||
gameLabel *gtk.Label
|
UpdateDecryptionProgress(progress float64)
|
||||||
bar *gtk.ProgressBar
|
Cancelled() bool
|
||||||
cancelButton *gtk.Button
|
|
||||||
cancelled bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateProgressWindow(parent *gtk.ApplicationWindow) (ProgressWindow, error) {
|
func downloadFile(progressWindow ProgressReporter, client *grab.Client, downloadURL string, dstPath string, doRetries bool) error {
|
||||||
win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
|
|
||||||
if err != nil {
|
|
||||||
return ProgressWindow{}, err
|
|
||||||
}
|
|
||||||
win.SetTitle("WiiUDownloader - Downloading")
|
|
||||||
|
|
||||||
win.SetTransientFor(parent)
|
|
||||||
|
|
||||||
box, err := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 5)
|
|
||||||
if err != nil {
|
|
||||||
return ProgressWindow{}, err
|
|
||||||
}
|
|
||||||
win.Add(box)
|
|
||||||
|
|
||||||
gameLabel, err := gtk.LabelNew("")
|
|
||||||
if err != nil {
|
|
||||||
return ProgressWindow{}, err
|
|
||||||
}
|
|
||||||
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)
|
|
||||||
|
|
||||||
cancelButton, err := gtk.ButtonNewWithLabel("Cancel")
|
|
||||||
if err != nil {
|
|
||||||
return ProgressWindow{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
bottomhBox, err := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 5)
|
|
||||||
if err != nil {
|
|
||||||
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,
|
|
||||||
gameLabel: gameLabel,
|
|
||||||
bar: progressBar,
|
|
||||||
cancelButton: cancelButton,
|
|
||||||
cancelled: false,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func downloadFile(progressWindow *ProgressWindow, client *grab.Client, downloadURL string, dstPath string, doRetries bool) error {
|
|
||||||
filePath := filepath.Base(dstPath)
|
filePath := filepath.Base(dstPath)
|
||||||
|
|
||||||
for attempt := 1; attempt <= maxRetries; attempt++ {
|
for attempt := 1; attempt <= maxRetries; attempt++ {
|
||||||
|
@ -98,7 +39,7 @@ func downloadFile(progressWindow *ProgressWindow, client *grab.Client, downloadU
|
||||||
req.BufferSize = bufferSize
|
req.BufferSize = bufferSize
|
||||||
|
|
||||||
resp := client.Do(req)
|
resp := client.Do(req)
|
||||||
updateProgressWindow(progressWindow, resp, filePath)
|
progressWindow.UpdateDownloadProgress(resp, filePath)
|
||||||
|
|
||||||
t := time.NewTicker(500 * time.Millisecond)
|
t := time.NewTicker(500 * time.Millisecond)
|
||||||
defer t.Stop()
|
defer t.Stop()
|
||||||
|
@ -107,13 +48,12 @@ func downloadFile(progressWindow *ProgressWindow, client *grab.Client, downloadU
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-t.C:
|
case <-t.C:
|
||||||
updateProgressWindow(progressWindow, resp, filePath)
|
progressWindow.UpdateDownloadProgress(resp, filePath)
|
||||||
if progressWindow.cancelled {
|
if progressWindow.Cancelled() {
|
||||||
resp.Cancel()
|
resp.Cancel()
|
||||||
break Loop
|
break Loop
|
||||||
}
|
}
|
||||||
case <-resp.Done:
|
case <-resp.Done:
|
||||||
forceUpdateUI()
|
|
||||||
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)
|
||||||
|
@ -129,30 +69,11 @@ func downloadFile(progressWindow *ProgressWindow, client *grab.Client, downloadU
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func forceUpdateUI() {
|
func DownloadTitle(titleID string, outputDirectory string, doDecryption bool, progressReporter ProgressReporter, deleteEncryptedContents bool, logger *Logger) error {
|
||||||
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 {
|
|
||||||
progressWindow.cancelButton.Connect("clicked", func() {
|
|
||||||
progressWindow.cancelled = true
|
|
||||||
})
|
|
||||||
|
|
||||||
titleEntry := getTitleEntryFromTid(titleID)
|
titleEntry := getTitleEntryFromTid(titleID)
|
||||||
|
|
||||||
glib.IdleAdd(func() {
|
progressReporter.SetGameTitle(titleEntry.Name)
|
||||||
progressWindow.gameLabel.SetText(titleEntry.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)
|
||||||
|
@ -167,7 +88,7 @@ func DownloadTitle(titleID string, outputDirectory string, doDecryption bool, pr
|
||||||
client := grab.NewClient()
|
client := grab.NewClient()
|
||||||
client.BufferSize = bufferSize
|
client.BufferSize = bufferSize
|
||||||
tmdPath := filepath.Join(outputDir, "title.tmd")
|
tmdPath := filepath.Join(outputDir, "title.tmd")
|
||||||
if err := downloadFile(progressWindow, client, fmt.Sprintf("%s/%s", baseURL, "tmd"), tmdPath, true); err != nil {
|
if err := downloadFile(progressReporter, client, fmt.Sprintf("%s/%s", baseURL, "tmd"), tmdPath, true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,7 +103,7 @@ func DownloadTitle(titleID string, outputDirectory string, doDecryption bool, pr
|
||||||
}
|
}
|
||||||
|
|
||||||
tikPath := filepath.Join(outputDir, "title.tik")
|
tikPath := filepath.Join(outputDir, "title.tik")
|
||||||
if err := downloadFile(progressWindow, client, fmt.Sprintf("%s/%s", baseURL, "cetk"), tikPath, false); err != nil {
|
if err := downloadFile(progressReporter, client, fmt.Sprintf("%s/%s", baseURL, "cetk"), tikPath, false); err != nil {
|
||||||
titleKey, err := GenerateKey(titleID)
|
titleKey, err := GenerateKey(titleID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -202,7 +123,7 @@ func DownloadTitle(titleID string, outputDirectory string, doDecryption bool, pr
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cert, err := GenerateCert(tmdData, contentCount, progressWindow, client)
|
cert, err := GenerateCert(tmdData, contentCount, progressReporter, client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -243,13 +164,13 @@ 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))
|
||||||
if err := downloadFile(progressWindow, client, fmt.Sprintf("%s/%08X", baseURL, id), filePath, true); err != nil {
|
if err := downloadFile(progressReporter, client, fmt.Sprintf("%s/%08X", baseURL, id), 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))
|
||||||
if err := downloadFile(progressWindow, client, fmt.Sprintf("%s/%08X.h3", baseURL, id), filePath, true); err != nil {
|
if err := downloadFile(progressReporter, client, fmt.Sprintf("%s/%08X.h3", baseURL, id), filePath, true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
content.Hash = tmdData[offset+16 : offset+0x14]
|
content.Hash = tmdData[offset+16 : offset+0x14]
|
||||||
|
@ -259,19 +180,19 @@ func DownloadTitle(titleID string, outputDirectory string, doDecryption bool, pr
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := checkContentHashes(outputDirectory, content, &cipherHashTree); err != nil {
|
if err := checkContentHashes(outputDirectory, content, &cipherHashTree); err != nil {
|
||||||
if progressWindow.cancelled {
|
if progressReporter.Cancelled() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if progressWindow.cancelled {
|
if progressReporter.Cancelled() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if doDecryption && !progressWindow.cancelled {
|
if doDecryption && !progressReporter.Cancelled() {
|
||||||
if err := DecryptContents(outputDir, progressWindow, deleteEncryptedContents); err != nil {
|
if err := DecryptContents(outputDir, progressReporter, deleteEncryptedContents); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue