aboutsummaryrefslogtreecommitdiff
path: root/steam/acf.go
blob: 7c034e104459388da9b8ddcdc9266b4e18c66e2b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package steam

import (
	"bufio"
	"fmt"
	"os"
	"path/filepath"
	"strings"
)

// FindACF will return the filename of the ACF file for a given `game`
func FindACF(libraryPath, game string) (string, error) {
	files, err := filepath.Glob(filepath.Join(libraryPath, "*.acf"))
	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)
		if err != nil {
			return "", err
		}
		defer f.Close()

		scanner := bufio.NewScanner(f)
		for scanner.Scan() {
			if strings.Contains(scanner.Text(), game) {
				return fn, nil
			}
		}

	}
	return "", fmt.Errorf("Couldn't find ACF file related to Game: %s", game)
}