Skip to content

Commit

Permalink
Force zip for steam
Browse files Browse the repository at this point in the history
  • Loading branch information
LordRalex committed Apr 19, 2024
1 parent 0ba1565 commit 7aa87e3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
15 changes: 13 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pufferpanel

import (
"github.com/cavaliergopher/grab/v3"
"github.com/mholt/archiver/v3"
"net/http"
"os"
)
Expand All @@ -17,14 +18,24 @@ func HttpGet(requestUrl string) (*http.Response, error) {
}

func HttpExtract(requestUrl, directory string) error {
//we will write this to temp so we can not keep so much in memory
//we will write this to temp so we can not keep so much in memoryf
response, err := grab.Get(os.TempDir(), requestUrl)
if err != nil {
return err
}
defer os.Remove(response.Filename)

err = Extract(nil, response.Filename, directory, "*", false, nil)
return err
}

func HttpExtractZip(requestUrl, directory string) error {
response, err := grab.Get(os.TempDir(), requestUrl)
if err != nil {
return err
}
defer os.Remove(response.Filename)

err = Extract(nil, response.Filename, directory, "*", false)
err = Extract(nil, response.Filename, directory, "*", false, archiver.DefaultZip)
return err
}
18 changes: 15 additions & 3 deletions compression.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func DetermineIfSingleRoot(sourceFile string) (bool, error) {
return isSingleRoot, err
}

func Extract(fs FileServer, sourceFile, targetPath, filter string, skipRoot bool) error {
func Extract(fs FileServer, sourceFile, targetPath, filter string, skipRoot bool, forcedType Walker) error {
if fs != nil {
sourceFile = filepath.Join(fs.Prefix(), sourceFile)
}
Expand All @@ -54,7 +54,15 @@ func Extract(fs FileServer, sourceFile, targetPath, filter string, skipRoot bool
}
}

return archiver.Walk(sourceFile, func(file archiver.File) (err error) {
if forcedType != nil {
return forcedType.Walk(sourceFile, walker(fs, targetPath, filter, skipRoot))
}

return archiver.Walk(sourceFile, walker(fs, targetPath, filter, skipRoot))
}

func walker(fs FileServer, targetPath, filter string, skipRoot bool) archiver.WalkFunc {
return func(file archiver.File) (err error) {
path := getCompressedItemName(file)

if !CompareWildcard(file.Name(), filter) {
Expand Down Expand Up @@ -103,7 +111,7 @@ func Extract(fs FileServer, sourceFile, targetPath, filter string, skipRoot bool
}

return
})
}
}

// getCompressedItemName Resolves headers in the event the wrapped interface fails
Expand All @@ -118,3 +126,7 @@ func getCompressedItemName(file archiver.File) string {
return file.Name()
}
}

type Walker interface {
Walk(archive string, walkFn archiver.WalkFunc) error
}
2 changes: 1 addition & 1 deletion operations/steamgamedl/steamgamedl.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func downloadMetadata(env pufferpanel.Environment) error {
return err
}

err = pufferpanel.HttpExtract(SteamMetadataServerLink+metadataName, filepath.Join(env.GetRootDirectory(), ".steam"))
err = pufferpanel.HttpExtractZip(SteamMetadataServerLink+metadataName, filepath.Join(env.GetRootDirectory(), ".steam"))
if err != nil {
return err
}
Expand Down

0 comments on commit 7aa87e3

Please sign in to comment.