-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
230 lines (201 loc) · 6.58 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
let globby = require("globby");
let fs = require("fs-extra");
let path = require("path");
const yargs = require("yargs/yargs");
const { hideBin } = require("yargs/helpers");
const argv = yargs(hideBin(process.argv)).argv;
const { printTable, Table } = require("console-table-printer");
const VST_DIR = argv.dir || __dirname;
const VST_GLOB = "/**/*.dll";
const DEDUPE_ARCH = argv.dedupeArch == "false" ? false : true;
const SHOW_SKIPPED = argv.showSkipped == "false" ? false : true;
const SHOW_MATCHED = argv.showMatched == "false" ? false : true;
const VST64Dir = path.resolve(path.join(VST_DIR, "../64")).replace(/\\/g, "/");
const VST32Dir = path.resolve(path.join(VST_DIR, "../32")).replace(/\\/g, "/");
const SCAN_GLOB = path
.resolve(path.join(VST_DIR, VST_GLOB))
.replace(/\\/g, "/");
console.log(SCAN_GLOB);
function getArchInformation(result) {
var index = result.indexOf("PE");
var archIdentifier = result[index + 4].toString(16).toLowerCase();
switch (archIdentifier) {
case "4c":
return "32-bit";
case "64":
return "64-bit";
}
return "unknown";
}
let listFiles = async () => {
let files = await globby(SCAN_GLOB);
let tableInfo = files.map(async (f, i) => {
let result = await fs.readFile(f);
let r = {
file: f,
name: path.basename(f),
architecture: getArchInformation(result),
};
return r;
});
function sortListPlugins(a, b) {
let _a = a.file.toString();
let _b = b.file.toString();
return _a > _b ? 1 : -1;
}
const possibleMatch = (p, root) => (checkPlug, i) => {
let _fileP = p.file.replace(root, "");
let _dirP = path.dirname(_fileP);
let creatorP = _dirP.split("/")[1];
let _fileCP = checkPlug.file.replace(root, "");
let _dirCP = path.dirname(_fileCP);
let creatorCP = _dirCP.split("/")[1];
let pad = 80;
if (creatorP === creatorCP) {
let plugP = _dirP.split("/")[2];
let plugCP = _dirCP.split("/")[2];
if (plugP == plugCP) {
//console.log(i, _fileP.padEnd(50, " "), _fileCP);
return true;
}
}
return false;
};
function listPlugins(label, plugs, plugsChecklist) {
if (plugs.length) {
const root = path.resolve(VST_DIR).replace(/\\/g, "/");
const _plugs = plugs.sort(sortListPlugins);
const _plugsChecklist = plugsChecklist.sort(sortListPlugins);
let table = _plugs.map((p) => {
let _file = p.file.replace(root, "");
let _dir = path.dirname(_file);
return {
arch: p.architecture,
creator: _dir.split("/")[1],
plug: _dir.split("/").splice(2, 999).join(" | "),
name: path.basename(_file),
match: _plugsChecklist.find(possibleMatch(p, root)) ? "Y" : "",
};
});
printTable(label, table);
}
}
function printTable(label, table) {
console.log(`${label} Plugins: ${table.length}`);
let p = new Table();
let lastCreator = null;
let stripes = ["blue", "magenta", "cyan"];
let stripeIndex = -1;
let currentColor = null;
table.forEach((tr, i) => {
if (tr.creator !== lastCreator) {
lastCreator = tr.creator;
stripeIndex++;
if (stripeIndex > stripes.length - 1) {
stripeIndex = 0;
}
currentColor = stripes[stripeIndex];
}
let color = { color: currentColor };
if (tr.match) {
color = { color: "yellow" };
}
let _tr = tr;
p.addRow(_tr, color);
});
p.printTable();
}
function enforceDir(dir) {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
}
const generateSymlink = (outputDir, report, arch, plugsChecklist) => (
item,
index
) => {
//console.log(item.file, outputDir);
const root = path.resolve(VST_DIR).replace(/\\/g, "/");
const predicate = item.file.replace(root, "");
const newFile = path
.resolve(path.join(outputDir, predicate))
.replace(/\\/g, "/");
//does this plugin have a match?
let matchingPlugin = null;
if (DEDUPE_ARCH && plugsChecklist && plugsChecklist.length) {
matchingPlugin = plugsChecklist.find(possibleMatch(item, root)) || null;
}
try {
enforceDir(path.dirname(newFile));
if (matchingPlugin) {
SHOW_MATCHED && report.push({ status: "☒ matched", newFile, arch });
} else if (!fs.existsSync(newFile)) {
fs.symlinkSync(item.file, newFile, "file");
report.push({ status: "✓ linked", newFile, arch });
} else if (fs.existsSync(newFile)) {
SHOW_SKIPPED && report.push({ status: "✗ skipped", newFile, arch });
} else {
report.push({ status: "???", newFile, arch });
}
} catch (err) {
console.log(err);
}
};
function printReport(data) {
const root = path.resolve(`${VST_DIR}`).replace(/\\/g, "/");
let table = data.map((d) => {
let _file = d.newFile.replace(root, "");
let _dir = path.dirname(_file);
return {
status: d.status,
arch: d.arch,
dir: _dir.split("/")[2],
creator: _dir.split("/")[3],
plug: _dir.split("/").splice(4, 999).join(" | "),
name: path.basename(_file),
};
});
let lastCreator = null;
let stripes = ["blue", "magenta"];
let stripeIndex = -1;
let currentColor = null;
let reportTable = new Table();
table.forEach((tr, i) => {
if (tr.creator !== lastCreator) {
lastCreator = tr.creator;
stripeIndex++;
if (stripeIndex > stripes.length - 1) {
stripeIndex = 0;
}
currentColor = stripes[stripeIndex];
}
let color = { color: currentColor };
if (tr.status.includes("☒")) {
color = { color: "yellow" };
} else if (tr.status.includes("✓")) {
color = { color: currentColor == stripes[0] ? "cyan" : "green" };
}
let _tr = tr;
reportTable.addRow(_tr, color);
});
reportTable.printTable();
}
const processPlugins = (plugins) => {
const plug32 = plugins.filter((p) => p.architecture == "32-bit");
const plug64 = plugins.filter((p) => p.architecture == "64-bit");
const plugUnknown = plugins.filter((p) => p.architecture == "unknown");
if (argv.list) {
listPlugins("32 Bit", plug32, plug64);
listPlugins("64 Bit", plug64, plug32);
listPlugins("??????", plugUnknown, []);
}
if (argv.sortArch) {
let report = [];
plug32.forEach(generateSymlink(VST32Dir, report, "32-bit", plug64));
plug64.forEach(generateSymlink(VST64Dir, report, "64-bit"));
printReport(report);
}
};
Promise.all(tableInfo).then(processPlugins);
};
listFiles();