use new version path fonction from LocalVersionService

This commit is contained in:
MathieuG-P
2022-07-19 21:28:19 +02:00
parent f0292fa783
commit bed81851cc
2 changed files with 9 additions and 9 deletions
+2 -2
View File
@@ -28,8 +28,8 @@ ipcMain.on('bs-version.installed-versions', async (event, req: IpcRequest<void>)
});
ipcMain.on("bs-version.open-folder", async (event, req: IpcRequest<BSVersion>) => {
const locationService = InstallationLocationService.getInstance();
const versionFolder = req.args.steam ? await SteamService.getInstance().getGameFolder(BS_APP_ID, "Beat Saber") : path.join(locationService.versionsDirectory, req.args.BSVersion);
const localVersionService = BSLocalVersionService.getInstance();
const versionFolder = await localVersionService.getVersionPath(req.args);
UtilsService.getInstance().folderExist(versionFolder) && exec(`start "" "${versionFolder}"`);
});
+7 -7
View File
@@ -6,6 +6,7 @@ import { BS_EXECUTABLE, BS_APP_ID } from "../constants";
import { ChildProcessWithoutNullStreams, spawn } from "child_process";
import { SteamService } from "./steam.service";
import { InstallationLocationService } from "./installation-location.service";
import { BSLocalVersionService } from "./bs-local-version.service";
export class BSLauncherService{
@@ -14,6 +15,7 @@ export class BSLauncherService{
private readonly utilsService: UtilsService;
private readonly steamService: SteamService;
private readonly installLocationService: InstallationLocationService;
private readonly localVersionService: BSLocalVersionService;
private bsProcess: ChildProcessWithoutNullStreams;
@@ -26,24 +28,22 @@ export class BSLauncherService{
this.utilsService = UtilsService.getInstance();
this.steamService = SteamService.getInstance();
this.installLocationService = InstallationLocationService.getInstance();
this.localVersionService = BSLocalVersionService.getInstance();
}
public isBsRunning(): boolean{
return this.bsProcess?.connected || this.utilsService.taskRunning(BS_EXECUTABLE);
}
public isExeExist(version: BSVersion): boolean{
const exePath = path.join(this.installLocationService.versionsDirectory, version.BSVersion, BS_EXECUTABLE);
return this.utilsService.pathExist(exePath);
}
public async launch(launchOptions: LauchOption): Promise<LaunchResult>{
if(!this.steamService.steamRunning()){ return "STEAM_NOT_RUNNING" }
if(!this.isExeExist(launchOptions.version)){ return "EXE_NOT_FINDED"; }
if(this.isBsRunning()){ return "BS_ALREADY_RUNNING" }
const cwd = launchOptions.version.steam ? await this.steamService.getGameFolder(BS_APP_ID, "Beat Saber") : path.join(this.installLocationService.versionsDirectory, launchOptions.version.BSVersion);
const cwd = await this.localVersionService.getVersionPath(launchOptions.version);
const exePath = path.join(cwd, BS_EXECUTABLE);
if(!this.utilsService.pathExist(exePath)){ return "EXE_NOT_FINDED"; }
const launchMods = [launchOptions.oculus && "-vrmode oculus", launchOptions.desktop && "fpfc", launchOptions.debug && "--verbose"];
this.bsProcess = spawn(`\"${exePath}\"`, launchMods, {shell: true, cwd: cwd, env: {...process.env, "SteamAppId": BS_APP_ID}});