-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ts
More file actions
48 lines (38 loc) · 1.5 KB
/
utils.ts
File metadata and controls
48 lines (38 loc) · 1.5 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
import * as vdf from "npm:simple-vdf-mstan";
const settingsPath = "./-settings.json";
const settingsJson = await getSettings();
export async function findTF2Location() {
const SteamLibraries = await vdf.parse(await Deno.readTextFile("C:\\Program Files (x86)\\Steam\\steamapps\\libraryfolders.vdf"))
for (const library in SteamLibraries.libraryfolders) {
if (SteamLibraries.libraryfolders[library].apps["440"]) {
console.log("[%cTF2 Installation%c] %cFound in " + SteamLibraries.libraryfolders[library].path.replace(/\\\\/g, `\\`) + "\\steamapps\\common\\Team Fortress 2\\", "color: orange", "color: white", "color: green")
return SteamLibraries.libraryfolders[library].path.replace(/\\\\/g, `\\`) + "\\steamapps\\common\\Team Fortress 2\\";
}
}
}
export async function getSettings() {
try {
return JSON.parse(await Deno.readTextFile(settingsPath));
} catch (e) {
console.log("Error read config:" + e.message);
}
}
export async function writeSettings(Data: JSON) {
try {
await Deno.writeTextFile(settingsPath, JSON.stringify(Data));
} catch (e) {
console.log("[Settings Writer] ERROR: " + e);
}
}
export async function getArrayFromFile(file: string) {
const lines: string[] = [];
const fileContent = await Deno.readTextFile("./arrays/" + file + ".txt");
const fileLines = fileContent.split("\n");
for (const line of fileLines) {
lines.push(line.replace(/(\r\n|\n|\r)/gm, ""));
}
if (settingsJson.debugMode) {
console.log(lines)
}
return lines;
}