mirror of
https://github.com/Xpl0itU/WiiUDownloader.git
synced 2025-05-30 15:05:18 -04:00
Add HTTP client and timeout to improve performance
This commit is contained in:
parent
965a1b6602
commit
06fdac5fa3
3 changed files with 18 additions and 5 deletions
|
@ -2,9 +2,11 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
wiiudownloader "github.com/Xpl0itU/WiiUDownloader"
|
||||
"github.com/gotk3/gotk3/glib"
|
||||
|
@ -39,8 +41,18 @@ func main() {
|
|||
if err != nil {
|
||||
logger.Fatal(err.Error())
|
||||
}
|
||||
|
||||
client := &http.Client{
|
||||
Transport: &http.Transport{
|
||||
MaxIdleConns: 1000,
|
||||
MaxIdleConnsPerHost: 1000,
|
||||
MaxConnsPerHost: 100,
|
||||
},
|
||||
Timeout: 30 * time.Second,
|
||||
}
|
||||
|
||||
app.Connect("activate", func() {
|
||||
win := NewMainWindow(app, wiiudownloader.GetTitleEntries(wiiudownloader.TITLE_CATEGORY_GAME), logger)
|
||||
win := NewMainWindow(app, wiiudownloader.GetTitleEntries(wiiudownloader.TITLE_CATEGORY_GAME), logger, client)
|
||||
win.ShowAll()
|
||||
app.AddWindow(win.window)
|
||||
app.GetActiveWindow().Show()
|
||||
|
|
|
@ -40,9 +40,10 @@ type MainWindow struct {
|
|||
titles []wiiudownloader.TitleEntry
|
||||
decryptContents bool
|
||||
currentRegion uint8
|
||||
client *http.Client
|
||||
}
|
||||
|
||||
func NewMainWindow(app *gtk.Application, entries []wiiudownloader.TitleEntry, logger *wiiudownloader.Logger) *MainWindow {
|
||||
func NewMainWindow(app *gtk.Application, entries []wiiudownloader.TitleEntry, logger *wiiudownloader.Logger, client *http.Client) *MainWindow {
|
||||
gSettings, err := gtk.SettingsGetDefault()
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
|
@ -72,6 +73,7 @@ func NewMainWindow(app *gtk.Application, entries []wiiudownloader.TitleEntry, lo
|
|||
currentRegion: wiiudownloader.MCP_REGION_EUROPE | wiiudownloader.MCP_REGION_JAPAN | wiiudownloader.MCP_REGION_USA,
|
||||
logger: logger,
|
||||
lastSearchText: "",
|
||||
client: client,
|
||||
}
|
||||
|
||||
searchEntry.Connect("changed", mainWindow.onSearchEntryChanged)
|
||||
|
@ -758,7 +760,7 @@ func (mw *MainWindow) onDownloadQueueClicked(selectedPath string) error {
|
|||
}
|
||||
tidStr := fmt.Sprintf("%016x", title.TitleID)
|
||||
titlePath := filepath.Join(selectedPath, fmt.Sprintf("%s [%s] [%s]", normalizeFilename(title.Name), wiiudownloader.GetFormattedKind(title.TitleID), tidStr))
|
||||
if err := wiiudownloader.DownloadTitle(queueCtx, tidStr, titlePath, mw.decryptContents, mw.progressWindow, mw.getDeleteEncryptedContents(), mw.logger); err != nil && err != context.Canceled {
|
||||
if err := wiiudownloader.DownloadTitle(queueCtx, tidStr, titlePath, mw.decryptContents, mw.progressWindow, mw.getDeleteEncryptedContents(), mw.logger, mw.client); err != nil && err != context.Canceled {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -111,7 +111,7 @@ func downloadFile(ctx context.Context, progressReporter ProgressReporter, client
|
|||
return nil
|
||||
}
|
||||
|
||||
func DownloadTitle(cancelCtx context.Context, titleID, outputDirectory string, doDecryption bool, progressReporter ProgressReporter, deleteEncryptedContents bool, logger *Logger) error {
|
||||
func DownloadTitle(cancelCtx context.Context, titleID, outputDirectory string, doDecryption bool, progressReporter ProgressReporter, deleteEncryptedContents bool, logger *Logger, client *http.Client) error {
|
||||
titleEntry := getTitleEntryFromTid(titleID)
|
||||
|
||||
progressReporter.SetTotalDownloaded(0)
|
||||
|
@ -128,7 +128,6 @@ func DownloadTitle(cancelCtx context.Context, titleID, outputDirectory string, d
|
|||
return err
|
||||
}
|
||||
|
||||
client := &http.Client{}
|
||||
tmdPath := filepath.Join(outputDir, "title.tmd")
|
||||
if err := downloadFile(cancelCtx, progressReporter, client, fmt.Sprintf("%s/%s", baseURL, "tmd"), tmdPath, true); err != nil {
|
||||
if progressReporter.Cancelled() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue