mirror of
https://github.com/Xpl0itU/WiiUDownloader.git
synced 2025-05-24 20:14:40 -04:00
Update getDefaultCert and GenerateCert functions to include a buffer parameter
This commit is contained in:
parent
06fdac5fa3
commit
34bdbbd8ce
3 changed files with 13 additions and 12 deletions
|
@ -28,12 +28,12 @@ func getCert(tmdData []byte, id int, numContents uint16) ([]byte, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDefaultCert(cancelCtx context.Context, progressReporter ProgressReporter, client *http.Client) ([]byte, error) {
|
func getDefaultCert(cancelCtx context.Context, progressReporter ProgressReporter, client *http.Client, buffer []byte) ([]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(cancelCtx, progressReporter, client, "http://ccs.cdn.c.shop.nintendowifi.net/ccs/download/000500101000400a/cetk", cetkDir, true); err != nil {
|
if err := downloadFile(cancelCtx, progressReporter, client, "http://ccs.cdn.c.shop.nintendowifi.net/ccs/download/000500101000400a/cetk", cetkDir, true, buffer); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
cetkData, err := os.ReadFile(cetkDir)
|
cetkData, err := os.ReadFile(cetkDir)
|
||||||
|
@ -51,7 +51,7 @@ func getDefaultCert(cancelCtx context.Context, progressReporter ProgressReporter
|
||||||
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, progressReporter ProgressReporter, client *http.Client, cancelCtx context.Context) (bytes.Buffer, error) {
|
func GenerateCert(tmdData []byte, contentCount uint16, progressReporter ProgressReporter, client *http.Client, cancelCtx context.Context, buffer []byte) (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, progressReporter Progress
|
||||||
}
|
}
|
||||||
cert.Write(cert1)
|
cert.Write(cert1)
|
||||||
|
|
||||||
defaultCert, err := getDefaultCert(cancelCtx, progressReporter, client)
|
defaultCert, err := getDefaultCert(cancelCtx, progressReporter, client, buffer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return bytes.Buffer{}, err
|
return bytes.Buffer{}, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -265,7 +265,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, http.DefaultClient, context.Background())
|
cert, err := wiiudownloader.GenerateCert(tmdData, contentCount, mw.progressWindow, http.DefaultClient, context.Background(), make([]byte, 0))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ func calculateDownloadSpeed(downloaded int64, startTime, endTime time.Time) int6
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func downloadFile(ctx context.Context, progressReporter ProgressReporter, client *http.Client, downloadURL, dstPath string, doRetries bool) error {
|
func downloadFile(ctx context.Context, progressReporter ProgressReporter, client *http.Client, downloadURL, dstPath string, doRetries bool, buffer []byte) error {
|
||||||
filePath := filepath.Base(dstPath)
|
filePath := filepath.Base(dstPath)
|
||||||
|
|
||||||
var speed int64
|
var speed int64
|
||||||
|
@ -73,7 +73,6 @@ func downloadFile(ctx context.Context, progressReporter ProgressReporter, client
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
buffer := make([]byte, bufferSize)
|
|
||||||
var downloaded int64
|
var downloaded int64
|
||||||
|
|
||||||
startTime = time.Now()
|
startTime = time.Now()
|
||||||
|
@ -128,8 +127,10 @@ func DownloadTitle(cancelCtx context.Context, titleID, outputDirectory string, d
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buffer := make([]byte, bufferSize)
|
||||||
|
|
||||||
tmdPath := filepath.Join(outputDir, "title.tmd")
|
tmdPath := filepath.Join(outputDir, "title.tmd")
|
||||||
if err := downloadFile(cancelCtx, progressReporter, client, fmt.Sprintf("%s/%s", baseURL, "tmd"), tmdPath, true); err != nil {
|
if err := downloadFile(cancelCtx, progressReporter, client, fmt.Sprintf("%s/%s", baseURL, "tmd"), tmdPath, true, buffer); err != nil {
|
||||||
if progressReporter.Cancelled() {
|
if progressReporter.Cancelled() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -147,7 +148,7 @@ func DownloadTitle(cancelCtx context.Context, titleID, outputDirectory string, d
|
||||||
}
|
}
|
||||||
|
|
||||||
tikPath := filepath.Join(outputDir, "title.tik")
|
tikPath := filepath.Join(outputDir, "title.tik")
|
||||||
if err := downloadFile(cancelCtx, progressReporter, client, fmt.Sprintf("%s/%s", baseURL, "cetk"), tikPath, false); err != nil {
|
if err := downloadFile(cancelCtx, progressReporter, client, fmt.Sprintf("%s/%s", baseURL, "cetk"), tikPath, false, buffer); err != nil {
|
||||||
if progressReporter.Cancelled() {
|
if progressReporter.Cancelled() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -186,7 +187,7 @@ func DownloadTitle(cancelCtx context.Context, titleID, outputDirectory string, d
|
||||||
|
|
||||||
progressReporter.SetDownloadSize(int64(titleSize))
|
progressReporter.SetDownloadSize(int64(titleSize))
|
||||||
|
|
||||||
cert, err := GenerateCert(tmdData, contentCount, progressReporter, client, cancelCtx)
|
cert, err := GenerateCert(tmdData, contentCount, progressReporter, client, cancelCtx, buffer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if progressReporter.Cancelled() {
|
if progressReporter.Cancelled() {
|
||||||
return nil
|
return nil
|
||||||
|
@ -230,7 +231,7 @@ func DownloadTitle(cancelCtx context.Context, titleID, outputDirectory string, d
|
||||||
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(cancelCtx, progressReporter, client, fmt.Sprintf("%s/%08X", baseURL, id), filePath, true); err != nil {
|
if err := downloadFile(cancelCtx, progressReporter, client, fmt.Sprintf("%s/%08X", baseURL, id), filePath, true, buffer); err != nil {
|
||||||
if progressReporter.Cancelled() {
|
if progressReporter.Cancelled() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -240,7 +241,7 @@ func DownloadTitle(cancelCtx context.Context, titleID, outputDirectory string, d
|
||||||
|
|
||||||
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(cancelCtx, progressReporter, client, fmt.Sprintf("%s/%08X.h3", baseURL, id), filePath, true); err != nil {
|
if err := downloadFile(cancelCtx, progressReporter, client, fmt.Sprintf("%s/%08X.h3", baseURL, id), filePath, true, buffer); err != nil {
|
||||||
if progressReporter.Cancelled() {
|
if progressReporter.Cancelled() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue