forked from dmitmel/CCUpdaterUI
/
gameFinderVfs.go
61 lines (55 loc) · 1.25 KB
/
gameFinderVfs.go
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package middle
import (
"os"
"runtime"
"io/ioutil"
"path/filepath"
)
// GameFinderVFSPathDefault is the path for the 'drives panel'. Should be virtual.
const GameFinderVFSPathDefault = "computer://"
// GameFinderVFSList lists potentially-virtual directories at each path.
func GameFinderVFSList(vfsPath string) []GameLocation {
vfsEntries := []GameLocation{}
if vfsPath == GameFinderVFSPathDefault {
// Determine drives (OS-dependent)
if runtime.GOOS == "windows" {
// we can get away with this, right?
for i := 0; i < 26; i++ {
drive := string(rune('A' + i)) + ":\\"
_, err := ioutil.ReadDir(drive)
if err == nil {
vfsEntries = append(vfsEntries, GameLocation{
Drive: drive,
Location: drive,
})
}
}
return vfsEntries
}
home := os.Getenv("HOME")
return []GameLocation{
GameLocation{
Drive: "Home",
Location: home,
},
GameLocation{
Drive: "Root",
Location: "/",
},
GameLocation{
Drive: "PWD",
Location: ".",
},
}
}
fileInfos, err := ioutil.ReadDir(vfsPath)
if err == nil {
for _, fi := range fileInfos {
if fi.IsDir() {
vfsEntries = append(vfsEntries, CheckGameLocation(filepath.Join(vfsPath, fi.Name())))
}
}
}
// List
return vfsEntries
}