aboutsummaryrefslogtreecommitdiff
path: root/steam/package.go
diff options
context:
space:
mode:
authorMitchell <mitch@riedstra.dev>2021-03-20 01:37:03 -0400
committerMitchell <mitch@riedstra.dev>2021-03-20 01:37:03 -0400
commitd047c36dd09b6169bf27c244196e99bb5df54c3a (patch)
tree5103e1951bd58bbef54c90a13c199e8d1d866492 /steam/package.go
parent0e62a3b46b25e7c101b14ed44235f3c276982fc0 (diff)
downloadsteam-export-d047c36dd09b6169bf27c244196e99bb5df54c3a.tar.gz
steam-export-d047c36dd09b6169bf27c244196e99bb5df54c3a.tar.xz
Update documentation. Remove all traces of chdir from the steam library. Remove most linter complaints.
Diffstat (limited to 'steam/package.go')
-rw-r--r--steam/package.go31
1 files changed, 16 insertions, 15 deletions
diff --git a/steam/package.go b/steam/package.go
index 7287e10..38b5819 100644
--- a/steam/package.go
+++ b/steam/package.go
@@ -10,9 +10,6 @@ import (
// Package writes the package, returning bytes written and an error if any
func (g *Game) Package(wr io.WriteCloser) error {
- if err := os.Chdir(g.LibraryPath); err != nil {
- return err
- }
acf, err := FindACF(g.LibraryPath, g.Name)
if err != nil {
return err
@@ -20,8 +17,13 @@ func (g *Game) Package(wr io.WriteCloser) error {
twriter := tar.NewWriter(wr)
- for _, pth := range []string{"common/" + g.Name, acf} {
- if err := filepath.Walk(pth, TarWalkfn(twriter)); err != nil {
+ paths := []string{
+ filepath.Join(g.LibraryPath, "common", g.Name),
+ acf,
+ }
+ for _, pth := range paths {
+ err := filepath.Walk(pth, tarWalkfn(twriter, g.LibraryPath))
+ if err != nil {
return err
}
}
@@ -36,11 +38,9 @@ func (g *Game) Package(wr io.WriteCloser) error {
return wr.Close()
}
+// Extract will read a tarball from the io.Reader and install the game into
+// the current library path
func (l *Library) Extract(r io.Reader) error {
- if err := os.Chdir(l.Folder); err != nil {
- return err
- }
-
treader := tar.NewReader(r)
for {
@@ -56,6 +56,8 @@ func (l *Library) Extract(r io.Reader) error {
// Fix windows slashes...
fileName := strings.Replace(hdr.Name, "\\", "/", -1)
+ fileName = filepath.Join(l.Folder, fileName)
+
info := hdr.FileInfo()
if info.IsDir() {
// I don't like hard-coded permissions but it
@@ -85,11 +87,8 @@ func (l *Library) Extract(r io.Reader) error {
return nil
}
+// Delete removes all of the game files and the ACF
func (g *Game) Delete() error {
- if err := os.Chdir(g.LibraryPath); err != nil {
- return err
- }
-
acf, err := FindACF(g.LibraryPath, g.Name)
if err != nil {
return err
@@ -97,14 +96,16 @@ func (g *Game) Delete() error {
if err := os.Remove(acf); err != nil {
return err
}
- if err := os.RemoveAll("common/" + g.Name); err != nil {
+
+ err = os.RemoveAll(filepath.Join(g.LibraryPath, "common", g.Name))
+ if err != nil {
return err
}
return nil
}
-// Get the Size of a game in a pretty format
+// GetSize returns the size of a game in a pretty format
func (g Game) GetSize() string {
return formatBytes(g.Size)
}