Add sha256sum check for update downloads
This commit is contained in:
@@ -66,11 +66,15 @@ export default function Home () {
|
||||
if (!launcherUpdateData) return
|
||||
const downloadResult = await invoke('download', {
|
||||
url: getDownloadLink(launcherUpdateData),
|
||||
name: launcherLatestRequest.data
|
||||
name: launcherLatestRequest.data,
|
||||
hash: getDownloadHash(launcherUpdateData)
|
||||
})
|
||||
if (downloadResult !== '1') {
|
||||
if (downloadResult == '-1') {
|
||||
setState('Failed. Check internet connection.')
|
||||
return
|
||||
} else if (downloadResult == '-2') {
|
||||
setState('File integrity check failed.')
|
||||
return
|
||||
}
|
||||
setState('Starting...')
|
||||
}
|
||||
@@ -101,6 +105,26 @@ export default function Home () {
|
||||
return undefined
|
||||
}
|
||||
|
||||
function getDownloadHash (version: LauncherUpdate): string | undefined {
|
||||
const p = platform()
|
||||
const a = arch()
|
||||
|
||||
const findUrl = (plat: string) => {
|
||||
const i = version.platforms.indexOf(plat)
|
||||
return i >= 0 ? version.sha256sums[i] : undefined
|
||||
}
|
||||
|
||||
if (p === 'windows') {
|
||||
if (a === 'x86_64') return findUrl('windows-x64')
|
||||
if (a === 'aarch64') return findUrl('windows-arm64')
|
||||
} else if (p === 'macos') {
|
||||
if (a === 'x86_64') return findUrl('macos-intel')
|
||||
if (a === 'aarch64') return findUrl('macos-silicon')
|
||||
} else if (p === 'linux') return findUrl(p)
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className='absolute left-1/2 top-[20%] -translate-x-1/2 flex flex-col items-center'>
|
||||
|
||||
@@ -3,5 +3,5 @@ export interface LauncherUpdate {
|
||||
releaseDate: number
|
||||
downloadUrls: string[]
|
||||
platforms: string[]
|
||||
executables: string[]
|
||||
sha256sums: string[]
|
||||
}
|
||||
Reference in New Issue
Block a user