aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config/config.go4
-rw-r--r--main.go21
-rw-r--r--steam/steam.go57
3 files changed, 71 insertions, 11 deletions
diff --git a/config/config.go b/config/config.go
index 541505e..5debdb6 100644
--- a/config/config.go
+++ b/config/config.go
@@ -1,3 +1,4 @@
+// Used to define and load this application's specific configuration
package config
import (
@@ -10,12 +11,11 @@ var (
)
type Config struct {
- // Repos []string
- // map[string]map[string]interface{}
SteamRepositories []string `yaml:"SteamRepositories"`
Listen string
}
+// By default it reads 'config.yml' in the current directory
func LoadConfig() (*Config, error) {
c := &Config{}
err := c.ReadDefaultConfig()
diff --git a/main.go b/main.go
index 510346b..aaf0edd 100644
--- a/main.go
+++ b/main.go
@@ -7,17 +7,28 @@ import (
)
func main() {
- // TODO: Error Checking
- config, _ := config.LoadConfig()
+ config, err := config.LoadConfig()
+ if err != nil {
+ fmt.Println(err)
+ }
- fmt.Println(config)
- fmt.Println("Made it motherfucker!")
+ // fmt.Println(config)
libs, err := steam.ProcessMultipleLibraries(config.SteamRepositories)
if err != nil {
fmt.Println(err)
} else {
- fmt.Println(libs)
+ // fmt.Println(libs)
+ }
+
+ fmt.Println(libs[0].Games[20])
+
+ str, err := libs[0].FindACF(libs[0].Games[20])
+ // str, err := libs[0].FindACF("/.")
+ if err != nil {
+ fmt.Println(err)
+ } else {
+ fmt.Println(str)
}
}
diff --git a/steam/steam.go b/steam/steam.go
index b8052ec..02ecd7e 100644
--- a/steam/steam.go
+++ b/steam/steam.go
@@ -1,9 +1,18 @@
+// This is designed to be a rather simplistic library to help pull information
+// from a local steam library
package steam
import (
"fmt"
"io/ioutil"
- //"log"
+
+ "errors"
+
+ "bufio"
+ "os"
+ "path/filepath"
+ "strings"
+ // "log"
)
type Library struct {
@@ -24,6 +33,7 @@ func ProcessMultipleLibraries(r []string) ([]*Library, error) {
return libs, nil
}
+// 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")
@@ -33,7 +43,6 @@ func (s *Library) ProcessLibrary(r string) error {
s.Folder = r
for _, f := range dirs {
if f.IsDir() {
- // log.Println(*s.Games)
s.Games = append(s.Games, f.Name())
}
}
@@ -41,12 +50,52 @@ func (s *Library) ProcessLibrary(r string) error {
return nil
}
+// Find the ACF files related to this video game
+func (l *Library) FindACF(g string) (string, error) {
+ globFolder := l.Folder + "/*.acf"
+ files, err := filepath.Glob(globFolder)
+ if err != nil {
+ return "", err
+ }
+ for _, fn := range files {
+ info, err := os.Lstat(fn)
+ if err != nil {
+ return "", err
+ }
+ // We don't want it if it's a directory
+ if info.IsDir() {
+ continue
+ }
+
+ // Open up the file
+ f, err := os.Open(fn)
+ defer f.Close()
+ if err != nil {
+ return "", err
+ }
+ 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) {
+ return fn, nil
+ // fmt.Printf("%s/%s:%d: %s\n", root, path, i, scanner.Text())
+ }
+ }
+
+ }
+ str := "Couldn't find ACF file related to Game: %s"
+ return "", errors.New(fmt.Sprintf(str, g))
+}
+
+// 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("----")
str = str + fmt.Sprintln(s.Folder)
str = str + "----\n"
- for _, v := range s.Games {
- str = str + fmt.Sprintln(v)
+ for k, v := range s.Games {
+ str = str + fmt.Sprintf("%d: %s\n", k, v)
+ //str = str + fmt.Sprintln(v)
}
return
}