<commit_before>import * as fs from 'fs';
import * as path from 'path';
import { app, BrowserWindow, ipcMain, screen } from 'electron';

import { GamesCollection } from '../models/GamesCollection';
import { PotentialGame } from '../models/PotentialGame';
import { PlayableGame } from '../models/PlayableGame';
import { getGameLauncher } from './GameLauncher';
import { getSteamCrawler } from './games/SteamGamesCrawler';
import { getPlayableGamesCrawler } from './games/PlayableGamesCrawler';
import { getIgdbWrapper } from './api/IgdbWrapper';
import { downloadFile, getEnvFolder, uuidV5 } from './helpers';

export class Vitrine {
	private windowsList;
	private mainEntryPoint: string;
	private loadingEntryPoint: string;
	private devTools: boolean;
	private iconPath: string;
	private potentialGames: GamesCollection<PotentialGame>;
	private playableGames: GamesCollection<PlayableGame>;

	constructor() {
		this.windowsList = {};
		this.mainEntryPoint = path.resolve('file://', __dirname, 'main.html');
		this.loadingEntryPoint = path.resolve('file://', __dirname, 'loading.html');
		this.iconPath = path.resolve(__dirname, '../build/icon.png');
		this.devTools = false;
	}

	public run(devTools?: boolean) {
		if (devTools)
			this.devTools = devTools;

		app.on('ready', () => {
			this.createLoadingWindow();
			this.createMainWindow();
		});
		app.on('window-all-closed', () => {
			if (process.platform !== 'darwin') {
				app.quit();
			}
		});
		app.on('activate', () => {
			if (this.windowsList.mainWindow === null) {
				this.createMainWindow();
			}
		});
	}

	public registerEvents() {
		ipcMain.on('client.ready', (event) => {
			this.potentialGames = new GamesCollection();
			this.playableGames = new GamesCollection();

			getSteamCrawler().then((games: GamesCollection<PotentialGame>) => {
				this.potentialGames = games;
				event.sender.send('server.add-potential-games', this.potentialGames.games);
			}).catch((error) => {
				throw error;
			});

			getPlayableGamesCrawler().then((games: GamesCollection<PlayableGame>) => {
				this.playableGames = games;
				event.sender.send('server.add-playable-games', this.playableGames.games);
				this.windowsList.loadingWindow.destroy();
				this.windowsList.mainWindow.show();
			}).catch((error) => {
				throw error;
			});
		});
		ipcMain.on('client.fill-igdb-game', (event, gameName) => {
			getIgdbWrapper(gameName).then((game) => {
				event.sender.send('server.send-igdb-game', null, game);
			}).catch((error) => {
				event.sender.send('server.send-igdb-game', error, null);
			});
		});
		ipcMain.on('client.add-game', (event, gameId) => {
			this.potentialGames.getGame(gameId, (error, potentialSteamGame) => {
				if (error)
					throw new Error(error);
				let addedGame: PlayableGame = PlayableGame.toPlayableGame(potentialSteamGame);
				delete addedGame.details.id;
				this.addGame(event, addedGame);
			});
		});
		ipcMain.on('client.add-game-manual', (event, gameForm) => {
			let gameName: string = gameForm.name;
			let programName: string = gameForm.executable;
			delete gameForm.name;
			delete gameForm.executable;
			let game: PlayableGame = new PlayableGame(gameName, gameForm);
			game.commandLine.push(programName);
			game.commandLine = game.commandLine.concat(gameForm.arguments.split(' '));
			game.details.rating = parseInt(game.details.rating);
			game.details.genres = game.details.genres.split(', ');
			game.details.releaseDate = new Date(game.details.date).getTime();
			delete game.details.date;<commit_msg>Command line arguments added for standard games<commit_after>import * as fs from 'fs';
import * as path from 'path';
import { app, BrowserWindow, ipcMain, screen } from 'electron';

import { GamesCollection } from '../models/GamesCollection';
import { PotentialGame } from '../models/PotentialGame';
import { PlayableGame } from '../models/PlayableGame';
import { getGameLauncher } from './GameLauncher';
import { getSteamCrawler } from './games/SteamGamesCrawler';
import { getPlayableGamesCrawler } from './games/PlayableGamesCrawler';
import { getIgdbWrapper } from './api/IgdbWrapper';
import { downloadFile, getEnvFolder, uuidV5 } from './helpers';

export class Vitrine {
	private windowsList;
	private mainEntryPoint: string;
	private loadingEntryPoint: string;
	private devTools: boolean;
	private iconPath: string;
	private potentialGames: GamesCollection<PotentialGame>;
	private playableGames: GamesCollection<PlayableGame>;

	constructor() {
		this.windowsList = {};
		this.mainEntryPoint = path.resolve('file://', __dirname, 'main.html');
		this.loadingEntryPoint = path.resolve('file://', __dirname, 'loading.html');
		this.iconPath = path.resolve(__dirname, '../build/icon.png');
		this.devTools = false;
	}

	public run(devTools?: boolean) {
		if (devTools)
			this.devTools = devTools;

		app.on('ready', () => {
			this.createLoadingWindow();
			this.createMainWindow();
		});
		app.on('window-all-closed', () => {
			if (process.platform !== 'darwin') {
				app.quit();
			}
		});
		app.on('activate', () => {
			if (this.windowsList.mainWindow === null) {
				this.createMainWindow();
			}
		});
	}

	public registerEvents() {
		ipcMain.on('client.ready', (event) => {
			this.potentialGames = new GamesCollection();
			this.playableGames = new GamesCollection();

			getSteamCrawler().then((games: GamesCollection<PotentialGame>) => {
				this.potentialGames = games;
				event.sender.send('server.add-potential-games', this.potentialGames.games);
			}).catch((error) => {
				throw error;
			});

			getPlayableGamesCrawler().then((games: GamesCollection<PlayableGame>) => {
				this.playableGames = games;
				event.sender.send('server.add-playable-games', this.playableGames.games);
				this.windowsList.loadingWindow.destroy();
				this.windowsList.mainWindow.show();
			}).catch((error) => {
				throw error;
			});
		});
		ipcMain.on('client.fill-igdb-game', (event, gameName) => {
			getIgdbWrapper(gameName).then((game) => {
				event.sender.send('server.send-igdb-game', null, game);
			}).catch((error) => {
				event.sender.send('server.send-igdb-game', error, null);
			});
		});
		ipcMain.on('client.add-game', (event, gameId) => {
			this.potentialGames.getGame(gameId, (error, potentialSteamGame) => {
				if (error)
					throw new Error(error);
				let addedGame: PlayableGame = PlayableGame.toPlayableGame(potentialSteamGame);
				delete addedGame.details.id;
				this.addGame(event, addedGame);
			});
		});
		ipcMain.on('client.add-game-manual', (event, gameForm) => {
			let gameName: string = gameForm.name;
			let programName: string = gameForm.executable;
			let game: PlayableGame = new PlayableGame(gameName, gameForm);

			game.commandLine.push(programName);
			game.commandLine = game.commandLine.concat(gameForm.arguments.split(' '));
			game.details.rating = parseInt(game.details.rating);
			game.details.genres = game.details.genres.split(', ');
			game.details.releaseDate = new Date(game.details.date).getTime();

			delete game.details.date;
			delete game.details.arguments;
{'fraction_non_alphanumeric': 0.1599489071813795, 'fraction_numerical': 0.0002838489923360772, 'mean_word_length': 4.338636363636364, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5908648', 'n_tokens_mistral': 2561, 'n_tokens_neox': 2235, 'n_words': 407}