-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwindows.js
80 lines (61 loc) · 1.78 KB
/
windows.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const fs = require('fs');
const ico = require('decode-ico');
const jimp = require('jimp');
const iniParser = require('ini-config-parser');
const path = require('path');
let findRightSize = (imgs) => new Promise((resolve,reject) => {
for (let each of [64, 32, 16]) {
let found = imgs.find((element) => {
return (element.width == each);
})
if (found) {
console.log(found);
let image = new jimp(found.width,found.height, (err,image) => {
image.bitmap.data = found.data;
image.getBuffer(jimp.MIME_PNG, (err,buffer) => {
if (err) {
return reject(err);
}
resolve(buffer);
})
});
return;
}
}
reject('No icon found');
});
module.exports = {
default: (_path) => new Promise((resolve,reject) => {
let filePath = _path + '/Desktop.ini';
fs.exists(filePath, (exists) => {
if (!exists) {
return reject('File does not exist');
}
let iniFile = {};
try {
let data = fs.readFileSync(filePath);
data = data.toString().replace(/\\/g,"/");
iniFile = iniParser.parse(data);
if (iniFile.hasOwnProperty(".ShellClassInfo")) {
if (iniFile[".ShellClassInfo"].IconFile) {
const f = fs.readFileSync(
path.resolve(_path,iniFile[".ShellClassInfo"].IconFile.split(',')[0])
);
const _imgs = ico(f);
findRightSize(_imgs)
.then((png) => {
resolve(png);
})
.catch(() => reject('no icon found'));
} else {
reject('no icon entry found');
}
} else {
reject('no valid desktop.ini found');
}
} catch (exception) {
reject (exception);
}
});
})
}