diff --git a/src/main/services/achievements/achievement-watcher-manager.ts b/src/main/services/achievements/achievement-watcher-manager.ts index b7c71f86..6a1eb11c 100644 --- a/src/main/services/achievements/achievement-watcher-manager.ts +++ b/src/main/services/achievements/achievement-watcher-manager.ts @@ -236,24 +236,28 @@ export class AchievementWatcherManager { }; public static preSearchAchievements = async () => { - const newAchievementsCount = - process.platform === "win32" - ? await this.preSearchAchievementsWindows() - : await this.preSearchAchievementsWithWine(); + try { + const newAchievementsCount = + process.platform === "win32" + ? await this.preSearchAchievementsWindows() + : await this.preSearchAchievementsWithWine(); - const totalNewGamesWithAchievements = newAchievementsCount.filter( - (achievements) => achievements - ).length; - const totalNewAchievements = newAchievementsCount.reduce( - (acc, val) => acc + val, - 0 - ); - - if (totalNewAchievements > 0) { - publishCombinedNewAchievementNotification( - totalNewAchievements, - totalNewGamesWithAchievements + const totalNewGamesWithAchievements = newAchievementsCount.filter( + (achievements) => achievements + ).length; + const totalNewAchievements = newAchievementsCount.reduce( + (acc, val) => acc + val, + 0 ); + + if (totalNewAchievements > 0) { + publishCombinedNewAchievementNotification( + totalNewAchievements, + totalNewGamesWithAchievements + ); + } + } catch (err) { + achievementsLogger.error("Error on preSearchAchievements", err); } this.hasFinishedMergingWithRemote = true; diff --git a/src/main/services/achievements/parse-achievement-file.ts b/src/main/services/achievements/parse-achievement-file.ts index 3aecadd6..18f0c25b 100644 --- a/src/main/services/achievements/parse-achievement-file.ts +++ b/src/main/services/achievements/parse-achievement-file.ts @@ -9,144 +9,134 @@ export const parseAchievementFile = ( ): UnlockedAchievement[] => { if (!existsSync(filePath)) return []; - if (type == Cracker.codex) { - const parsed = iniParse(filePath); - return processDefault(parsed); + try { + if (type == Cracker.codex) { + const parsed = iniParse(filePath); + return processDefault(parsed); + } + + if (type == Cracker.rune) { + const parsed = iniParse(filePath); + return processDefault(parsed); + } + + if (type === Cracker.onlineFix) { + const parsed = iniParse(filePath); + return processOnlineFix(parsed); + } + + if (type === Cracker.goldberg) { + const parsed = jsonParse(filePath); + return processGoldberg(parsed); + } + + if (type == Cracker.userstats) { + const parsed = iniParse(filePath); + return processUserStats(parsed); + } + + if (type == Cracker.rld) { + const parsed = iniParse(filePath); + return processRld(parsed); + } + + if (type === Cracker.skidrow) { + const parsed = iniParse(filePath); + return processSkidrow(parsed); + } + + if (type === Cracker._3dm) { + const parsed = iniParse(filePath); + return process3DM(parsed); + } + + if (type === Cracker.flt) { + const achievements = readdirSync(filePath); + + return achievements.map((achievement) => { + return { + name: achievement, + unlockTime: Date.now(), + }; + }); + } + + if (type === Cracker.creamAPI) { + const parsed = iniParse(filePath); + return processCreamAPI(parsed); + } + + if (type === Cracker.empress) { + const parsed = jsonParse(filePath); + return processGoldberg(parsed); + } + + if (type === Cracker.razor1911) { + return processRazor1911(filePath); + } + + achievementsLogger.log( + `Unprocessed ${type} achievements found on ${filePath}` + ); + return []; + } catch (err) { + achievementsLogger.error(`Error parsing ${type} - ${filePath}`, err); + return []; } - - if (type == Cracker.rune) { - const parsed = iniParse(filePath); - return processDefault(parsed); - } - - if (type === Cracker.onlineFix) { - const parsed = iniParse(filePath); - return processOnlineFix(parsed); - } - - if (type === Cracker.goldberg) { - const parsed = jsonParse(filePath); - return processGoldberg(parsed); - } - - if (type == Cracker.userstats) { - const parsed = iniParse(filePath); - return processUserStats(parsed); - } - - if (type == Cracker.rld) { - const parsed = iniParse(filePath); - return processRld(parsed); - } - - if (type === Cracker.skidrow) { - const parsed = iniParse(filePath); - return processSkidrow(parsed); - } - - if (type === Cracker._3dm) { - const parsed = iniParse(filePath); - return process3DM(parsed); - } - - if (type === Cracker.flt) { - const achievements = readdirSync(filePath); - - return achievements.map((achievement) => { - return { - name: achievement, - unlockTime: Date.now(), - }; - }); - } - - if (type === Cracker.creamAPI) { - const parsed = iniParse(filePath); - return processCreamAPI(parsed); - } - - if (type === Cracker.empress) { - const parsed = jsonParse(filePath); - return processGoldberg(parsed); - } - - if (type === Cracker.razor1911) { - return processRazor1911(filePath); - } - - achievementsLogger.log( - `Unprocessed ${type} achievements found on ${filePath}` - ); - return []; }; const iniParse = (filePath: string) => { - try { - const fileContent = readFileSync(filePath, "utf-8"); + const fileContent = readFileSync(filePath, "utf-8"); - const lines = - fileContent.charCodeAt(0) === 0xfeff - ? fileContent.slice(1).split(/[\r\n]+/) - : fileContent.split(/[\r\n]+/); + const lines = + fileContent.charCodeAt(0) === 0xfeff + ? fileContent.slice(1).split(/[\r\n]+/) + : fileContent.split(/[\r\n]+/); - let objectName = ""; - const object: Record> = {}; + let objectName = ""; + const object: Record> = {}; - for (const line of lines) { - if (line.startsWith("###") || !line.length) continue; + for (const line of lines) { + if (line.startsWith("###") || !line.length) continue; - if (line.startsWith("[") && line.endsWith("]")) { - objectName = line.slice(1, -1); - object[objectName] = {}; - } else { - const [name, ...value] = line.split("="); - object[objectName][name.trim()] = value.join("=").trim(); - } + if (line.startsWith("[") && line.endsWith("]")) { + objectName = line.slice(1, -1); + object[objectName] = {}; + } else { + const [name, ...value] = line.split("="); + object[objectName][name.trim()] = value.join("=").trim(); } - - return object; - } catch (err) { - achievementsLogger.error(`Error parsing ${filePath}`, err); - return {}; } + + return object; }; const jsonParse = (filePath: string) => { - try { - return JSON.parse(readFileSync(filePath, "utf-8")); - } catch (err) { - achievementsLogger.error(`Error parsing ${filePath}`, err); - return {}; - } + return JSON.parse(readFileSync(filePath, "utf-8")); }; const processRazor1911 = (filePath: string): UnlockedAchievement[] => { - try { - const fileContent = readFileSync(filePath, "utf-8"); + const fileContent = readFileSync(filePath, "utf-8"); - const lines = - fileContent.charCodeAt(0) === 0xfeff - ? fileContent.slice(1).split(/[\r\n]+/) - : fileContent.split(/[\r\n]+/); + const lines = + fileContent.charCodeAt(0) === 0xfeff + ? fileContent.slice(1).split(/[\r\n]+/) + : fileContent.split(/[\r\n]+/); - const achievements: UnlockedAchievement[] = []; - for (const line of lines) { - if (!line.length) continue; + const achievements: UnlockedAchievement[] = []; + for (const line of lines) { + if (!line.length) continue; - const [name, unlocked, unlockTime] = line.split(" "); - if (unlocked === "1") { - achievements.push({ - name, - unlockTime: Number(unlockTime) * 1000, - }); - } + const [name, unlocked, unlockTime] = line.split(" "); + if (unlocked === "1") { + achievements.push({ + name, + unlockTime: Number(unlockTime) * 1000, + }); } - - return achievements; - } catch (err) { - achievementsLogger.error(`Error processing ${filePath}`, err); - return []; } + + return achievements; }; const processOnlineFix = (unlockedAchievements: any): UnlockedAchievement[] => {