From e5a39a021e91712febb3b120309a7a5baf89988b Mon Sep 17 00:00:00 2001 From: MathieuG-P <40181755+Zagrios@users.noreply.github.com> Date: Wed, 18 May 2022 23:13:37 +0200 Subject: [PATCH] =?UTF-8?q?utilisation=20de=20send=20a=20la=20place=20de?= =?UTF-8?q?=20reply=20pour=20l'envoie=20d'ipcs,=20commencement=20du=20proc?= =?UTF-8?q?ess=20de=20t=C3=A9l=C3=A9chargement=20de=20verions=20beat=20sab?= =?UTF-8?q?er?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/depot-downloader/DepotDownloader.dll | Bin 102381 -> 102382 bytes assets/depot-downloader/SteamKit2.dll | Bin 5843875 -> 5843876 bytes assets/depot-downloader/protobuf-net.Core.dll | Bin 262649 -> 262650 bytes assets/depot-downloader/protobuf-net.dll | Bin 259579 -> 259580 bytes src/main/ipcs/bs-download-ipcs.ts | 6 +- src/main/ipcs/bs-version-ipcs.ts | 7 +- src/main/main.ts | 6 +- src/main/services/bs-installer.service.ts | 95 +++++++++++++++++- src/main/services/utils.service.ts | 11 +- 9 files changed, 115 insertions(+), 10 deletions(-) diff --git a/assets/depot-downloader/DepotDownloader.dll b/assets/depot-downloader/DepotDownloader.dll index 909efbff46e01aa6b669c0247b73132cdb600e3c..93041c3776e17aa573b97416866bf2b1958e0608 100644 GIT binary patch delta 17 YcmaDmpY7dzwh5(-yp5$>OBpNr0Y}aUVE_OC delta 15 WcmaDipY82@wh5(;Wn0S_EBXOH6bDrR diff --git a/assets/depot-downloader/SteamKit2.dll b/assets/depot-downloader/SteamKit2.dll index be97b22405c1d1f47d28b01c16d1e76a5b7a8897..488924402c33bd2db1aa102a619eebf61bc2e914 100644 GIT binary patch delta 283 zcmWN=SvCRy06@{xfI^fEnHvxyLdiU5EK{O|yao7p|LuV-Sc?r-R7C-Q6J& z`$Pf~l#qm_M|!1CA`+E;8IVDV$&d_7ToN)ONg0(f8J7u3$)rrlw9Lq?%*ni@B_mnM z$$~7(lH_GsR%BHQvL@?NlnvRGl5EMg>_}NEvMW{DlYKdmLphRTIgwL2lXJO{OSzJo jT+5Bz%AMTHgVd!VkMbnX@*=O&ls9R~yL|l6E*Aa)O^9vd delta 281 zcmWN=SvCRy06@{BOl7RhGs#etu>m0@^IT~mz5hPme|umH)?xz|l6%hm{{0Jl{cks0 zNS6d8DBaQ{z0xQB5|XeC$e;|#u#Cv4L?kLP8Iy6DkV%=6X_=8(nUi^0kVRRNWm%E9 ztV%-GWL-97Q<9RBE!mc|WMoHnWl#3yKn^7eE!f#r#fSEZZ7}; diff --git a/assets/depot-downloader/protobuf-net.Core.dll b/assets/depot-downloader/protobuf-net.Core.dll index 97a41dd97b329f8f872bcf48e0b21f4e9f86efdf..13a805ffcdaaa6ef53acc680d2207fcc3d68ff86 100644 GIT binary patch delta 26 hcmey_EbyyYU_vP)Z)0g|DPwCXQ)?;n)>4)hMgWuj3CaKf delta 24 fcmey>Eby~gU_xnQS!)?%YZ+5(8S~aMmKH_;iv$V5 diff --git a/assets/depot-downloader/protobuf-net.dll b/assets/depot-downloader/protobuf-net.dll index 1d846daf6997a16b2b1f436d73cc818f4477d609..4b47f341d1ca474a06453e46a584ef6b8d192e1d 100644 GIT binary patch delta 23 fcmezUn*Yyh{t2awyp5%;rHrkmOj}Et+r9z-i4F>s delta 21 dcmezKn*aA}{t2axWvyk5tz}GG%b44~0swxC3W@*# 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); + } + }