Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
93b73d7bea | ||
|
|
110d8c073d | ||
|
|
2fa2b48611 | ||
|
|
8f0fcdca4a | ||
|
|
345bd44323 |
@@ -146,8 +146,8 @@ func parseDirectory(r *bytes.Reader, path string, dataBlockOffset int64) ([]PakE
|
|||||||
return entries, totalSize, nil
|
return entries, totalSize, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPakFileInfo(data []byte) ([]PakEntry, error) {
|
func GetPakFileInfo(data *[]byte) ([]PakEntry, error) {
|
||||||
r := bytes.NewReader(data)
|
r := bytes.NewReader(*data)
|
||||||
|
|
||||||
// Read FORM header
|
// Read FORM header
|
||||||
if err := readString(r, "FORM"); err != nil {
|
if err := readString(r, "FORM"); err != nil {
|
||||||
|
|||||||
15
util.go
15
util.go
@@ -12,6 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var Debug = false
|
var Debug = false
|
||||||
|
var DownThreads = 8
|
||||||
|
|
||||||
func DoAssetsRequest(addonID, version string) (AssetsReply, error) {
|
func DoAssetsRequest(addonID, version string) (AssetsReply, error) {
|
||||||
url := "https://api-ar-workshop.bistudio.com/workshop-api/api/v3.0/s2s/assets/download-list"
|
url := "https://api-ar-workshop.bistudio.com/workshop-api/api/v3.0/s2s/assets/download-list"
|
||||||
@@ -37,7 +38,7 @@ func DoAssetsRequest(addonID, version string) (AssetsReply, error) {
|
|||||||
// print entire body
|
// print entire body
|
||||||
body, _ := io.ReadAll(res.Body)
|
body, _ := io.ReadAll(res.Body)
|
||||||
fmt.Println(string(body))
|
fmt.Println(string(body))
|
||||||
panic("bad status: " + res.Status)
|
return AssetsReply{}, fmt.Errorf("bad status: %s", res.Status)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process response
|
// Process response
|
||||||
@@ -80,7 +81,7 @@ func Download(manifest Manifest, downloadDir string, filen string) ([]byte, erro
|
|||||||
|
|
||||||
if Debug {
|
if Debug {
|
||||||
// create the directory if it doesn't exist
|
// create the directory if it doesn't exist
|
||||||
if err := os.MkdirAll(downloadDir + "/fragments/" + filen, os.ModePerm); err != nil {
|
if err := os.MkdirAll(downloadDir+"/fragments/"+filen, os.ModePerm); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,7 +90,7 @@ func Download(manifest Manifest, downloadDir string, filen string) ([]byte, erro
|
|||||||
downloaded := 0
|
downloaded := 0
|
||||||
remContent := make([]byte, 0)
|
remContent := make([]byte, 0)
|
||||||
currentRem := 0
|
currentRem := 0
|
||||||
if (manifest.Remainder.Size > 0) {
|
if manifest.Remainder.Size > 0 {
|
||||||
url := transformShaToURL(manifest.Remainder.Sha512, manifest.Remainder.Size)
|
url := transformShaToURL(manifest.Remainder.Sha512, manifest.Remainder.Size)
|
||||||
content, err := getContent(url)
|
content, err := getContent(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -109,8 +110,8 @@ func Download(manifest Manifest, downloadDir string, filen string) ([]byte, erro
|
|||||||
trackFrag := make([]Frag, 0)
|
trackFrag := make([]Frag, 0)
|
||||||
|
|
||||||
// start downloading chunks
|
// start downloading chunks
|
||||||
//currentOffset := 0
|
|
||||||
ret := make([]byte, manifest.Size)
|
ret := make([]byte, manifest.Size)
|
||||||
|
totalMB := float32(manifest.Size) / 1024.0 / 1024.0
|
||||||
for _, fragment := range manifest.Fragments {
|
for _, fragment := range manifest.Fragments {
|
||||||
url := transformShaToURL(fragment.Sha512, fragment.Size)
|
url := transformShaToURL(fragment.Sha512, fragment.Size)
|
||||||
content, err := getContent(url)
|
content, err := getContent(url)
|
||||||
@@ -131,7 +132,8 @@ func Download(manifest Manifest, downloadDir string, filen string) ([]byte, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
percent := float32(downloaded) / float32(manifest.Size) * 100.0
|
percent := float32(downloaded) / float32(manifest.Size) * 100.0
|
||||||
fmt.Printf("\r\033[32mDownloaded\033[0m %d/%d (\033[36m%.2f%%\033[0m) of \033[33m%s\033[0m", downloaded, manifest.Size, percent, filen)
|
downedMB := float32(downloaded) / 1024.0 / 1024.0
|
||||||
|
fmt.Printf("\r\033[32mDownloaded\033[0m %fMB/%fMB (\033[36m%.2f%%\033[0m) of \033[33m%s\033[0m", downedMB, totalMB, percent, filen)
|
||||||
}
|
}
|
||||||
|
|
||||||
// sort trackFrag by Offset
|
// sort trackFrag by Offset
|
||||||
@@ -141,11 +143,12 @@ func Download(manifest Manifest, downloadDir string, filen string) ([]byte, erro
|
|||||||
|
|
||||||
// check for gaps in trackFrag and fill with remainder content
|
// check for gaps in trackFrag and fill with remainder content
|
||||||
curPos := 0
|
curPos := 0
|
||||||
|
|
||||||
for _, frag := range trackFrag {
|
for _, frag := range trackFrag {
|
||||||
if frag.Offset > curPos {
|
if frag.Offset > curPos {
|
||||||
// gap detected
|
// gap detected
|
||||||
gapSize := frag.Offset - curPos
|
gapSize := frag.Offset - curPos
|
||||||
if currentRem + gapSize > len(remContent) {
|
if currentRem+gapSize > len(remContent) {
|
||||||
panic("not enough remainder content to fill gap")
|
panic("not enough remainder content to fill gap")
|
||||||
}
|
}
|
||||||
copy(ret[curPos:curPos+gapSize], remContent[currentRem:currentRem+gapSize])
|
copy(ret[curPos:curPos+gapSize], remContent[currentRem:currentRem+gapSize])
|
||||||
|
|||||||
Reference in New Issue
Block a user