-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile-interaction.js
executable file
·54 lines (44 loc) · 981 Bytes
/
file-interaction.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
const os = require('os')
const path = require('path')
const fs = require('fs')
const child_process = require('child_process')
class FileInteraction {
constructor () {
this.path = os.homedir() + '/.password-gen-presetsrc'
this.configPath = os.homedir() + '/.password-gen-cfg'
if (fs.existsSync(this.configPath))
this.config = JSON.parse(fs.readFileSync(this.configPath))
else
this.config = {
usingWSL: false
}
if(fs.existsSync(this.path)) {
this.presets = JSON.parse(fs.readFileSync(this.path))
} else {
this.presets = []
this.write()
}
}
write () {
fs.writeFileSync(this.path, JSON.stringify(this.presets), 'utf8')
}
add (preset) {
this.presets.push(preset)
this.write()
}
get (index) {
return this.presets[index]
}
list (){
return this.presets
}
isUsingWSL() {
return this.config.usingWSL
}
WSLCopy(data) {
child_process.spawnSync('clip.exe', [], {
input: data
})
}
}
module.exports = FileInteraction