-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstalllocators.ts
109 lines (96 loc) · 2.94 KB
/
installlocators.ts
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
/* eslint-disable */
import { lstat, readFile, readdir } from "node:fs/promises"
import path from "node:path"
import { list } from "drivelist"
import regedit from "winreg"
// TODO: refactor
function locateSteamInstall() {
return new Promise((resolve, reject) => {
const key = new regedit({
hive: regedit.HKLM,
key: "\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Steam App 1272080",
})
key.keyExists((err, exists) => {
if (err) {
console.error(err)
reject("ERROR")
} else if (exists) {
key.values((err, items) => {
if (err) {
console.error(err)
reject("ERROR")
} else {
let steamLocation = null
for (let i = 0; i < items.length; i++) {
if (items[i].name === "InstallLocation") {
steamLocation = items[i].value
console.log(`InstallLocation: ${steamLocation}`)
resolve(steamLocation)
return
}
}
console.log("InstallLocation not found in the registry key.")
reject("NOTFOUND")
}
})
} else {
console.log("Registry key not found.")
reject("NOTFOUND")
}
})
})
}
async function locateMsStoreInstall(): Promise<string> {
const drives = await list()
const mountPaths = drives
.filter((drive) => drive.isSystem)
.flatMap((drive) => drive.mountpoints)
.map((mountPoint) => mountPoint.path)
for (const mountPath of new Set(mountPaths)) {
const installPath = path.join(mountPath, "/XboxGames/Payday 3/Content")
try {
await lstat(installPath)
return installPath
} catch {
continue
}
}
throw new Error("NOT_FOUND")
}
async function locateEpicInstall(): Promise<string> {
const epicManifestPath =
"C:/ProgramData/Epic/EpicGamesLauncher/Data/Manifests"
try {
await lstat(epicManifestPath)
} catch (err) {
throw err
}
const manifests = await readdir(epicManifestPath)
// TODO: change "PAYDAY 3" to whatever the game uses to identify itself
for (const mf of manifests) {
if (!mf.endsWith(".item")) continue
const manifestJson = JSON.parse(
await readFile(path.join(epicManifestPath, mf)).toString()
)
if (manifestJson["DisplayName"] === "PAYDAY 3") {
return manifestJson["InstallLocation"]
}
}
throw new Error("NOT_FOUND")
}
export function resolveInstall() {
return locateSteamInstall().catch(() => {
console.log(
"Steam installation not found or encountered an error. Falling back to Xbox."
)
return locateMsStoreInstall().catch(() => {
console.error(
"Xbox installation not found or encountered an error. Falling back to Epic"
)
return locateEpicInstall().catch(() => {
console.error("Epic installation not found or encountered an error.")
throw new Error("No game installation not found.")
})
})
})
}