From 6acceb7b7404f2f71541d8a1cccc4758d1f80735 Mon Sep 17 00:00:00 2001 From: Mitch Riedstra Date: Fri, 30 Dec 2016 22:32:01 -0500 Subject: Initial --- .gitignore | 1 + config-example.yml | 6 +++++ config/config.go | 35 +++++++++++++++++++++++++++++ main.go | 23 +++++++++++++++++++ steam/steam.go | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 130 insertions(+) create mode 100644 .gitignore create mode 100644 config-example.yml create mode 100644 config/config.go create mode 100644 main.go create mode 100644 steam/steam.go 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 +} -- cgit v1.2.3