Skip to content

Commit 4a087df

Browse files
committed
fix: Address a few ancient typing errors
refactor: Remove all references to GameData 'Path' as we shift to building it from scratch each time
1 parent 58e0231 commit 4a087df

File tree

15 files changed

+23
-36
lines changed

15 files changed

+23
-36
lines changed

src/back/Downloader.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
2-
import { downloadGameData } from './download';
3-
import { fpDatabase } from '.';
2+
import { BackOut } from '@shared/back/types';
3+
import { getGameDataFilename } from '@shared/utils/misc';
4+
import { AxiosError } from 'axios';
5+
import { DownloaderStatus, DownloadTask, DownloadTaskStatus, DownloadWorkerState, Game, GameDataSource } from 'flashpoint-launcher';
46
import * as fs from 'fs-extra';
57
import * as path from 'node:path';
6-
import { DownloaderStatus, DownloadTask, DownloadTaskStatus, DownloadWorkerState, Game, GameDataSource } from 'flashpoint-launcher';
8+
import { fpDatabase } from '.';
79
import { axios } from './dns';
10+
import { downloadGameData } from './download';
811
import { BackState } from './types';
9-
import { BackOut } from '@shared/back/types';
12+
import { EventQueue } from './util/EventQueue';
1013
import { promiseSleep } from './util/misc';
1114
import { WrappedEventEmitter } from './util/WrappedEventEmitter';
12-
import { EventQueue } from './util/EventQueue';
13-
import { AxiosError } from 'axios';
14-
import { getGameDataFilename } from '@shared/utils/misc';
1515

1616
export interface Downloader {
1717
on (event: string, listener: (...args: any[]) => void): this;
@@ -319,8 +319,7 @@ class DownloadWorker {
319319
// Calc the path on disk and check if the file already matches
320320
const realPath = path.join(this.downloader.flashpointPath, this.downloader.dataPacksFolderPath, getGameDataFilename(gameData));
321321
if (fs.existsSync(realPath)) {
322-
if (gameData.path !== realPath || gameData.presentOnDisk === false) {
323-
gameData.path = realPath;
322+
if (gameData.presentOnDisk === false) {
324323
gameData.presentOnDisk = true;
325324
await new Promise<void>((resolve, reject) => {
326325
this.downloader.databaseQueue.push(async () => {

src/back/ManagedChildProcess.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ChildProcess, spawn } from 'child_process';
44
import { EventEmitter } from 'events';
55
import { IBackProcessInfo, ManagedChildProcessEvents, ProcessState } from 'flashpoint-launcher';
66
import * as readline from 'readline';
7-
import * as kill from 'tree-kill';
7+
import _treeKill from 'tree-kill';
88
import { TypedEmitter } from 'typed-emitter';
99
import { onServiceChange } from './util/events';
1010
import { Disposable } from './util/lifecycle';
@@ -166,7 +166,7 @@ export class ManagedChildProcess extends (EventEmitter as new () => TypedEmitter
166166

167167
private treeKill = async (PID: number): Promise<void> => {
168168
await new Promise<void>((resolve, reject) => {
169-
kill(PID, (error) => {
169+
_treeKill(PID, (error) => {
170170
if (error) {
171171
reject(error);
172172
} else {

src/back/Themes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export async function newThemeWatcher(id: string, basePath: string, themePath: s
5454
watcher.on('ready', () => {
5555
// Add event listeners
5656
watcher.on('add', onFileAdd);
57-
watcher.on('change', (filename: string, offsetPath: string) => {
57+
watcher.on('change', (filename, offsetPath) => {
5858
themeState.queue.push(() => {
5959
const relativePath = path.join(offsetPath, filename);
6060
console.log(`CHANGE (File Path: "${filename}", Theme: "${theme.themePath}")`);
@@ -66,7 +66,7 @@ export async function newThemeWatcher(id: string, basePath: string, themePath: s
6666
}
6767
});
6868
});
69-
watcher.on('remove', (filename: string, offsetPath: string) => {
69+
watcher.on('remove', (filename, stats, offsetPath) => {
7070
themeState.queue.push(() => {
7171
const relativePath = path.join(offsetPath, filename);
7272
if (!theme.files.includes(relativePath)) {

src/back/curate/util.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { BackOut } from '@shared/back/types';
99
import { CURATIONS_FOLDER_WORKING } from '@shared/constants';
1010
import { getContentFolderByKey } from '@shared/curate/util';
1111
import { GamePropSuggestions } from '@shared/interfaces';
12+
import { getGameDataFilename } from '@shared/utils/misc';
1213
import { AddAppCuration, CurationFpfssInfo, CurationState, CurationWarnings, LangContainer, LoadedCuration } from 'flashpoint-launcher';
1314
import * as fs from 'fs-extra';
1415
import * as http from 'http';
@@ -375,9 +376,9 @@ export async function makeCurationFromGame(state: BackState, gameId: string, ski
375376
if (game.activeDataId) {
376377
await checkAndDownloadGameData(game.activeDataId);
377378
const activeData = await fpDatabase.findGameDataById(game.activeDataId);
378-
if (activeData && activeData.path && !skipDataPack) {
379+
if (activeData && activeData.presentOnDisk && !skipDataPack) {
379380
// Extract data pack into curation folder
380-
const dataPath = path.join(state.config.flashpointPath, state.preferences.dataPacksFolderPath, activeData.path);
381+
const dataPath = getGameDataFilename(activeData);
381382
await extractFullPromise([dataPath, curPath, { $bin: state.sevenZipPath }]);
382383
// Clean up content.json file from extracted data pack
383384
await fs.unlink(path.join(curPath, 'content.json'))

src/back/download.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ export async function importGameDataSkipHash(gameId: string, filePath: string, d
4848
const newPath = path.join(dataPacksFolderPath, newFilename);
4949
await fs.promises.copyFile(filePath, newPath);
5050
if (existingGameData) {
51-
existingGameData.path = newFilename;
5251
existingGameData.presentOnDisk = true;
5352
if (databaseQueue !== undefined) {
5453
return new Promise<GameData>((resolve, reject) => {

src/back/flashpoint/WebgameContentRunner.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ export function getApplicationPath(filePath: string, execMappings: ExecMapping[]
221221
}
222222

223223
function runGameService(state: BackState, launchInfo: LaunchInfo, id: string, name: string): ManagedChildProcess {
224-
console.log(launchInfo);
225224
const dirname = path.dirname(launchInfo.gamePath);
226225
// Keep file path relative to cwd
227226
const proc = runService(

src/back/importGame.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ function importGameData(gameId: string, filePath: string, dataPacksFolderPath: s
304304
if (existingGameData) {
305305
if (existingGameData.presentOnDisk === false) {
306306
// File wasn't on disk before but is now, update GameData info
307-
existingGameData.path = newFilename;
308307
existingGameData.presentOnDisk = true;
309308
fpDatabase.saveGameData(existingGameData)
310309
.then(async (gameData) => {

src/back/responses.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,6 @@ export function registerRequestCallbacks(state: BackState, init: () => Promise<v
10381038
await onWillUninstallGameData.fire(gameData);
10391039
const gameDataPath = path.join(state.config.flashpointPath, state.preferences.dataPacksFolderPath, gameDataFilename);
10401040
await fs.promises.unlink(gameDataPath);
1041-
gameData.path = undefined;
10421041
gameData.presentOnDisk = false;
10431042
onDidUninstallGameData.fire(gameData);
10441043
}
@@ -1083,7 +1082,6 @@ export function registerRequestCallbacks(state: BackState, init: () => Promise<v
10831082
}
10841083
});
10851084
console.log('deleted file on disk');
1086-
gameData.path = undefined;
10871085
gameData.presentOnDisk = false;
10881086
await fpDatabase.saveGameData(gameData);
10891087
onDidUninstallGameData.fire(gameData);
@@ -2758,7 +2756,6 @@ async function getGame(state: BackState, id: string) {
27582756
if (game.gameData) {
27592757
for (const gameData of game.gameData) {
27602758
const gameDataFilename = getGameDataFilename(gameData);
2761-
gameData.path = gameDataFilename;
27622759
try {
27632760
await fs.promises.access(path.join(state.config.flashpointPath, state.preferences.dataPacksFolderPath, gameDataFilename), fs.constants.F_OK);
27642761
if (!gameData.presentOnDisk) {
@@ -2777,4 +2774,3 @@ async function getGame(state: BackState, id: string) {
27772774
}
27782775
return game;
27792776
}
2780-

src/renderer/components/GameDataBrowser.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { LangContext } from '@renderer/util/lang';
22
import { BackIn } from '@shared/back/types';
33
import { memoizeOne } from '@shared/memoize';
4+
import { Game, GameData } from 'flashpoint-launcher';
45
import * as React from 'react';
56
import { FloatingContainer } from './FloatingContainer';
67
import { GameDataInfo } from './GameDataInfo';
78
import { OpenIcon } from './OpenIcon';
89
import { SimpleButton } from './SimpleButton';
9-
import { Game, GameData } from 'flashpoint-launcher';
1010

1111
export type GameDataBrowserState = {
1212
error?: string;
@@ -147,7 +147,6 @@ export class GameDataBrowser extends React.Component<GameDataBrowserProps, GameD
147147
.then(() => {
148148
const newDatas = [...this.state.gameData];
149149
newDatas[index].presentOnDisk = false;
150-
newDatas[index].path = undefined;
151150
this.setState({ gameData: newDatas });
152151
this.props.onForceUpdateGameData();
153152
})

src/renderer/components/GameDataInfo.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ export function GameDataInfo(props: GameDataInfoProps) {
100100
props.onUpdateLaunchCommand(event.target.value);
101101
}} />
102102
</CurateBoxRow>
103-
<CurateBoxRow title='Path'>
104-
{data.path || <i>Not Downloaded</i>}
105-
</CurateBoxRow>
106103
<CurateBoxRow title='Size'>
107104
{`${sizeToString(data.size)} (${data.size} bytes)`}
108105
</CurateBoxRow>

0 commit comments

Comments
 (0)