mirror of
https://github.com/Xpl0itU/WiiUDownloader.git
synced 2025-05-29 22:45:17 -04:00
Improve cancelling the queue
This commit is contained in:
parent
8f13b57ae8
commit
0a16ffdb7f
2 changed files with 15 additions and 2 deletions
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
@ -743,11 +744,20 @@ func (mw *MainWindow) onDownloadQueueClicked(selectedPath string) error {
|
||||||
defer close(queueStatusChan)
|
defer close(queueStatusChan)
|
||||||
errGroup := errgroup.Group{}
|
errGroup := errgroup.Group{}
|
||||||
|
|
||||||
|
queueCtx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
for _, title := range mw.titleQueue {
|
for _, title := range mw.titleQueue {
|
||||||
errGroup.Go(func() error {
|
errGroup.Go(func() error {
|
||||||
|
select {
|
||||||
|
case <-queueCtx.Done():
|
||||||
|
queueStatusChan <- true
|
||||||
|
return nil
|
||||||
|
default:
|
||||||
|
}
|
||||||
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(cancel, tidStr, titlePath, mw.decryptContents, mw.progressWindow, mw.getDeleteEncryptedContents(), mw.logger); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package wiiudownloader
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"crypto/aes"
|
"crypto/aes"
|
||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
@ -69,7 +70,7 @@ func downloadFile(progressReporter ProgressReporter, client *grab.Client, downlo
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func DownloadTitle(titleID, outputDirectory string, doDecryption bool, progressReporter ProgressReporter, deleteEncryptedContents bool, logger *Logger) error {
|
func DownloadTitle(cancel context.CancelFunc, titleID, outputDirectory string, doDecryption bool, progressReporter ProgressReporter, deleteEncryptedContents bool, logger *Logger) error {
|
||||||
titleEntry := getTitleEntryFromTid(titleID)
|
titleEntry := getTitleEntryFromTid(titleID)
|
||||||
|
|
||||||
progressReporter.SetGameTitle(titleEntry.Name)
|
progressReporter.SetGameTitle(titleEntry.Name)
|
||||||
|
@ -181,12 +182,14 @@ func DownloadTitle(titleID, outputDirectory string, doDecryption bool, progressR
|
||||||
}
|
}
|
||||||
if err := checkContentHashes(outputDirectory, content, cipherHashTree); err != nil {
|
if err := checkContentHashes(outputDirectory, content, cipherHashTree); err != nil {
|
||||||
if progressReporter.Cancelled() {
|
if progressReporter.Cancelled() {
|
||||||
|
cancel()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if progressReporter.Cancelled() {
|
if progressReporter.Cancelled() {
|
||||||
|
cancel()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue