Steam: Cross-Platform support
This commit is contained in:
parent
602f00d359
commit
56b2faf88a
|
@ -8,6 +8,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -41,6 +42,21 @@ type SteamAppListResponse struct {
|
||||||
AppList SteamAppList `json:"applist"`
|
AppList SteamAppList `json:"applist"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getBasePathForOS() string {
|
||||||
|
var path string
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "darwin":
|
||||||
|
path = helpers.ExpandUser("~/Library/Application Support/Steam")
|
||||||
|
case "linux":
|
||||||
|
path = helpers.ExpandUser("~/.local/share/Steam")
|
||||||
|
case "windows":
|
||||||
|
path = "C:\\Program Files (x86)\\Steam"
|
||||||
|
default:
|
||||||
|
log.Panic("Unsupported OS: ", runtime.GOOS)
|
||||||
|
}
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
|
||||||
func GetSteamAppsList(c chan SteamAppList) {
|
func GetSteamAppsList(c chan SteamAppList) {
|
||||||
log.Println("Updating steam game list...")
|
log.Println("Updating steam game list...")
|
||||||
steamGetAppListURL, _ := url.Parse("https://api.steampowered.com/ISteamApps/GetAppList/v2/")
|
steamGetAppListURL, _ := url.Parse("https://api.steampowered.com/ISteamApps/GetAppList/v2/")
|
||||||
|
@ -80,19 +96,19 @@ func GetSteamAppsList(c chan SteamAppList) {
|
||||||
|
|
||||||
func GuessUsers() []string {
|
func GuessUsers() []string {
|
||||||
var users []string
|
var users []string
|
||||||
|
var path string = filepath.Join(getBasePathForOS(), "userdata")
|
||||||
|
log.Println(path)
|
||||||
|
|
||||||
if runtime.GOOS == "linux" {
|
if _, err := os.Stat(path); !os.IsNotExist(err) {
|
||||||
if _, err := os.Stat(helpers.ExpandUser("~/.local/share/Steam/userdata")); !os.IsNotExist(err) {
|
files, err := ioutil.ReadDir(path)
|
||||||
files, err := ioutil.ReadDir(helpers.ExpandUser("~/.local/share/Steam/userdata"))
|
if err != nil {
|
||||||
if err != nil {
|
log.Fatal(err)
|
||||||
log.Fatal(err)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
if _, err := strconv.ParseInt(file.Name(), 10, 64); err == nil {
|
if _, err := strconv.ParseInt(file.Name(), 10, 64); err == nil {
|
||||||
log.Printf("Found local install Steam user: %s", file.Name())
|
log.Printf("Found local install Steam user: %s", file.Name())
|
||||||
users = append(users, file.Name())
|
users = append(users, file.Name())
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,29 +118,28 @@ func GuessUsers() []string {
|
||||||
func GetGamesFromUser(user string) []uint64 {
|
func GetGamesFromUser(user string) []uint64 {
|
||||||
log.Println("Getting Steam games for user: " + user)
|
log.Println("Getting Steam games for user: " + user)
|
||||||
var userGames []uint64
|
var userGames []uint64
|
||||||
path := helpers.ExpandUser("~/.local/share/Steam/userdata/" + user + "/760/remote")
|
var path string = filepath.Join(getBasePathForOS(), "userdata", user, "760", "remote")
|
||||||
|
|
||||||
if runtime.GOOS == "linux" {
|
if _, err := os.Stat(path); !os.IsNotExist(err) {
|
||||||
if _, err := os.Stat(path); !os.IsNotExist(err) {
|
files, err := ioutil.ReadDir(path)
|
||||||
files, err := ioutil.ReadDir(path)
|
if err != nil {
|
||||||
if err != nil {
|
log.Fatal(err)
|
||||||
log.Fatal(err)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
// len(file.Name()) == 20 -> Custom added Game to steam
|
// len(file.Name()) == 20 -> Custom added Game to steam
|
||||||
gameID, err := strconv.ParseUint(file.Name(), 10, 64)
|
gameID, err := strconv.ParseUint(file.Name(), 10, 64)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
userGames = append(userGames, gameID)
|
userGames = append(userGames, gameID)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return userGames
|
return userGames
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetScreenshotsForGame(user string, game *games.Game) {
|
func GetScreenshotsForGame(user string, game *games.Game) {
|
||||||
path := helpers.ExpandUser("~/.local/share/Steam/userdata/" + user + "/760/remote/" + strconv.FormatUint(game.ID, 10) + "/screenshots")
|
path := filepath.Join(getBasePathForOS(), "userdata", user, "/760/remote/", strconv.FormatUint(game.ID, 10), "screenshots")
|
||||||
files, err := ioutil.ReadDir(path)
|
files, err := ioutil.ReadDir(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|
Loading…
Reference in New Issue