diff --git a/src/main/services/bs-installer.service.ts b/src/main/services/bs-installer.service.ts index c6c6ea35..430e4b44 100644 --- a/src/main/services/bs-installer.service.ts +++ b/src/main/services/bs-installer.service.ts @@ -1,3 +1,4 @@ +/* eslint-disable prefer-promise-reject-errors */ import { BS_APP_ID, BS_DEPOT } from "../constants"; import path from "path"; import { BSVersion, PartialBSVersion } from 'shared/bs-version.interface'; @@ -71,20 +72,19 @@ export class BSInstallerService{ }); } - public async isDotNet6Installed(): Promise{ + public async isDotNet6Installed(): Promise{ try{ - const process = spawnSync("(dir (Get-Command dotnet).Path.Replace('dotnet.exe', 'shared\\Microsoft.NETCore.App')).Name", {shell: "powershell.exe"}); + const process = spawnSync(this.getDepotDownloaderExePath(), {shell: true}); if(process.stderr.toString()){ - log.error("try isDotNet6Installed", process.stderr.toString()); - return false; + log.error("no dotnet", process.stderr.toString()); + return false; } - const versions = process.stdout.toString().split("\n"); - return versions.some(version => satisfies(clean(version), "6.x")); + return true; } catch(e){ - log.error("catch isDotNet6Installed", e); + log.error("Error while checking .NET 6", e); return false; - } + } } public async downloadBsVersion(downloadInfos: DownloadInfo): Promise{ @@ -109,8 +109,7 @@ export class BSInstallerService{ `-depot ${BS_DEPOT}`, `-manifest ${bsVersion.BSManifest}`, `-username ${downloadInfos.username}`, - `-dir \"${this.localVersionService.getVersionFolder(downloadVersion)}\"`, - (downloadInfos.stay || !downloadInfos.password) && "-remember-password" + `-dir \"${this.localVersionService.getVersionFolder(downloadVersion)}\"` ], {shell: true, cwd: this.installLocationService.versionsDirectory} ); @@ -161,16 +160,25 @@ export class BSInstallerService{ this.downloadProcess.stdout.on('error', (err) => { log.error("BS-DOWNLOAD ERROR", err.toString()); this.killDownloadProcess(); + if(err.toString().includes(".NET") || err.toString().includes("dotnet") || err.toString().includes(".dll")){ + reject("dotnet"); + } reject(); }); this.downloadProcess.stderr.on('data', (err) => { log.error("BS-DOWNLOAD ERROR", err.toString()); this.killDownloadProcess(); + if(err.toString().includes(".NET") || err.toString().includes("dotnet") || err.toString().includes(".dll")){ + reject("dotnet"); + } reject(); }); this.downloadProcess.stderr.on('error', (err) => { log.error("BS-DOWNLOAD ERROR", err.toString()); this.killDownloadProcess(); + if(err.toString().includes(".NET") || err.toString().includes("dotnet") || err.toString().includes(".dll")){ + reject("dotnet"); + } reject(); }); diff --git a/src/renderer/services/bs-downloader.service.ts b/src/renderer/services/bs-downloader.service.ts index e1e4843a..78f69574 100644 --- a/src/renderer/services/bs-downloader.service.ts +++ b/src/renderer/services/bs-downloader.service.ts @@ -96,11 +96,7 @@ export class BsDownloaderService{ return this.ipcService.send("is-dotnet-6-installed").then(res => res.success && res.data) } - public async download(bsVersion: BSVersion, isVerification?: boolean, isFirstCall = true): Promise>{ - if(isFirstCall && !this.progressBarService.require()){ return {success: false}; } - - if(isFirstCall && !(await this.isDotNet6Installed())){ - + private async showDotNetNotInstalledError(): Promise{ const choice = await this.notificationService.notifyError({ duration: 11_000, title: "notifications.bs-download.errors.titles.dotnet-required", @@ -111,7 +107,16 @@ export class BsDownloaderService{ if(choice === "0"){ this.linkOpener.open("https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-6.0.12-windows-x64-installer"); } + } + public async download(bsVersion: BSVersion, isVerification?: boolean, isFirstCall = true): Promise>{ + + // TODO : to remake cause we don't need recursion anymore + + if(isFirstCall && !this.progressBarService.require()){ return {success: false}; } + + if(isFirstCall && !(await this.isDotNet6Installed())){ + await this.showDotNetNotInstalledError(); return {success: false}; } @@ -142,7 +147,13 @@ export class BsDownloaderService{ this.progressBarService.hide(true); this.resetDownload(); if(res.success && isFirstCall){ this.notificationService.notifySuccess({title: `notifications.bs-download.success.titles.${isVerification ? "verification-finished" : "download-success"}`, duration: 3000}); } - else if(res.data && isFirstCall){ this.notificationService.notifyError({title: `notifications.types.error`, desc: `notifications.bs-download.errors.msg.${res.data}`, duration: 3000}); } + else if(res.data === "dotnet" && isFirstCall){ + await this.showDotNetNotInstalledError(); + return res; + } + else if(res.data && isFirstCall){ + this.notificationService.notifyError({title: `notifications.types.error`, desc: `notifications.bs-download.errors.msg.${res.data}`, duration: 3000}); + } return res; }