[AsarUpdate] Fix for new request polyfill changes
This commit is contained in:
parent
af5629e40b
commit
c701c8f307
2 changed files with 34 additions and 11 deletions
|
@ -43,6 +43,9 @@ const request = (options, callback) => { // Main function
|
||||||
const listener = {};
|
const listener = {};
|
||||||
|
|
||||||
nodeReq(options).then(async (res) => { // No error handling because yes
|
nodeReq(options).then(async (res) => { // No error handling because yes
|
||||||
|
if (listener['response']) listener['response'](res);
|
||||||
|
if (!callback) return;
|
||||||
|
|
||||||
let body = '';
|
let body = '';
|
||||||
res.setEncoding('utf8');
|
res.setEncoding('utf8');
|
||||||
|
|
||||||
|
@ -50,8 +53,7 @@ const request = (options, callback) => { // Main function
|
||||||
|
|
||||||
await new Promise((resolve) => res.on('end', resolve)); // Wait to read full body
|
await new Promise((resolve) => res.on('end', resolve)); // Wait to read full body
|
||||||
|
|
||||||
if (callback) callback(undefined, res, body);
|
callback(undefined, res, body);
|
||||||
if (listener['response']) listener['response'](res);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -7,6 +7,9 @@ const { join } = require('path');
|
||||||
const asarPath = join(require.main.filename, '..');
|
const asarPath = join(require.main.filename, '..');
|
||||||
log('AsarUpdate', 'Asar Path:', asarPath);
|
log('AsarUpdate', 'Asar Path:', asarPath);
|
||||||
|
|
||||||
|
const downloadPath = join(require.main.filename, '..', '..', 'app.asar.download');
|
||||||
|
log('AsarUpdate', 'Download Path:', downloadPath);
|
||||||
|
|
||||||
const downloadUrls = {
|
const downloadUrls = {
|
||||||
nightly: 'https://github.com/GooseMod/OpenAsar/releases/download/nightly/app.asar'
|
nightly: 'https://github.com/GooseMod/OpenAsar/releases/download/nightly/app.asar'
|
||||||
};
|
};
|
||||||
|
@ -19,7 +22,7 @@ module.exports = async () => { // (Try) update asar
|
||||||
log('AsarUpdate', 'Updating...');
|
log('AsarUpdate', 'Updating...');
|
||||||
|
|
||||||
if (!oaVersion.startsWith('nightly-')) {
|
if (!oaVersion.startsWith('nightly-')) {
|
||||||
return log('AsarUpdate', 'Found non-standard version, not updating');
|
// return log('AsarUpdate', 'Found non-standard version, not updating');
|
||||||
}
|
}
|
||||||
|
|
||||||
const asarUrl = downloadUrls[channel];
|
const asarUrl = downloadUrls[channel];
|
||||||
|
@ -28,8 +31,8 @@ module.exports = async () => { // (Try) update asar
|
||||||
const originalHash = getAsarHash();
|
const originalHash = getAsarHash();
|
||||||
log('AsarUpdate', 'Original Hash:', originalHash);
|
log('AsarUpdate', 'Original Hash:', originalHash);
|
||||||
|
|
||||||
const updateSuccess = await new Promise((res) => {
|
const downloadSuccess = await new Promise((res) => {
|
||||||
const file = fs.createWriteStream(asarPath);
|
const file = fs.createWriteStream(downloadPath);
|
||||||
|
|
||||||
let writeError = false;
|
let writeError = false;
|
||||||
file.on('error', err => {
|
file.on('error', err => {
|
||||||
|
@ -40,14 +43,16 @@ module.exports = async () => { // (Try) update asar
|
||||||
res(false);
|
res(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
log('AsarUpdate', 'Opened write stream to asar');
|
log('AsarUpdate', 'Opened write stream to download asar');
|
||||||
|
|
||||||
request(asarUrl, (_err, res) => {
|
const req = request.get(asarUrl);
|
||||||
|
|
||||||
|
req.on('response', (res) => {
|
||||||
if (writeError) return;
|
if (writeError) return;
|
||||||
|
|
||||||
log('AsarUpdate', 'Piping download response to stream');
|
log('AsarUpdate', 'Piping download response to stream');
|
||||||
res.pipe(file);
|
res.pipe(file);
|
||||||
});
|
})
|
||||||
|
|
||||||
file.on('finish', () => {
|
file.on('finish', () => {
|
||||||
file.close();
|
file.close();
|
||||||
|
@ -55,12 +60,28 @@ module.exports = async () => { // (Try) update asar
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!updateSuccess) {
|
if (!downloadSuccess) {
|
||||||
log('AsarUpdate', 'Aborting rest of update due to update error');
|
log('AsarUpdate', 'Aborting rest of update due to download error');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
log('AsarUpdate', 'Completed download');
|
log('AsarUpdate', 'Completed download, copying over');
|
||||||
|
|
||||||
|
const copySuccess = await new Promise((res) => {
|
||||||
|
try {
|
||||||
|
fs.copyFileSync(downloadPath, asarPath); // Overwrite actual app.asar
|
||||||
|
fs.unlinkSync(downloadPath); // Delete downloaded temp file
|
||||||
|
res(true);
|
||||||
|
} catch (err) {
|
||||||
|
log('AsarUpdate', 'Copy error', err);
|
||||||
|
res(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!copySuccess) {
|
||||||
|
log('AsarUpdate', 'Aborting rest of update due to copy error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const newHash = getAsarHash();
|
const newHash = getAsarHash();
|
||||||
const changed = originalHash !== newHash;
|
const changed = originalHash !== newHash;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue