-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsteam.go
64 lines (56 loc) · 1.71 KB
/
steam.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
62
63
64
// QCLauncher by syncore <[email protected]> 2017
// https://github.com/syncore/qclauncher
package qclauncher
import (
"fmt"
"os/exec"
"golang.org/x/sys/windows/registry"
)
func getSteamInstallPath() string {
installed, steamBasePath := getSteamRegistryInfo()
if installed {
return buildFullSteamPath(steamBasePath)
}
return ""
}
func getSteamRegistryInfo() (bool, string) {
w64key, w64err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Wow6432Node\Valve\Steam`, registry.QUERY_VALUE)
if w64err != nil {
// couldn't find 64bit, check 32bit
logger.Debugw("error getting 64-bit Steam info", "error", w64err)
w32key, w32err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Valve\Steam`, registry.QUERY_VALUE)
if w32err != nil {
logger.Debugw("error getting 32-bit Steam info", "error", w32err)
return false, ""
}
defer w32key.Close()
s, _, werr := w32key.GetStringValue("InstallPath")
if werr == nil {
return s != "", s
}
logger.Errorw("error extracting 32-bit InstallPath value", "error", werr)
} else {
defer w64key.Close()
s, _, werr := w64key.GetStringValue("InstallPath")
if werr == nil {
return s != "", s
}
logger.Errorw("error extracting 64-bit InstallPath value", "error", werr)
}
return false, ""
}
func buildFullSteamPath(steamBasePath string) string {
return fmt.Sprintf("%s\\Steam.exe", steamBasePath)
}
func isSteamInstalled() bool {
installed, _ := getSteamRegistryInfo()
return installed
}
func addNonSteamGame(steamFilePath string) error {
s := exec.Command(steamFilePath, "steam://AddNonSteamGame")
if err := s.Start(); err != nil {
logger.Errorw(fmt.Sprintf("%s: error launching Steam", GetCaller()), "error", err)
return err
}
return nil
}