Skip to content

Commit

Permalink
fix: Removed datakeeper PlayerData-Cache to prevent crashing after sy…
Browse files Browse the repository at this point in the history
…nchronization
  • Loading branch information
PKMNPlatin committed Jan 27, 2024
1 parent eac9e41 commit 1231eed
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const PLAYERDATA_FILE = 'PlayerData.dat';
export const PLAYERDATA_PATH_QUEST = `/sdcard/Android/data/com.beatgames.beatsaber/files/${PLAYERDATA_FILE}`;
export const TEMP_PLAYERDATA_PATH_QUEST = `/sdcard/ModData/com.beatgames.beatsaber/Mods/datakeeper/${PLAYERDATA_FILE}`;
// Old path for playlists TODO: scan in both paths, IMPORTANT: old version needs .bplist instead of _BMBF.json
// export const PLAYLISTS_PATH_QUEST = '/sdcard/BMBFData/Playlists/';
export const PLAYLISTS_PATH_QUEST =
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ async function syncFavorites(client: DeviceClient) {
} else {
// remove favorites from quest
questLocalPlayer.favoritesLevelIds = onlyOnQuestFavorites;
await updateQuestPlayerData(sync, questPlayerData);
await updateQuestPlayerData(sync, questPlayerData, client);
}
}

Expand Down Expand Up @@ -223,7 +223,7 @@ async function syncFavorites(client: DeviceClient) {
if (action === 'quest') {
// add favorites to quest
questLocalPlayer.favoritesLevelIds = [...questFavorites, ...onlyOnPcFavorites];
await updateQuestPlayerData(sync, questPlayerData);
await updateQuestPlayerData(sync, questPlayerData, client);
} else {
// remove favorites from pc
pcLocalPlayer.favoritesLevelIds = onlyOnPcFavorites;
Expand Down
7 changes: 4 additions & 3 deletions src/sync/playerData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Sync } from '@u4/adbkit';
import { DeviceClient, Sync } from '@u4/adbkit';
import { LocalPlayer, PlayerData } from '../types/playerData';
import { PLAYERDATA_PATH_QUEST } from '../constants';
import { PLAYERDATA_PATH_QUEST, SONGS_PATH_QUEST, TEMP_PLAYERDATA_PATH_QUEST } from '../constants';

Check warning on line 3 in src/sync/playerData.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest, 20)

'SONGS_PATH_QUEST' is defined but never used
import fs from 'fs';
import chalk from 'chalk';
import { streamToString, stringToStream } from '../utils/streams';
Expand All @@ -21,9 +21,10 @@ export async function getQuestPlayerData(sync: Sync): Promise<PlayerData> {
return JSON.parse(data.trim());
}

export async function updateQuestPlayerData(sync: Sync, playerData: PlayerData) {
export async function updateQuestPlayerData(sync: Sync, playerData: PlayerData, client: DeviceClient) {
const data = stringToStream(JSON.stringify(playerData));
await sync.push(data, PLAYERDATA_PATH_QUEST);
await client.exec(`rm -rf '${TEMP_PLAYERDATA_PATH_QUEST}'`);
}

export function getLocalPlayer(playerData: PlayerData): LocalPlayer {
Expand Down

0 comments on commit 1231eed

Please sign in to comment.