diff --git a/src/asarUpdate.js b/src/asarUpdate.js index 4808c33..8d57687 100644 --- a/src/asarUpdate.js +++ b/src/asarUpdate.js @@ -5,31 +5,24 @@ const electron = require('electron'); const { join } = require('path'); const asarPath = join(require.main.filename, '..'); -log('AsarUpdate', 'Asar Path:', asarPath); - const downloadPath = join(require.main.filename, '..', '..', 'app.asar.download'); -log('AsarUpdate', 'Download Path:', downloadPath); const downloadUrls = { nightly: 'https://github.com/GooseMod/OpenAsar/releases/download/nightly/app.asar' }; -const channel = 'nightly'; // Have prod, etc. once stable / 1.0 +const channel = 'nightly'; const getAsarHash = () => crypto.createHash('sha512').update(fs.readFileSync(asarPath)).digest('hex'); module.exports = async () => { // (Try) update asar log('AsarUpdate', 'Updating...'); - if (!oaVersion.startsWith('nightly-')) { - return log('AsarUpdate', 'Found non-standard version, not updating'); - } + if (!oaVersion.startsWith('nightly-')) return log('AsarUpdate', 'Non-standard version'); const asarUrl = downloadUrls[channel]; - log('AsarUpdate', 'Release Channel:', channel, 'Download URL:', asarUrl); const originalHash = getAsarHash(); - log('AsarUpdate', 'Original Hash:', originalHash); const downloadSuccess = await new Promise((res) => { const file = fs.createWriteStream(downloadPath); @@ -43,14 +36,11 @@ module.exports = async () => { // (Try) update asar res(false); }); - log('AsarUpdate', 'Opened write stream to download asar'); - const req = request.get(asarUrl); req.on('response', (res) => { if (writeError) return; - log('AsarUpdate', 'Piping download response to stream'); res.pipe(file); }); @@ -61,12 +51,10 @@ module.exports = async () => { // (Try) update asar }); if (!downloadSuccess) { - log('AsarUpdate', 'Aborting rest of update due to download error'); + log('AsarUpdate', 'Download error'); return; } - log('AsarUpdate', 'Completed download, copying over'); - const copySuccess = await new Promise((res) => { try { fs.copyFileSync(downloadPath, asarPath); // Overwrite actual app.asar @@ -78,18 +66,14 @@ module.exports = async () => { // (Try) update asar } }); - if (!copySuccess) { - log('AsarUpdate', 'Aborting rest of update due to copy error'); - return; - } + if (!copySuccess) return; const newHash = getAsarHash(); const changed = originalHash !== newHash; log('AsarUpdate', `Hash Comparison: -Original Hash: ${originalHash} -New Hash: ${newHash} -Changed: ${changed}`); +Original: ${originalHash} +New: ${newHash}`); if (changed && oaConfig.updatePrompt === true) { const { response } = await electron.dialog.showMessageBox(null, { @@ -99,11 +83,7 @@ Changed: ${changed}`); defaultId: 0 }); - log('AsarUpdate', 'Modal response', response); - if (response === 0) { - log('AsarUpdate', 'Restarting'); - electron.app.relaunch(); electron.app.exit(); }