aboutsummaryrefslogtreecommitdiff
path: root/steam/steam.go
diff options
context:
space:
mode:
authorMitch Riedstra <mitch@riedstra.us>2020-11-20 22:46:45 -0500
committerMitch Riedstra <mitch@riedstra.us>2020-11-20 22:46:45 -0500
commit891447f0e40a6d1a9637b3333cffed8eb2543c51 (patch)
treefb748b0c6af1670a2b73e5d581f206d0fe26e003 /steam/steam.go
parent971cc396e1d01f53f65a86278fd0ac4490565335 (diff)
downloadsteam-export-891447f0e40a6d1a9637b3333cffed8eb2543c51.tar.gz
steam-export-891447f0e40a6d1a9637b3333cffed8eb2543c51.tar.xz
Works after reorganization.
Diffstat (limited to 'steam/steam.go')
-rw-r--r--steam/steam.go62
1 files changed, 32 insertions, 30 deletions
diff --git a/steam/steam.go b/steam/steam.go
index ea27e5a..7071a20 100644
--- a/steam/steam.go
+++ b/steam/steam.go
@@ -5,19 +5,21 @@ package steam
import (
"fmt"
"io/ioutil"
-
"errors"
-
"bufio"
"os"
"path/filepath"
"strings"
- // "log"
)
type Library struct {
Folder string
- Games []string
+ Games map[string]Game
+}
+
+type Game struct {
+ Name string
+ LibraryPath string
}
func ProcessMultipleLibraries(r []string) ([]*Library, error) {
@@ -35,30 +37,33 @@ func ProcessMultipleLibraries(r []string) ([]*Library, error) {
// Populate the "Folder" and "Games" fields based on the provided directory
func (s *Library) ProcessLibrary(r string) error {
- if hasCommon(r) {
- dirs, err := ioutil.ReadDir(r + "/common")
- if err != nil {
- return err
- }
- s.Folder = r
- for _, f := range dirs {
- if f.IsDir() {
- s.Games = append(s.Games, f.Name())
+ if !hasCommon(r) {
+ return errors.New(fmt.Sprintf("No common directory in: %s", r))
+ }
+
+ s.Games = make(map[string]Game)
+
+ dirs, err := ioutil.ReadDir(r + "/common")
+ if err != nil {
+ return err
+ }
+ s.Folder = r
+ for _, f := range dirs {
+ if f.IsDir() {
+ s.Games[f.Name()] = Game{
+ Name: f.Name(),
+ LibraryPath: r,
}
+ // s.Games = append(s.Games, f.Name())
}
- } else {
- return errors.New(fmt.Sprintf("No common directory in: %s", r))
}
+
return nil
}
// Find the ACF files related to this video game
-func (l *Library) FindACF(g string) (string, error) {
- working_dir, err := os.Getwd()
- if err != nil {
- return "", err
- }
- if err = os.Chdir(l.Folder); err != nil {
+func FindACF(libraryPath, game string) (string, error) {
+ if err := os.Chdir(libraryPath); err != nil {
return "", err
}
files, err := filepath.Glob("*.acf")
@@ -84,8 +89,7 @@ func (l *Library) FindACF(g string) (string, error) {
scanner := bufio.NewScanner(f)
for scanner.Scan() {
// Finally check and see if the file has the video game name
- if strings.Contains(scanner.Text(), g) {
- os.Chdir(working_dir)
+ if strings.Contains(scanner.Text(), game) {
return fn, nil
// fmt.Printf("%s/%s:%d: %s\n", root, path, i, scanner.Text())
}
@@ -93,18 +97,16 @@ func (l *Library) FindACF(g string) (string, error) {
}
str := "Couldn't find ACF file related to Game: %s"
- return "", errors.New(fmt.Sprintf(str, g))
+ return "", errors.New(fmt.Sprintf(str, game))
}
// This is automatically called to print out the contents of the struct
// when things like fmt.Println are used
func (s *Library) String() (str string) {
- str = fmt.Sprintln("\n----")
- str = str + fmt.Sprintln(s.Folder)
- str = str + "\n----\n"
- for k, v := range s.Games {
- str = str + fmt.Sprintf("%d: %s\n", k, v)
- //str = str + fmt.Sprintln(v)
+ str = fmt.Sprintf("Library: %s\n", s.Folder)
+ str = str + "----\n"
+ for _, v := range s.Games {
+ str = str + fmt.Sprintf("%s\n", v.Name)
}
return
}