[bugfix-733] manually set WINEPREFIX when executing IPA.exe

This commit is contained in:
silentrald
2025-01-09 23:42:56 +08:00
parent 664e28ad05
commit 65d26dc819
6 changed files with 78 additions and 46 deletions
@@ -5,7 +5,7 @@ import path from "path";
import log from "electron-log";
import { sToMs } from "../../../shared/helpers/time.helpers";
import { LinuxService } from "../linux.service";
import { bsmSpawn } from "main/helpers/os.helpers";
import { BsmShellLog, bsmSpawn } from "main/helpers/os.helpers";
import { IS_FLATPAK } from "main/constants";
import { LaunchMods } from "shared/models/bs-launch/launch-option.interface";
@@ -56,7 +56,7 @@ export abstract class AbstractLauncherService {
spawnOptions.shell = true; // For windows to spawn properly
return bsmSpawn(`"${bsExePath}"`, {
args, options: spawnOptions, log: true,
args, options: spawnOptions, log: BsmShellLog.Command,
linux: { prefix: this.linux.getProtonPrefix() },
flatpak: {
host: IS_FLATPAK,
+24 -11
View File
@@ -3,9 +3,10 @@ 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 { 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 { bsmExec } from "main/helpers/os.helpers";
import { BsmShellLog, bsmExec } from "main/helpers/os.helpers";
import { LaunchMods } from "shared/models/bs-launch/launch-option.interface";
export class LinuxService {
@@ -19,16 +20,31 @@ export class LinuxService {
}
private readonly staticConfig: StaticConfigurationService;
private readonly steamService: SteamService;
private protonPrefix = "";
private nixOS: boolean | undefined;
private constructor() {
this.staticConfig = StaticConfigurationService.getInstance();
this.steamService = SteamService.getInstance();
}
// === Launching === //
private getCompatDataPath(steamPath: string) {
// 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 = path.join(steamPath, "steamapps", "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;
}
public async setupLaunch(
launchOptions: LaunchOption,
steamPath: string,
@@ -40,15 +56,7 @@ 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 = `${steamPath}/steamapps/compatdata/${BS_APP_ID}`;
if (!fs.existsSync(compatDataPath)) {
log.info(`Proton compat data path not found at '${compatDataPath}', creating directory`);
fs.mkdirSync(compatDataPath);
}
const compatDataPath = this.getCompatDataPath(steamPath);
if (!this.staticConfig.has("proton-folder")) {
throw CustomError.fromError(
@@ -120,6 +128,11 @@ export class LinuxService {
return winePath;
}
public async getWinePrefixPath(): Promise<string> {
const compatDataPath = this.getCompatDataPath(await this.steamService.getSteamPath());
return path.join(compatDataPath, "pfx");
}
public getProtonPrefix(): string {
// Set in setupLaunch
return this.protonPrefix;
@@ -134,7 +147,7 @@ export class LinuxService {
try {
await bsmExec("nixos-version", {
log: true,
log: BsmShellLog.Command,
flatpak: { host: IS_FLATPAK },
});
this.nixOS = true;
@@ -17,7 +17,7 @@ import { LinuxService } from "../linux.service";
import { tryit } from "shared/helpers/error.helpers";
import crypto from "crypto";
import { BsmZipExtractor } from "main/models/bsm-zip-extractor.class";
import { bsmSpawn } from "main/helpers/os.helpers";
import { BsmShellLog, bsmSpawn } from "main/helpers/os.helpers";
import { BbmFullMod, BbmModVersion, ExternalMod } from "../../../shared/models/mods/mod.interface";
export class BsModsManagerService {
@@ -139,25 +139,35 @@ export class BsModsManagerService {
return false;
}
const env: Record<string, string> = {};
const cmd = `"${ipaPath}" "${bsExePath}" ${args.join(" ")}`;
let winePath: string = "";
if (process.platform === "linux") {
const { error, result } = tryit(() => this.linuxService.getWinePath());
if (error) {
log.error(error);
const { error: winePathError, result: winePathResult } =
tryit(() => this.linuxService.getWinePath());
if (winePathError) {
log.error(winePathError);
return false;
}
winePath = `"${result}"`;
winePath = `"${winePathResult}"`;
const { error: winePrefixError, result: winePrefixResult } =
await tryit(async () => this.linuxService.getWinePrefixPath());
if (winePrefixError) {
log.warn("Could not get WINEPREFIX value", winePrefixError);
} else {
env.WINEPREFIX = winePrefixResult;
}
}
return new Promise<boolean>(resolve => {
log.info("START IPA PROCESS", cmd);
const processIPA = bsmSpawn(cmd, {
log: true,
log: BsmShellLog.Command | BsmShellLog.EnvVariables,
options: {
cwd: versionPath,
detached: true,
shell: true
shell: true,
env
},
linux: { prefix: winePath },
});