forked from boltgolt/boltobserv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetectcfg.js
More file actions
70 lines (56 loc) · 1.77 KB
/
detectcfg.js
File metadata and controls
70 lines (56 loc) · 1.77 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
const fs = require("fs")
const path = require("path")
const steamPaths = [
// Default Windows install path
path.join("C:", "Program Files (x86)", "Steam", "steamapps"),
// For development
path.join(__dirname)
]
module.exports = {
found: [],
search: () => {
let exp = /"\d"\s*"(.*)"/g
let commonPaths = []
for (let steamPath of steamPaths) {
let vdfPath = path.join(steamPath, "libraryfolders.vdf")
commonPaths.push(path.join(steamPath, "common"))
if (fs.existsSync(vdfPath)) {
let vdfContent = fs.readFileSync(vdfPath, "utf8")
let appPath = exp.exec(vdfContent)
while (appPath != null) {
commonPaths.push(path.join(appPath[1], "steamapps", "common"))
appPath = exp.exec(vdfContent)
}
}
}
for (let commonPath of commonPaths) {
let gamePath = path.join(commonPath, "Counter-Strike Global Offensive")
if (fs.existsSync(gamePath)) {
console.info("Found installation in", gamePath)
let configPath = path.join(gamePath, "csgo", "cfg", "gamestate_integration_boltobserv.cfg")
if (fs.existsSync(configPath)) {
let foundHeader = fs.readFileSync(configPath, "utf8").split("\n")[0]
let ownHeader = fs.readFileSync(path.join(__dirname, "gamestate_integration_boltobserv.cfg"), "utf8").split("\n")[0]
if (foundHeader != ownHeader) {
module.exports.found.push({
type: "update",
path: gamePath
})
}
}
else {
module.exports.found.push({
type: "install",
path: gamePath
})
}
}
}
},
install: (target) => {
let template = path.join(__dirname, "gamestate_integration_boltobserv.cfg")
let dest = path.join(target, "csgo", "cfg", "gamestate_integration_boltobserv.cfg")
fs.copyFileSync(template, dest)
console.info("Installed config file as", dest)
}
}