Skip to content

Commit

Permalink
Automatically update runtimes (#3799)
Browse files Browse the repository at this point in the history
  • Loading branch information
Etaash-mathamsetty authored Jun 13, 2024
1 parent 296d636 commit 3722111
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
10 changes: 7 additions & 3 deletions src/backend/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,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

0 comments on commit 3722111

Please sign in to comment.