Skip to content

A games launcher for GOG, Amazon and Epic Games for Linux, Windows and macOS.

1.1 KB
Raw Blame
import * as fs from 'fs'
import { ZoomDownloadFile } from 'common/types/zoom'
import { ExecResult } from 'common/types'
import { findStartScript } from './install'

type RunZoomFile = (file: ZoomDownloadFile) => Promise<ExecResult>

// Applies the Linux game files in order. A base archive and a later patch can
// add separate top-level folders, so the start script is looked up after each
// file and the last one found is kept: a later archive that makes the lookup
// ambiguous must not discard an executable that already worked.
export async function applyLinuxGameFiles(
  gameFiles: ZoomDownloadFile[],
  installPath: string,
  run: RunZoomFile,
  log: (message: string) => void
): Promise<{ executable?: string; error?: string }> {
  let executable: string | undefined

  for (const file of gameFiles) {
    const result = await run(file)

    if (result.error) {
      return { error: result.error }
    }

    const found = findStartScript(installPath)
    if (found) {
      executable = found
      await fs.promises.chmod(found, '755')
      log(`Found start script: ${found}`)
    }
  }

  return { executable }
}