From d8254353b5b3df45a8a7aa4c84fcecab6173df88 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Tue, 22 Oct 2024 23:24:22 -0300 Subject: [PATCH] feat: refactor achievements file --- .../achievement-watcher-manager.ts | 12 +++- .../achievements/find-achivement-files.ts | 66 ++++++++++++------- .../achievements/parse-achievement-file.ts | 5 ++ 3 files changed, 56 insertions(+), 27 deletions(-) diff --git a/src/main/services/achievements/achievement-watcher-manager.ts b/src/main/services/achievements/achievement-watcher-manager.ts index 2345e3be..40f3024c 100644 --- a/src/main/services/achievements/achievement-watcher-manager.ts +++ b/src/main/services/achievements/achievement-watcher-manager.ts @@ -242,10 +242,18 @@ export class AchievementWatcherManager { ? await this.preSearchAchievementsWindows() : await this.preSearchAchievementsWithWine(); + const totalNewGamesWithAchievements = newAchievementsCount.filter( + (achievements) => achievements + ).length; + const totalNewAchievements = newAchievementsCount.reduce( + (acc, val) => acc + val, + 0 + ); + WindowManager.notificationWindow?.webContents.send( "on-combined-achievements-unlocked", - newAchievementsCount.filter((achievements) => achievements).length, - newAchievementsCount.reduce((acc, val) => acc + val, 0) + totalNewGamesWithAchievements, + totalNewAchievements ); this.hasFinishedMergingWithRemote = true; diff --git a/src/main/services/achievements/find-achivement-files.ts b/src/main/services/achievements/find-achivement-files.ts index 85c5b767..4fc6a4cd 100644 --- a/src/main/services/achievements/find-achivement-files.ts +++ b/src/main/services/achievements/find-achivement-files.ts @@ -79,11 +79,11 @@ const getPathFromCracker = (cracker: Cracker) => { return [ { folderPath: path.join(publicDocuments, "Steam", "CODEX"), - fileLocation: ["achievements.ini"], + fileLocation: ["", "achievements.ini"], }, { folderPath: path.join(appData, "Steam", "CODEX"), - fileLocation: ["achievements.ini"], + fileLocation: ["", "achievements.ini"], }, ]; } @@ -92,7 +92,7 @@ const getPathFromCracker = (cracker: Cracker) => { return [ { folderPath: path.join(publicDocuments, "Steam", "RUNE"), - fileLocation: ["achievements.ini"], + fileLocation: ["", "achievements.ini"], }, ]; } @@ -101,11 +101,11 @@ const getPathFromCracker = (cracker: Cracker) => { return [ { folderPath: path.join(publicDocuments, "OnlineFix"), - fileLocation: ["Stats", "Achievements.ini"], + fileLocation: ["", "Stats", "Achievements.ini"], }, { folderPath: path.join(publicDocuments, "OnlineFix"), - fileLocation: ["Achievements.ini"], + fileLocation: ["", "Achievements.ini"], }, ]; } @@ -114,11 +114,11 @@ const getPathFromCracker = (cracker: Cracker) => { return [ { folderPath: path.join(appData, "Goldberg SteamEmu Saves"), - fileLocation: ["achievements.json"], + fileLocation: ["", "achievements.json"], }, { folderPath: path.join(appData, "GSE Saves"), - fileLocation: ["achievements.json"], + fileLocation: ["", "achievements.json"], }, ]; } @@ -131,19 +131,19 @@ const getPathFromCracker = (cracker: Cracker) => { return [ { folderPath: path.join(programData, "RLD!"), - fileLocation: ["achievements.ini"], + fileLocation: ["", "achievements.ini"], }, { folderPath: path.join(programData, "Steam", "Player"), - fileLocation: ["stats", "achievements.ini"], + fileLocation: ["", "stats", "achievements.ini"], }, { folderPath: path.join(programData, "Steam", "RLD!"), - fileLocation: ["stats", "achievements.ini"], + fileLocation: ["", "stats", "achievements.ini"], }, { folderPath: path.join(programData, "Steam", "dodi"), - fileLocation: ["stats", "achievements.ini"], + fileLocation: ["", "stats", "achievements.ini"], }, ]; } @@ -152,11 +152,16 @@ const getPathFromCracker = (cracker: Cracker) => { return [ { folderPath: path.join(appData, "EMPRESS", "remote"), - fileLocation: ["achievements.json"], + fileLocation: ["", "achievements.json"], }, { - folderPath: path.join(publicDocuments, "EMPRESS", "remote"), - fileLocation: ["achievements.json"], + folderPath: path.join(publicDocuments, "EMPRESS"), + fileLocation: [ + "", + "remote", + "", + "achievements.json", + ], }, ]; } @@ -165,15 +170,15 @@ const getPathFromCracker = (cracker: Cracker) => { return [ { folderPath: path.join(documents, "SKIDROW"), - fileLocation: ["SteamEmu", "UserStats", "achiev.ini"], + fileLocation: ["", "SteamEmu", "UserStats", "achiev.ini"], }, { folderPath: path.join(documents, "Player"), - fileLocation: ["SteamEmu", "UserStats", "achiev.ini"], + fileLocation: ["", "SteamEmu", "UserStats", "achiev.ini"], }, { folderPath: path.join(localAppData, "SKIDROW"), - fileLocation: ["SteamEmu", "UserStats", "achiev.ini"], + fileLocation: ["", "SteamEmu", "UserStats", "achiev.ini"], }, ]; } @@ -182,7 +187,7 @@ const getPathFromCracker = (cracker: Cracker) => { return [ { folderPath: path.join(appData, "CreamAPI"), - fileLocation: ["stats", "CreamAPI.Achievements.cfg"], + fileLocation: ["", "stats", "CreamAPI.Achievements.cfg"], }, ]; } @@ -191,7 +196,7 @@ const getPathFromCracker = (cracker: Cracker) => { return [ { folderPath: path.join(appData, "SmartSteamEmu"), - fileLocation: ["User", "Achievements.ini"], + fileLocation: ["", "User", "Achievements.ini"], }, ]; } @@ -213,11 +218,11 @@ const getPathFromCracker = (cracker: Cracker) => { return [ { folderPath: path.join(appData, "RLE"), - fileLocation: ["achievements.ini"], + fileLocation: ["", "achievements.ini"], }, { folderPath: path.join(appData, "RLE"), - fileLocation: ["Achievements.ini"], + fileLocation: ["", "Achievements.ini"], }, ]; } @@ -226,7 +231,7 @@ const getPathFromCracker = (cracker: Cracker) => { return [ { folderPath: path.join(appData, ".1911"), - fileLocation: ["achievement"], + fileLocation: ["", "achievement"], }, ]; } @@ -253,8 +258,7 @@ export const findAchievementFiles = (game: Game) => { const filePath = path.join( game.winePrefixPath ?? "", folderPath, - objectId, - ...fileLocation + ...mapFileLocationWithObjectId(fileLocation, objectId) ); if (fs.existsSync(filePath)) { @@ -303,6 +307,15 @@ export const findAchievementFileInExecutableDirectory = ( ]; }; +const mapFileLocationWithObjectId = ( + fileLocation: string[], + objectId: string +) => { + return fileLocation.map((location) => + location.replace("", objectId) + ); +}; + export const findAllAchievementFiles = () => { const gameAchievementFiles = new Map(); @@ -315,7 +328,10 @@ export const findAllAchievementFiles = () => { const objectIds = fs.readdirSync(folderPath); for (const objectId of objectIds) { - const filePath = path.join(folderPath, objectId, ...fileLocation); + const filePath = path.join( + folderPath, + ...mapFileLocationWithObjectId(fileLocation, objectId) + ); if (!fs.existsSync(filePath)) continue; diff --git a/src/main/services/achievements/parse-achievement-file.ts b/src/main/services/achievements/parse-achievement-file.ts index 38b388ca..f39ed45e 100644 --- a/src/main/services/achievements/parse-achievement-file.ts +++ b/src/main/services/achievements/parse-achievement-file.ts @@ -65,6 +65,11 @@ export const parseAchievementFile = ( return processCreamAPI(parsed); } + if (type === Cracker.empress) { + const parsed = jsonParse(filePath); + return processGoldberg(parsed); + } + if (type === Cracker.razor1911) { return processRazor1911(filePath); }