forked from TinkoLiu/blizzard-product-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
60 lines (59 loc) · 1.37 KB
/
index.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
import decoder from './src/js/database'
import settings from './src/js/settings'
import fs from 'fs'
export class BlizzardParser {
constructor (path = null) {
this.decoder = decoder
if (path == null) {
path = settings.dbPath[process.platform]
}
this.path = path
}
getPath () {
return this.path
}
setPath (path) {
this.path = path
}
isDBExist () {
if (this.path == null) {
throw new Error('product.db path is null')
}
return fs.existsSync(this.path)
}
decode () {
if (!this.isDBExist()) {
throw new Error('product.db not found at ' + this.path)
}
this.buffer = fs.readFileSync(this.path)
this.data = this.decoder.decode(this.buffer)
}
getRaw () {
if (!this.data) {
throw new Error('You should decode first')
}
return this.data
}
getProducts () {
if (!this.data) {
throw new Error('You should decode first')
}
var t = []
this.data.productInstall.forEach(element => {
t.push(element.uid)
})
return t
}
getInstallPath (uid) {
if (!this.data) {
throw new Error('You should decode first')
}
for (let index = 0; index < this.data.productInstall.length; index++) {
const element = this.data.productInstall[index]
if (element.uid === uid) {
return element.settings.installPath
}
}
return undefined
}
}