From c3d214d8a3cc05442e167a74dc955af95457e8c6 Mon Sep 17 00:00:00 2001 From: MathieuG-P <40181755+Zagrios@users.noreply.github.com> Date: Thu, 26 May 2022 22:28:02 +0200 Subject: [PATCH] temporary code to lunch BS --- src/main/ipcs/bs-launcher-ipcs.ts | 54 ++++++++++++++++--------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/src/main/ipcs/bs-launcher-ipcs.ts b/src/main/ipcs/bs-launcher-ipcs.ts index febc06cc..a2c4a248 100644 --- a/src/main/ipcs/bs-launcher-ipcs.ts +++ b/src/main/ipcs/bs-launcher-ipcs.ts @@ -3,34 +3,36 @@ import path from "path"; import { spawn } from 'child_process'; import { UtilsService } from '../services/utils.service' import { SteamService } from '../services/steam.service'; -import { BSVersionManagerService } from '../services/bs-version-manager.service'; +import { BSVersion, BSVersionManagerService } from '../services/bs-version-manager.service'; import { BSInstallerService } from '../services/bs-installer.service' import { BS_EXECUTABLE, BS_APP_ID } from '../constants'; -ipcMain.on('test-launch', async () => { - console.log("steam "+ UtilsService.getInstance().taskRunning('steam.exe')); - console.log(await SteamService.getInstance().getSteamGamesFolder()); - console.log(BSInstallerService.getInstance().getBSInstallationFolder()); - console.log((await BSVersionManagerService.getInstance().getAvailableVersions())); - console.log(await BSVersionManagerService.getInstance().getVersionOfBSFolder(path.join(await SteamService.getInstance().getSteamGamesFolder(), "Beat Saber"))); - console.log(await BSInstallerService.getInstance().getInstalledBsVersion()); - return; +export interface LauchOption { + version: BSVersion, + oculus: boolean, + desktop: boolean, + debug: boolean +} - const BS_EXE = "Beat Saber.exe" - const BS_PATH = path.join('C:', 'Users', 'Mathieu', 'Desktop', 'BSLegacyLauncher', 'Beat Saber') - let a = spawn(`\"${path.join(BS_PATH, BS_EXE)}\"`, ["-vrmode oculus", "--verbose"], { shell: true, cwd: BS_PATH, env: {...process.env ,"SteamAppId": "620980"}}); - a.stdout.on('data', data => console.log(data.toString())); - a.stderr.on('data', data => console.log(data.toString())); - a.on('message', m => console.log(m)); - a.on('error', err => console.log(err)); - a.on('exit', e => console.log(e)); - a.on('disconnect', (d: any) => console.log(d)) - console.log('oui'); -}); - -ipcMain.on('bs-launch.steam', async (event, args) => { +ipcMain.on('bs-launch.launch', async (event, args: LauchOption) => { //Create a service BSLauncherService const steamService = SteamService.getInstance(); - const beatSaberSteamFolder = await steamService.getGameFolder(BS_APP_ID, "Beat Saber"); - const beatSaberSteamExe = path.join(beatSaberSteamFolder, BS_EXECUTABLE); - const spawnProcess = spawn(`\"${beatSaberSteamExe}\"`, [], {shell: true, cwd: beatSaberSteamFolder, env: {...process.env, "SteamAppId": BS_APP_ID}}); -}) + const installerService = BSInstallerService.getInstance(); + let cwd = ""; + if(!steamService.steamRunning()){ UtilsService.getInstance().ipcSend("bs-launch.launch", 1); return; } + if(args.version.steam){ + cwd = await steamService.getGameFolder(BS_APP_ID, "Beat Saber"); + } + else{ + cwd = path.join(installerService.getBSInstallationFolder(), args.version.BSVersion); + } + const exePath = path.join(cwd, BS_EXECUTABLE); + if(!UtilsService.getInstance().pathExist(exePath)){ UtilsService.getInstance().ipcSend("bs-launch.launch", 2); return; } + + const launchMods = []; + if(args.oculus){ launchMods.push("-vrmode oculus"); } + if(args.debug){ launchMods.push("--verbose"); } + if(args.desktop){ launchMods.push("fpfc"); } + spawn(`\"${exePath}\"`, launchMods, {shell: true, cwd: cwd, env: {...process.env, "SteamAppId": BS_APP_ID}}); + + UtilsService.getInstance().ipcSend("bs-launch.launch", 0); +});