Skip to content

Automatically update runtimes #3799

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

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/backend/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,18 @@ async function prepareWineLaunch(
}
}

if (gameSettings.eacRuntime && !isInstalled('eac_runtime') && isOnline()) {
if (
gameSettings.eacRuntime &&
isOnline() &&
!(await isInstalled('eac_runtime'))
) {
await download('eac_runtime')
}

if (
gameSettings.battlEyeRuntime &&
!isInstalled('battleye_runtime') &&
isOnline()
isOnline() &&
!(await isInstalled('battleye_runtime'))
) {
await download('battleye_runtime')
}
Expand Down
2 changes: 1 addition & 1 deletion src/backend/wine/runtimes/ipc_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ ipcMain.handle('downloadRuntime', async (e, runtime_name) =>
download(runtime_name)
)

ipcMain.handle('isRuntimeInstalled', (e, runtime_name) =>
ipcMain.handle('isRuntimeInstalled', async (e, runtime_name) =>
isInstalled(runtime_name)
)
40 changes: 37 additions & 3 deletions src/backend/wine/runtimes/runtimes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { existsSync, mkdirSync, unlinkSync } from 'graceful-fs'
import {
existsSync,
mkdirSync,
readFileSync,
unlinkSync,
writeFileSync,
rmSync
} from 'graceful-fs'
import { join } from 'path'
import { runtimePath } from './../../constants'
import { logError, logInfo, LogPrefix } from './../../logger/logger'
Expand Down Expand Up @@ -36,11 +43,21 @@ async function download(name: RuntimeName): Promise<boolean> {
await downloadFile(runtime.url, tarFilePath)

const extractedFolderPath = join(runtimePath, name)

if (existsSync(extractedFolderPath)) {
rmSync(extractedFolderPath, { recursive: true })
}

await extractTarFile(tarFilePath, content_type, {
extractedPath: extractedFolderPath,
strip: 1
})

writeFileSync(
join(extractedFolderPath, 'current_version'),
runtime.created_at
)

unlinkSync(tarFilePath)

return true
Expand All @@ -53,8 +70,25 @@ async function download(name: RuntimeName): Promise<boolean> {
}
}

function isInstalled(name: RuntimeName) {
return existsSync(join(runtimePath, name))
async function isInstalled(name: RuntimeName) {
if (!existsSync(join(runtimePath, name))) return false

const runtimes = await _get()
const runtime = runtimes.find((inst) => inst.name === name)

// this should be impossible, so prevent redownload by faking it's installed
if (!runtime) {
logError('Runtime not found in runtime list', LogPrefix.Runtime)
return true
}

const version_path = join(runtimePath, name, 'current_version')

if (!existsSync(version_path)) return false

const current_version = readFileSync(version_path)

return runtime.created_at === current_version.toString()
}

export { download, isInstalled }
2 changes: 1 addition & 1 deletion src/common/typedefs/ipcBridge.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ interface AsyncIPCFunctions {
disableEosOverlay: (appName: string) => Promise<void>
isEosOverlayEnabled: (appName?: string) => Promise<boolean>
downloadRuntime: (runtime_name: RuntimeName) => Promise<boolean>
isRuntimeInstalled: (runtime_name: RuntimeName) => boolean
isRuntimeInstalled: (runtime_name: RuntimeName) => Promise<boolean>
getDMQueueInformation: () => {
elements: DMQueueElement[]
finished: DMQueueElement[]
Expand Down
Loading