Skip to content

Commit

Permalink
Merge pull request #295 from Zagrios/bugfix/unable-download-bs-versio…
Browse files Browse the repository at this point in the history
…n-with-fresh-install

[bugfix] Ensure BSInstances exist before running depotdownloader
  • Loading branch information
Zagrios authored Aug 8, 2023
2 parents 1305756 + 6296a78 commit 73e8e0f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
21 changes: 15 additions & 6 deletions src/main/models/depot-downloader.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ export class DepotDownloader {
private processOut$: Observable<string>;
private subscriber: Subscriber<string>;

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<string>(subscriber => {

Expand All @@ -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;
}

Expand All @@ -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; }
Expand Down Expand Up @@ -98,4 +101,10 @@ export class DepotDownloader {
return args;
}

}

interface Logger {
info: (...args: unknown[]) => void,
warn: (...args: unknown[]) => void,
error: (...args: unknown[]) => void,
}
6 changes: 4 additions & 2 deletions src/main/services/bs-installer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<DepotDownloaderEvent> {
Expand Down

0 comments on commit 73e8e0f

Please sign in to comment.