2022-01-15 11:29:22 +00:00
|
|
|
// Jank replacement for yauzl by just using unzip where it expects and skipping (speed++, size--, jank++)
|
2022-01-25 22:21:47 +00:00
|
|
|
const { execFile } = require('child_process');
|
2022-01-15 11:29:22 +00:00
|
|
|
const { mkdirSync } = require('fs');
|
2022-01-14 14:02:26 +00:00
|
|
|
const { join, basename } = require('path');
|
|
|
|
|
|
|
|
exports.open = async (zipPath, _options, callback) => {
|
|
|
|
const extractPath = join(global.moduleDataPath, basename(zipPath).split('.')[0].split('-')[0]);
|
|
|
|
const listeners = [];
|
|
|
|
log('Yauzl', 'Zip path:', zipPath, 'Extract path:', extractPath);
|
|
|
|
|
|
|
|
const errorOut = (err) => {
|
|
|
|
listeners.error(err);
|
|
|
|
};
|
|
|
|
|
|
|
|
callback(null, {
|
|
|
|
on: (event, listener) => {
|
|
|
|
listeners[event] = listener;
|
|
|
|
},
|
|
|
|
|
2022-01-15 11:29:22 +00:00
|
|
|
readEntry: () => {}, // Stubs as not used
|
2022-01-14 14:02:26 +00:00
|
|
|
openReadStream: () => {},
|
|
|
|
close: () => {}
|
|
|
|
});
|
|
|
|
|
|
|
|
mkdirSync(extractPath, { recursive: true });
|
|
|
|
|
2022-01-25 22:41:00 +00:00
|
|
|
const proc = execFile('unzip', ['-o', zipPath.replaceAll('"', ''), '-d', extractPath]);
|
2022-01-15 11:29:22 +00:00
|
|
|
log('Yauzl', 'Spawned');
|
2022-01-14 14:02:26 +00:00
|
|
|
|
2022-01-25 22:41:00 +00:00
|
|
|
proc.stderr.on('data', errorOut);
|
2022-01-14 14:02:26 +00:00
|
|
|
|
|
|
|
proc.on('error', (err) => {
|
2022-01-25 22:38:42 +00:00
|
|
|
if (err.code === 'ENOENT') {
|
|
|
|
require('electron').dialog.showErrorBox('Failed Dependency', 'Please install "unzip", exiting');
|
|
|
|
process.exit(1); // Close now
|
|
|
|
}
|
|
|
|
|
2022-01-14 14:02:26 +00:00
|
|
|
errorOut(err);
|
|
|
|
});
|
|
|
|
|
|
|
|
proc.on('close', async () => {
|
2022-01-15 11:29:22 +00:00
|
|
|
log('Yauzl', 'Closed');
|
2022-01-14 14:02:26 +00:00
|
|
|
listeners.end();
|
|
|
|
});
|
|
|
|
};
|