forked from Nexus-Mods/Vortex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createMD5List.js
48 lines (40 loc) · 1.33 KB
/
createMD5List.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
const crypto = require('crypto');
const fs = require('fs').promises;
const path = require('path');
async function walk(base, rel) {
let files = [];
const dirs = [];
try {
await Promise.all((await fs.readdir(path.join(base, rel)))
.map(async name => {
const stats = await fs.stat(path.join(base, rel, name));
const rPath = path.join(rel, name);
if (stats.isDirectory()) {
dirs.push(rPath);
} else {
files.push(rPath);
}
}));
await Promise.all(await dirs.map(async dir => {
const rec = await walk(base, dir);
files = [].concat(files, rec);
}));
} catch (err) {
console.error('Failed to walk', base, err.message);
}
return files;
}
exports.default = async function(context) {
const assetsPath = path.join(context.appOutDir, 'resources', 'app.asar.unpacked', 'assets');
const hashes = await Promise.all((await walk(context.appOutDir, ''))
.map(async relPath => {
const hash = crypto.createHash('md5');
const fileData = await fs.readFile(path.join(context.appOutDir, relPath));
const buf = hash
.update(fileData)
.digest();
return `${relPath}:${buf.toString('hex')}`;
}));
fs.writeFile(path.join(assetsPath, 'md5sums.csv'), hashes.join('\n'));
return [path.join(assetsPath, 'md5sums.csv')];
}