diff --git a/src/main/services/bs-installer.service.ts b/src/main/services/bs-installer.service.ts index 8d969a2b..82f828e3 100644 --- a/src/main/services/bs-installer.service.ts +++ b/src/main/services/bs-installer.service.ts @@ -86,6 +86,11 @@ export class BSInstallerService{ if(!(await isOnline({timeout: 1500}))){ throw "no-internet"; } this.utils.createFolderIfNotExist(this.installLocationService.versionsDirectory); + + const dest = this.getPathNotAleardyExist(await this.localVersionService.getVersionPath(bsVersion)); + + const downloadVersion: BSVersion = {...downloadInfos.bsVersion, ...(path.basename(dest) !== downloadInfos.bsVersion.BSVersion && {name: path.basename(dest)})} + this.downloadProcess = spawn( this.getDepotDownloaderExePath(), [ @@ -93,12 +98,14 @@ export class BSInstallerService{ `-depot ${BS_DEPOT}`, `-manifest ${bsVersion.BSManifest}`, `-username ${downloadInfos.username}`, - `-dir \"${this.localVersionService.getVersionFolder(bsVersion)}\"`, + `-dir \"${this.localVersionService.getVersionFolder(downloadVersion)}\"`, (downloadInfos.stay || !downloadInfos.password) && "-remember-password" ], {shell: true, cwd: this.installLocationService.versionsDirectory} ); + this.utils.ipcSend("start-download-version", {success: true, data: downloadVersion}); + return new Promise((resolve, reject) => { this.downloadProcess.stdout.on('data', data => { @@ -160,22 +167,27 @@ export class BSInstallerService{ }) } + private getPathNotAleardyExist(path: string): string{ + let destPath = path; + let folderExist = this.utils.pathExist(destPath); + let i = 0; + + while(folderExist){ + i++; + destPath = `${path} (${i})`; + folderExist = this.utils.pathExist(destPath); + } + + return destPath + } + public async importVersion(path: string): Promise{ const rawBsVersion = await this.localVersionService.getVersionOfBSFolder(path); if(!rawBsVersion){ throw new Error("NOT_BS_FOLDER"); } - const originalPath = await this.localVersionService.getVersionPath(rawBsVersion); - let destPath = originalPath; - let folderExist = this.utils.pathExist(destPath); - let i = 0; - - while(folderExist){ - i++; - destPath = `${originalPath} (${i})`; - folderExist = this.utils.pathExist(destPath); - } + const destPath = this.getPathNotAleardyExist(await this.localVersionService.getVersionPath(rawBsVersion)); await copy(path, destPath, {dereference: true}); @@ -197,7 +209,7 @@ export interface DownloadInfo { export interface DownloadEvent{ type: DownloadEventType, - data?: unknown, + data?: unknown } export type DownloadEventType = "[Password]" | "[Guard]" | "[2FA]" | "[Progress]" | "[Validated]" | "[Finished]" | "[AlreadyDownloading]" | "[Error]" | "[Warning]" | "[SteamID]" | "[Exit]" | "[NoInternet]"; 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 1e8e11bc..3a1c6685 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 @@ -41,13 +41,11 @@ export function BsVersionItem(props: {version: BSVersion}) { ) } - const cancel = () => { - const versionDownload = downloaderService.currentBsVersionDownload$.value; - downloaderService.cancelDownload().then(async res => { - if(!res.success){ return; } - if(!downloaderService.isVerification){ - bsUninstallerService.uninstall(versionDownload).then(res => res && verionManagerService.askInstalledVersions()); - } + const cancel = () => { + const versionDownload = downloaderService.currentBsVersionDownload$.value; + downloaderService.cancelDownload().then(async res => { + if(!res.success){ return; } + bsUninstallerService.uninstall(versionDownload).then(res => res && verionManagerService.askInstalledVersions()); }); } diff --git a/src/renderer/pages/available-versions-list.components.tsx b/src/renderer/pages/available-versions-list.components.tsx index 652f54f9..979952f1 100644 --- a/src/renderer/pages/available-versions-list.components.tsx +++ b/src/renderer/pages/available-versions-list.components.tsx @@ -31,7 +31,7 @@ export function AvailableVersionsList() { const startDownload = () => { setDownloading(() => true) - bsDownloaderService.download(versionSelected, versionManagerService.isVersionInstalled(versionSelected)).finally(() => { + bsDownloaderService.download(versionSelected).finally(() => { setDownloading(() => false); }); } @@ -91,7 +91,7 @@ export function AvailableVersionsList() { { versionSelected && !downloading && ( - + )} diff --git a/src/renderer/services/bs-downloader.service.ts b/src/renderer/services/bs-downloader.service.ts index 28a6ae7f..155c7ce0 100644 --- a/src/renderer/services/bs-downloader.service.ts +++ b/src/renderer/services/bs-downloader.service.ts @@ -25,8 +25,6 @@ export class BsDownloaderService{ private readonly notificationService: NotificationService; private readonly linkOpener: LinkOpenerService; - private _isVerification: boolean = false; - public readonly currentBsVersionDownload$: BehaviorSubject = new BehaviorSubject(null); public readonly downloadProgress$: BehaviorSubject = new BehaviorSubject(0); public readonly selectedBsVersion$: BehaviorSubject = new BehaviorSubject(null); @@ -71,10 +69,15 @@ export class BsDownloaderService{ this.ipcService.sendLazy('bs-download.[2FA]', {args: res.data}); }); + this.ipcService.watch("start-download-version").subscribe(res => { + this.currentBsVersionDownload$.next(res.data); + }); + this.currentBsVersionDownload$.subscribe(version => { if(version){ this.bsVersionManager.setInstalledVersions([...this.bsVersionManager.installedVersions$.value, version]); } else{ this.bsVersionManager.askInstalledVersions(); } }); + } private resetDownload(): void{ @@ -91,7 +94,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>{ + public async download(bsVersion: BSVersion, isFirstCall = true): Promise>{ if(isFirstCall && !this.progressBarService.require()){ return {success: false}; } if(isFirstCall && !(await this.isDotNet6Installed())){ @@ -111,7 +114,6 @@ export class BsDownloaderService{ } this.progressBarService.show(this.downloadProgress$); - this._isVerification = !!isVerification; let promise; if(!this.authService.sessionExist()){ @@ -127,25 +129,22 @@ export class BsDownloaderService{ promise = this.ipcService.send('bs-download.start', {args: {bsVersion, username: this.authService.getSteamUsername()}}); } - this.currentBsVersionDownload$.next(bsVersion); - let res = await promise; if(res.data?.type === "[Password]"){ this.authService.deleteSteamSession(); - res = await this.download(bsVersion, isVerification, false); + res = await this.download(bsVersion, false); } 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}); } + if(res.success && isFirstCall){ this.notificationService.notifySuccess({title: "notifications.bs-download.success.titles.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}); } return res; } public get isDownloading(): boolean{ return !!this.currentBsVersionDownload$.value; } - public get isVerification(): boolean{ return this._isVerification; } public async getInstallationFolder(): Promise{ const res = await this.ipcService.send("bs-download.installation-folder");