4 Commits

Author SHA1 Message Date
Sotirios Pupakis
110d8c073d ffs 2025-09-08 04:27:09 +02:00
Sotirios Pupakis
2fa2b48611 change 2025-09-08 04:20:15 +02:00
Sotirios Pupakis
8f0fcdca4a Added reference for data 2025-09-06 23:34:53 +02:00
Sotirios Pupakis
345bd44323 Added error hadnling 2025-09-06 23:01:41 +02:00
2 changed files with 13 additions and 15 deletions

View File

@@ -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 {

14
util.go
View File

@@ -21,11 +21,7 @@ func DoAssetsRequest(addonID, version string) (AssetsReply, error) {
return AssetsReply{}, err return AssetsReply{}, err
} }
req.Header.Add("x-client-id", "$edb1b7862bba5cade1f6e06bfdeac2c") // ffs
req.Header.Add("x-client-secret", "$8b415ea2aa11bd51f2f5b5a9dcb8476")
req.Header.Add("Content-Type", "application/json")
req.Header.Add("user-agent", "Arma Reforger/1.4.0.53 (Headless; Windows)")
req.Header.Add("content-length", fmt.Sprintf("%d", len(body)))
res, err := http.DefaultClient.Do(req) res, err := http.DefaultClient.Do(req)
if err != nil { if err != nil {
@@ -37,7 +33,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
@@ -89,7 +85,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 {
@@ -111,6 +107,7 @@ func Download(manifest Manifest, downloadDir string, filen string) ([]byte, erro
// start downloading chunks // start downloading chunks
//currentOffset := 0 //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 +128,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