Skip to content

Commit

Permalink
feat: Game Redirect Sync
Browse files Browse the repository at this point in the history
  • Loading branch information
colin969 committed Mar 6, 2024
1 parent 6624bef commit 0c582ef
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 29 deletions.
2 changes: 1 addition & 1 deletion extensions/core-curation
Submodule core-curation updated 1 files
+12,341 −12,341 package-lock.json
2 changes: 2 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
"enablePlaytimeTrackingExtremeDesc": "Allow tracking last played date, total playtime and play count for Extreme games.",
"enableTagFilterIndex": "Tag Filter Index",
"enableTagFilterIndexDesc": "Enable use of the Tag Filter Index to speed up lots of queries",
"enableVerboseLogging": "Verbose Logging",
"enableVerboseLoggingDesc": "Enables verbose logging for external libraries.",
"clearPlaytimeTracking": "Clear Playtime Data",
"clearPlaytimeTrackingDesc": "Clears last played, total playtime and play count for every game. Irreversible.",
"clearData": "Clear Data",
Expand Down
48 changes: 24 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@fortawesome/fontawesome-svg-core": "1.2.36",
"@fortawesome/free-solid-svg-icons": "5.15.4",
"@fortawesome/react-fontawesome": "0.1.18",
"@fparchive/flashpoint-archive": "0.5.0",
"@fparchive/flashpoint-archive": "0.6.2",
"@types/react-virtualized": "^9.21.21",
"axios": "1.3.4",
"connected-react-router": "6.9.2",
Expand Down
6 changes: 5 additions & 1 deletion src/back/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
CURATIONS_FOLDER_WORKING, CURATION_META_FILENAMES
} from '@shared/constants';
import axios from 'axios';
import { FlashpointArchive, parseUserSearchInput } from '@fparchive/flashpoint-archive';
import { FlashpointArchive, enableDebug, parseUserSearchInput } from '@fparchive/flashpoint-archive';
import { Game, GameData, Playlist, PlaylistGame } from 'flashpoint-launcher';
import { Tail } from 'tail';
import { ConfigFile } from './ConfigFile';
Expand Down Expand Up @@ -686,6 +686,10 @@ async function initialize() {
// Non-fatal, don't quit.
}

if (state.preferences.enableVerboseLogging) {
enableDebug();
}

const databasePath = path.resolve(state.config.flashpointPath, 'Data', 'flashpoint.sqlite');
try {
fpDatabase.loadDatabase(databasePath);
Expand Down
4 changes: 3 additions & 1 deletion src/back/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import { fpDatabase, loadCurationArchive, onDidUninstallGameData, onWillUninstal
import { importGames, importPlatforms, importTagCategories, importTags } from './metadataImport';
import { addPlaylistGame, deletePlaylist, deletePlaylistGame, duplicatePlaylist, filterPlaylists, getPlaylistGame, importPlaylist, savePlaylistGame, updatePlaylist } from './playlist';
import { copyFolder, genContentTree } from './rust';
import { getMetaUpdateInfo, syncGames, syncPlatforms, syncTags } from './sync';
import { getMetaUpdateInfo, syncGames, syncPlatforms, syncRedirects, syncTags } from './sync';
import { BackState, MetadataRaw, TagsFile } from './types';
import { pathToBluezip } from './util/Bluezip';
import { pathTo7zBack } from './util/SevenZip';
Expand Down Expand Up @@ -374,6 +374,7 @@ export function registerRequestCallbacks(state: BackState, init: () => Promise<v
const progress = chunk / chunks;
state.socketServer.broadcast(BackOut.UPDATE_DIALOG_FIELD_VALUE, dialogId, 'progress', progress * 100);
});
await syncRedirects(source);
if (sourceIdx !== -1) {
state.preferences.gameMetadataSources[sourceIdx].games.latestUpdateTime = lastDate.toISOString();
state.preferences.gameMetadataSources[sourceIdx].games.actualUpdateTime = newDate.toISOString();
Expand Down Expand Up @@ -1326,6 +1327,7 @@ export function registerRequestCallbacks(state: BackState, init: () => Promise<v
// --- GAMES ----

// Collect games

const search = parseUserSearchInput('');
search.limit = 5000;
let games = await fpDatabase.searchGames(search);
Expand Down
17 changes: 16 additions & 1 deletion src/back/sync.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RemoteCategory, RemoteDeletedGamesRes, RemoteGamesRes, RemotePlatform, RemoteTag } from '@fparchive/flashpoint-archive';
import { GameRedirect, RemoteCategory, RemoteDeletedGamesRes, RemoteGamesRes, RemotePlatform, RemoteTag } from '@fparchive/flashpoint-archive';
import axios from 'axios';
import { GameMetadataSource } from 'flashpoint-launcher';
import { camelCase, transform } from 'lodash';
Expand Down Expand Up @@ -132,6 +132,21 @@ export async function syncGames(source: GameMetadataSource, dataPacksFolder: str
return new Date(lastDate);
}

export async function syncRedirects(source: GameMetadataSource): Promise<void> {
const gamesUrl = `${source.baseUrl}/api/game-redirects`;
const res = await axios.get(gamesUrl)
.catch((err) => {
throw 'Failed to search game redirects';
});

const data = res.data.map((d: any) => { return {
sourceId: d.source_id,
destId: d.id
};}) as any as Array<GameRedirect>;
console.log('applying redirects');
await fpDatabase.updateApplyRedirects(data);
}

export async function getMetaUpdateInfo(source: GameMetadataSource, accurate?: boolean, fromScratch?: boolean): Promise<number> {
// Add 1 second to update time to prevent rounding down errors
const d = new Date(source.games.latestUpdateTime);
Expand Down
10 changes: 10 additions & 0 deletions src/renderer/components/pages/ConfigPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@ export class ConfigPage extends React.Component<ConfigPageProps, ConfigPageState
icon='plus' />
</div>
</ConfigBox>
{/* Verbose Logging */}
<ConfigBoxCheckbox
title={strings.enableVerboseLogging}
description={strings.enableVerboseLoggingDesc}
checked={this.props.preferencesData.enableVerboseLogging}
onToggle={this.onVerboseLoggingToggle} />
</div>
</div>

Expand Down Expand Up @@ -806,6 +812,10 @@ export class ConfigPage extends React.Component<ConfigPageProps, ConfigPageState
updatePreferencesData({ enableTagFilterIndex: isChecked });
};

onVerboseLoggingToggle = (isChecked: boolean): void => {
updatePreferencesData({ enableVerboseLogging: isChecked });
};

onSearchLimitChange = (event: React.ChangeEvent<HTMLSelectElement>): void => {
updatePreferencesData({ searchLimit: num(event.target.value) });
};
Expand Down
2 changes: 2 additions & 0 deletions src/shared/lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const langTemplate = {
'enablePlaytimeTrackingDesc',
'enableTagFilterIndex',
'enableTagFilterIndexDesc',
'enableVerboseLogging',
'enableVerboseLoggingDesc',
'enablePlaytimeTrackingExtreme',
'enablePlaytimeTrackingExtremeDesc',
'clearPlaytimeTracking',
Expand Down
2 changes: 2 additions & 0 deletions src/shared/preferences/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export const defaultPreferencesData: Readonly<AppPreferencesData> = Object.freez
enablePlaytimeTracking: true,
enablePlaytimeTrackingExtreme: true,
enableTagFilterIndex: true,
enableVerboseLogging: false,
});

/**
Expand Down Expand Up @@ -221,6 +222,7 @@ export function overwritePreferenceData(
parser.prop('enablePlaytimeTracking', v => source.enablePlaytimeTracking = !!v, true);
parser.prop('enablePlaytimeTrackingExtreme', v => source.enablePlaytimeTrackingExtreme = !!v, true);
parser.prop('enableTagFilterIndex', v => source.enableTagFilterIndex = !!v, true);
parser.prop('enableVerboseLogging', v => source.enableVerboseLogging = !!v, true);

// Migrate onDemandBaseUrl from the older FP url
if (source.onDemandBaseUrl == 'https://infinity.unstable.life/Flashpoint/Data/Images/') {
Expand Down
1 change: 1 addition & 0 deletions tests/unit/back/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ describe('Configuration Files', () => {
'enablePlaytimeTracking': false,
'enablePlaytimeTrackingExtreme': false,
'enableTagFilterIndex': false,
'enableVerboseLogging': true,
};
const newData = deepCopy(defaultPreferencesData);
overwritePreferenceData(newData, data);
Expand Down
2 changes: 2 additions & 0 deletions typings/flashpoint-launcher.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,8 @@ declare module 'flashpoint-launcher' {
enablePlaytimeTrackingExtreme: boolean;
/** Enable tag filter indexing */
enableTagFilterIndex: boolean;
/** Use verbose logging for the rust library */
enableVerboseLogging: boolean;
};

type GameDataSource = {
Expand Down

0 comments on commit 0c582ef

Please sign in to comment.