Skip to content

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

26.0 KB
Raw Blame
import {
  ExecResult,
  GameSettings,
  Runner,
  Tool,
  WineCommandArgs
} from 'common/types'

import {
  existsSync,
  readFileSync,
  writeFileSync,
  readdirSync,
  copyFile,
  rm,
  mkdirSync,
  rmSync
} from 'graceful-fs'

import { spawn } from 'child_process'
import {
  axiosClient,
  downloadFile,
  execAsync,
  extractFiles,
  getWineFromProton
} from '../utils'
import { execOptions } from 'backend/constants/others'
import { logError, logInfo, LogPrefix, logWarning } from 'backend/logger'
import i18next from 'i18next'
import { dirname, join } from 'path'
import { isOnline } from '../online_monitor'
import { showDialogBoxModalAuto } from '../dialog/dialog'
import {
  runWineCommand,
  setupEnvVars,
  setupWineEnvVars,
  validWine
} from '../launcher'
import { chmod, copyFile as copyFilePromise, readFile } from 'fs/promises'
import {
  any_gpu_supports_version,
  get_nvngx_path,
  get_vulkan_instance_version
} from '../utils/graphics/vulkan'
import { lt as semverLt } from 'semver'
import { createAbortController } from '../utils/aborthandler/aborthandler'
import { libraryManagerMap } from '../storeManagers'
import { sendFrontendMessage } from '../ipc'
import {
  DAYS,
  downloadFile as downloadFileInet
} from '../utils/inet/downloader'
import { getUmuPath, isUmuSupported } from 'backend/utils/compatibility_layers'
import { summarizeError } from 'backend/utils/error_summary'
import { toolsPath, userHome } from 'backend/constants/paths'
import {
  isIntelMac,
  isLinux,
  isMac,
  isWindows
} from 'backend/constants/environment'
import './dxmt'
import { Game } from '../../common/types/game_manager'

type ReleasesResponse = {
  assets: {
    name: string
    browser_download_url: string
  }[]
}

export async function installOrUpdateTool(tool: Tool) {
  if (tool.os !== process.platform) return

  const {
    data: { assets }
  } = await axiosClient.get<ReleasesResponse>(tool.url)

  let asset = assets[0]
  if (tool.name === 'dxvk-macOS' && asset.name.includes('-builtin')) {
    // Do not use -builtin asset for dxvk macos
    // TODO: implement proper use of the -builtin using the WINEDLLPATH_PREPEND
    // env variable, check https://github.com/Heroic-Games-Launcher/HeroicGamesLauncher/pull/5342#issuecomment-3936553327
    // for more details
    asset = assets.find((asset) => asset.name.endsWith('repack.tar.gz'))!
  }
  const { name, browser_download_url: downloadUrl } = asset

  const latestVersion = name.replace('.tar.gz', '').replace('.tar.xz', '')
  const latestVersionArchivePath = `${toolsPath}/${tool.name}/${name}`

  const installedVersionStorage = `${toolsPath}/${tool.name}/latest_${tool.name}`
  let installedVersion = ''
  if (existsSync(installedVersionStorage)) {
    installedVersion = readFileSync(installedVersionStorage)
      .toString()
      .split('\n')[0]
  }

  const alreadyUpToDate =
    installedVersion === latestVersion &&
    existsSync(join(toolsPath, tool.name, installedVersion))
  if (alreadyUpToDate) return

  mkdirSync(join(toolsPath, tool.name), { recursive: true })

  logInfo([`Updating ${tool.name} to:`, latestVersion], LogPrefix.ToolInstaller)

  try {
    await downloadFile({
      url: downloadUrl,
      dest: latestVersionArchivePath,
      abortSignal: createAbortController(tool.name).signal
    })
  } catch (error) {
    logWarning(
      [`Error when downloading ${tool.name}`, error],
      LogPrefix.ToolInstaller
    )

    let title = ''
    let message = ''

    if (tool.name === 'dxmt') {
      title = i18next.t('box.error.dxmt.title', 'DXMT download error')
      message = i18next.t(
        'box.error.dxmt.message',
        'Error downloading DXMT! Check your connection!'
      )
    } else {
      title = i18next.t('box.error.dxvk.title', 'DXVK/VKD3D error')
      message = i18next.t(
        'box.error.dxvk.message',
        'Error installing DXVK/VKD3D! Check your connection!'
      )
    }
    showDialogBoxModalAuto({
      title,
      message,
      type: 'ERROR'
    })
    return
  }

  logInfo(`Downloaded ${tool.name}, extracting...`, LogPrefix.ToolInstaller)

  const extractDestination = join(toolsPath, tool.name, latestVersion)
  mkdirSync(extractDestination, { recursive: true })
  const extractResult = await extractFiles({
    path: latestVersionArchivePath,
    destination: extractDestination,
    strip: tool.strip ?? 1
  })
  rmSync(latestVersionArchivePath)

  if (extractResult.status === 'done') {
    writeFileSync(installedVersionStorage, latestVersion)
    logInfo(`${tool.name} updated!`, LogPrefix.ToolInstaller)
  }
}

export const DXVK = {
  getLatest: async () => {
    if (isWindows) {
      return
    }
    if (!isOnline()) {
      logWarning(
        'App offline, skipping possible DXVK update.',
        LogPrefix.ToolInstaller
      )
      return
    }

    const tools: Tool[] = [
      {
        name: 'vkd3d',
        url: getVkd3dUrl(),
        os: 'linux'
      },
      {
        name: 'dxvk',
        url: getDxvkUrl(),
        os: 'linux'
      },
      {
        name: 'dxvk-nvapi',
        url: 'https://api.github.com/repos/jp7677/dxvk-nvapi/releases/latest',
        os: 'linux',
        strip: 0
      },
      {
        name: 'dxvk-macOS',
        // url: 'https://api.github.com/repos/Gcenx/DXVK-macOS/releases/latest',
        // TODO: go back to using latest once we implement the WINEDLLPATH_PREPEND
        // env variable for dxvk-macos and dxmt
        url: 'https://api.github.com/repos/Gcenx/DXVK-macOS/releases/tags/v1.10.3-20230507-repack',
        os: 'darwin'
      }
    ]

    await Promise.all(
      tools.map((tool) =>
        installOrUpdateTool(tool).catch((error) => {
          // A blocked or rate limited GitHub API must not break the other
          // tools, nor surface as an unhandled rejection.
          logWarning(
            `Could not update ${tool.name}: ${summarizeError(error)}`,
            LogPrefix.ToolInstaller
          )
        })
      )
    )
  },

  installRemove: async (
    gameSettings: GameSettings,
    tool: 'dxvk' | 'dxvk-nvapi' | 'vkd3d' | 'dxvk-macOS',
    action: 'backup' | 'restore'
  ): Promise<boolean> => {
    if (gameSettings.wineVersion.bin.includes('toolkit')) {
      // we don't want to install dxvk on the toolkit prefix since it breaks Apple's implementation
      logWarning(
        'Skipping DXVK install on Game Porting Toolkit prefix!',
        LogPrefix.ToolInstaller
      )
      return true
    }

    if (isMac && gameSettings.wineVersion.name.endsWith('-DXMT')) {
      // we don't want to install dxvk if we use DXMT
      logWarning(
        'Skipping DXVK install on Wine Staging with DXMT!',
        LogPrefix.ToolInstaller
      )
      return true
    }

    if (isMac && tool !== 'dxvk') {
      return true
    }

    const prefix = gameSettings.winePrefix
    const winePrefix = prefix.replace('~', userHome)
    const isValidPrefix = existsSync(`${winePrefix}/.update-timestamp`)

    if (!isValidPrefix) {
      logWarning(
        'DXVK cannot be installed on a Proton or a invalid prefix!',
        LogPrefix.ToolInstaller
      )
      // will return true anyway because otherwise the toggle will be stuck and the prefix might just not be crated yet.
      return true
    }

    tool = isMac ? 'dxvk-macOS' : tool

    const is64bitPrefix = existsSync(`${winePrefix}/drive_c/windows/syswow64`)

    if (!is64bitPrefix) {
      logWarning('32-bit prefix detected!', LogPrefix.ToolInstaller)
    }

    if (!existsSync(`${toolsPath}/${tool}/latest_${tool}`)) {
      logWarning('dxvk not found!', LogPrefix.ToolInstaller)
      await DXVK.getLatest()
    }

    const globalVersion = readFileSync(`${toolsPath}/${tool}/latest_${tool}`)
      .toString()
      .split('\n')[0]

    const toolPathx32 = `${toolsPath}/${tool}/${globalVersion}/${
      tool === 'vkd3d' ? 'x86' : 'x32'
    }`

    const dlls32 = readdirSync(toolPathx32)

    const toolPathx64 = `${toolsPath}/${tool}/${globalVersion}/x64`
    const dlls64 = readdirSync(toolPathx64)

    const currentVersionCheck = `${winePrefix}/current_${tool}`
    let currentVersion = ''

    if (existsSync(currentVersionCheck)) {
      currentVersion = readFileSync(currentVersionCheck)
        .toString()
        .split('\n')[0]
    }

    if (action === 'restore') {
      logInfo(`Removing ${tool} version information`, LogPrefix.ToolInstaller)
      if (existsSync(currentVersionCheck)) {
        rm(currentVersionCheck, { force: true }, (err) => {
          if (err) {
            logError(
              [`Error removing ${tool} version information`, err],
              LogPrefix.ToolInstaller
            )
          }
        })
      }

      logInfo('Removing DLL overrides', LogPrefix.ToolInstaller)

      // unregister the dlls on the wine prefix
      if (is64bitPrefix) {
        dlls64.forEach(async (dll) => {
          dll = dll.replace('.dll', '')
          const unregisterDll = [
            'reg',
            'delete',
            'HKEY_CURRENT_USER\\Software\\Wine\\DllOverrides',
            '/v',
            dll,
            '/f'
          ]
          await runWineCommand({
            gameSettings,
            commandParts: unregisterDll,
            wait: true,
            protonVerb: 'run'
          })
        })
      }
      dlls32.forEach(async (dll) => {
        dll = dll.replace('.dll', '')
        const unregisterDll = [
          'reg',
          'delete',
          'HKEY_CURRENT_USER\\Software\\Wine\\DllOverrides',
          '/v',
          dll,
          '/f'
        ]
        await runWineCommand({
          gameSettings,
          commandParts: unregisterDll,
          wait: true,
          protonVerb: 'run'
        })
      })

      logInfo('Removing DXVK DLLs', LogPrefix.ToolInstaller)

      // removing DXVK dlls
      let dllsToRemove
      if (is64bitPrefix) {
        dllsToRemove = dlls64.map(
          (dll) => `${winePrefix}/drive_c/windows/system32/${dll}`
        )
        dllsToRemove.concat(
          dlls32.map((dll) => `${winePrefix}/drive_c/windows/syswow64/${dll}`)
        )
      } else {
        dllsToRemove = dlls32.map(
          (dll) => `${winePrefix}/drive_c/windows/system32/${dll}`
        )
      }
      dllsToRemove.forEach((dllFile) => {
        try {
          rmSync(dllFile)
        } catch (err) {
          logError([`Error removing ${dllFile}`, err], LogPrefix.ToolInstaller)
        }
      })

      // Restore stock Wine libraries
      logInfo('Restoring Wine stock DLLs', LogPrefix.ToolInstaller)

      await runWineCommand({
        gameSettings,
        commandParts: ['wineboot', '-u'],
        wait: true,
        protonVerb: 'run'
      })
      return true
    }

    logInfo([`installing ${tool} on...`, prefix], LogPrefix.ToolInstaller)

    if (currentVersion === globalVersion) {
      logInfo(`${tool} already installed!`, LogPrefix.ToolInstaller)
      return true
    }

    // copy the new dlls to the prefix
    const copyTasks: Promise<void>[] = []
    if (is64bitPrefix) {
      dlls32.forEach((dll) => {
        copyTasks.push(
          copyFilePromise(
            `${toolPathx32}/${dll}`,
            `${winePrefix}/drive_c/windows/syswow64/${dll}`
          )
        )
      })
      dlls64.forEach((dll) => {
        copyTasks.push(
          copyFilePromise(
            `${toolPathx64}/${dll}`,
            `${winePrefix}/drive_c/windows/system32/${dll}`
          )
        )
      })
    } else {
      dlls32.forEach((dll) => {
        copyTasks.push(
          copyFilePromise(
            `${toolPathx32}/${dll}`,
            `${winePrefix}/drive_c/windows/system32/${dll}`
          )
        )
      })
    }

    try {
      await Promise.all(copyTasks)
    } catch (err) {
      logError(
        [`Error when copying ${tool} DLLs`, err],
        LogPrefix.ToolInstaller
      )
      return false
    }

    // register dlls on the wine prefix
    if (is64bitPrefix) {
      dlls64.forEach(async (dll) => {
        // remove the .dll extension otherwise will fail
        dll = dll.replace('.dll', '')
        const registerDll = [
          'reg',
          'add',
          'HKEY_CURRENT_USER\\Software\\Wine\\DllOverrides',
          '/v',
          dll,
          '/d',
          'native,builtin',
          '/f'
        ]
        await runWineCommand({
          gameSettings,
          commandParts: registerDll,
          wait: true,
          protonVerb: 'run'
        })
      })
    }
    dlls32.forEach(async (dll) => {
      // remove the .dll extension otherwise will fail
      dll = dll.replace('.dll', '')
      const registerDll = [
        'reg',
        'add',
        'HKEY_CURRENT_USER\\Software\\Wine\\DllOverrides',
        '/v',
        dll,
        '/d',
        'native,builtin',
        '/f'
      ]
      await runWineCommand({
        gameSettings,
        commandParts: registerDll,
        wait: true,
        protonVerb: 'run'
      })
    })

    //locate and copy nvngx.dll to support DLSS on Nvidia GPUs
    if (tool === 'dxvk-nvapi' && action === 'backup') {
      try {
        let nvngx_path = get_nvngx_path()
        if (nvngx_path.length !== 0) {
          nvngx_path += '/nvidia/wine'
          const copyDlls = ['nvngx.dll', '_nvngx.dll']
          copyDlls.forEach((dll) => {
            copyFile(
              `${nvngx_path}/${dll}`,
              `${winePrefix}/drive_c/windows/system32/${dll}`,
              (err) => {
                if (err) {
                  logError(
                    [`Error when copying ${dll}`, err],
                    LogPrefix.ToolInstaller
                  )
                }
              }
            )
          })
          const regModNvngx = [
            'reg',
            'add',
            'HKEY_LOCAL_MACHINE\\SOFTWARE\\NVIDIA Corporation\\Global\\NGXCore',
            '/v',
            'FullPath',
            '/d',
            'C:\\windows\\system32',
            '/f'
          ]
          await runWineCommand({
            gameSettings,
            commandParts: regModNvngx,
            wait: true,
            protonVerb: 'run'
          })
        } else {
          logWarning(
            'Could not find nvngx.dll for DLSS!',
            LogPrefix.ToolInstaller
          )
        }
      } catch (err) {
        logError([`Error when finding nvngx.dll`, err], LogPrefix.ToolInstaller)
      }
    }

    try {
      writeFileSync(currentVersionCheck, globalVersion)
    } catch (err) {
      logError(
        [`Error when writing ${tool} version`, err],
        LogPrefix.ToolInstaller
      )
      return false
    }
    return true
  }
}

let installingComponent = ''
export const Winetricks = {
  download: async () => {
    if (isWindows) {
      return
    }

    const url =
      'https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks'
    const path = `${toolsPath}/winetricks`

    if (!isOnline()) {
      return
    }

    try {
      logInfo('Downloading Winetricks', LogPrefix.WineTricks)
      await downloadFileInet(url, {
        writeToFile: path,
        maxCache: 7 * DAYS,
        axiosConfig: { responseType: 'text' }
      })
      await chmod(path, 0o755)
      return
    } catch (error) {
      return logWarning(
        ['Error Downloading Winetricks', error],
        LogPrefix.WineTricks
      )
    }
  },
  runWithArgs: async (
    runner: Runner,
    appName: string,
    args: string[],
    returnOutput = false
  ) => {
    const gameSettings = await libraryManagerMap[runner]
      .getGame(appName)
      .getSettings()

    const { wineVersion } = gameSettings

    if (!(await validWine(wineVersion))) {
      return
    }

    let winetricks = `${toolsPath}/winetricks`
    const gui = args.includes('--gui')

    if (!existsSync(winetricks)) {
      await Winetricks.download()
    }

    if (await isUmuSupported(gameSettings)) {
      winetricks = await getUmuPath()

      if (args.includes('-q')) {
        args.splice(args.indexOf('-q'), 1)
      }

      if (gui) {
        args.splice(args.indexOf('--gui'), 1)
        args.unshift('')
      } else {
        args.unshift('winetricks')
      }
    }

    const { winePrefix, wineVersion: alwaysWine_wineVersion } =
      await getWineFromProton(gameSettings)
    return new Promise<string[] | null>((resolve) => {
      const wineBin = alwaysWine_wineVersion.bin
      // We have to run Winetricks with an actual `wine` binary, meaning we
      // might need to set some environment variables differently than normal
      // (e.g. `WINEESYNC=1` vs `PROTON_NO_ESYNC=0`).
      // These settings will be a copy of the normal game settings, but with
      // their wineVersion set to one always of the type `wine`
      const settingsWithWineVersion = {
        ...gameSettings,
        wineVersion: alwaysWine_wineVersion
      }

      const winepath = dirname(wineBin)

      const linuxEnvs = {
        ...process.env,
        ...setupEnvVars(settingsWithWineVersion),
        ...setupWineEnvVars(settingsWithWineVersion, appName),
        WINEPREFIX: winePrefix,
        PATH: `${winepath}:${process.env.PATH}`,
        GAMEID:
          gameSettings.umuGameId?.trim() || (gui ? 'winetricks-gui' : 'umu-0'),
        UMU_RUNTIME_UPDATE: '0'
      }

      const wineServer = join(winepath, 'wineserver')

      const macEnvs = {
        ...process.env,
        // FIXME: Do we want to use `settingsWithWineVersion` here?
        ...setupEnvVars(gameSettings),
        ...setupWineEnvVars(gameSettings, appName),
        WINEPREFIX: winePrefix,
        WINESERVER: wineServer,
        WINE: wineBin,
        WINE64: wineBin,
        PATH: isIntelMac
          ? `/opt/local/bin:/usr/local/bin:${process.env.PATH}`
          : `/opt/local/bin:/opt/homebrew/bin:${process.env.PATH}`
      }

      const envs = isMac ? macEnvs : linuxEnvs

      const executeMessages: string[] = []
      let progressUpdated = false
      const appendMessage = (message: string) => {
        // Don't store more than 100 messages, to not
        // fill the storage and make render still fast
        if (executeMessages.length > 100) {
          executeMessages.shift()
        }
        executeMessages.push(message)
        progressUpdated = true
      }
      const sendProgress = setInterval(() => {
        if (progressUpdated) {
          sendFrontendMessage('progressOfWinetricks', {
            messages: executeMessages,
            installingComponent
          })
          progressUpdated = false
        }
      }, 1000)

      Winetricks.checkDependencies(envs, appendMessage)

      logInfo(`Running ${winetricks} ${args.join(' ')}`, LogPrefix.WineTricks)

      const child = spawn(winetricks, args, { env: envs })

      const output: string[] = []

      child.stdout.setEncoding('utf8')
      child.stdout.on('data', (data: string) => {
        if (returnOutput) {
          output.push(data)
        } else {
          appendMessage(data)
          logInfo(data, LogPrefix.WineTricks)
        }
      })

      child.stderr.setEncoding('utf8')
      child.stderr.on('data', (data: string) => {
        logError(data, LogPrefix.WineTricks)
        appendMessage(data)
      })

      child.on('error', (error) => {
        logError(['Winetricks threw Error:', error], LogPrefix.WineTricks)
        showDialogBoxModalAuto({
          title: i18next.t('box.error.winetricks.title', 'Winetricks error'),
          message: i18next.t('box.error.winetricks.message', {
            defaultValue:
              'Winetricks returned the following error during execution:{{newLine}}{{error}}',
            newLine: '\n',
            error: `${error}`
          }),
          type: 'ERROR'
        })
        clearInterval(sendProgress)
        resolve(returnOutput ? output : null)
      })

      child.on('exit', () => {
        sendFrontendMessage('progressOfWinetricks', {
          messages: ['Done'],
          installingComponent
        })
        clearInterval(sendProgress)
        resolve(returnOutput ? output : null)
      })

      child.on('close', () => {
        clearInterval(sendProgress)
        resolve(returnOutput ? output : null)
      })
    })
  },
  run: async (runner: Runner, appName: string) => {
    await Winetricks.runWithArgs(runner, appName, ['-q', '--gui'])
  },
  listAvailable: async (runner: Runner, appName: string) => {
    try {
      const dlls: string[] = []
      const outputDlls = await Winetricks.runWithArgs(
        runner,
        appName,
        ['dlls', 'list'],
        true
      )
      if (outputDlls) {
        // the output is an array of strings, the first word is the component name
        outputDlls.forEach((component: string) =>
          dlls.push(component.split(' ', 1)[0])
        )
      }

      const fonts: string[] = []
      const outputFonts = await Winetricks.runWithArgs(
        runner,
        appName,
        ['fonts', 'list'],
        true
      )
      if (outputFonts) {
        // the output is an array of strings, the first word is the font name
        outputFonts.forEach((font: string) => fonts.push(font.split(' ', 1)[0]))
      }
      return [...dlls, ...fonts]
    } catch {
      return []
    }
  },
  listInstalled: async (game: Game) => {
    const gameSettings = await game.getSettings()
    const { winePrefix } = await getWineFromProton(gameSettings)
    const winetricksLogPath = join(winePrefix, 'winetricks.log')
    try {
      const winetricksLog = await readFile(winetricksLogPath, 'utf8')
      return winetricksLog.split('\n').filter(Boolean)
    } catch {
      return []
    }
  },
  install: async (runner: Runner, appName: string, component: string) => {
    sendFrontendMessage('installing-winetricks-component', component)
    try {
      installingComponent = component
      await Winetricks.runWithArgs(runner, appName, ['-q', component])
    } finally {
      installingComponent = ''
      sendFrontendMessage('installing-winetricks-component', '')
    }
  },
  checkDependencies: async (
    envs: Record<string, string>,
    appendMessage: (message: string) => void
  ) => {
    // check if winetricks dependencies are installed
    const dependencies = ['7z', 'cabextract', 'zenity', 'unzip', 'curl']
    const missingDeps: string[] = []
    for (const dependency of dependencies) {
      try {
        await execAsync(`which ${dependency}`, { ...execOptions, env: envs })
      } catch {
        missingDeps.push(dependency)
        const message = `${dependency} not installed! Winetricks might fail to install some packages or even open`
        appendMessage(message)
        logWarning([message], LogPrefix.WineTricks)
      }
    }

    if (missingDeps.length > 0 && isMac) {
      const message = `Check https://github.com/Heroic-Games-Launcher/HeroicGamesLauncher/wiki/Using-Heroic-on-a-Mac-computer#winetricks-setup to install the missing dependencies.`
      appendMessage(message)
      logWarning([message], LogPrefix.WineTricks)
    }
  }
}

/**
 * Figures out the right DXVK version to use, taking the user's hardware
 * (specifically their Vulkan support) into account
 */
function getDxvkUrl(): string {
  if (!isLinux) {
    return ''
  }

  if (any_gpu_supports_version([1, 4, 0])) {
    const instance_version = get_vulkan_instance_version()
    if (instance_version && semverLt(instance_version.join('.'), '1.4.0')) {
      logWarning(
        'Vulkan 1.4 is supported by GPUs in this system, but instance version is outdated',
        LogPrefix.ToolInstaller
      )
    }
    return 'https://api.github.com/repos/doitsujin/dxvk/releases/latest'
  }
  if (any_gpu_supports_version([1, 3, 0])) {
    logInfo(
      'The GPU(s) in this system support Vulkan 1.3, falling back to DXVK 2.7.1 for Wine',
      LogPrefix.ToolInstaller
    )
    return 'https://api.github.com/repos/doitsujin/dxvk/releases/tags/v2.7.1'
  }
  if (any_gpu_supports_version([1, 1, 0])) {
    logInfo(
      'The GPU(s) in this system only support Vulkan 1.1/1.2, falling back to DXVK 1.10.3 for Wine, or use DXVK-Sarek with proton-cachyos',
      LogPrefix.ToolInstaller
    )
    return 'https://api.github.com/repos/doitsujin/dxvk/releases/tags/v1.10.3'
  }
  logWarning(
    'No GPU with Vulkan 1.1 support found, DXVK will not work',
    LogPrefix.ToolInstaller
  )
  // FIXME: We currently lack a "Don't download at all" option here, but
  //        that would also need bigger changes in the frontend
  return 'https://api.github.com/repos/doitsujin/dxvk/releases/tags/v1.10.3'
}

/**
 * Figures out the right VKD3D version to use, taking the user's hardware
 * (specifically their Vulkan support) into account
 */
function getVkd3dUrl(): string {
  if (!isLinux) {
    return ''
  }

  if (any_gpu_supports_version([1, 3, 0])) {
    const instance_version = get_vulkan_instance_version()
    if (instance_version && semverLt(instance_version.join('.'), '1.3.0')) {
      // FIXME: How does the instance version matter? Even with 1.2, newer VKD3D seems to work fine
      logWarning(
        'Vulkan 1.3 is supported by GPUs in this system, but instance version is outdated',
        LogPrefix.ToolInstaller
      )
    }
    return 'https://api.github.com/repos/Heroic-Games-Launcher/vkd3d-proton/releases/latest'
  }
  if (any_gpu_supports_version([1, 1, 0])) {
    logInfo(
      'The GPU(s) in this system only support Vulkan 1.1/1.2, falling back to VKD3D 2.6 for Wine, or use DXVK-Sarek with proton-cachyos',
      LogPrefix.ToolInstaller
    )
    return 'https://api.github.com/repos/Heroic-Games-Launcher/vkd3d-proton/releases/tags/v2.6'
  }
  logWarning(
    'No GPU with Vulkan 1.1 support found, VKD3D will not work',
    LogPrefix.ToolInstaller
  )
  // FIXME: We currently lack a "Don't download at all" option here, but
  //        that would also need bigger changes in the frontend
  return 'https://api.github.com/repos/Heroic-Games-Launcher/vkd3d-proton/releases/tags/v2.6'
}

export async function runWineCommandOnGame(
  runner: Runner,
  appName: string,
  { commandParts, wait = false, protonVerb, startFolder }: WineCommandArgs
): Promise<ExecResult> {
  const game = libraryManagerMap[runner].getGame(appName)
  if (game.isNative()) {
    logError('runWineCommand called on native game!', LogPrefix.Gog)
    return { stdout: '', stderr: '' }
  }
  const { folder_name, install } = game.getGameInfo()
  const gameSettings = await game.getSettings()

  return runWineCommand({
    gameSettings,
    installFolderName: folder_name,
    gameInstallPath: install.install_path,
    commandParts,
    wait,
    protonVerb,
    startFolder
  })
}