From 0fa298bc095dcd21b4554e4220dee2d6493ad8be Mon Sep 17 00:00:00 2001 From: MathieuG-P <40181755+Zagrios@users.noreply.github.com> Date: Fri, 17 Nov 2023 21:02:55 +0100 Subject: [PATCH 1/2] [chore] add logs for installed versions detection --- src/main/services/bs-local-version.service.ts | 48 ++++++++++++------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/src/main/services/bs-local-version.service.ts b/src/main/services/bs-local-version.service.ts index c15d646f..d58dbe05 100644 --- a/src/main/services/bs-local-version.service.ts +++ b/src/main/services/bs-local-version.service.ts @@ -11,9 +11,9 @@ import log from "electron-log"; import { OculusService } from "./oculus.service"; import { DownloadLinkType } from "shared/models/mods"; import sanitize from "sanitize-filename"; -import { Progression, copyDirectoryWithJunctions, deleteFolder, ensurePathNotAlreadyExist, getFoldersInFolder, pathExist, rxCopy } from "../helpers/fs.helpers"; +import { Progression, copyDirectoryWithJunctions, deleteFolder, ensurePathNotAlreadyExist, getFoldersInFolder, rxCopy } from "../helpers/fs.helpers"; import { FolderLinkerService } from "./folder-linker.service"; -import { ReadStream, createReadStream, readFile, writeFile } from "fs-extra"; +import { ReadStream, createReadStream, pathExists, readFile, writeFile } from "fs-extra"; import readline from "readline"; import { Observable, Subject, catchError, finalize, from, map, switchMap, throwError } from "rxjs"; import { BsStore } from "../../shared/models/bs-store.enum"; @@ -53,7 +53,10 @@ export class BSLocalVersionService { private async getVersionFromGlobalGameManagerFile(versionFilePath: string): Promise { - if(!(await pathExist(versionFilePath))){ return null; } + if(!(await pathExists(versionFilePath))){ + log.info("globalgamemanagers file not found", versionFilePath); + return null; + } const versionsDict = await this.remoteVersionService.getAvailableVersions(); @@ -81,6 +84,8 @@ export class BSLocalVersionService { stream?.close(); } + log.info("unable to get version from globalgamemanagers file", versionFilePath); + return null; } @@ -92,6 +97,8 @@ export class BSLocalVersionService { } ): Promise{ + log.info("getVersionOfBSFolder", bsPath, options); + if(!bsPath){ return null; } const versionFilePath = path.join(bsPath, 'Beat Saber_Data', 'globalgamemanagers'); @@ -129,7 +136,7 @@ export class BSLocalVersionService { const contents = await readFile(path.join(versionPath, this.METADATA_FILE), "utf-8"); return JSON.parse(contents); })().catch(e => { - log.warn(e); + log.warn("Not a critical error", e); return {}; }).then(metadata => ({...defaultMetadata, ...metadata})); } @@ -139,7 +146,7 @@ export class BSLocalVersionService { const metadata = await this.getAllVersionMetadata(version); return metadata?.[key]; })().catch(e => { - log.warn(e); + log.warn("Not a critical error", e); return null; }).then(value => (value ?? defaultValue) as T); } @@ -196,7 +203,7 @@ export class BSLocalVersionService { */ public async getInstalledVersionPath(version: BSVersion): Promise{ const versionPath = await this.getVersionPath(version); - if(await pathExist(versionPath)){ return versionPath; } + if(await pathExists(versionPath)){ return versionPath; } const versionFolders = await getFoldersInFolder(await this.installLocationService.versionsDirectory()); @@ -227,7 +234,7 @@ export class BSLocalVersionService { private async getSteamVersion(): Promise { const steamBsFolder = await this.steamService.getGameFolder(BS_APP_ID, "Beat Saber"); - if (!steamBsFolder || !(await pathExist(steamBsFolder))) { + if (!steamBsFolder || !(await pathExists(steamBsFolder))) { return null; } @@ -247,26 +254,35 @@ export class BSLocalVersionService { public async getInstalledVersions(): Promise { const versions: BSVersion[] = []; - const steamVersion = await this.getSteamVersion(); + const steamVersion = await this.getSteamVersion().catch(e => { + log.error("unable to get original Steam version", e); + }); + if (steamVersion) { versions.push(steamVersion); } - const oculusVersion = await this.getOculusVersion(); + const oculusVersion = await this.getOculusVersion().catch(e => { + log.error("unable to get original Oculus version", e); + }); + if (oculusVersion) { versions.push(oculusVersion); } - if (!(await pathExist(await this.installLocationService.versionsDirectory()))) { + if (!(await pathExists(await this.installLocationService.versionsDirectory()))) { return versions; } const folderInInstallation = await getFoldersInFolder(await this.installLocationService.versionsDirectory()); - for (const f of folderInInstallation) { - log.info("try get version from folder", f); + log.info("Finded versions folders", folderInInstallation); - const version = await this.getVersionOfBSFolder(f); + for (const f of folderInInstallation) { + + const version = await this.getVersionOfBSFolder(f).catch(e => { + log.error("unable to get version of folder", f, e); + }); if(!version){ continue; } @@ -283,7 +299,7 @@ export class BSLocalVersionService { public async deleteVersion(version: BSVersion): Promise{ if(version.steam || version.oculus){ return false; } const versionFolder = await this.getVersionPath(version); - if(!(await pathExist(versionFolder))){ return true; } + if(!(await pathExists(versionFolder))){ return true; } return deleteFolder(versionFolder) .then(() => { return true; }) @@ -304,7 +320,7 @@ export class BSLocalVersionService { return editedVersion; } - if((await pathExist(newPath)) && newPath === oldPath){ throw {title: "VersionAlreadExist"} as BsmException; } + if((await pathExists(newPath)) && newPath === oldPath){ throw {title: "VersionAlreadExist"} as BsmException; } return rename(oldPath, newPath).then(() => { this.deleteCustomVersion(version); @@ -328,7 +344,7 @@ export class BSLocalVersionService { this.addCustomVersion(cloneVersion); } - if(await pathExist(newPath)){ throw {title: "VersionAlreadExist"} as BsmException; } + if(await pathExists(newPath)){ throw {title: "VersionAlreadExist"} as BsmException; } return copyDirectoryWithJunctions(originPath, newPath).then(() => { this.addCustomVersion(cloneVersion); From 3db58391adb34db277890a5dafc0eaa6f50ee17a Mon Sep 17 00:00:00 2001 From: MathieuG-P <40181755+Zagrios@users.noreply.github.com> Date: Fri, 17 Nov 2023 21:52:36 +0100 Subject: [PATCH 2/2] [bugfix] Prevent being able to launch downloading BS version --- .../nav-bar-items/bs-version-item.component.tsx | 6 ++++-- .../slides/launch/launch-slide.component.tsx | 12 +++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/renderer/components/nav-bar/nav-bar-items/bs-version-item.component.tsx b/src/renderer/components/nav-bar/nav-bar-items/bs-version-item.component.tsx index 2a9eb236..4b204c82 100644 --- a/src/renderer/components/nav-bar/nav-bar-items/bs-version-item.component.tsx +++ b/src/renderer/components/nav-bar/nav-bar-items/bs-version-item.component.tsx @@ -1,7 +1,7 @@ import { BSVersion } from "shared/bs-version.interface"; import { Link, useLocation } from "react-router-dom"; import { useState } from "react"; -import { distinctUntilChanged, lastValueFrom, map, of, Subscription, switchMap } from "rxjs"; +import { distinctUntilChanged, lastValueFrom, map, of, Subscription, switchMap, take } from "rxjs"; import { BSLauncherService, LaunchMods } from "renderer/services/bs-launcher.service"; import { ConfigurationService } from "renderer/services/configuration.service"; import { BSUninstallerService } from "renderer/services/bs-uninstaller.service"; @@ -55,7 +55,9 @@ export function BsVersionItem(props: { version: BSVersion }) { return props.version?.BSVersion === state?.BSVersion && props?.version.steam === state?.steam && props?.version.oculus === state?.oculus && props?.version.name === state?.name; }; - const handleDoubleClick = () => { + const handleDoubleClick = async () => { + const downloadingVersion = await lastValueFrom(bsDownloader.downloadingVersion$.pipe(take(1))); + if(equal(downloadingVersion, props.version)){ return; } const launch$ = launcherService.launch({ version: state, oculus: !!configService.get(LaunchMods.OCULUS_MOD), diff --git a/src/renderer/components/version-viewer/slides/launch/launch-slide.component.tsx b/src/renderer/components/version-viewer/slides/launch/launch-slide.component.tsx index 5475687a..67d3100d 100644 --- a/src/renderer/components/version-viewer/slides/launch/launch-slide.component.tsx +++ b/src/renderer/components/version-viewer/slides/launch/launch-slide.component.tsx @@ -12,6 +12,8 @@ import { BsmImage } from "renderer/components/shared/bsm-image.component"; import { useService } from "renderer/hooks/use-service.hook"; import { BsStore } from "shared/models/bs-store.enum"; import { lastValueFrom } from "rxjs"; +import { BsDownloaderService } from "renderer/services/bs-version-download/bs-downloader.service"; +import equal from "fast-deep-equal"; type Props = { version: BSVersion }; @@ -20,12 +22,14 @@ export function LaunchSlide({ version }: Props) { const configService = useService(ConfigurationService); const bsLauncherService = useService(BSLauncherService); + const bsDownloader = useService(BsDownloaderService); const [oculusMode, setOculusMode] = useState(!!configService.get(LaunchMods.OCULUS_MOD)); const [desktopMode, setDesktopMode] = useState(!!configService.get(LaunchMods.DESKTOP_MOD)); const [debugMode, setDebugMode] = useState(!!configService.get(LaunchMods.DEBUG_MOD)); const [advancedLaunch, setAdvancedLaunch] = useState(false); const [additionalArgsString, setAdditionalArgsString] = useState(configService.get("additionnal-args") || ""); + const versionDownloading = useObservable(bsDownloader.downloadingVersion$); const versionRunning = useObservable(bsLauncherService.versionRunning$); @@ -96,7 +100,13 @@ export function LaunchSlide({ version }: Props) {
- +
);