diff --git a/src/main/models/depot-downloader.class.ts b/src/main/models/depot-downloader.class.ts index d07965ccd..34558213f 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 81d1ca8ac..4cf477d62 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 {