-
-
Notifications
You must be signed in to change notification settings - Fork 80
Fix #184: Use electron/net instead of https to download updates.
#187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
17d3add
7e5008d
2b4290f
1f514f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,18 @@ | ||
| const { get } = require('https'); | ||
| const get = require('./utils/get'); | ||
| const fs = require('original-fs'); // Use original-fs, not Electron's modified fs | ||
| const { join } = require('path'); | ||
|
|
||
| const asarPath = join(__filename, '..'); | ||
|
|
||
| const asarUrl = `https://github.com/GooseMod/OpenAsar/releases/download/${oaVersion.split('-')[0]}/app.asar`; | ||
|
|
||
| // 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); | ||
| })); | ||
|
|
||
| module.exports = async () => { // (Try) update asar | ||
| if (!oaVersion.includes('-')) return; | ||
| log('AsarUpdate', 'Updating...'); | ||
|
|
||
| const res = (await redirs(asarUrl)); | ||
|
|
||
| let data = []; | ||
| res.on('data', d => { | ||
| data.push(d); | ||
| }); | ||
| const buf = (await get(asarUrl))[1]; | ||
|
|
||
| res.on('end', () => { | ||
| const buf = Buffer.concat(data); | ||
| if (!buf.toString('hex').startsWith('04000000')) return log('AsarUpdate', 'Download error'); // Not like ASAR header | ||
| if (!buf || !buf.toString('hex').startsWith('04000000')) return log('AsarUpdate', 'Download error'); // Request failed or ASAR header not present | ||
|
|
||
| fs.writeFile(asarPath, buf, e => log('AsarUpdate', 'Downloaded', e ?? '')); | ||
| }); | ||
| fs.writeFile(asarPath, buf, e => log('AsarUpdate', 'Downloaded', e ?? '')); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| const { net } = require('electron'); | ||
|
|
||
| // returns a promise that resolves to [statusCode, Buffer, headers] | ||
| // [code, null, null] if request failed | ||
| module.exports = async (url) => { | ||
Richardn2002 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const request = new Request(url, { | ||
|
||
| method: 'GET', | ||
| redirect: 'follow' | ||
| }); | ||
| const response = await net.fetch(request); | ||
Richardn2002 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if (response.ok) { | ||
| return [response.status, Buffer.from(await response.arrayBuffer()), response.headers]; | ||
| } else { | ||
| return [response.status, null, null]; | ||
| } | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.