From 1231eed5843ff1dd9a2d633c8721d2fc55f5f372 Mon Sep 17 00:00:00 2001 From: PKMNPlatin Date: Sat, 27 Jan 2024 02:08:50 +0100 Subject: [PATCH] fix: Removed datakeeper PlayerData-Cache to prevent crashing after synchronization --- src/constants.ts | 1 + src/index.ts | 4 ++-- src/sync/playerData.ts | 7 ++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 194e2ca..59c8b8f 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -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 = diff --git a/src/index.ts b/src/index.ts index 2495748..d0f5200 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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); } } @@ -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; diff --git a/src/sync/playerData.ts b/src/sync/playerData.ts index 611c959..334600a 100644 --- a/src/sync/playerData.ts +++ b/src/sync/playerData.ts @@ -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'; import fs from 'fs'; import chalk from 'chalk'; import { streamToString, stringToStream } from '../utils/streams'; @@ -21,9 +21,10 @@ export async function getQuestPlayerData(sync: Sync): Promise { 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 {