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, '..');
|
2022-02-16 09:03:43 +00:00
|
|
|
const downloadPath = join(asarPath, '..', 'app.asar.download');
|
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
|
2021-12-11 09:59:39 +00:00
|
|
|
log('AsarUpdate', 'Updating...');
|
|
|
|
|
2022-04-27 10:05:17 +00:00
|
|
|
if (!oaVersion.includes('-')) return;
|
2021-12-13 11:02:22 +00:00
|
|
|
|
2022-12-02 22:23:46 +00:00
|
|
|
const file = fs.createWriteStream(downloadPath);
|
|
|
|
(await redirs(asarUrl)).pipe(file);
|
2022-04-12 12:38:09 +00:00
|
|
|
|
2022-12-02 22:23:46 +00:00
|
|
|
await new Promise(res => file.on('finish', res));
|
2021-12-11 09:59:39 +00:00
|
|
|
|
2022-04-27 10:05:17 +00:00
|
|
|
if (fs.readFileSync(downloadPath, 'utf8').startsWith('<')) return log('AsarUpdate', 'Download error');
|
2021-12-18 20:20:48 +00:00
|
|
|
|
2022-04-14 22:32:02 +00:00
|
|
|
fs.copyFileSync(downloadPath, asarPath); // Overwrite actual app.asar
|
|
|
|
fs.unlinkSync(downloadPath); // Delete downloaded temp file
|
2021-12-11 09:59:39 +00:00
|
|
|
};
|