From 6296a78cbca25cf87c1f58434afd75db2d7dd1e2 Mon Sep 17 00:00:00 2001 From: MathieuG-P <40181755+Zagrios@users.noreply.github.com> Date: Tue, 8 Aug 2023 01:51:07 +0200 Subject: [PATCH] [bugfix] Ensure BSInstances exist before running depotdownloader --- src/main/models/depot-downloader.class.ts | 21 +++++++++++++++------ src/main/services/bs-installer.service.ts | 6 ++++-- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main/models/depot-downloader.class.ts b/src/main/models/depot-downloader.class.ts index d07965cc..34558213 100644 --- a/src/main/models/depot-downloader.class.ts +++ b/src/main/models/depot-downloader.class.ts @@ -8,9 +8,12 @@ export class DepotDownloader { private processOut$: Observable; private subscriber: Subscriber; - public constructor(options: { - command: string, args?: string[], options?: SpawnOptionsWithoutStdio, echoStartData?: unknown - }){ + public constructor( + options: { + command: string, args?: string[], options?: SpawnOptionsWithoutStdio, echoStartData?: unknown + }, + logger?: Logger + ){ this.processOut$ = new Observable(subscriber => { @@ -25,11 +28,13 @@ export class DepotDownloader { lines.forEach(line => subscriber.next(line)); }); + this.process.on("error", error => subscriber.error(error)); this.process.stderr.on("error", error => subscriber.error(error)); - this.process.on("exit", code => subscriber.complete()); + this.process.on("exit", () => subscriber.complete()); return () => { this.process.kill(); + logger?.info("DepotDownloader process end with code", this.process.exitCode); this.process = null; } @@ -48,8 +53,6 @@ export class DepotDownloader { return this.processOut$.pipe(map(line => { - console.log(line); - const matched = (line.toString() as string).match(/(?:\[(.*?)\])\|(?:\[(.*?)\]\|)?(.*?)(?=$|\[)/gm)?.[0] ?? null; if(!matched){ return null; } @@ -98,4 +101,10 @@ export class DepotDownloader { return args; } +} + +interface Logger { + info: (...args: unknown[]) => void, + warn: (...args: unknown[]) => void, + error: (...args: unknown[]) => void, } \ No newline at end of file diff --git a/src/main/services/bs-installer.service.ts b/src/main/services/bs-installer.service.ts index 81d1ca8a..4cf477d6 100644 --- a/src/main/services/bs-installer.service.ts +++ b/src/main/services/bs-installer.service.ts @@ -7,7 +7,7 @@ import log from "electron-log"; import { InstallationLocationService } from "./installation-location.service"; import { BSLocalVersionService } from "./bs-local-version.service"; import { WindowManagerService } from "./window-manager.service"; -import { copy } from "fs-extra"; +import { copy, ensureDir } from "fs-extra"; import { pathExist } from "../helpers/fs.helpers"; import { Observable, map } from "rxjs"; import { DepotDownloaderArgsOptions, DepotDownloaderErrorEvent, DepotDownloaderEvent, DepotDownloaderEventType, DepotDownloaderInfoEvent } from "../../shared/models/depot-downloader.model"; @@ -77,12 +77,14 @@ export class BSInstallerService { qr } + await ensureDir(this.installLocationService.versionsDirectory); + return new DepotDownloader({ command: this.getDepotDownloaderExePath(), args: DepotDownloader.buildArgs(depotDownloaderOptions), options: { cwd: this.installLocationService.versionsDirectory }, echoStartData: downloadVersion - }); + }, log); } private buildDepotDownloaderObservable(downloadInfos: DownloadInfo, qr?: boolean): Observable {