From 6ee10241fdea37c17d5d5ff38115c00689ce2fc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20B=C3=A4rtschi?= Date: Wed, 21 Feb 2024 10:12:57 +0100 Subject: [PATCH] feat: add option to prevent overwrite recording --- backend/app.ts | 4 ++-- backend/data/league/LeagueDataProviderService.ts | 10 ++++++++-- backend/package-lock.json | 3 +++ backend/package.json | 4 ++++ backend/startTest.bat | 2 +- backend/types/dto/Config.ts | 1 + 6 files changed, 19 insertions(+), 5 deletions(-) diff --git a/backend/app.ts b/backend/app.ts index 76ff04b..c1805cb 100644 --- a/backend/app.ts +++ b/backend/app.ts @@ -40,7 +40,7 @@ log.info(' '); log.debug('Logging in debug mode!'); log.info('Configuration: ' + JSON.stringify(GlobalContext.commandLine)); -const state = new State(); +export const state = new State(); const ddragon = new DataDragon(state); const dataProvider = getDataProvider(); const controller = new Controller({ dataProvider, state, ddragon }); @@ -50,7 +50,7 @@ const main = async (): Promise => { await ddragon.init(); const server = http.createServer(app); - app.use('/cache', express.static(__dirname + '/../cache')); + app.use('/cache', express.static('./cache')); const wsServer = new WebSocketServer(server, state); wsServer.startHeartbeat(); diff --git a/backend/data/league/LeagueDataProviderService.ts b/backend/data/league/LeagueDataProviderService.ts index ed50e3d..8ee90cc 100644 --- a/backend/data/league/LeagueDataProviderService.ts +++ b/backend/data/league/LeagueDataProviderService.ts @@ -2,6 +2,7 @@ import logger from '../../logging'; import { Session, Cell, Summoner } from '../../types/lcu'; import { CurrentState } from '../CurrentState'; +import { state } from '../../app'; import { EventEmitter } from 'events'; import DataProviderService from '../DataProviderService'; import Recorder from '../../recording/Recorder'; @@ -11,6 +12,7 @@ import Connector, { LibraryConnector, ExperimentalConnector, } from './connector'; +import fs from 'fs'; import { Response } from 'league-connect'; const log = logger('LCUDataProviderService'); @@ -47,8 +49,12 @@ class LeagueDataProviderService extends EventEmitter this.getCurrentData = this.getCurrentData.bind(this); if (GlobalContext.commandLine.record) { - this.recorder = new Recorder(GlobalContext.commandLine.record); - log.info('Recording to ' + GlobalContext.commandLine.record); + if (fs.existsSync('../recordings' + '/' + GlobalContext.commandLine.record + '.json') && !state.data.config.overwriteRecording) { + log.error('Recording ' + GlobalContext.commandLine.record + ' already exists. Will not overwrite and therefore not perform recording.') + } else { + this.recorder = new Recorder(GlobalContext.commandLine.record); + log.info('Recording to ' + GlobalContext.commandLine.record); + } } this.connector.on('connect', this.onLeagueConnected); diff --git a/backend/package-lock.json b/backend/package-lock.json index 6461f7a..808f6fe 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -22,6 +22,9 @@ "winston": "^3.2.1", "ws": "^7.4.6" }, + "bin": { + "lol-pick-ban-ui": "backend-build/app.js" + }, "devDependencies": { "@types/cli-progress": "^1.8.1", "@types/express": "^4.17.1", diff --git a/backend/package.json b/backend/package.json index e28e516..7b56b59 100644 --- a/backend/package.json +++ b/backend/package.json @@ -3,6 +3,10 @@ "version": "0.0.0", "private": true, "main": "electron-main.js", + "bin": "./backend-build/app.js", + "pkg": { + "assets": ["node_modules/league-connect/riotgames.pem"] + }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build": "tsc", diff --git a/backend/startTest.bat b/backend/startTest.bat index 2dd6b51..7f1732a 100644 --- a/backend/startTest.bat +++ b/backend/startTest.bat @@ -1 +1 @@ -yarn start --data recordings/tournament-draft \ No newline at end of file +yarn start --data ../recordings/tournament-draft \ No newline at end of file diff --git a/backend/types/dto/Config.ts b/backend/types/dto/Config.ts index ca05b38..fc577d3 100644 --- a/backend/types/dto/Config.ts +++ b/backend/types/dto/Config.ts @@ -1,4 +1,5 @@ export class Config { contentPatch = 'latest'; contentCdn = 'https://ddragon.leagueoflegends.com/cdn'; + overwriteRecording = true; }