-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
119 lines (97 loc) · 2.28 KB
/
main.go
File metadata and controls
119 lines (97 loc) · 2.28 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package main
import (
"bufio"
"errors"
"fmt"
"os"
"os/exec"
"os/user"
)
func main() {
if len(os.Args) < 2 {
checkRequirements()
}
csgoRes, originRes := readConfigSettings()
applyCsgoRes(csgoRes).Run()
startCsgo().Run()
applyOriginRes(originRes).Run()
}
func checkRequirements() {
err := false
nvErr := checkForNvidia()
if nvErr != nil {
fmt.Println(nvErr)
err = true
}
sErr := checkForSteam()
if sErr != nil {
fmt.Println(sErr)
err = true
}
cErr := checkForCsbb()
if cErr != nil {
fmt.Println(cErr)
err = true
}
if err {
os.Exit(1)
}
fmt.Println("Requirements have been met.")
fmt.Println("Make sure to write your settings in ~/.csbb")
os.Exit(0)
}
func checkForNvidia() error {
_, nvErr := exec.LookPath("nvidia-settings")
if nvErr != nil {
return errors.New("REQUIRED: 'nvidia-settings' not found. Please check " +
"that you have installed NVIDIA X Server Settings or make sure your " +
"PATH variable is correct.")
}
return nil
}
func checkForSteam() error {
_, sErr := exec.LookPath("steam")
if sErr != nil {
return errors.New("REQUIRED: 'steam' not found. Please check that you " +
"have installed Steam or make sure your PATH variable is correct.")
}
return nil
}
func checkForCsbb() error {
u, _ := user.Current()
f, err := os.Open(u.HomeDir + "/.csbb")
if err != nil {
return errors.New("NOT FOUND: Could not locate '~/.csbb'.")
}
s := bufio.NewScanner(f)
settings := []string{}
for s.Scan() {
settings = append(settings, s.Text())
}
if len(settings) != 2 {
return errors.New("INVALID CSBB: Parsed (" + string(len(settings)) +
") but expected (2), make sure there are only 2 lines in your '~/.csbb'.")
}
return nil
}
func readConfigSettings() (string, string) {
u, _ := user.Current()
f, _ := os.Open(u.HomeDir + "/.csbb")
defer f.Close()
s := bufio.NewScanner(f)
settings := []string{}
for s.Scan() {
settings = append(settings, s.Text())
}
return settings[0], settings[1]
}
func applyCsgoRes(arg string) *exec.Cmd {
return exec.Command("nvidia-settings", "--assign", "currentmetamode="+arg)
}
func applyOriginRes(arg string) *exec.Cmd {
return exec.Command("nvidia-settings", "--assign", "currentmetamode="+arg)
}
func startCsgo() *exec.Cmd {
args := os.Args[1:]
return exec.Command(args[0], args...)
}