From 1d3f80e6cd982d4d0c20811a44a519efbade6c22 Mon Sep 17 00:00:00 2001 From: Etaash Mathamsetty <45927311+Etaash-mathamsetty@users.noreply.github.com> Date: Wed, 13 Sep 2023 05:30:19 -0400 Subject: [PATCH] [FIX] Install dxvk and vkd3d on new prefixes if enabled (#2873) * install dxvk and vkd3d on new prefixes if enabled * fix everything * Update main.ts * fix winetricks * Update main.ts * Update tools.ts --- src/backend/main.ts | 26 +++---------- src/backend/storeManagers/legendary/games.ts | 2 + .../storeManagers/storeManagerCommon/games.ts | 14 ++++--- src/backend/tools.ts | 38 ++++++++++++------- 4 files changed, 39 insertions(+), 41 deletions(-) diff --git a/src/backend/main.ts b/src/backend/main.ts index 91d823f622..bb73abb2e1 100644 --- a/src/backend/main.ts +++ b/src/backend/main.ts @@ -49,8 +49,6 @@ import { GlobalConfig } from './config' import { LegendaryUser } from 'backend/storeManagers/legendary/user' import { GOGUser } from './storeManagers/gog/user' import { NileUser } from './storeManagers/nile/user' -import setup from './storeManagers/gog/setup' -import nileSetup from './storeManagers/nile/setup' import { clearCache, execAsync, @@ -111,7 +109,7 @@ import { } from './logger/logger' import { gameInfoStore } from 'backend/storeManagers/legendary/electronStores' import { getFonts } from 'font-list' -import { runWineCommand, verifyWinePrefix } from './launcher' +import { prepareWineLaunch, runWineCommand } from './launcher' import shlex from 'shlex' import { initQueue } from './downloadmanager/downloadqueue' import { @@ -144,7 +142,6 @@ import { initStoreManagers, libraryManagerMap } from './storeManagers' -import { legendarySetup } from 'backend/storeManagers/legendary/setup' import { logFileLocation as getLogFileLocation } from './storeManagers/storeManagerCommon/games' import { addNewApp } from './storeManagers/sideload/library' @@ -567,7 +564,7 @@ ipcMain.on('removeFolder', async (e, [path, folderName]) => { }) async function runWineCommandOnGame( - runner: string, + runner: Runner, appName: string, { commandParts, wait = false, protonVerb, startFolder }: WineCommandArgs ): Promise { @@ -578,6 +575,8 @@ async function runWineCommandOnGame( const { folder_name, install } = gameManagerMap[runner].getGameInfo(appName) const gameSettings = await gameManagerMap[runner].getSettings(appName) + await prepareWineLaunch(runner, appName) + return runWineCommand({ gameSettings, installFolderName: folder_name, @@ -592,12 +591,10 @@ async function runWineCommandOnGame( // Calls WineCFG or Winetricks. If is WineCFG, use the same binary as wine to launch it to dont update the prefix ipcMain.handle('callTool', async (event, { tool, exe, appName, runner }) => { const gameSettings = await gameManagerMap[runner].getSettings(appName) - const { wineVersion, winePrefix } = gameSettings - await verifyWinePrefix(gameSettings) switch (tool) { case 'winetricks': - await Winetricks.run(wineVersion, winePrefix, event) + await Winetricks.run(runner, appName, event) break case 'winecfg': runWineCommandOnGame(runner, appName, { @@ -1547,22 +1544,9 @@ ipcMain.handle('getFonts', async (event, reload) => { ipcMain.handle( 'runWineCommandForGame', async (event, { appName, commandParts, runner }) => { - const gameSettings = await gameManagerMap[runner].getSettings(appName) - if (isWindows) { return execAsync(commandParts.join(' ')) } - const { updated } = await verifyWinePrefix(gameSettings) - - if (runner === 'gog' && updated) { - await setup(appName) - } - if (runner === 'nile' && updated) { - await nileSetup(appName) - } - if (runner === 'legendary' && updated) { - await legendarySetup(appName) - } // FIXME: Why are we using `runinprefix` here? return runWineCommandOnGame(runner, appName, { diff --git a/src/backend/storeManagers/legendary/games.ts b/src/backend/storeManagers/legendary/games.ts index 2aabac01c2..80d878cb54 100644 --- a/src/backend/storeManagers/legendary/games.ts +++ b/src/backend/storeManagers/legendary/games.ts @@ -1014,6 +1014,8 @@ export async function runWineCommandOnGame( const { folder_name, install } = getGameInfo(appName) const gameSettings = await getSettings(appName) + await prepareWineLaunch('legendary', appName) + return runWineCommandUtil({ gameSettings, gameInstallPath: install.install_path, diff --git a/src/backend/storeManagers/storeManagerCommon/games.ts b/src/backend/storeManagers/storeManagerCommon/games.ts index ab368f43ec..6197f7a547 100644 --- a/src/backend/storeManagers/storeManagerCommon/games.ts +++ b/src/backend/storeManagers/storeManagerCommon/games.ts @@ -9,6 +9,7 @@ import { callRunner, launchCleanup, prepareLaunch, + prepareWineLaunch, runWineCommand, setupEnvVars, setupWrapperEnvVars, @@ -134,6 +135,8 @@ export async function launchGame( steamRuntime } = await prepareLaunch(gameSettings, gameInfo, isNative) + if (!isNative) await prepareWineLaunch(runner, appName) + const wrappers = setupWrappers( gameSettings, mangoHudCommand, @@ -154,12 +157,6 @@ export async function launchGame( return false } - const env = { - ...process.env, - ...setupWrapperEnvVars({ appName, appRunner: runner }), - ...setupEnvVars(gameSettings) - } - // Native if (isNative) { logInfo( @@ -181,6 +178,11 @@ export async function launchGame( } const commandParts = shlex.split(launcherArgs ?? '') + const env = { + ...process.env, + ...setupWrapperEnvVars({ appName, appRunner: runner }), + ...setupEnvVars(gameSettings) + } await callRunner( commandParts, diff --git a/src/backend/tools.ts b/src/backend/tools.ts index b13424c1d0..e50b2a6447 100644 --- a/src/backend/tools.ts +++ b/src/backend/tools.ts @@ -1,4 +1,4 @@ -import { GameSettings, WineInstallation } from 'common/types' +import { GameSettings, Runner } from 'common/types' import axios from 'axios' import { existsSync, @@ -24,7 +24,12 @@ import i18next from 'i18next' import { dirname, join } from 'path' import { isOnline } from './online_monitor' import { showDialogBoxModalAuto } from './dialog/dialog' -import { runWineCommand, validWine } from './launcher' +import { + runWineCommand, + setupEnvVars, + setupWineEnvVars, + validWine +} from './launcher' import { chmod } from 'fs/promises' import { any_gpu_supports_version, @@ -32,6 +37,7 @@ import { get_vulkan_instance_version } from './utils/graphics/vulkan' import { lt as semverLt } from 'semver' +import { gameManagerMap } from './storeManagers' export const DXVK = { getLatest: async () => { @@ -420,11 +426,16 @@ export const Winetricks = { } }, runWithArgs: async ( - wineVersion: WineInstallation, - baseWinePrefix: string, + runner: Runner, + appName: string, args: string[], event?: Electron.IpcMainInvokeEvent ) => { + const gameSettings = await gameManagerMap[runner].getSettings(appName) + + const { wineVersion } = gameSettings + const baseWinePrefix = gameSettings.winePrefix + if (!(await validWine(wineVersion))) { return } @@ -445,7 +456,9 @@ export const Winetricks = { const linuxEnvs = { ...process.env, WINEPREFIX: winePrefix, - PATH: `${winepath}:${process.env.PATH}` + PATH: `${winepath}:${process.env.PATH}`, + ...setupEnvVars(gameSettings), + ...setupWineEnvVars(gameSettings, appName) } const wineServer = join(winepath, 'wineserver') @@ -456,7 +469,9 @@ export const Winetricks = { WINESERVER: wineServer, WINE: wineBin, WINE64: wineBin, - PATH: `/opt/homebrew/bin:${process.env.PATH}` + PATH: `/opt/homebrew/bin:${process.env.PATH}`, + ...setupEnvVars(gameSettings), + ...setupWineEnvVars(gameSettings, appName) } const envs = isMac ? macEnvs : linuxEnvs @@ -547,16 +562,11 @@ export const Winetricks = { }) }, run: async ( - wineVersion: WineInstallation, - baseWinePrefix: string, + runner: Runner, + appName: string, event: Electron.IpcMainInvokeEvent ) => { - await Winetricks.runWithArgs( - wineVersion, - baseWinePrefix, - ['--force', '-q'], - event - ) + await Winetricks.runWithArgs(runner, appName, ['--force', '-q'], event) } }