OpenAsar/src/asarUpdate.js

36 lines
1.2 KiB
JavaScript
Raw Normal View History

const request = require('request');
const fs = require('original-fs'); // Use original-fs, not Electron's modified fs
2022-03-28 07:20:03 +00:00
const { createHash } = require('crypto');
2022-02-16 09:03:43 +00:00
const { dialog, app } = require('electron');
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');
const asarUrl = `https://github.com/GooseMod/OpenAsar/releases/download/${oaVersion.split('-')[0]}/app.asar`;
2022-03-28 07:20:03 +00:00
const getAsarHash = () => createHash('sha512').update(fs.readFileSync(asarPath)).digest('hex');
module.exports = async () => { // (Try) update asar
log('AsarUpdate', 'Updating...');
if (!oaVersion.includes('-')) return;
const originalHash = getAsarHash();
2022-04-12 12:38:09 +00:00
await new Promise((res) => {
const file = fs.createWriteStream(downloadPath);
file.on('finish', () => {
file.close();
2022-04-12 12:38:09 +00:00
res();
});
2022-04-12 12:38:09 +00:00
2022-04-14 22:32:02 +00:00
request.get(asarUrl).on('response', r => r.pipe(file));
});
if (fs.readFileSync(downloadPath, 'utf8').startsWith('<')) return log('AsarUpdate', 'Download error');
2022-04-14 22:32:02 +00:00
fs.copyFileSync(downloadPath, asarPath); // Overwrite actual app.asar
fs.unlinkSync(downloadPath); // Delete downloaded temp file
};