diff --git a/assets/depot-downloader/DepotDownloader.dll b/assets/depot-downloader/DepotDownloader.dll index 909efbff..93041c37 100644 Binary files a/assets/depot-downloader/DepotDownloader.dll and b/assets/depot-downloader/DepotDownloader.dll differ diff --git a/assets/depot-downloader/SteamKit2.dll b/assets/depot-downloader/SteamKit2.dll index be97b224..48892440 100644 Binary files a/assets/depot-downloader/SteamKit2.dll and b/assets/depot-downloader/SteamKit2.dll differ diff --git a/assets/depot-downloader/protobuf-net.Core.dll b/assets/depot-downloader/protobuf-net.Core.dll index 97a41dd9..13a805ff 100644 Binary files a/assets/depot-downloader/protobuf-net.Core.dll and b/assets/depot-downloader/protobuf-net.Core.dll differ diff --git a/assets/depot-downloader/protobuf-net.dll b/assets/depot-downloader/protobuf-net.dll index 1d846daf..4b47f341 100644 Binary files a/assets/depot-downloader/protobuf-net.dll and b/assets/depot-downloader/protobuf-net.dll differ diff --git a/src/main/ipcs/bs-download-ipcs.ts b/src/main/ipcs/bs-download-ipcs.ts index 79cc9737..907f4049 100644 --- a/src/main/ipcs/bs-download-ipcs.ts +++ b/src/main/ipcs/bs-download-ipcs.ts @@ -2,7 +2,8 @@ import { ipcMain } from 'electron'; import path from 'path'; import { ChildProcessWithoutNullStreams, spawn } from 'child_process'; import { UtilsService } from '../services/utils.service'; -import { BSVersion } from 'main/services/bs-version-manager.service'; +import { BSVersion } from '../services/bs-version-manager.service'; +import { BSInstallerService } from '../services/bs-installer.service'; export interface InitDownloadInfoInterface { @@ -27,7 +28,8 @@ const DEPOT_DOWNLOADER_EXE = 'DepotDownloader.exe'; let PROCESS: ChildProcessWithoutNullStreams; ipcMain.on('bs-download.start', async (event, args: DownloadInfo) => { - console.log(args); return; + BSInstallerService.getInstance().downloadBsVersion(args); + return; const DEPOT_DOWNLOADER_PATH = path.join(UtilsService.getInstance().getAssetsPath(), 'depot-downloader', DEPOT_DOWNLOADER_EXE); console.log(UtilsService.getInstance().getAssetsPath()); console.log(DEPOT_DOWNLOADER_PATH); diff --git a/src/main/ipcs/bs-version-ipcs.ts b/src/main/ipcs/bs-version-ipcs.ts index d8263071..96b48dd9 100644 --- a/src/main/ipcs/bs-version-ipcs.ts +++ b/src/main/ipcs/bs-version-ipcs.ts @@ -1,5 +1,4 @@ import { ipcMain } from 'electron'; -import { readdirSync } from 'fs'; import { UtilsService } from '../services/utils.service'; import { BSInstallerService } from '../services/bs-installer.service'; import { BSVersionManagerService } from '../services/bs-version-manager.service' @@ -7,9 +6,9 @@ import { BSVersionManagerService } from '../services/bs-version-manager.service' ipcMain.on('bs-version.request-versions', async (event, args) => { const bsVersionService = BSVersionManagerService.getInstance(); const versions = (await bsVersionService.getAvailableVersions()); - event.reply('bs-version.request-versions', versions); + UtilsService.getInstance().ipcSend('bs-version.request-versions', versions); }); ipcMain.on('bs-version.installed-versions', async (event, args) => { - event.reply('bs-version.installed-versions', await BSInstallerService.getInstance().getInstalledBsVersion()) -}) + UtilsService.getInstance().ipcSend('bs-version.installed-versions', await BSInstallerService.getInstance().getInstalledBsVersion()) +}); diff --git a/src/main/main.ts b/src/main/main.ts index 6e10bb6d..492c9e0f 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -25,9 +25,9 @@ export default class AppUpdater { } } -let mainWindow: BrowserWindow | null = null; +let mainWindow: BrowserWindow = null; -export function getMainWindow(): BrowserWindow | null{ +export function getMainWindow(): BrowserWindow{ return mainWindow; } @@ -91,6 +91,8 @@ const createWindow = async () => { }, }); + UtilsService.getInstance().setMainWindow(mainWindow); + mainWindow.loadURL(resolveHtmlPath('index.html')); diff --git a/src/main/services/bs-installer.service.ts b/src/main/services/bs-installer.service.ts index 3ac2b356..ff46f71b 100644 --- a/src/main/services/bs-installer.service.ts +++ b/src/main/services/bs-installer.service.ts @@ -1,8 +1,9 @@ -import { BS_APP_ID } from "../constants"; +import { BS_APP_ID, BS_DEPOT } from "../constants"; import path from "path"; import { BSVersion, BSVersionManagerService } from "./bs-version-manager.service"; import { SteamService } from "./steam.service"; import { UtilsService } from "./utils.service"; +import { ChildProcessWithoutNullStreams, spawn } from "child_process"; export class BSInstallerService{ @@ -14,6 +15,8 @@ export class BSInstallerService{ private readonly steamService: SteamService = SteamService.getInstance(); private readonly bsVersionService: BSVersionManagerService = BSVersionManagerService.getInstance(); + private downloadProcess: ChildProcessWithoutNullStreams; + private installationFolder: string; private constructor(){ @@ -25,6 +28,10 @@ export class BSInstallerService{ return BSInstallerService.instance; } + private getDepotDownloaderExePath(): string{ + return path.join(this.utils.getAssetsPath(), 'depot-downloader', 'DepotDownloader.exe'); + } + public getBSInstallationFolder(): string{ return this.installationFolder; } public setBSInstallationFolder(path: string){ this.installationFolder = path; } @@ -53,4 +60,90 @@ export class BSInstallerService{ return versions; } + public sendInputProcess(input: string){ + if(this.downloadProcess.stdin.writable){ + this.downloadProcess.stdin.write(input+"\n"); + } + } + + public downloadBsVersion(downloadInfos: DownloadInfo){ + if(this.downloadProcess?.connected){ this.utils.ipcSend(`bs-download.${DownloadEventType.ALREADY_DOAWNLOADING}`); return; } + + const bsVersion = this.bsVersionService.getVersionDetailFromVersionNumber(downloadInfos.bsVersion.BSVersion); + if(!bsVersion){ this.utils.ipcSend(`bs-download.${DownloadEventType.ERROR}`); return; } + + this.utils.createFolderIfNotExist(this.getBSInstallationFolder()); + console.log(this.getDepotDownloaderExePath()) + this.downloadProcess = spawn( + this.getDepotDownloaderExePath(), + [ + `-app ${BS_APP_ID}`, + `-depot ${BS_DEPOT}`, + `-manifest ${bsVersion.BSManifest}`, + `-username ${downloadInfos.username}`, + `-dir ${bsVersion.BSVersion}`, + `-remember-password` + ], + {shell: true, cwd: this.getBSInstallationFolder()} + ) + console.log("oui"); + + this.downloadProcess.stdout.on('data', (data) => { + console.log(data.toString()); + const out = (data.toString() as string).split("|"); + if(out[0] === DownloadEventType.NOT_LOGGED_IN && downloadInfos.password){ this.sendInputProcess(downloadInfos.password); } + else if(out[0] === DownloadEventType.NOT_LOGGED_IN){ this.downloadProcess.kill(); this.utils.ipcSend(`bs-download.${DownloadEventType.NOT_LOGGED_IN}`); } + else if(out[0] === DownloadEventType.GUARD_CODE){ this.utils.ipcSend(`bs-download.${DownloadEventType.GUARD_CODE}`); } + else if(out[0] === DownloadEventType.TWO_FA_CODE){ this.utils.ipcSend(`bs-download.${DownloadEventType.TWO_FA_CODE}`); } + else if(out[0] === DownloadEventType.PROGESS){ this.utils.ipcSend(`bs-download.${DownloadEventType.PROGESS}`, parseFloat(out[1])); } + else if(out[0] === DownloadEventType.FINISH){ this.utils.ipcSend(`bs-download.${DownloadEventType.FINISH}`); this.downloadProcess.kill(); } + else if(out[0] === DownloadEventType.ERROR){ this.utils.ipcSend(`bs-download.${DownloadEventType.ERROR}`); this.downloadProcess.kill(); } + }) + + this.downloadProcess.stdout.on('error', err => { + console.log(err.toString()); + this.utils.ipcSend(`bs-download.${DownloadEventType.ERROR}`); + this.downloadProcess.kill(); + }) + + this.downloadProcess.stderr.on('data', err => { + console.log(err.toString()); + console.log("a"); + this.utils.ipcSend(`bs-download.${DownloadEventType.ERROR}`); + this.downloadProcess.kill(); + }) + + this.downloadProcess.stderr.on('error', err => { + console.log(err.toString()); + console.log("b"); + this.utils.ipcSend(`bs-download.${DownloadEventType.ERROR}`); + this.downloadProcess.kill(); + }) + } + +} + + + + +export interface DownloadInfo { + bsVersion: BSVersion, + username: string, + password?: string, + stay?: boolean +} + +export interface DownloadEvent{ + type: DownloadEventType, + data?: any, +} + +export enum DownloadEventType{ + NOT_LOGGED_IN = "[Password]", + GUARD_CODE = "[Guard]", + TWO_FA_CODE = "[2FA]", + PROGESS = "[Progress]", + FINISH = "[Finished]", + ALREADY_DOAWNLOADING = "[AlreadyDownloading]", + ERROR = "[Error]", } diff --git a/src/main/services/utils.service.ts b/src/main/services/utils.service.ts index 93f686b5..8205aa53 100644 --- a/src/main/services/utils.service.ts +++ b/src/main/services/utils.service.ts @@ -2,6 +2,7 @@ import { existsSync, mkdirSync, readdirSync, readFile } from "fs"; import { spawnSync } from "child_process"; import { homedir } from "os"; import path from "path"; +import { BrowserWindow } from "electron"; export class UtilsService{ @@ -9,6 +10,8 @@ export class UtilsService{ private assetsPath: string = ''; + private mainWindow: BrowserWindow; + private constructor(){} public static getInstance(){ @@ -19,13 +22,15 @@ export class UtilsService{ public setAssetsPath(path: string): void{ this.assetsPath = path; } public getAssetsPath(): string{ return this.assetsPath; } + public setMainWindow(win: BrowserWindow){ this.mainWindow = win; } + //à supprimer public folderExist(path: string): boolean{ return existsSync(path); } public pathExist(path: string): boolean{ return existsSync(path); } public createFolderIfNotExist(path: string): void{ - if(!this.folderExist(path)){ mkdirSync(path); } + if(!this.folderExist(path)){ mkdirSync(path, {recursive: true}); } } public taskRunning(task: string): boolean{ @@ -54,4 +59,8 @@ export class UtilsService{ return files.map(f => f.name); } + public ipcSend(channel: string, args?: any){ + this.mainWindow.webContents.send(channel, args); + } + }