-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathuserdata.js
40 lines (35 loc) · 1006 Bytes
/
userdata.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
const fs = require('fs');
function userData() {
this.path = utools.getPath('userData') + '/jFlower' + (utools.isDev() ? '/dev' : '');//dev
console.log(this.path);
fs.mkdirSync(this.path, {
recursive: true
});
}
Object.assign(userData.prototype, {
get(file_name, _default) {
try {
var json = fs.readFileSync(this.path + '/' + file_name + '.json', {
encoding: 'utf8'
});
json = JSON.parse(json);
} catch (e) {
console.log(e)
return typeof _default == 'undefined' ? {} : _default;
}
return json;
},
put(file_name, data) {
try {
fs.writeFile(this.path + '/' + file_name + '.json', JSON.stringify(data) ,(err)=>{
if(err)
console.log(err)
});
return true;
} catch (e) {
console.log(e)
return false;
}
}
});
module.exports = new userData();