-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.js
More file actions
51 lines (40 loc) · 1.01 KB
/
Copy pathconfig.js
File metadata and controls
51 lines (40 loc) · 1.01 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
var fs = require('fs');
var path = require('path');
var child_process = require('child_process');
var cfg_dir = null;
function init(cfg_dir_) {
cfg_dir = cfg_dir_;
}
function store_cfg(id, data) {
try {
var filepath = path.join(cfg_dir, id + '.json');
fs.writeFileSync(filepath, JSON.stringify(data), { encoding: 'utf8' });
return true;
} catch (e) {
console.log("store_cfg error: ", e);
}
return false;
}
function load_cfg(id, fail_ok) {
try {
var filepath = path.join(cfg_dir, id + '.json');
var buf = fs.readFileSync(filepath, { encoding: 'utf8' });
var data = JSON.parse(buf);
return data;
} catch (e) {
if (!fail_ok) {
console.log("load_cfg error: ", e);
}
}
return null;
}
function remove_cfg(id) {
var filepath = path.join(cfg_dir, id + '.json');
fs.unlinkSync(filepath);
}
module.exports = {
init: init,
store: store_cfg,
load: load_cfg,
remove: remove_cfg,
};