mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
réarganisation du back en services, mise de depot downloader dans les assets
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import path from "path";
|
||||
import { BSVersionManagerService } from "./bs-version-manager.service";
|
||||
import { UtilsService } from "./utils.service";
|
||||
|
||||
export class BSInstallerService{
|
||||
|
||||
private static readonly INSTALLATION_FOLDER = "BSManager";
|
||||
|
||||
private static instance: BSInstallerService;
|
||||
|
||||
private readonly utils: UtilsService = UtilsService.getInstance();
|
||||
|
||||
private installationFolder: string;
|
||||
|
||||
private constructor(){
|
||||
this.installationFolder = path.join(this.utils.getUserDocumentsFolder(), BSInstallerService.INSTALLATION_FOLDER)
|
||||
}
|
||||
|
||||
public static getInstance(){
|
||||
if(!BSInstallerService.instance){ BSInstallerService.instance = new BSInstallerService(); }
|
||||
return BSInstallerService.instance;
|
||||
}
|
||||
|
||||
public getBSInstallationFolder(): string{ return this.installationFolder; }
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { get } from 'https'
|
||||
|
||||
export class BSVersionManagerService{
|
||||
|
||||
private static readonly REMOTE_BS_VERSIONS_URL: string = "https://raw.githubusercontent.com/Zagrios/bs-manager/master/dynamic-resources/bs-versions.json"
|
||||
|
||||
private static instance: BSVersionManagerService;
|
||||
|
||||
private bsVersions: BSVersion[] = [];
|
||||
|
||||
private constructor(){}
|
||||
|
||||
public static getInstance(): BSVersionManagerService{
|
||||
if(!BSVersionManagerService.instance){ BSVersionManagerService.instance = new BSVersionManagerService() }
|
||||
return BSVersionManagerService.instance;
|
||||
}
|
||||
|
||||
public loadBsVersions(): Promise<BSVersion[]>{
|
||||
return new Promise<BSVersion[]>((resolve, reject) => {
|
||||
let body = ''
|
||||
get(BSVersionManagerService.REMOTE_BS_VERSIONS_URL, (res) => {
|
||||
res.on('data', chunk => body += chunk);
|
||||
res.on('end', () => {
|
||||
this.bsVersions = JSON.parse(body);
|
||||
resolve(this.bsVersions);
|
||||
});
|
||||
res.on('error', (err) => reject(err))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
public getVersionDetailFromVersionNumber(version: string): BSVersion{
|
||||
return this.bsVersions.find(v => v.BSVersion === version);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export interface BSVersion { BSVersion: string, BSManifest: string, ReleaseURL: string, year: string }
|
||||
@@ -0,0 +1,62 @@
|
||||
import { UtilsService } from "./utils.service";
|
||||
import regedit from 'regedit'
|
||||
import path from "path";
|
||||
import { parse } from "@node-steam/vdf";
|
||||
import { readFile } from "fs/promises";
|
||||
|
||||
export class SteamService{
|
||||
|
||||
private static instance: SteamService;
|
||||
|
||||
private readonly utils: UtilsService = UtilsService.getInstance();
|
||||
|
||||
private steamPath: string = '';
|
||||
|
||||
private constructor(){}
|
||||
|
||||
public static getInstance(){
|
||||
if(!SteamService.instance){ SteamService.instance = new SteamService(); }
|
||||
return SteamService.instance;
|
||||
}
|
||||
|
||||
public steamRunning(): boolean{
|
||||
return this.utils.taskRunning('steam.exe');
|
||||
}
|
||||
|
||||
public async getSteamPath(): Promise<string>{
|
||||
if(this.steamPath !== ''){ return this.steamPath; }
|
||||
const [win32Res, win64Res] = await Promise.all([
|
||||
regedit.promisified.list(['HKLM\\SOFTWARE\\Valve\\Steam']),
|
||||
regedit.promisified.list(['HKLM\\SOFTWARE\\WOW6432Node\\Valve\\Steam'])
|
||||
]);
|
||||
const [win32, win64] = [win32Res["HKLM\\SOFTWARE\\Valve\\Steam"], win64Res["HKLM\\SOFTWARE\\WOW6432Node\\Valve\\Steam"]];
|
||||
let res = ''
|
||||
if(win64.values.InstallPath.value){ res = win64.values.InstallPath.value as string; }
|
||||
else if(win32.values.InstallPath.value){ res = win32.values.InstallPath.value as string; }
|
||||
this.steamPath = res;
|
||||
return this.steamPath;
|
||||
}
|
||||
|
||||
public async getSteamGameFolder(): Promise<string>{
|
||||
const steamFolder = await this.getSteamPath();
|
||||
return path.join(steamFolder, 'common');
|
||||
}
|
||||
|
||||
public async isGameInstalled(gameId: string): Promise<boolean>{
|
||||
const steamPath = await this.getSteamPath();
|
||||
let libraryFolders: any = path.join(steamPath, 'steamapps', 'libraryfolders.vdf');
|
||||
|
||||
if(!this.utils.pathExist(libraryFolders)){ return false; }
|
||||
libraryFolders = parse(await readFile(libraryFolders, {encoding: 'utf-8'}));
|
||||
|
||||
if(!libraryFolders.libraryfolders){ return false; }
|
||||
libraryFolders = libraryFolders.libraryfolders
|
||||
|
||||
for(const libKey in Object.keys(libraryFolders)){
|
||||
if(!libraryFolders[libKey]["apps"]){ continue; }
|
||||
if(libraryFolders[libKey]["apps"][gameId]){ return true };
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { existsSync, mkdirSync } from "fs";
|
||||
import { spawnSync } from "child_process";
|
||||
import { homedir } from "os";
|
||||
import path from "path";
|
||||
|
||||
export class UtilsService{
|
||||
|
||||
private static instance: UtilsService;
|
||||
|
||||
private assetsPath: string = '';
|
||||
|
||||
private constructor(){}
|
||||
|
||||
public static getInstance(){
|
||||
if(!this.instance){ UtilsService.instance = new UtilsService(); }
|
||||
return UtilsService.instance;
|
||||
}
|
||||
|
||||
public setAssetsPath(path: string): void{ this.assetsPath = path; }
|
||||
public getAssetsPath(): string{ return this.assetsPath; }
|
||||
|
||||
//à 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); }
|
||||
}
|
||||
|
||||
public taskRunning(task: string): boolean{
|
||||
const tasks = spawnSync('tasklist').stdout.toString();
|
||||
return tasks.includes(task);
|
||||
}
|
||||
|
||||
public getUserFolder(){ return homedir(); }
|
||||
|
||||
public getUserDocumentsFolder(): string{
|
||||
return path.join(this.getUserFolder(), 'Documents');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user