-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathconfig.js
65 lines (49 loc) · 1.13 KB
/
config.js
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
var CONFIG_FILE = "CFG.JSN";
function Config() {
this.DefConfig = {
"lastTag": null,
"autoReloadDelay": 300,
"maxPoll": 30,
"smallCacheSize": 50,
"profileCacheSize": 15,
"largeCacheSize": 15,
"diskCacheMaxAge": 14,
"ignoreCw": false
};
this.DiskConfig = {};
try {
this.DiskConfig = JSON.parse(Read(CONFIG_FILE));
} catch (e) {
Println("Could not load config: " + e);
}
}
Config.prototype.Get = function (k) {
if (k in this.DiskConfig) {
return this.DiskConfig[k];
}
if (k in this.DefConfig) {
return this.DefConfig[k];
}
throw new Error("Unknown config key: " + k);
}
Config.prototype.Set = function (k, v) {
if (k in this.DefConfig) {
this.DiskConfig[k] = v;
} else {
throw new Error("Unknown config key: " + k);
}
}
Config.prototype.Save = function () {
var storedConfig = {};
var keys = Object.keys(this.DefConfig);
for (var i = 0; i < keys.length; i++) {
var k = keys[i];
storedConfig[k] = this.Get(k);
}
var f = new File(CONFIG_FILE, FILE.WRITE);
f.WriteString(JSON.stringify(storedConfig));
f.Close();
}
// export functions and version
exports.__VERSION__ = 1;
exports.Config = Config;