From 9862dfa78d3efaeb3e3f8b1cab4f412f7cb35211 Mon Sep 17 00:00:00 2001 From: MathieuG-P <40181755+Zagrios@users.noreply.github.com> Date: Mon, 13 Mar 2023 23:55:22 +0100 Subject: [PATCH 1/2] force not launch steamvr when desktop mode --- src/main/constants.ts | 2 ++ src/main/ipcs/window-manager-ipcs.ts | 5 +++ src/main/main.ts | 11 ++---- src/main/services/bs-launcher.service.ts | 43 +++++++++++++++++++++--- src/main/services/steam.service.ts | 2 +- 5 files changed, 50 insertions(+), 13 deletions(-) diff --git a/src/main/constants.ts b/src/main/constants.ts index 74ca8198..f9fb7319 100644 --- a/src/main/constants.ts +++ b/src/main/constants.ts @@ -3,3 +3,5 @@ export const OCULUS_BS_DIR = "hyperbolic-magnetism-beat-saber" export const BS_APP_ID = "620980"; export const BS_DEPOT = "620981"; export const APP_NAME = "BSManager"; + +export const STEAMVR_APP_ID = "250820"; diff --git a/src/main/ipcs/window-manager-ipcs.ts b/src/main/ipcs/window-manager-ipcs.ts index e0393d68..1da08082 100644 --- a/src/main/ipcs/window-manager-ipcs.ts +++ b/src/main/ipcs/window-manager-ipcs.ts @@ -2,6 +2,9 @@ import { ipcMain } from "electron"; import { WindowManagerService } from "../services/window-manager.service"; import { IpcRequest } from "shared/models/ipc"; import { AppWindow } from "shared/models/window-manager/app-window.model"; +import { BSLauncherService } from "../services/bs-launcher.service"; + +const launcher = BSLauncherService.getInstance(); ipcMain.on("open-window-then-close-all", async (event, request: IpcRequest) => { const windowManager = WindowManagerService.getInstance(); @@ -12,11 +15,13 @@ ipcMain.on("open-window-then-close-all", async (event, request: IpcRequest) => { + await launcher.restoreSteamVR(); const windowManager = WindowManagerService.getInstance(); windowManager.closeAllWindows(request.args); }); ipcMain.on("close-windows", async (event, request: IpcRequest) => { + await launcher.restoreSteamVR(); const windowManager = WindowManagerService.getInstance(); windowManager.close(...request.args); }); \ No newline at end of file diff --git a/src/main/main.ts b/src/main/main.ts index 10bd4c52..d3366433 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -20,6 +20,7 @@ import { LocalMapsManagerService } from './services/additional-content/local-map import { LocalPlaylistsManagerService } from './services/additional-content/local-playlists-manager.service'; import { LocalModelsManagerService } from './services/additional-content/local-models-manager.service'; import { APP_NAME } from './constants'; +import { BSLauncherService } from './services/bs-launcher.service'; const isDebug = process.env.NODE_ENV === 'development' || process.env.DEBUG_PROD === 'true'; @@ -63,14 +64,6 @@ const initServicesMustBeInitialized = () => { // Model } -app.on('window-all-closed', () => { - // Respect the OSX convention of having the application in memory even - // after all windows have been closed - if (process.platform !== 'darwin') { - app.quit(); - } -}); - const gotTheLock = app.requestSingleInstanceLock(); if(!gotTheLock){ @@ -108,5 +101,7 @@ else{ callback(pathname); }); + BSLauncherService.getInstance().restoreSteamVR(); + }).catch(log.error); } \ No newline at end of file diff --git a/src/main/services/bs-launcher.service.ts b/src/main/services/bs-launcher.service.ts index 23bdbaac..443b4acb 100644 --- a/src/main/services/bs-launcher.service.ts +++ b/src/main/services/bs-launcher.service.ts @@ -1,12 +1,15 @@ import path from "path"; import { LaunchResult, LauchOption } from "shared/models/bs-launch"; import { UtilsService } from "./utils.service"; -import { BS_EXECUTABLE, BS_APP_ID } from "../constants"; +import { BS_EXECUTABLE, BS_APP_ID, STEAMVR_APP_ID } from "../constants"; import { ChildProcessWithoutNullStreams, spawn } from "child_process"; import { SteamService } from "./steam.service"; import { BSLocalVersionService } from "./bs-local-version.service"; import { OculusService } from "./oculus.service"; import { pathExist } from "../helpers/fs.helpers"; +import { rename } from "fs/promises"; +import log from "electron-log"; +import { timer } from "rxjs"; export class BSLauncherService{ @@ -31,6 +34,23 @@ export class BSLauncherService{ this.localVersionService = BSLocalVersionService.getInstance(); } + private getSteamVRPath(): Promise{ + return this.steamService.getGameFolder(STEAMVR_APP_ID, "SteamVR"); + } + + private async backupSteamVR(): Promise{ + const steamVrFolder = await this.getSteamVRPath(); + if(!await pathExist(steamVrFolder)){ return; } + return rename(steamVrFolder, steamVrFolder + ".bak"); + } + + public async restoreSteamVR(): Promise{ + const steamVrFolder = await this.getSteamVRPath(); + const steamVrBackup = steamVrFolder + ".bak"; + if(!await pathExist(steamVrBackup)){ return; } + return rename(steamVrFolder + ".bak", steamVrFolder); + } + public isBsRunning(): boolean{ return this.bsProcess?.connected || this.utilsService.taskRunning(BS_EXECUTABLE); } @@ -55,6 +75,19 @@ export class BSLauncherService{ launchArgs = Array.from(new Set(launchArgs).values()); + if(launchArgs.includes("fpfc")){ + await this.backupSteamVR().catch(e => { + log.error(e); + this.restoreSteamVR(); + }).finally(() => { + setTimeout(() => this.restoreSteamVR(), 20_000); + }); + await timer(2_000).toPromise(); + } + else{ + await this.restoreSteamVR(); + } + if(launchOptions.debug){ this.bsProcess = spawn(`\"${exePath}\"`, launchArgs, {shell: true, cwd, env: {...process.env, "SteamAppId": BS_APP_ID}, detached: true, windowsVerbatimArguments: true }); } @@ -62,9 +95,11 @@ export class BSLauncherService{ this.bsProcess = spawn(`\"${exePath}\"`, launchArgs, {shell: true, cwd, env: {...process.env, "SteamAppId": BS_APP_ID} }); } - this.bsProcess.on('message', msg => console.log(msg)); - this.bsProcess.on('error', err => console.log(err)); - this.bsProcess.on('exit', code => this.utilsService.ipcSend("bs-launch.exit", {data: code, success: code === 0})); + this.bsProcess.on('error', err => log.error(err)); + this.bsProcess.on('exit', code => { + this.restoreSteamVR(); + this.utilsService.ipcSend("bs-launch.exit", {data: code, success: code === 0}) + }); return "LAUNCHED"; } diff --git a/src/main/services/steam.service.ts b/src/main/services/steam.service.ts index ad6aacb6..80ec8f43 100644 --- a/src/main/services/steam.service.ts +++ b/src/main/services/steam.service.ts @@ -59,7 +59,7 @@ export class SteamService{ for(const libKey in Object.keys(libraryFolders)){ if(!libraryFolders[libKey] || !libraryFolders[libKey]["apps"]){ continue; } - if(libraryFolders[libKey]["apps"][gameId]){ return path.join(libraryFolders[libKey]["path"], "steamapps", "common", gameFolder); }; + if(libraryFolders[libKey]["apps"][gameId] != null){ return path.join(libraryFolders[libKey]["path"], "steamapps", "common", gameFolder); }; } return null; } From ec3c6ce26e01b5602adc40514172fc7d067cc83e Mon Sep 17 00:00:00 2001 From: MathieuG-P <40181755+Zagrios@users.noreply.github.com> Date: Tue, 14 Mar 2023 00:26:53 +0100 Subject: [PATCH 2/2] fix vbs regidit not find script --- src/main/main.ts | 3 --- src/main/services/bs-launcher.service.ts | 2 +- src/main/services/steam.service.ts | 27 +++++++++++++++--------- src/main/services/utils.service.ts | 2 +- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/main/main.ts b/src/main/main.ts index d3366433..04e81bb6 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -32,9 +32,6 @@ log.transports.file.resolvePath = (() => { log.catchErrors(); -const utilsService = UtilsService.getInstance(); -utilsService.setAssetsPath(app.isPackaged ? path.join(process.resourcesPath, 'assets') : path.join(__dirname, '../../assets')); - if (process.env.NODE_ENV === 'production') { const sourceMapSupport = require('source-map-support'); sourceMapSupport.install(); diff --git a/src/main/services/bs-launcher.service.ts b/src/main/services/bs-launcher.service.ts index 443b4acb..2e36a730 100644 --- a/src/main/services/bs-launcher.service.ts +++ b/src/main/services/bs-launcher.service.ts @@ -80,7 +80,7 @@ export class BSLauncherService{ log.error(e); this.restoreSteamVR(); }).finally(() => { - setTimeout(() => this.restoreSteamVR(), 20_000); + setTimeout(() => this.restoreSteamVR(), 35_000); }); await timer(2_000).toPromise(); } diff --git a/src/main/services/steam.service.ts b/src/main/services/steam.service.ts index 80ec8f43..0f1cf7db 100644 --- a/src/main/services/steam.service.ts +++ b/src/main/services/steam.service.ts @@ -5,6 +5,7 @@ import { parse } from "@node-steam/vdf"; import { readFile } from "fs/promises"; import { spawn } from "child_process"; import { pathExist } from "../helpers/fs.helpers"; +import log from "electron-log"; export class SteamService{ @@ -47,21 +48,27 @@ export class SteamService{ } public async getGameFolder(gameId: string, gameFolder?: string): Promise{ - const steamPath = await this.getSteamPath(); + try{ + const steamPath = await this.getSteamPath(); - let libraryFolders: any = path.join(steamPath, 'steamapps', 'libraryfolders.vdf'); + let libraryFolders: any = path.join(steamPath, 'steamapps', 'libraryfolders.vdf'); - if(!(await pathExist(libraryFolders))){ return null; } - libraryFolders = parse(await readFile(libraryFolders, {encoding: 'utf-8'})); + if(!(await pathExist(libraryFolders))){ return null; } + libraryFolders = parse(await readFile(libraryFolders, {encoding: 'utf-8'})); - if(!libraryFolders.libraryfolders){ return null; } - libraryFolders = libraryFolders.libraryfolders + if(!libraryFolders.libraryfolders){ return null; } + libraryFolders = libraryFolders.libraryfolders - for(const libKey in Object.keys(libraryFolders)){ - if(!libraryFolders[libKey] || !libraryFolders[libKey]["apps"]){ continue; } - if(libraryFolders[libKey]["apps"][gameId] != null){ return path.join(libraryFolders[libKey]["path"], "steamapps", "common", gameFolder); }; + for(const libKey in Object.keys(libraryFolders)){ + if(!libraryFolders[libKey] || !libraryFolders[libKey]["apps"]){ continue; } + if(libraryFolders[libKey]["apps"][gameId] != null){ return path.join(libraryFolders[libKey]["path"], "steamapps", "common", gameFolder); }; + } + return null; + } + catch(e){ + log.error(e); + return null; } - return null; } public openSteam(): Promise{ diff --git a/src/main/services/utils.service.ts b/src/main/services/utils.service.ts index 462e0158..2bc862c2 100644 --- a/src/main/services/utils.service.ts +++ b/src/main/services/utils.service.ts @@ -12,7 +12,7 @@ export class UtilsService{ private static instance: UtilsService; - private assetsPath: string = ''; + private assetsPath: string = app.isPackaged ? path.join(process.resourcesPath, 'assets') : path.join(__dirname, '../../../assets'); private windows: Map = new Map();