-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.js
More file actions
103 lines (86 loc) · 2.67 KB
/
model.js
File metadata and controls
103 lines (86 loc) · 2.67 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
class Model {
constructor() {
this.activeRules = [
Rules.listMods,
Rules.checkSJCrash,
Rules.checkFMODCrash,
Rules.checkOutOfMemoryException,
Rules.checkSteam
];
}
resetState() {
this.issues = [];
this.logLines = [];
this.modsVersions = {};
this.componentsOutOfDate = false;
}
readLog(logText) {
this.resetState();
var criticalErrorFound = false;
const lines = logText.split('\n');
for (const text of lines) {
var loglevel = -1;
var criticalError = false;
for (const level in LOG_LEVELS) {
if (text.includes("[" + level + "]")) {
loglevel = LOG_LEVELS[level];
break;
}
}
if (text.includes(CRITICAL_ERROR_MARK)) {
criticalError = true;
}
for (const rule of this.activeRules) {
rule.bind(this)(text); // bind rule so it can access instance of model
}
this.logLines.push({text, loglevel, criticalError});
}
this.onLogLoaded(this.logLines);
this.onModsChanged(this.modsVersions);
}
addIssue(issue) {
this.issues.push(issue);
this.onIssueAdded(issue);
}
addLoadedMod(mod, loadedVersion) {
this.modsVersions[mod] = {loadedVersion};
}
async fetchModsLatestVersions() {
var outOfDateVersionsFound = false;
const yamlLines = await fetch(MADDIE_MODS_VERSIONS_URL)
.then((response) => response.text())
.then((text) => text.split(('\n')));
// very crude YAML parsing
for (const line of yamlLines) {
if (!line.startsWith(" ")) {
var mod = cleanQuotes(line.slice(0, -1)); // remove trailing `:`
} else if (line.startsWith(" Version: ")) {
if (mod in this.modsVersions) {
const latestVersion = cleanQuotes(line.slice(" Version: ".length));
this.modsVersions[mod]['latestVersion'] = latestVersion;
if (!outOfDateVersionsFound && this.modsVersions[mod]['latestVersion'] != this.modsVersions[mod]['loadedVersion']) {
outOfDateVersionsFound = true;
this.addIssue("Some mods are out of date! Update your mods.");
this.componentsOutOfDate = true;
}
}
}
}
}
async fetchStableEverestVersion() {
const json = await fetch(GITHUB_EVEREST_VERSION_URL)
.then((response) => response.json());
const stableEverestVersion = removePrefix(json[0]['tag_name'], 'stable-');
this.modsVersions['Everest']['latestVersion'] = stableEverestVersion;
if (stableEverestVersion != this.modsVersions['Everest']['loadedVersion']) {
this.addIssue("Everest is out of date! Update Everest."); // assume stable version
this.componentsOutOfDate = true;
}
}
async checkForUpdates() {
await this.fetchModsLatestVersions();
await this.fetchStableEverestVersion();
this.onModsChanged(this.modsVersions);
this.onVersionsChecked(this.componentsOutOfDate);
}
}