From 11e61b72b30a8e9f2479e4ca9791c6cb04eb1b19 Mon Sep 17 00:00:00 2001 From: silentrald Date: Sun, 12 Jan 2025 10:44:31 +0800 Subject: [PATCH] [bugfix-733] custom compatdata folder for specific BSManager usage --- src/main/services/linux.service.ts | 35 ++++++++++--------- .../services/mods/bs-mods-manager.service.ts | 9 +++-- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/main/services/linux.service.ts b/src/main/services/linux.service.ts index 5498a0d0..8db15e8d 100644 --- a/src/main/services/linux.service.ts +++ b/src/main/services/linux.service.ts @@ -2,8 +2,8 @@ import fs from "fs-extra"; import log from "electron-log"; import path from "path"; import { BS_APP_ID, IS_FLATPAK, PROTON_BINARY_PREFIX, WINE_BINARY_PREFIX } from "main/constants"; +import { InstallationLocationService } from "./installation-location.service"; import { StaticConfigurationService } from "./static-configuration.service"; -import { SteamService } from "./steam.service"; import { CustomError } from "shared/models/exceptions/custom-error.class"; import { BSLaunchError, LaunchOption } from "shared/models/bs-launch"; import { BsmShellLog, bsmExec } from "main/helpers/os.helpers"; @@ -19,31 +19,22 @@ export class LinuxService { return LinuxService.instance; } + private readonly installLocationService: InstallationLocationService; private readonly staticConfig: StaticConfigurationService; - private readonly steamService: SteamService; private protonPrefix = ""; private nixOS: boolean | undefined; private constructor() { + this.installLocationService = InstallationLocationService.getInstance(); this.staticConfig = StaticConfigurationService.getInstance(); - this.steamService = SteamService.getInstance(); } // === Launching === // - private async getCompatDataPath() { - // Create the compat data path if it doesn't exist. - // If the user never ran Beat Saber through steam before - // using bsmanager, it won't exist, and proton will fail - // to launch the game. - const commonFolder = await this.steamService.getGameFolder(BS_APP_ID); - const compatDataPath = path.resolve(commonFolder, "..", "compatdata", BS_APP_ID); - if (!fs.existsSync(compatDataPath)) { - log.info(`Proton compat data path not found at '${compatDataPath}', creating directory`); - fs.mkdirSync(compatDataPath); - } - return compatDataPath; + private getCompatDataPath() { + const sharedFolder = this.installLocationService.sharedContentPath(); + return path.resolve(sharedFolder, "compatdata"); } public async setupLaunch( @@ -57,7 +48,15 @@ export class LinuxService { launchOptions.admin = false; } + // Create the compat data path if it doesn't exist. + // If the user never ran Beat Saber through steam before + // using bsmanager, it won't exist, and proton will fail + // to launch the game. const compatDataPath = this.getCompatDataPath(); + if (!fs.existsSync(compatDataPath)) { + log.info(`Proton compat data path not found at '${compatDataPath}', creating directory`); + fs.mkdirSync(compatDataPath); + } if (!this.staticConfig.has("proton-folder")) { throw CustomError.fromError( @@ -129,8 +128,10 @@ export class LinuxService { return winePath; } - public async getWinePrefixPath(): Promise { - return path.join(await this.getCompatDataPath(), "pfx"); + public getWinePrefixPath(): string { + const compatDataPath = this.getCompatDataPath(); + return fs.existsSync(compatDataPath) + ? path.join(compatDataPath, "pfx") : ""; } public getProtonPrefix(): string { diff --git a/src/main/services/mods/bs-mods-manager.service.ts b/src/main/services/mods/bs-mods-manager.service.ts index 60983370..aef7b68e 100644 --- a/src/main/services/mods/bs-mods-manager.service.ts +++ b/src/main/services/mods/bs-mods-manager.service.ts @@ -151,12 +151,11 @@ export class BsModsManagerService { } winePath = `"${winePathResult}"`; - const { error: winePrefixError, result: winePrefixResult } = - await tryit(async () => this.linuxService.getWinePrefixPath()); - if (winePrefixError) { - log.warn("Could not get WINEPREFIX value", winePrefixError); + const winePrefix = this.linuxService.getWinePrefixPath(); + if (winePrefix) { + env.WINEPREFIX = winePrefix; } else { - env.WINEPREFIX = winePrefixResult; + log.warn("Could not find BSManager WINEPREFIX path, using system's default value instead"); } }