mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
utilisation de send a la place de reply pour l'envoie d'ipcs, commencement du process de téléchargement de verions beat saber
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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);
|
||||
|
||||
@@ -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())
|
||||
});
|
||||
|
||||
+4
-2
@@ -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'));
|
||||
|
||||
@@ -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]",
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user