[feature] Can now launch a bs version from cmd + fix some bugs + some code cleaning

This commit is contained in:
MathieuG-P
2023-06-30 21:00:02 +02:00
parent 6eb3f75e9d
commit 943118538d
19 changed files with 253 additions and 206 deletions
+8
View File
@@ -557,5 +557,13 @@
"ReleaseImg": "https://clan.akamai.steamstatic.com/images/32055887/6d78e092c54f411b36f2c0577d62eb1b25f91aa3.png",
"ReleaseDate": "1686668364",
"year": "2023"
},
{
"BSVersion": "1.31.0",
"BSManifest": "676582354127623831",
"ReleaseURL": "https://steamcommunity.com/games/620980/announcements/detail/3674423070127121445",
"ReleaseImg": "https://clan.cloudflare.steamstatic.com/images/32055887/28993aecc56a75c52295fa07620f58cb0e4b09e8.png",
"ReleaseDate": "1688050646",
"year": "2023"
}
]
+1
View File
@@ -353,6 +353,7 @@
"EXIT": "Abrupter Stop"
},
"msg": {
"UNKNOWN_ERROR": "Ein unbekannter Fehler ist aufgetreten.",
"STEAM_NOT_RUNNING": "Steam muss laufen, um BeatSaber zu starten.",
"OCULUS_NOT_RUNNING": "Oculus muss ausgeführt werden, um BeatSaber zu starten.",
"BS_ALREADY_RUNNING": "Schließe BeatSaber, bevor Du es erneut startest.",
+1
View File
@@ -353,6 +353,7 @@
"EXIT": "Abrupt stop"
},
"msg": {
"UNKNOWN_ERROR": "An unknown error has occurred.",
"STEAM_NOT_RUNNING": "Steam must be running to launch BeatSaber.",
"OCULUS_NOT_RUNNING": "Oculus must be running to launch BeatSaber.",
"BS_ALREADY_RUNNING": "Close BeatSaber before launching it again.",
+1
View File
@@ -352,6 +352,7 @@
"EXIT": "Parada abrupta"
},
"msg": {
"UNKNOWN_ERROR": "Se ha producido un error desconocido.",
"STEAM_NOT_RUNNING": "Para iniciar BeatSaber es necesario que Steam esté en funcionamiento.",
"OCULUS_NOT_RUNNING": "Oculus debe estar funcionando para lanzar BeatSaber.",
"BS_ALREADY_RUNNING": "Cierra BeatSaber antes de volver a lanzarlo.",
+2 -1
View File
@@ -339,7 +339,7 @@
},
"msg": {
"BS_LAUNCHING": "N'oublie pas de t'échauffer 😉",
"STEAM_LAUNCHING": "Beat Saber se lancera automatiquement après Steam"
"STEAM_LAUNCHING": "Beat Saber se lancera automatiquement après Steam."
}
},
"errors": {
@@ -352,6 +352,7 @@
"EXIT": "Arrêt brutal"
},
"msg": {
"UNKNOWN_ERROR": "Une erreur inconnue s'est produite.",
"STEAM_NOT_RUNNING": "Steam doit être en cours d'exécution pour lancer Beat Saber.",
"OCULUS_NOT_RUNNING": "Oculus doit être en cours d'exécution pour lancer Beat Saber.",
"BS_ALREADY_RUNNING": "Ferme Beat Saber avant de le lancer à nouveau.",
+7 -24
View File
@@ -27,7 +27,6 @@
"md5-file": "^5.0.0",
"node-fetch": "^2.6.7",
"node-stream-zip": "^1.15.0",
"ps-list": "^7.2.0",
"react": "^18.2.0",
"react-colorful": "^5.6.1",
"react-dom": "^18.2.0",
@@ -81,7 +80,7 @@
"css-loader": "^6.7.1",
"css-minimizer-webpack-plugin": "^4.1.0",
"detect-port": "^1.3.0",
"electron": "^25.2.0",
"electron": "^24.3.1",
"electron-builder": "^24.4.0",
"electron-devtools-installer": "^3.2.0",
"electron-notarize": "^1.2.1",
@@ -6561,9 +6560,9 @@
}
},
"node_modules/electron": {
"version": "25.2.0",
"resolved": "https://registry.npmjs.org/electron/-/electron-25.2.0.tgz",
"integrity": "sha512-I/rhcW2sV2fyiveVSBr2N7v5ZiCtdGY0UiNCDZgk2fpSC+irQjbeh7JT2b4vWmJ2ogOXBjqesrN9XszTIG6DHg==",
"version": "24.6.1",
"resolved": "https://registry.npmjs.org/electron/-/electron-24.6.1.tgz",
"integrity": "sha512-SXbRtatpvBqtOwlOiEbaI47Repspz5a/qoaNZ+GB3DLhi9Z0r28t14pu+a9nXgX5tXj8lOfN8D9wmwVYdo4TAg==",
"dev": true,
"hasInstallScript": true,
"dependencies": {
@@ -14861,17 +14860,6 @@
"node": ">= 0.10"
}
},
"node_modules/ps-list": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/ps-list/-/ps-list-7.2.0.tgz",
"integrity": "sha512-v4Bl6I3f2kJfr5o80ShABNHAokIgY+wFDTQfE+X3zWYgSGQOCBeYptLZUpoOALBqO5EawmDN/tjTldJesd0ujQ==",
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/ps-scrollbar-tailwind": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/ps-scrollbar-tailwind/-/ps-scrollbar-tailwind-0.0.1.tgz",
@@ -23797,9 +23785,9 @@
}
},
"electron": {
"version": "25.2.0",
"resolved": "https://registry.npmjs.org/electron/-/electron-25.2.0.tgz",
"integrity": "sha512-I/rhcW2sV2fyiveVSBr2N7v5ZiCtdGY0UiNCDZgk2fpSC+irQjbeh7JT2b4vWmJ2ogOXBjqesrN9XszTIG6DHg==",
"version": "24.6.1",
"resolved": "https://registry.npmjs.org/electron/-/electron-24.6.1.tgz",
"integrity": "sha512-SXbRtatpvBqtOwlOiEbaI47Repspz5a/qoaNZ+GB3DLhi9Z0r28t14pu+a9nXgX5tXj8lOfN8D9wmwVYdo4TAg==",
"dev": true,
"requires": {
"@electron/get": "^2.0.0",
@@ -30001,11 +29989,6 @@
}
}
},
"ps-list": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/ps-list/-/ps-list-7.2.0.tgz",
"integrity": "sha512-v4Bl6I3f2kJfr5o80ShABNHAokIgY+wFDTQfE+X3zWYgSGQOCBeYptLZUpoOALBqO5EawmDN/tjTldJesd0ujQ=="
},
"ps-scrollbar-tailwind": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/ps-scrollbar-tailwind/-/ps-scrollbar-tailwind-0.0.1.tgz",
-1
View File
@@ -248,7 +248,6 @@
"md5-file": "^5.0.0",
"node-fetch": "^2.6.7",
"node-stream-zip": "^1.15.0",
"ps-list": "^7.2.0",
"react": "^18.2.0",
"react-colorful": "^5.6.1",
"react-dom": "^18.2.0",
+35 -2
View File
@@ -1,13 +1,46 @@
{
"name": "bs-manager",
"version": "1.1.1",
"lockfileVersion": 1,
"version": "1.2.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "bs-manager",
"version": "1.2.0",
"hasInstallScript": true,
"license": "MIT",
"dependencies": {
"ctrlc-windows": "^2.1.0",
"ps-list": "^7.2.0"
}
},
"node_modules/ctrlc-windows": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/ctrlc-windows/-/ctrlc-windows-2.1.0.tgz",
"integrity": "sha512-OrX5KI+K+2NMN91QIhYZdW7VDO2YsSdTZW494pA7Nvw/wBdU2hz+MGP006bR978zOTrG6Q8EIeJvLJmLqc6MsQ=="
},
"node_modules/ps-list": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/ps-list/-/ps-list-7.2.0.tgz",
"integrity": "sha512-v4Bl6I3f2kJfr5o80ShABNHAokIgY+wFDTQfE+X3zWYgSGQOCBeYptLZUpoOALBqO5EawmDN/tjTldJesd0ujQ==",
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
}
},
"dependencies": {
"ctrlc-windows": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/ctrlc-windows/-/ctrlc-windows-2.1.0.tgz",
"integrity": "sha512-OrX5KI+K+2NMN91QIhYZdW7VDO2YsSdTZW494pA7Nvw/wBdU2hz+MGP006bR978zOTrG6Q8EIeJvLJmLqc6MsQ=="
},
"ps-list": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/ps-list/-/ps-list-7.2.0.tgz",
"integrity": "sha512-v4Bl6I3f2kJfr5o80ShABNHAokIgY+wFDTQfE+X3zWYgSGQOCBeYptLZUpoOALBqO5EawmDN/tjTldJesd0ujQ=="
}
}
}
+2 -1
View File
@@ -14,7 +14,8 @@
"postinstall": "npm run electron-rebuild && npm run link-modules"
},
"dependencies": {
"ctrlc-windows": "^2.1.0"
"ctrlc-windows": "^2.1.0",
"ps-list": "^7.2.0"
},
"license": "MIT"
}
+2 -15
View File
@@ -1,25 +1,12 @@
import { ipcMain } from 'electron';
import { UtilsService } from '../services/utils.service'
import { LaunchOption } from "shared/models/bs-launch";
import { BSLauncherService } from "../services/bs-launcher.service"
import { IpcRequest } from 'shared/models/ipc';
import { BsmException } from 'shared/models/bsm-exception.model';
import { IpcService } from '../services/ipc.service';
// ipcMain.on('bs-launch.launch', (event, request: IpcRequest<LauchOption>) => {
// const launcherService = BSLauncherService.getInstance();
// const utilsService = UtilsService.getInstance();
// launcherService.launch(request.args).then(res => {
// utilsService.ipcSend(request.responceChannel, {success: true, data: res});
// }).catch((err: BsmException) => {
// utilsService.ipcSend(request.responceChannel, {success: false, error: err});
// })
// });
const ipc = IpcService.getInstance();
ipc.on('bs-launch.launch', async (req: IpcRequest<LaunchOption>, reply) => {
const bsLauncher = BSLauncherService.getInstance();
reply(bsLauncher.launchV2(req.args));
reply(bsLauncher.launch(req.args));
});
+5 -2
View File
@@ -58,7 +58,8 @@ const initServicesMustBeInitialized = () => {
LocalMapsManagerService.getInstance();
LocalPlaylistsManagerService.getInstance();
LocalModelsManagerService.getInstance();
// Model
BSLauncherService.getInstance();
}
const gotTheLock = app.requestSingleInstanceLock();
@@ -79,10 +80,12 @@ else{
});
app.whenReady().then(() => {
app.setAppUserModelId(APP_NAME);
initServicesMustBeInitialized();
//DeepLinkService.getInstance().dispatchLinkOpened("bsmanager://launch/?launchOptions=%7B%22debug%22%3Afalse%2C%22oculus%22%3Atrue%2C%22desktop%22%3Atrue%2C%22version%22%3A%7B%22BSVersion%22%3A%221.29.0%22%2C%22BSManifest%22%3A%223341527958186345367%22%2C%22ReleaseURL%22%3A%22https%3A%2F%2Fsteamcommunity.com%2Fgames%2F620980%2Fannouncements%2Fdetail%2F6169409105082976092%22%2C%22ReleaseImg%22%3A%22https%3A%2F%2Fcdn.cloudflare.steamstatic.com%2Fsteamcommunity%2Fpublic%2Fimages%2Fclans%2F%2F32055887%2F255fd49cd96042b97089f754609be291293e783f.png%22%2C%22ReleaseDate%22%3A%221680188760%22%2C%22year%22%3A%222023%22%2C%22name%22%3A%221.29.0+%281%29%22%7D%7D");
const deepLink = process.argv.find(arg => DeepLinkService.getInstance().isDeepLink(arg));
+27 -79
View File
@@ -1,5 +1,5 @@
import path from "path";
import { LaunchResult, LaunchOption, BSLaunchEvent, BSLaunchErrorEvent, BSLaunchErrorType, BSLaunchEventType } from "../../shared/models/bs-launch";
import { LaunchOption, BSLaunchEvent, BSLaunchErrorEvent, BSLaunchErrorType, BSLaunchEventType } from "../../shared/models/bs-launch";
import { UtilsService } from "./utils.service";
import { BS_EXECUTABLE, BS_APP_ID, STEAMVR_APP_ID } from "../constants";
import { ChildProcessWithoutNullStreams, SpawnOptionsWithoutStdio, spawn } from "child_process";
@@ -10,8 +10,8 @@ import { pathExist } from "../helpers/fs.helpers";
import { rename } from "fs/promises";
import log from "electron-log";
import { Observable, lastValueFrom, timer } from "rxjs";
import { NotificationService } from "./notification.service";
import { NotificationType } from "../../shared/models/notification/notification.model";
import { BsmProtocolService } from "./bsm-protocol.service";
import { URL } from "url";
export class BSLauncherService{
@@ -21,7 +21,7 @@ export class BSLauncherService{
private readonly steamService: SteamService;
private readonly oculusService: OculusService;
private readonly localVersionService: BSLocalVersionService;
private readonly notification: NotificationService;
private readonly bsmProtocolService: BsmProtocolService;
private bsProcess: ChildProcessWithoutNullStreams;
@@ -35,7 +35,13 @@ export class BSLauncherService{
this.steamService = SteamService.getInstance();
this.oculusService = OculusService.getInstance();
this.localVersionService = BSLocalVersionService.getInstance();
this.notification = NotificationService.getInstance();
this.bsmProtocolService = BsmProtocolService.getInstance();
this.bsmProtocolService.on("launch", link => {
log.info("Launch from bsm protocol", link.toString());
if(!link.searchParams.has("launchOptions")){ return; }
this.launch(JSON.parse(link.searchParams.get("launchOptions"))).subscribe();
});
}
private getSteamVRPath(): Promise<string>{
@@ -56,69 +62,7 @@ export class BSLauncherService{
}
public async isBsRunning(): Promise<boolean> {
return this.bsProcess?.connected || await this.utilsService.taskRunning(BS_EXECUTABLE) === true;
}
// TODO : Rework with shortcuts implementation
public async launch(launchOptions: LaunchOption): Promise<LaunchResult>{
if(await this.isBsRunning() === true){ return "BS_ALREADY_RUNNING" }
if(launchOptions.version.oculus && await this.oculusService.oculusRunning() === false){ return "OCULUS_NOT_RUNNING" }
const steamRunning = await this.steamService.steamRunning().catch(() => true); // True if error (error not not means that steam is not running)
if(!launchOptions.version.oculus && !steamRunning){
this.notification.notifyRenderer({
title: "notifications.steam.steam-launching.title",
desc: "notifications.steam.steam-launching.description",
type: NotificationType.SUCCESS,
});
await this.steamService.openSteam().catch(log.error);
}
const cwd = await this.localVersionService.getVersionPath(launchOptions.version);
const exePath = path.join(cwd, BS_EXECUTABLE);
if(!(await pathExist(exePath))){ return "EXE_NOT_FINDED"; }
let launchArgs = [];
if(!launchOptions.version.steam && !launchOptions.version.oculus){ launchArgs.push("--no-yeet"); }
if(launchOptions.oculus){ launchArgs.push("-vrmode oculus"); }
if(launchOptions.desktop){ launchArgs.push("fpfc"); }
if(launchOptions.debug){ launchArgs.push("--verbose"); }
if(launchOptions.additionalArgs){ launchArgs.push(...launchOptions.additionalArgs); }
launchArgs = Array.from(new Set(launchArgs).values());
let restoreTimout: NodeJS.Timeout;
if(launchArgs.includes("fpfc")){
await this.backupSteamVR().catch(() => {
this.restoreSteamVR();
}).finally(() => {
restoreTimout = setTimeout(() => this.restoreSteamVR(), 35_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 });
}
else{
this.bsProcess = spawn(`\"${exePath}\"`, launchArgs, {shell: true, cwd, env: {...process.env, "SteamAppId": BS_APP_ID} });
}
this.bsProcess.on('error', err => log.error(err));
this.bsProcess.on('exit', code => {
this.restoreSteamVR().finally(() => clearTimeout(restoreTimout));
this.utilsService.ipcSend("bs-launch.exit", {data: code, success: code === 0})
});
return "LAUNCHED";
return this.utilsService.taskRunning(BS_EXECUTABLE);
}
private buildBsLaunchArgs(launchOptions: LaunchOption){
@@ -160,18 +104,23 @@ export class BSLauncherService{
}
public launchV2(launchOptions: LaunchOption): Observable<BSLaunchEvent>{
public launch(launchOptions: LaunchOption): Observable<BSLaunchEvent>{
// const t = new URL("bsmanager://launch");
// t.searchParams.set("launchOptions", JSON.stringify(launchOptions));
// console.log(t.toString());
return new Observable<BSLaunchEvent>(obs => {(async () => {
if(this.isBsRunning()){
if(await this.isBsRunning()){
return obs.error({type: BSLaunchErrorType.BS_ALREADY_RUNNING} as BSLaunchErrorEvent);
}
if(launchOptions.version.oculus && (await this.oculusService.oculusRunning()) === false){
if(launchOptions.version.oculus && (await this.oculusService.oculusRunning())){
return obs.error({type: BSLaunchErrorType.OCULUS_NOT_RUNNING} as BSLaunchErrorEvent);
}
const bsFolderPath = await this.localVersionService.getVersionPath(launchOptions.version);
const bsFolderPath = await this.localVersionService.getInstalledVersionPath(launchOptions.version);
const exePath = path.join(bsFolderPath, BS_EXECUTABLE);
if(!(await pathExist(exePath))){
@@ -187,8 +136,7 @@ export class BSLauncherService{
// Backup SteamVR when desktop mode is enabled
if(!launchOptions.version.oculus && launchOptions.desktop){
await this.backupSteamVR().catch(e => {
log.error("ERR_BACKUP_STEAM_VR", e);
this.restoreSteamVR();
return this.restoreSteamVR();
});
await lastValueFrom(timer(2_000));
} else if(!launchOptions.version.oculus){
@@ -197,17 +145,17 @@ export class BSLauncherService{
const launchArgs = this.buildBsLaunchArgs(launchOptions);
obs.next({type: BSLaunchEventType.BS_LAUNCHING}); // Add BS_FORCE_LAUNCH when steam not succeded to launch
obs.next({type: BSLaunchEventType.BS_LAUNCHING});
await this.launchBSProcess(exePath, launchArgs, launchOptions.debug).catch(() => {
obs.error({type: BSLaunchErrorType.BS_EXIT_ERROR} as BSLaunchErrorEvent);
await this.launchBSProcess(exePath, launchArgs, launchOptions.debug).catch(err => {
obs.error({type: BSLaunchErrorType.BS_EXIT_ERROR, data: err} as BSLaunchErrorEvent);
}).finally(() => {
if(!launchOptions.desktop || launchOptions.version.oculus){ return; }
this.restoreSteamVR().catch(e => log.error("ERR_RESTORE_STEAM_VR", e));
this.restoreSteamVR();
});
})().then(() => {
obs.complete()
obs.complete();
}).catch(err => {
obs.error({type: BSLaunchErrorType.UNKNOWN_ERROR, data: err} as BSLaunchErrorEvent);
})});
+81 -42
View File
@@ -6,7 +6,7 @@ import { BS_APP_ID, OCULUS_BS_DIR } from "../constants";
import path from "path";
import { createReadStream } from "fs";
import { ConfigurationService } from "./configuration.service";
import { rename } from "fs/promises";
import { lstat, rename } from "fs/promises";
import { BsmException } from "shared/models/bsm-exception.model";
import log from "electron-log";
import { OculusService } from "./oculus.service";
@@ -44,36 +44,41 @@ export class BSLocalVersionService{
public async getVersionOfBSFolder(bsPath: string): Promise<PartialBSVersion>{
const versionFilePath = path.join(bsPath, 'Beat Saber_Data', 'globalgamemanagers');
if(!(await pathExist(versionFilePath))){ return null; }
const versionsAvailable = await this.remoteVersionService.getAvailableVersions();
return new Promise<PartialBSVersion>(resolve => {
const stream = createReadStream(versionFilePath);
let findVersion: PartialBSVersion = null;
stream.on('data', (line) => {
line = line.toString();
for(const version of versionsAvailable){
if(line.includes(version.BSVersion)){
findVersion = {BSVersion: version.BSVersion};
public async getVersionOfBSFolder(bsPath: string): Promise<PartialBSVersion>{
const versionFilePath = path.join(bsPath, 'Beat Saber_Data', 'globalgamemanagers');
if(!(await pathExist(versionFilePath))){ return null; }
const versionsAvailable = await this.remoteVersionService.getAvailableVersions();
return new Promise<PartialBSVersion>(async resolve => {
const stream = createReadStream(versionFilePath);
stream.on('data', async line => {
line = line.toString();
for(const version of versionsAvailable){
if(!line.includes(version.BSVersion)){ continue; }
const findVersion: PartialBSVersion = {BSVersion: version.BSVersion};
if(findVersion.BSVersion !== path.basename(bsPath)){
findVersion.name = path.basename(bsPath);
}
const folderStats = await lstat(bsPath);
if(folderStats.ino){
findVersion.ino = folderStats.ino;
}
stream.close();
stream.destroy();
break;
return resolve(findVersion);
}
}
});
stream.on('end', () => {
if(findVersion){ resolve(findVersion) }
resolve(findVersion);
});
stream.on('close', () => {
if(findVersion){ resolve(findVersion) }
resolve(findVersion);
})
})
});
});
}
private setCustomVersions(versions: BSVersion[]): void{
@@ -93,14 +98,42 @@ export class BSLocalVersionService{
this.setCustomVersions(customVersions.filter(v => (v.name !== version.name || v.BSVersion !== version.BSVersion || v.color !== version.color)));
}
public async getVersionPath(version: BSVersion): Promise<string>{
if(version.steam){ return this.steamService.getGameFolder(BS_APP_ID, "Beat Saber") }
if(version.oculus){ return this.oculusService.getGameFolder(OCULUS_BS_DIR); }
return path.join(
this.installLocationService.versionsDirectory,
this.getVersionFolder(version)
);
}
/**
* Return path of a version even if it's not installed.
* @param {BSVersion} version
* @returns {Promise<string>}
*/
public async getVersionPath(version: BSVersion): Promise<string>{
if(version.steam){ return this.steamService.getGameFolder(BS_APP_ID, "Beat Saber") }
if(version.oculus){ return this.oculusService.getGameFolder(OCULUS_BS_DIR); }
return path.join(
this.installLocationService.versionsDirectory,
this.getVersionFolder(version)
);
}
/**
* Return path of an installed version. Returns null if not found.
* @param {BSVersion} version
* @returns {Promise<string>}
*/
public async getInstalledVersionPath(version: BSVersion): Promise<string>{
const versionPath = await this.getVersionPath(version);
if(await pathExist(versionPath)){ return versionPath; }
const versionFolders = await getFoldersInFolder(this.installLocationService.versionsDirectory);
for(const folder of versionFolders){
const stats = await lstat(folder);
if(stats.ino === version.ino){
return folder;
}
}
return null;
}
private removeSpecialChar(seq: string): string{
return sanitize(seq);
@@ -131,6 +164,7 @@ export class BSLocalVersionService{
const oculusBsFolder = await this.oculusService.getGameFolder(OCULUS_BS_DIR);
if(!oculusBsFolder){ return null; }
const oculusBsVersion = await this.getVersionOfBSFolder(oculusBsFolder);
if(!oculusBsVersion){ return null; }
const version = await this.remoteVersionService.getVersionDetails(oculusBsVersion.BSVersion);
if(!version){ return null; }
@@ -154,9 +188,13 @@ export class BSLocalVersionService{
for(const f of folderInInstallation){
log.info("try get version from folder", f);
const rawVersion = await this.getVersionOfBSFolder(f);
if(!rawVersion){ continue; }
const bsVersion = {...await this.remoteVersionService.getVersionDetails(rawVersion.BSVersion)};
if(!bsVersion){ continue; }
bsVersion.name = path.basename(f) !== bsVersion.BSVersion ? path.basename(f) : undefined;
const customVersion = this.getCustomVersions().find(custom => custom.BSVersion === bsVersion.BSVersion && custom.name === bsVersion.name);
@@ -167,20 +205,21 @@ export class BSLocalVersionService{
versions.push(bsVersion);
};
this.setCustomVersions(versions.filter(v => !!v.color));
return versions;
}
}
public async deleteVersion(version: BSVersion): Promise<boolean>{
if(version.steam || version.oculus){ return false; }
const versionFolder = await this.getVersionPath(version);
if(!(await pathExist(versionFolder))){ return true; }
public async deleteVersion(version: BSVersion): Promise<boolean>{
if(version.steam || version.oculus){ return false; }
const versionFolder = await this.getVersionPath(version);
if(!(await pathExist(versionFolder))){ return true; }
return deleteFolder(versionFolder)
.then(() => { return true; })
.catch(() => { return false; })
}
return deleteFolder(versionFolder)
.then(() => { return true; })
.catch(() => { return false; })
}
public async editVersion(version: BSVersion, name: string, color: string): Promise<BSVersion>{
if(version.steam || version.oculus){ throw {title: "CantEditSteam", message: "CantEditSteam"} as BsmException; }
+41
View File
@@ -0,0 +1,41 @@
import { Subject, Subscription, filter } from "rxjs";
import { DeepLinkService } from "./deep-link.service";
import { URL } from "url";
import { isValidUrl } from "../../shared/helpers/url.helpers";
export class BsmProtocolService {
private static instance: BsmProtocolService;
public static getInstance(): BsmProtocolService{
if(!BsmProtocolService.instance){ BsmProtocolService.instance = new BsmProtocolService(); }
return BsmProtocolService.instance;
}
private readonly BSM_PROTOCOL = "bsmanager";
private readonly deepLink: DeepLinkService;
private linkeReceived$ = new Subject<URL>();
private constructor(){
this.deepLink = DeepLinkService.getInstance();
this.registerBsmProtocol();
this.deepLink.addLinkOpenedListener(this.BSM_PROTOCOL, link => {
if(!isValidUrl(link)){ return; }
this.linkeReceived$.next(new URL(link));
});
}
private registerBsmProtocol(): boolean{
if(this.deepLink.isDeepLinkRegistred(this.BSM_PROTOCOL)){ return true; }
return this.deepLink.registerDeepLink(this.BSM_PROTOCOL);
}
public on(host: string, listener: (link: URL) => void): Subscription {
return this.linkeReceived$.pipe(filter(link => link.host === host)).subscribe(listener);
}
}
+1 -1
View File
@@ -69,7 +69,7 @@ export class DeepLinkService {
public dispatchLinkOpened(link: string){
log.info("DEISPATCH", link);
log.info("DISPATCH", link);
const url = new URL(link);
+35 -34
View File
@@ -27,47 +27,48 @@ export class SteamService{
return SteamService.instance;
}
public async getActiveUser(): Promise<number>{
const res = await regedit.promisified.list(["HKCU\\Software\\Valve\\Steam\\ActiveProcess"]);
const keys = res?.["HKCU\\Software\\Valve\\Steam\\ActiveProcess"];
if(!keys?.exists){ throw "Key \"HKCU\\Software\\Valve\\Steam\\ActiveProcess\" not exist"; }
return (keys.values?.ActiveUser.value || undefined) as number;
}
public async steamRunning(): Promise<boolean>{
if (process.platform === 'win32') {
return !!(await this.getActiveUser());
public async getActiveUser(): Promise<number>{
const res = await regedit.promisified.list(["HKCU\\Software\\Valve\\Steam\\ActiveProcess"]);
const keys = res?.["HKCU\\Software\\Valve\\Steam\\ActiveProcess"];
if(!keys?.exists){ throw "Key \"HKCU\\Software\\Valve\\Steam\\ActiveProcess\" not exist"; }
return (keys.values?.ActiveUser.value || undefined) as number;
}
public async steamRunning(): Promise<boolean>{
const steamProcessRunning = await this.utils.taskRunning("steam");
if(process.platform === "linux") { return steamProcessRunning; }
return steamProcessRunning && !!(await this.getActiveUser());
}
return await psList()
.then(processes => !!processes.find(process => process.cmd.includes('steam')))
.catch(e => {log.error(e); throw e})
}
public async getSteamPath(): Promise<string>{
if(this.steamPath){ return this.steamPath; }
if(this.steamPath){ return this.steamPath; }
switch (process.platform) {
case "linux":
this.steamPath = path.join(app.getPath('home'), '.steam', "steam");
return this.steamPath;
case "win32":
const [win32Res, win64Res] = await Promise.all([
regedit.promisified.list(['HKLM\\SOFTWARE\\Valve\\Steam']),
regedit.promisified.list(['HKLM\\SOFTWARE\\WOW6432Node\\Valve\\Steam'])
]);
switch (process.platform) {
case "linux":
this.steamPath = path.join(app.getPath('home'), '.steam', "steam");
return this.steamPath;
case "win32":
const [win32Res, win64Res] = await Promise.all([
regedit.promisified.list(['HKLM\\SOFTWARE\\Valve\\Steam']),
regedit.promisified.list(['HKLM\\SOFTWARE\\WOW6432Node\\Valve\\Steam'])
]);
const [win32, win64] = [win32Res["HKLM\\SOFTWARE\\Valve\\Steam"], win64Res["HKLM\\SOFTWARE\\WOW6432Node\\Valve\\Steam"]];
const [win32, win64] = [win32Res["HKLM\\SOFTWARE\\Valve\\Steam"], win64Res["HKLM\\SOFTWARE\\WOW6432Node\\Valve\\Steam"]];
let res = '';
if(win64.exists && win64?.values?.InstallPath?.value){ res = win64.values.InstallPath.value as string; }
else if(win32.exists && win32?.values?.InstallPath?.value){ res = win32.values.InstallPath.value as string; }
this.steamPath = res;
return res;
default:
return null;
if(win64.exists && win64?.values?.InstallPath?.value){
this.steamPath = win64.values.InstallPath.value as string;
}
else if (win32.exists && win32?.values?.InstallPath?.value){
this.steamPath = win32.values.InstallPath.value as string;
}
return this.steamPath;
default:
return null;
}
}
}
public async getGameFolder(gameId: string, gameFolder?: string): Promise<string>{
try{
@@ -105,7 +106,7 @@ export class SteamService{
if(!steamRunning){ return; }
clearInterval(interval);
resolve();
}, 3000);
}, 4000);
// If steam is not running after 60 seconds, reject
setTimeout(() => {
+1 -2
View File
@@ -1,4 +1,3 @@
import { spawnSync } from "child_process";
import path from "path";
import { app, BrowserWindow } from "electron";
import { IpcResponse } from "shared/models/ipc";
@@ -37,7 +36,7 @@ export class UtilsService{
public async taskRunning(task: string): Promise<boolean> {
try{
const processes = await psList();
return !!processes.find(process => process.cmd.includes(task));
return processes.some(process => process.name?.includes(task) || process.cmd?.includes(task));
}
catch(error){
log.error(error);
+2 -2
View File
@@ -77,8 +77,8 @@ export class BSLauncherService{
this.notificationService.notifySuccess({title: `notifications.bs-launch.success.titles.${event.type}`, desc: `notifications.bs-launch.success.msg.${event.type}`});
},
error: (err: BSLaunchErrorEvent) => {
if(err.type === BSLaunchErrorType.UNKNOWN_ERROR || !Object.values(BSLaunchErrorType).includes(err.type)){
this.notificationService.notifyError({title: "notifications.bs-launch.errors.titles.UNABLE_TO_LAUNCH"});
if(!Object.values(BSLaunchErrorType).includes(err.type)){
this.notificationService.notifyError({title: "notifications.bs-launch.errors.titles.UNKNOWN_ERROR", desc: "notifications.bs-launch.errors.msg.UNKNOWN_ERROR"});
} else {
this.notificationService.notifyError({title: `notifications.bs-launch.errors.titles.${err.type}`, desc: `notifications.bs-launch.errors.msg.${err.type}`})
}
+1
View File
@@ -1,6 +1,7 @@
export interface PartialBSVersion {
BSVersion: string,
name?: string
ino?: number,
}
export interface BSVersion extends PartialBSVersion {