mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
manage models
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { ipcMain } from 'electron';
|
||||
import { BSVersion } from '../services/bs-version-lib.service';
|
||||
import { BSVersion } from 'shared/bs-version.interface';
|
||||
import { BSInstallerService, DownloadEventType } from '../services/bs-installer.service';
|
||||
import { IpcRequest } from 'shared/models/ipc';
|
||||
import { InstallationLocationService } from '../services/installation-location.service';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ipcMain } from 'electron';
|
||||
import { UtilsService } from '../services/utils.service'
|
||||
import { LauchOption } from "../../shared/models/launch-models.model";
|
||||
import { LauchOption } from "shared/models/bs-launch";
|
||||
import { BSLauncherService } from "../services/bs-launcher.service"
|
||||
import { IpcRequest } from 'shared/models/ipc';
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ipcMain } from "electron";
|
||||
import { BSVersion } from "main/services/bs-version-lib.service";
|
||||
import { BSVersion } from 'shared/bs-version.interface';
|
||||
import { UtilsService } from "../services/utils.service";
|
||||
import { IpcRequest } from "shared/models/ipc";
|
||||
import { BSLocalVersionService } from "../services/bs-local-version.service";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ipcMain } from 'electron';
|
||||
import { UtilsService } from '../services/utils.service';
|
||||
import { BSVersionLibService } from '../services/bs-version-lib.service'
|
||||
import { BSVersion } from "main/services/bs-version-lib.service";
|
||||
import { BSVersion } from 'shared/bs-version.interface';
|
||||
import path from 'path';
|
||||
import { exec } from 'child_process';
|
||||
import { SteamService } from '../services/steam.service';
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { BS_APP_ID, BS_DEPOT } from "../constants";
|
||||
import path from "path";
|
||||
import { BSVersion, BSVersionLibService } from "./bs-version-lib.service";
|
||||
import { BSVersionLibService } from "./bs-version-lib.service";
|
||||
import { BSVersion } from 'shared/bs-version.interface';
|
||||
import { UtilsService } from "./utils.service";
|
||||
import { ChildProcessWithoutNullStreams, spawn } from "child_process";
|
||||
import log from "electron-log";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import path from "path";
|
||||
import { BsLaunchResult, LauchOption } from "shared/models/launch-models.model";
|
||||
import { BSVersion } from "./bs-version-lib.service";
|
||||
import { LaunchResult, LauchOption } from "shared/models/bs-launch";
|
||||
import { BSVersion } from 'shared/bs-version.interface';
|
||||
import { UtilsService } from "./utils.service";
|
||||
import { BS_EXECUTABLE, BS_APP_ID } from "../constants";
|
||||
import { ChildProcessWithoutNullStreams, spawn } from "child_process";
|
||||
@@ -37,7 +37,7 @@ export class BSLauncherService{
|
||||
return this.utilsService.pathExist(exePath);
|
||||
}
|
||||
|
||||
public async launch(launchOptions: LauchOption): Promise<BsLaunchResult>{
|
||||
public async launch(launchOptions: LauchOption): Promise<LaunchResult>{
|
||||
if(!this.steamService.steamRunning()){ return "STEAM_NOT_RUNNING" }
|
||||
if(!this.isExeExist(launchOptions.version)){ return "EXE_NOT_FINDED"; }
|
||||
if(this.isBsRunning()){ return "BS_ALREADY_RUNNING" }
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { BSVersion, BSVersionLibService } from "./bs-version-lib.service";
|
||||
import { BSVersionLibService } from "./bs-version-lib.service";
|
||||
import { BSVersion } from 'shared/bs-version.interface';
|
||||
import { InstallationLocationService } from "./installation-location.service";
|
||||
import { SteamService } from "./steam.service";
|
||||
import { UtilsService } from "./utils.service";
|
||||
|
||||
@@ -2,75 +2,73 @@ import { get } from 'https'
|
||||
import { UtilsService } from './utils.service';
|
||||
import path from 'path';
|
||||
import { writeFileSync } from 'fs';
|
||||
import { BSVersion } from 'shared/bs-version.interface';
|
||||
|
||||
export class BSVersionLibService{
|
||||
|
||||
private readonly REMOTE_BS_VERSIONS_URL: string = "https://raw.githubusercontent.com/Zagrios/bs-manager/master/assets/jsons/bs-versions.json"
|
||||
private readonly VERSIONS_FILE: string = "bs-versions.json";
|
||||
private readonly REMOTE_BS_VERSIONS_URL: string = "https://raw.githubusercontent.com/Zagrios/bs-manager/master/assets/jsons/bs-versions.json"
|
||||
private readonly VERSIONS_FILE: string = "bs-versions.json";
|
||||
|
||||
private static instance: BSVersionLibService;
|
||||
private static instance: BSVersionLibService;
|
||||
|
||||
private utilsService: UtilsService;
|
||||
private utilsService: UtilsService;
|
||||
|
||||
private bsVersions: BSVersion[] = [];
|
||||
private bsVersions: BSVersion[] = [];
|
||||
|
||||
private constructor(){
|
||||
this.utilsService = UtilsService.getInstance();
|
||||
}
|
||||
private constructor(){
|
||||
this.utilsService = UtilsService.getInstance();
|
||||
}
|
||||
|
||||
|
||||
public static getInstance(): BSVersionLibService{
|
||||
if(!BSVersionLibService.instance){ BSVersionLibService.instance = new BSVersionLibService(); }
|
||||
return BSVersionLibService.instance;
|
||||
}
|
||||
public static getInstance(): BSVersionLibService{
|
||||
if(!BSVersionLibService.instance){ BSVersionLibService.instance = new BSVersionLibService(); }
|
||||
return BSVersionLibService.instance;
|
||||
}
|
||||
|
||||
private getRemoteVersions(): Promise<BSVersion[]>{
|
||||
return new Promise<BSVersion[]>((resolve, reject) => {
|
||||
let body = ''
|
||||
get(this.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(null))
|
||||
private getRemoteVersions(): Promise<BSVersion[]>{
|
||||
return new Promise<BSVersion[]>((resolve, reject) => {
|
||||
let body = ''
|
||||
get(this.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(null))
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private async getLocalVersions(): Promise<BSVersion[]>{
|
||||
const localVersionsPath = path.join(this.utilsService.getAssestsJsonsPath(), this.VERSIONS_FILE);
|
||||
const rawVersion = (await this.utilsService.readFileAsync(localVersionsPath)).toString();
|
||||
return JSON.parse(rawVersion);
|
||||
}
|
||||
private async getLocalVersions(): Promise<BSVersion[]>{
|
||||
const localVersionsPath = path.join(this.utilsService.getAssestsJsonsPath(), this.VERSIONS_FILE);
|
||||
const rawVersion = (await this.utilsService.readFileAsync(localVersionsPath)).toString();
|
||||
return JSON.parse(rawVersion);
|
||||
}
|
||||
|
||||
private async updateLocalVersions(versions: BSVersion[]): Promise<void>{
|
||||
const localVersionsPath = path.join(this.utilsService.getAssestsJsonsPath(), this.VERSIONS_FILE);
|
||||
writeFileSync(localVersionsPath, JSON.stringify(versions, null, "\t"), {encoding: 'utf-8', flag: 'w'});
|
||||
};
|
||||
private async updateLocalVersions(versions: BSVersion[]): Promise<void>{
|
||||
const localVersionsPath = path.join(this.utilsService.getAssestsJsonsPath(), this.VERSIONS_FILE);
|
||||
writeFileSync(localVersionsPath, JSON.stringify(versions, null, "\t"), {encoding: 'utf-8', flag: 'w'});
|
||||
};
|
||||
|
||||
private async loadBsVersions(): Promise<BSVersion[]>{
|
||||
const [localVersions, remoteVersions] = await Promise.all([
|
||||
this.getLocalVersions(), this.getRemoteVersions()
|
||||
]);
|
||||
let resVersions = localVersions;
|
||||
if(remoteVersions && remoteVersions.length){ resVersions = remoteVersions; this.updateLocalVersions(resVersions); }
|
||||
this.bsVersions = resVersions;
|
||||
return this.bsVersions;
|
||||
}
|
||||
private async loadBsVersions(): Promise<BSVersion[]>{
|
||||
const [localVersions, remoteVersions] = await Promise.all([
|
||||
this.getLocalVersions(), this.getRemoteVersions()
|
||||
]);
|
||||
let resVersions = localVersions;
|
||||
if(remoteVersions && remoteVersions.length){ resVersions = remoteVersions; this.updateLocalVersions(resVersions); }
|
||||
this.bsVersions = resVersions;
|
||||
return this.bsVersions;
|
||||
}
|
||||
|
||||
public async getAvailableVersions(): Promise<BSVersion[]>{
|
||||
if(this.bsVersions && this.bsVersions.length){ return this.bsVersions; }
|
||||
const bsVersions = await this.loadBsVersions();
|
||||
if(!bsVersions || !bsVersions.length){ return []; }
|
||||
return bsVersions;
|
||||
|
||||
}
|
||||
public async getAvailableVersions(): Promise<BSVersion[]>{
|
||||
if(this.bsVersions && this.bsVersions.length){ return this.bsVersions; }
|
||||
const bsVersions = await this.loadBsVersions();
|
||||
if(!bsVersions || !bsVersions.length){ return []; }
|
||||
return bsVersions;
|
||||
}
|
||||
|
||||
public getVersionDetails(version: string): BSVersion{
|
||||
return this.bsVersions.find(v => v.BSVersion === version);
|
||||
}
|
||||
public getVersionDetails(version: string): BSVersion{
|
||||
return this.bsVersions.find(v => v.BSVersion === version);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export interface BSVersion { BSVersion: string, BSManifest?: string, ReleaseURL?: string, ReleaseImg?: string, ReleaseDate?: string, year?: string, steam?: boolean }
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BSVersion } from "main/services/bs-version-lib.service";
|
||||
import { BSVersion } from 'shared/bs-version.interface';
|
||||
import './available-version-item.component.css';
|
||||
import { useEffect, useState, memo } from "react";
|
||||
import { BsDownloaderService } from "renderer/services/bs-downloader.service";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BSVersion } from "main/services/bs-version-lib.service";
|
||||
import { BSVersion } from 'shared/bs-version.interface';
|
||||
import { useEffect, useState } from "react"
|
||||
import { BSVersionManagerService } from "renderer/services/bs-version-manager.service";
|
||||
import { filter, take } from "rxjs";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ModalExitCode, ModalResponse, ModalService } from "../../../services/modale.service";
|
||||
import BeatConflict from "../../../../../assets/images/apngs/beat-conflict.png"
|
||||
import { BSVersion } from "main/services/bs-version-lib.service";
|
||||
import { BSVersion } from 'shared/bs-version.interface';
|
||||
import { BsmButton } from "renderer/components/shared/bsm-button.component";
|
||||
import { BsmImage } from "renderer/components/shared/bsm-image.component";
|
||||
import { useTranslation } from "renderer/hooks/use-translation.hook";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BSVersion } from "main/services/bs-version-lib.service";
|
||||
import { BSVersion } from 'shared/bs-version.interface';
|
||||
import { Link, useLocation } from "react-router-dom";
|
||||
import { BsDownloaderService } from "renderer/services/bs-downloader.service";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
@@ -2,7 +2,7 @@ import { AvailableVersionsSlider } from "../components/available-versions/availa
|
||||
import { BsDownloaderService } from "../services/bs-downloader.service";
|
||||
import { Slideshow } from "renderer/components/slideshow/slideshow.component";
|
||||
import { useEffect, useState } from "react";
|
||||
import { BSVersion } from "main/services/bs-version-lib.service";
|
||||
import { BSVersion } from 'shared/bs-version.interface';
|
||||
import { BsmButton } from "renderer/components/shared/bsm-button.component";
|
||||
import { AnimatePresence, motion } from "framer-motion";
|
||||
import { useTranslation } from "renderer/hooks/use-translation.hook";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BSVersion } from '../../main/services/bs-version-lib.service';
|
||||
import { BSVersion } from 'shared/bs-version.interface';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useLocation, useNavigate } from 'react-router-dom';
|
||||
import BSLogo from '../../../assets/images/apngs/bs-logo.png';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { DownloadEvent } from 'main/services/bs-installer.service';
|
||||
import { BehaviorSubject, distinctUntilChanged, filter, debounceTime } from 'rxjs';
|
||||
import { IpcResponse } from 'shared/models/ipc';
|
||||
import { BSVersion } from '../../main/services/bs-version-lib.service'
|
||||
import { BSVersion } from 'shared/bs-version.interface';
|
||||
import { AuthUserService } from './auth-user.service';
|
||||
import { BSVersionManagerService } from './bs-version-manager.service';
|
||||
import { IpcService } from './ipc.service';
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { LauchOption } from "../../shared/models/launch-models.model";
|
||||
import { BSVersion } from "../../main/services/bs-version-lib.service";
|
||||
import { LauchOption, LaunchResult } from "shared/models/bs-launch";
|
||||
import { BSVersion } from 'shared/bs-version.interface';
|
||||
import { IpcService } from "./ipc.service";
|
||||
import { BsLaunchResult } from "../../shared/models/launch-models.model";
|
||||
import { NotificationResult, NotificationService } from "./notification.service";
|
||||
import { BsDownloaderService } from "./bs-downloader.service";
|
||||
|
||||
@@ -26,7 +25,7 @@ export class BSLauncherService{
|
||||
|
||||
public launch(version: BSVersion, oculus: boolean, desktop: boolean, debug: boolean): Promise<NotificationResult|string>{
|
||||
const lauchOption: LauchOption = {debug, oculus, desktop, version};
|
||||
return this.ipcService.send<BsLaunchResult>("bs-launch.launch", {args: lauchOption}).then(res => {
|
||||
return this.ipcService.send<LaunchResult>("bs-launch.launch", {args: lauchOption}).then(res => {
|
||||
if(!res.success){ return this.notificationService.notifyError({title: "notifications.bs-launch.errors.titles.UNABLE_TO_LAUNCH", desc: res.error.title}); }
|
||||
if(res.data === "EXE_NOT_FINDED"){
|
||||
this.notificationService.notifyError({title: "notifications.bs-launch.errors.titles.EXE_NOT_FINDED", desc: "notifications.bs-launch.errors.msg.EXE_NOT_FINDED", actions: [{id: "0", title:"misc.verify"}]}).then(res => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BSVersion } from "main/services/bs-version-lib.service";
|
||||
import { BSVersion } from 'shared/bs-version.interface';
|
||||
import { IpcService } from "./ipc.service";
|
||||
|
||||
export class BSUninstallerService{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BSVersion } from "../../main/services/bs-version-lib.service";
|
||||
import { BSVersion } from 'shared/bs-version.interface';
|
||||
import { BehaviorSubject } from "rxjs";
|
||||
import { IpcService } from "./ipc.service";
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
export interface BSVersion {
|
||||
BSVersion: string,
|
||||
BSManifest?: string,
|
||||
ReleaseURL?: string,
|
||||
ReleaseImg?: string,
|
||||
ReleaseDate?: string,
|
||||
year?: string,
|
||||
steam?: boolean
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export { LauchOption } from "./launch-option.interface"
|
||||
export { LaunchResult } from "./launch-result.interface"
|
||||
@@ -0,0 +1,8 @@
|
||||
import { BSVersion } from "shared/bs-version.interface";
|
||||
|
||||
export interface LauchOption {
|
||||
version: BSVersion,
|
||||
oculus: boolean,
|
||||
desktop: boolean,
|
||||
debug: boolean
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
export type LaunchResult = (
|
||||
"LAUNCHED"|
|
||||
"STEAM_NOT_RUNNING"|
|
||||
"EXE_NOT_FINDED"|
|
||||
"BS_ALREADY_RUNNING"
|
||||
)
|
||||
@@ -1,10 +0,0 @@
|
||||
import { BSVersion } from "main/services/bs-version-lib.service";
|
||||
|
||||
export interface LauchOption {
|
||||
version: BSVersion,
|
||||
oculus: boolean,
|
||||
desktop: boolean,
|
||||
debug: boolean
|
||||
}
|
||||
|
||||
export type BsLaunchResult = "LAUNCHED" | "STEAM_NOT_RUNNING" | "EXE_NOT_FINDED" | "BS_ALREADY_RUNNING";
|
||||
Reference in New Issue
Block a user