[AsarUpdate] Source cleanup
This commit is contained in:
parent
a8dd97e3cc
commit
031d634ac9
1 changed files with 15 additions and 28 deletions
|
@ -18,55 +18,42 @@ module.exports = async () => { // (Try) update asar
|
||||||
|
|
||||||
const originalHash = getAsarHash();
|
const originalHash = getAsarHash();
|
||||||
|
|
||||||
const downloadSuccess = await new Promise((res) => {
|
await new Promise((res) => {
|
||||||
const file = fs.createWriteStream(downloadPath);
|
const file = fs.createWriteStream(downloadPath);
|
||||||
|
|
||||||
let writeError;
|
|
||||||
file.on('error', e => {
|
file.on('error', e => {
|
||||||
log('AsarUpdate', 'Failed to write', e);
|
log('AsarUpdate', e);
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
writeError = true;
|
res();
|
||||||
res(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
const req = request.get(asarUrl);
|
|
||||||
|
|
||||||
req.on('response', (res) => {
|
|
||||||
if (writeError) return;
|
|
||||||
|
|
||||||
res.pipe(file);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
file.on('finish', () => {
|
file.on('finish', () => {
|
||||||
file.close();
|
file.close();
|
||||||
res(true);
|
res();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const req = request.get(asarUrl);
|
||||||
|
|
||||||
|
req.on('response', (res) => res.pipe(file));
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!downloadSuccess || fs.readFileSync(downloadPath, 'utf8').startsWith('<Error>')) return log('AsarUpdate', 'Download error');
|
if (fs.readFileSync(downloadPath, 'utf8').startsWith('<Error>')) return log('AsarUpdate', 'Download error');
|
||||||
|
|
||||||
const copySuccess = await new Promise((res) => {
|
if (await new Promise((res) => {
|
||||||
try {
|
try {
|
||||||
fs.copyFileSync(downloadPath, asarPath); // Overwrite actual app.asar
|
fs.copyFileSync(downloadPath, asarPath); // Overwrite actual app.asar
|
||||||
fs.unlinkSync(downloadPath); // Delete downloaded temp file
|
fs.unlinkSync(downloadPath); // Delete downloaded temp file
|
||||||
res(true);
|
res();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log('AsarUpdate', 'Copy error', err);
|
log('AsarUpdate', err);
|
||||||
res(false);
|
res(true);
|
||||||
}
|
}
|
||||||
});
|
})) return;
|
||||||
|
|
||||||
if (!copySuccess) return;
|
|
||||||
|
|
||||||
const newHash = getAsarHash();
|
const newHash = getAsarHash();
|
||||||
const changed = originalHash !== newHash;
|
|
||||||
|
|
||||||
log('AsarUpdate', `Hash Comparison:
|
if (oaConfig.updatePrompt === true && originalHash !== newHash) {
|
||||||
Original: ${originalHash}
|
|
||||||
New: ${newHash}`);
|
|
||||||
|
|
||||||
if (changed && oaConfig.updatePrompt === true) {
|
|
||||||
const { response } = await dialog.showMessageBox(null, {
|
const { response } = await dialog.showMessageBox(null, {
|
||||||
message: 'Updated OpenAsar',
|
message: 'Updated OpenAsar',
|
||||||
detail: `Restart required to use new version.`,
|
detail: `Restart required to use new version.`,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue