aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitch Riedstra <mitch@riedstra.us>2016-12-30 22:32:01 -0500
committerMitch Riedstra <mitch@riedstra.us>2016-12-30 22:32:01 -0500
commit6acceb7b7404f2f71541d8a1cccc4758d1f80735 (patch)
tree82eff717ddcd2baeca493fa0b2215e8dd752b612
downloadsteam-export-6acceb7b7404f2f71541d8a1cccc4758d1f80735.tar.gz
steam-export-6acceb7b7404f2f71541d8a1cccc4758d1f80735.tar.xz
Initial
-rw-r--r--.gitignore1
-rw-r--r--config-example.yml6
-rw-r--r--config/config.go35
-rw-r--r--main.go23
-rw-r--r--steam/steam.go65
5 files changed, 130 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..1d3ed4c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+config.yml
diff --git a/config-example.yml b/config-example.yml
new file mode 100644
index 0000000..51b32d0
--- /dev/null
+++ b/config-example.yml
@@ -0,0 +1,6 @@
+---
+listen: 0.0.0.0:9413
+SteamRepositories:
+ # We're ideally looking for the full path to the steamapps folder
+ - "C:\Program Files (x86)\Steam\steamapps"
+ # - "/usr/mitch/SteamGames/steamapps"
diff --git a/config/config.go b/config/config.go
new file mode 100644
index 0000000..541505e
--- /dev/null
+++ b/config/config.go
@@ -0,0 +1,35 @@
+package config
+
+import (
+ "gopkg.in/yaml.v2"
+ "io/ioutil"
+)
+
+var (
+ defaultConfig string = "config.yml"
+)
+
+type Config struct {
+ // Repos []string
+ // map[string]map[string]interface{}
+ SteamRepositories []string `yaml:"SteamRepositories"`
+ Listen string
+}
+
+func LoadConfig() (*Config, error) {
+ c := &Config{}
+ err := c.ReadDefaultConfig()
+ return c, err
+}
+
+func (c *Config) ReadDefaultConfig() error {
+ return c.ReadConfig(defaultConfig)
+}
+
+func (c *Config) ReadConfig(cfg string) error {
+ contents, err := ioutil.ReadFile(cfg)
+ if err != nil {
+ return err
+ }
+ return yaml.Unmarshal([]byte(contents), c)
+}
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..510346b
--- /dev/null
+++ b/main.go
@@ -0,0 +1,23 @@
+package main
+
+import (
+ "fmt"
+ "git.riedstra.us/mitch/steam-export/config"
+ "git.riedstra.us/mitch/steam-export/steam"
+)
+
+func main() {
+ // TODO: Error Checking
+ config, _ := config.LoadConfig()
+
+ fmt.Println(config)
+ fmt.Println("Made it motherfucker!")
+
+ libs, err := steam.ProcessMultipleLibraries(config.SteamRepositories)
+ if err != nil {
+ fmt.Println(err)
+ } else {
+ fmt.Println(libs)
+ }
+
+}
diff --git a/steam/steam.go b/steam/steam.go
new file mode 100644
index 0000000..b8052ec
--- /dev/null
+++ b/steam/steam.go
@@ -0,0 +1,65 @@
+package steam
+
+import (
+ "fmt"
+ "io/ioutil"
+ //"log"
+)
+
+type Library struct {
+ Folder string
+ Games []string
+}
+
+func ProcessMultipleLibraries(r []string) ([]*Library, error) {
+ var libs []*Library
+ for _, i := range r {
+ lib := &Library{}
+ err := lib.ProcessLibrary(i)
+ if err != nil {
+ return nil, err
+ }
+ libs = append(libs, lib)
+ }
+ return libs, nil
+}
+
+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() {
+ // log.Println(*s.Games)
+ s.Games = append(s.Games, f.Name())
+ }
+ }
+ }
+ return nil
+}
+
+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)
+ }
+ return
+}
+
+func hasCommon(d string) bool {
+ dirs, err := ioutil.ReadDir(d)
+ if err != nil {
+ return false
+ }
+ for _, f := range dirs {
+ if f.Name() == "common" && f.IsDir() {
+ return true
+ }
+ }
+ return false
+}