mirror of
https://github.com/Xpl0itU/WiiUDownloader.git
synced 2025-05-29 22:45:17 -04:00
Use channels for the queue thread
This commit is contained in:
parent
99887ad529
commit
8e69ec1cea
1 changed files with 27 additions and 15 deletions
|
@ -601,11 +601,13 @@ func (mw *MainWindow) onDownloadQueueClicked(selectedPath string) error {
|
||||||
if len(mw.titleQueue) == 0 {
|
if len(mw.titleQueue) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
queueCancelled := false
|
|
||||||
errorHappened := false
|
|
||||||
var wg sync.WaitGroup
|
|
||||||
ch := make(chan error, 1)
|
|
||||||
|
|
||||||
|
queueStatusChan := make(chan bool, 1)
|
||||||
|
errorChan := make(chan error, 1)
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
|
queueProcessingLoop:
|
||||||
for _, title := range mw.titleQueue {
|
for _, title := range mw.titleQueue {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
|
||||||
|
@ -615,26 +617,36 @@ func (mw *MainWindow) onDownloadQueueClicked(selectedPath string) error {
|
||||||
tidStr := fmt.Sprintf("%016x", title.TitleID)
|
tidStr := fmt.Sprintf("%016x", title.TitleID)
|
||||||
titlePath := fmt.Sprintf("%s/%s [%s] [%s]", selectedPath, normalizeFilename(title.Name), wiiudownloader.GetFormattedKind(title.TitleID), tidStr)
|
titlePath := fmt.Sprintf("%s/%s [%s] [%s]", selectedPath, normalizeFilename(title.Name), wiiudownloader.GetFormattedKind(title.TitleID), tidStr)
|
||||||
if err := wiiudownloader.DownloadTitle(tidStr, titlePath, mw.decryptContents, progressWindow, mw.getDeleteEncryptedContents(), mw.logger); err != nil {
|
if err := wiiudownloader.DownloadTitle(tidStr, titlePath, mw.decryptContents, progressWindow, mw.getDeleteEncryptedContents(), mw.logger); err != nil {
|
||||||
queueCancelled = true
|
errorChan <- err
|
||||||
errorHappened = true
|
return
|
||||||
ch <- err
|
|
||||||
}
|
}
|
||||||
mw.removeFromQueue(tidStr)
|
|
||||||
|
queueStatusChan <- true
|
||||||
}(title, selectedPath, &mw.progressWindow)
|
}(title, selectedPath, &mw.progressWindow)
|
||||||
|
|
||||||
if queueCancelled || errorHappened {
|
select {
|
||||||
break
|
case err := <-errorChan:
|
||||||
}
|
queueStatusChan <- false
|
||||||
|
wg.Wait()
|
||||||
|
mw.titleQueue = []wiiudownloader.TitleEntry{}
|
||||||
|
mw.progressWindow.Window.Close()
|
||||||
|
mw.updateTitlesInQueue()
|
||||||
|
mw.onSelectionChanged()
|
||||||
|
return err
|
||||||
|
|
||||||
wg.Wait()
|
case queueStatus := <-queueStatusChan:
|
||||||
|
if !queueStatus {
|
||||||
|
wg.Wait()
|
||||||
|
break queueProcessingLoop
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mw.titleQueue = []wiiudownloader.TitleEntry{} // Clear the queue
|
mw.titleQueue = []wiiudownloader.TitleEntry{} // Clear the queue
|
||||||
mw.progressWindow.Window.Close()
|
mw.progressWindow.Window.Close()
|
||||||
mw.updateTitlesInQueue()
|
mw.updateTitlesInQueue()
|
||||||
mw.onSelectionChanged()
|
mw.onSelectionChanged()
|
||||||
if errorHappened {
|
|
||||||
return <-ch
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue