2022-12-02 22:23:46 +00:00
|
|
|
const { get } = require('https');
|
2021-12-11 09:59:39 +00:00
|
|
|
const fs = require('original-fs'); // Use original-fs, not Electron's modified fs
|
|
|
|
const { join } = require('path');
|
|
|
|
|
|
|
|
const asarPath = join(require.main.filename, '..');
|
2021-12-18 22:48:34 +00:00
|
|
|
|
2022-03-23 22:49:07 +00:00
|
|
|
const asarUrl = `https://github.com/GooseMod/OpenAsar/releases/download/${oaVersion.split('-')[0]}/app.asar`;
|
2021-12-11 09:59:39 +00:00
|
|
|
|
2022-12-02 22:23:46 +00:00
|
|
|
// todo: have these https utils centralised?
|
|
|
|
const redirs = url => new Promise(res => get(url, r => { // Minimal wrapper around https.get to follow redirects
|
|
|
|
const loc = r.headers.location;
|
|
|
|
if (loc) return redirs(loc).then(res);
|
|
|
|
|
|
|
|
res(r);
|
|
|
|
}));
|
|
|
|
|
2021-12-18 20:20:48 +00:00
|
|
|
module.exports = async () => { // (Try) update asar
|
2022-04-27 10:05:17 +00:00
|
|
|
if (!oaVersion.includes('-')) return;
|
2022-12-11 12:51:28 +00:00
|
|
|
log('AsarUpdate', 'Updating...');
|
2021-12-13 11:02:22 +00:00
|
|
|
|
2022-12-11 12:51:28 +00:00
|
|
|
const res = (await redirs(asarUrl));
|
2022-04-12 12:38:09 +00:00
|
|
|
|
2022-12-11 12:51:28 +00:00
|
|
|
let data = [];
|
|
|
|
res.on('data', d => {
|
|
|
|
data.push(d);
|
|
|
|
});
|
2021-12-11 09:59:39 +00:00
|
|
|
|
2022-12-11 12:51:28 +00:00
|
|
|
res.on('end', () => {
|
|
|
|
const buf = Buffer.concat(data);
|
|
|
|
if (!buf.toString('hex').startsWith('04000000')) return log('AsarUpdate', 'Download error'); // Not like ASAR header
|
2021-12-18 20:20:48 +00:00
|
|
|
|
2022-12-11 12:51:28 +00:00
|
|
|
fs.writeFile(asarPath, buf, e => log('AsarUpdate', 'Downloaded', e ?? ''));
|
|
|
|
});
|
2021-12-11 09:59:39 +00:00
|
|
|
};
|