-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
84 lines (61 loc) · 2.42 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const lsDir = require('list-files-in-dir');
const os = require("os");
const path = require('path');
const lnkParser = require('./lnkParser')
const codePage = require("./win-codepage.js");
const myExport = {
async _getpath(folder) {
const myCodePage = await codePage()
const files = await lsDir.listFiles(folder);
const getTargetPath = async (myItem) => {
try {
const lnkObj = await lnkParser(myItem, myCodePage)
return {lnk: myItem, target: lnkObj.targetPath}
}catch (e) {
return ""
}
}
const promises = [];
for (const item of files) {
let ext = path.extname(item);
if (ext.toLowerCase() === ".lnk") {
promises.push(getTargetPath(item))
}
}
return (await Promise.all(promises)).filter(ele=>ele!=="")
},
async getAllPaths(keyword = "") {
const homePath = os.homedir();
const usersPath = path.dirname(homePath);
const drivePath = path.dirname(usersPath);
const folders = [
homePath + "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs",
usersPath + "\\Default\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs",
drivePath + "ProgramData\\Microsoft\\Windows\\Start Menu\\Programs"
]
const promises = [this._getpath(folders[0]), this._getpath(folders[1]), this._getpath(folders[2])];
const allPaths = await Promise.all(promises);
const pathsInfo =[...allPaths[0], ...allPaths[1], ...allPaths[2]];
if (keyword ==="") {
return pathsInfo;
}
const filteredPaths = pathsInfo.filter((x)=>{
if (path.basename(x.lnk).includes(keyword)) {
return true;
}
if (path.basename(x.target).includes(keyword)) {
return true;
}
})
if (filteredPaths.length ===0) {
return false;
} else {
return filteredPaths;
}
}
}
module.exports = myExport
// const installedPaths = myExport
// installedPaths.getAllPaths("Microsoft Word").then (paths=>{
// console.log(paths) //paths is an array that contains the paths of all installed apps
// })